J-Flash SPI

From SEGGER Wiki
Revision as of 09:32, 27 February 2023 by JanB (talk | contribs) (Command Line Interface)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
J-Flash SPI (GUI) main window

This article describes J-Flash SPI and J-Flash SPI CL (separate software executables), which allow direct programming of SPI flashes, without any additional hardware. Both, J-Flash SPI and J-Flash SPI CL are part of the J-Link Software and Documentation Pack available on the SEGGER Homepage.

J-Flash SPI and J-Flash SPI CL are available cross platform (Windows, Linux and macOS).

Contents

Note:
This article assumes that you already possess working knowledge of the J-Link device.

Introduction

In this section, J-Flash SPI and J-Flash SPI CL are introduced.

What is J-Flash SPI?

J-Flash SPI is a stand-alone flash programming software for PCs running Windows, Linux or macOS. It allows direct programming of SPI flashes, without any additional hardware. J-Flash SPI has an intuitive user interface and makes programming flash devices convenient. It requires a J-Link or Flasher to interface to the hardware. J-Flash SPI is able to program all kinds of SPI flashes, even if the CPU connected to them, is not supported by J-Link / Flasher. This is because J-Flash SPI communicates directly with the SPI flash, bypassing all other components of the hardware.

J-Flash SPI CL (Windows, Linux, macOS)

J-Flash SPI CL is a commandline-only version of the J-Flash SPI programming tool. Except from the missing GUI, J-Flash SPI CL is identical to the GUI version. The commands, used to configure / control J-Flash SPI CL, are exactly the same as for the command line interface of the J-Flash SPI GUI version. For further information, please refer to Command Line Interface.

Features

  • Directly communicates with the SPI flash via SPI protocol, no MCU in between required.
  • Programming of all kinds of SPI flashes is supported
  • Can also program SPI flashes that are connected to CPUs that are not supported by J-Link.
  • Supports any kind of custom command sequences (e.g. write protection register)
  • Verbose logging of all communication.
  • Intuitive user interface.
  • Data files supported:
    • .hex
    • .mot
    • .srec
    • .bin

Requirements

This section describes the requirements for Host and Target side, using J-Flash SPI (CL).

Host

J-Flash SPI requires a PC running one of the supported operating system with a free USB port dedicated to a J-Link. A network connection is required only if you want to use J-Flash SPI together with J-Link Remote Server.

Target

The flash device must be an SPI flash that supports standard SPI protocols.

Licensing

For using J-Flash SPI (CL), a J-Flash license is required. The following SEGGER emulators is come with this license:

  • J-Link PLUS or higher
  • Flasher ARM/PRO
  • J-Trace PRO (Cortex/Cortex-M)

No additional license is required / available.

Getting Started

This section provides an overview of the included sample projects and describes the menu structure of J-Flash SPI in detail.

Setup

Refer to the J-Link User Guide

What is included?

The following table shows the contents of all subdirectories of the J-Link Software and Documentation Pack with regard to J-Flash SPI:

Directory Contents
. The J-Flash SPI application. Please refer to the J-Link User Guide for more information about the other J-Link related tools.
.\Doc Contains the J-Flash SPI documentation and the other J-Link related manuals.
.\Samples\JFlashSPI\ProjectFiles Contains sample projects for J-Flash SPI.

Using J-Flash SPI for the first time

Start J-Flash SPI. The main window will appear, which contains a log window at the bottom and the Project window of a default project on the left. The application log will initially display:

  • The version and time of compilation for the application.
  • The version and time of compilation for the J-Link DLL.
  • The location of the default project.

The Project window contains an overview of the current project settings (initially, a default project is opened).

Menu structure

The main window of J-Flash SPI contains seven drop-down menus (File, Edit, View, Target, Options, Window, Help). Any option within these drop-down menus that is followed by a three period ellipsis (...), is an option that requires more information before proceeding.

File menu elements

Command Description
Open data file... Opens a data file that may be used to flash the target device. The data file must be an Intel HEX file, a Motorola S file, or a Binary file (.hex, .mot, .srec, or .bin).
Merge data file Merges two data files (.hex, .mot, .srec, .bin). All gaps will be filled with FF.

Find below a short example of merging two data files named, File0.bin and File1.bin into File3.bin.
File0.bin -> Addr 0x0200 - 0x02FF
File1.bin -> Addr 0x1000 - 0x13FF
Merge File0.bin & File1.bin
0x0200 - 0x02FF Data of File0.bin
0x0300 - 0x0FFF gap (will be filled with 0xFF if image is saved as *.bin file)
0x1000 - 0x13FF Data of File1.bin
Can be saved in new data file (File3.bin).

Save data file Saves the data file that currently has focus.
Save data file as... Saves the data file that currently has focus using the name and location given.
New Project Creates a new project using the default settings.
Open Project... Opens a project file. Note that only one project file may be open at a time. Opening a project will close any other project currently open.
Save Project Saves a project file.
Save Project as... Saves a project file using the name and location given.
Close Project Closes a project file.
Recent Files > Contains a list of the most recently open data files.
Recent Projects > Contains a list of the most recently open project files.
Exit Exits Exits the application.

Edit menu elements

Command Description
Relocate... Relocates the start of the data file to the supplied hex offset from the current start location.
Delete range... Deletes a range of values from the data file, starting and ending at given addresses.
The End address must be greater than the Start address otherwise nothing will be done.
Eliminate blank areas... Eliminates blank regions within the data file.

View menu elements

Command Description
Show log Opens and/or sets the focus to the log window.
Show project information Opens and/or sets the focus to the project window.

Target menu elements

Command Description
Connect Creates a connection through the J-Link using the configuration options set in the Project settings... of the Options dropdown menu.
Disconnect Disconnects a current connection that has been made through the J-Link.
Test > Generate test data Generates data which can be used to test if the flash can be programmed correctly. The size of the generated data file can be defined.
Erase Sectors Erases all selected flash sectors.
Erase Chip Erases the entire chip.
Program Programs the chip using the currently active data file.
Program & Verify Programs the chip using the currently active data file and then verifies that it was written successfully.
Auto Performs a sequence of steps, which can be configured in the Production tab of the Project settings.

Additionally, the first step executed are the init steps and the last step executed are the exit steps,
which both can be configured in the MCU tab of the project settings.
The range of sectors to be erased can be configured through the Global settings dialog.

Verify Verifies the data found on the chip with the data file.
Read back > Entire chip Reads back the data found on the chip and creates a new data file to store this information.
Read back > Range Reads back the data found in a range specified by the user and creates a new data file to store this information.

Options menu elements

Command Description
Project settings... Location of the project settings that are displayed in the snapshot view found in the Project window of the J-Flash SPI application.

Furthermore various settings needed to locate the J-Link and pass specified commands needed for chip initialization.

Global settings... Settings that influence the general operation of J-Flash SPI.

Help menu elements

Command Description
J-Flash SPI Wiki Opens the J-Flash SPI wiki in a browser.
J-Link Wiki Opens the J-Link wiki in a browser.
Flasher Wiki Opens the Flasher wiki in a browser.
J-Flash User Guide Opens the J-Flash Manual (UM08003) document in the default .PDF application of the system.
J-Link User Guide Opens the J-Link Manual (UM08001) in the default .PDF application of the system.
Flasher User Guide Opens the Flasher Manual (UM08022) in the default .PDF application of the system.
Flasher ATE User Guide Opens the Flasher ATE Manual (UM08035) in the default .PDF application of the system.
Flasher Hub User Guide Opens the Flasher Hub Manual (UM08039) in the default .PDF application of the system.
Licenses... Shows a dialog with licensing information. The serial number of a connected J-Link may be read and licenses added or removed.
About... J-Flash and company information.

Settings

The following chapter provides an overview of the program settings. Both general and per project settings are considered.

Project Settings

Project settings are available from the Options menu in the main window or by using the ALT-F7 keyboard shortcut.

General Settings

J-Flash SPI Project settings dialog - General

This tab is used to choose the connection to J-Link. The J-Link can either be connected over USB or via TCP/IP to the host system. Refer to the UM08001 J-Link / J-Trace User Guide for more information regarding the operation of J-Link and J-Link Remote Server.

Setting Explanation
USB Connect to emulator with the specified device number (default: 0) via USB port.
USB SN Connect to emulator with the specified serial number (default: 0) via USB port.
TCP/IP Connect to emulator with the specified IP or to J-Link Remote Server with the specified host name via TCP/IP.


Setup Settings

J-Flash SPI Project settings dialog - Setup

This tab is used to configure the SPI interface settings like SPI communication speed and allows to add Init steps and Exit steps which can be used to execute custom command sequences.

Setting Explanation
Interface Speed Specifies the SPI communication speed J-Link uses to communicate with the SPI flash.


Init and Exit steps
J-Flash SPI Project settings dialog - Setup - Init steps

Can be used to add custom command sequences like for example write protection register. For further information regarding this, please refer to custom command sequences.

Flash Settings

J-Flash SPI Project settings dialog - Flash

This tab is used to select and configure the parameters of the SPI flash that J-Flash SPI will connect to. Examples for flash parameters are: Sector size (Smallest erasable unit), page size (smallest programmable unit), Flash ID, etc. There is also the option to try to auto-detect the connected flash device. The latter option will prompt J-Flash SPI to try to identify the flash by its Flash ID, looking up in an internal list of known flash devices. For a list of all out-of-the-box supported flashes, please refer to the SEGGER homepage. If you find that a SPI Flash you want support for is missing, please contact us via the SEGGER Support Ticket System.

Production Settings

J-Flash SPI Project settings dialog - Production
Enable target power

Enables 5V target power supply via pin 19 of the emulator. Can be used for targets which can be powered through the emulator for production. Delay before start defines the delay (in ms) after enabling the target power supply and before starting to communicate with the target.

Actions performed by "Auto"

The checked options will be performed when auto programming a target (Target -> Auto, shortcut: F7). The default behavior is Compare, Erase sectors if not blank, Program and Verify. Find below a table which describes the commands:

Command Description
Compare Performs a compare of the current flash content and the data to be programmed.

Sectors which do already match will be skipped by Erase / Program operation.
Note: If Erase is enabled and Erase type is "Chip", the compare will be skipped as after mass erase, the entire device is empty and needs to be re-programmed.

Erase Performs an erase depending on the settings, selected in the drop down box:
  • Sectors: Erases all sectors which are effected by the image to be programmed.
  • Sectors if not blank: Erases all sectors which are both, effected by the image to be programmed and not already blank.
  • Chip: Erase the entire chip independent of the content.
Program Programs the data file.
Verify Verifies the programmed data via read.


Performance tab

J-Flash SPI Project settings dialog - Performance

Currently, the only option in this tab is to skip blank data on program "F5". This way, blank data of the data to be flashed is skipped to increase the download speed. It is selected by default.

Global Settings

J-Flash SPI Project settings dialog - Global

Global settings are available from the Options menu in the main window.

Operation

The Operation options define the behavior of some actions such as "Auto" or "Program & Verify".

Auto mode affects
Setting Description
Affected sectors only (Default) Auto mode actions performed for affected sectors only
Selected sectors only Auto mode actions performed for selected sectors only
All sectors Auto mode actions performed for all selected sectors
Disconnect after each operation

If this option is checked, connection to the target will be closed at the end of each operation.

Perform blank check

If this option is checked, a blank check is performed before any program operation to examine if the affected flash sectors are completely empty. The user will be asked to erase the affected sectors if they are not empty.

Skip blank areas on read

If this option is checked, a blank check is performed before any read back operation to examine which flash areas need to be read back from target. This improves performance of read back operations since it minimizes the amount of data to be transferred via JTAG and USB.

Logging

The Logging options provide settings to customize the log output of J-Flash SPI.

General log level

This specifies the log level of J-Flash SPI. Increasing log levels result in a more verbose output in the log window.

Enable J-Link logfile

If this option is checked, you can specify a file name for the J-Link logfile. The J-Link logfile differs from the log window output of J-Flash SPI. It does not log J-Flash SPI operations performed. Instead of that, it logs the J-Link ARM DLL API functions called from within J-Flash SPI.

Projects

The "Projects" section provides settings for general project handling.

Save project file on close

If selected, the project file will automatically be saved on close.

Command Line Interface

This chapter describes the J-Flash SPI command line interface. The command line allows using J-Flash SPI in batch processing mode and other advanced uses.

Overview

J-Flash SPI Command line overview

In addition to a graphical user interface (GUI), J-Flash SPI supports a command line mode as well. This makes it possible to use J-Flash SPI for batch processing purposes. All important options accessible from the menus are available in command line mode as well. If you provide command line options, J-Flash SPI will still start its GUI, but processing will start immediately.

The screenshot on the right shows the command line help dialog, which is displayed if you start J-Flash SPI in a console window with JFlashSPI.exe -help or JFlashSPI.exe -?.

Command line options

This section lists and describes all available command line options. Some options accept additional parameters which are enclosed in angle brackets, e.g. <FILENAME>. If these parameters are optional they are enclosed in square brackets too, e.g. [<SADDR>]. Neither the angel nor the square brackets must be typed on the command line, they are used here only to denote (optional) parameters.
The command line options are evaluated in the order they are passed to J-Flash, so please ensure that a project and data file has already been opened when evaluating a command line option which requires this.
It is recommended to always use -open<FILENAME>[,<SADDR>] to make sure the right data file is opened.

All command line options return 0 if the processing was successful. A return value unequal 0 means that an error occurred.


Note: Entries marked with * only work for J-Flash SPI (GUI), entries marked with ** only work for J-Flash SPI CL

Option Description
-? Displays the help dialog.
-auto Executes the steps selected in Production Programming.
Default: Erases, programs and verifies target.
-connect Connects to the target.
-delrange<SADDR>,<EADDR> * Deletes data in the given range.
-disconnect Disconnects from the target.
-eliminate * Eliminates blank areas in data file.
-erasechip Erases the entire flash chip.
-erasesectors Erases selected sectors.
-exit * Exits J-Flash SPI.
-help Displays the help dialog.
-jflashlog<FILENAME> Sets a temporary J-Flash SPI logfile.
-jlinklog<FILENAME> Sets a temporary J-Link logfile.
-merge<FILENAME>[.bin,<ADDR>] * Saves the current data file into the specified file. <ADDR> parameter only applies if the data file is a *.bin- or *.c-file.
-min * Starts application minimized
-open<FILENAME>[,<SADDR>] Opens a data file. Please note that the <SADDR> parameter applies only if the data file is a *.bin file
-openprj<FILENAME> Opens an existing project file. This will also automatically open the data file that has been recently used with this project.
-program Programs the target.
-programverify Programs and verify the target.
-readchip Reads the entire flash chip.
-readrange<SADDR>,<EADDR> Reads specified range of target memory.
-relocate<Offset> * Relocate data by <Offsest>.
-save[<SADDR>,<EADDR>] Saves the current data file. Please note that the parameters <SADDR>,<EADDR> apply only if the data file is a *.bin file or *.c file.
-saveas<FILENAME>[,<SADDR>,<EADDR>] Saves the current data file into the specified file. Please note that the parameters <SADDR>,<EADDR> apply only if the data file is a *.bin file or *.c file.
-saveprj * Saves the current project.
-saveprjas<FILENAME> * Saves the current project in the specified file.
-verify Verifies the target memory.
-usb<SN> Overrides connection settings to USB S/N.
  • -ip<xxx.xxx.xxx.xxx>
  • -ip<HostName>
Overrides connection settings to IP.
-speed<SpeedInkHZ> ** Sets the connection speed.
-verbose<Level> ** Sets the log verbosity level to <Level>.
<Level>-range is from 0-9.

Batch processing

J-Flash SPI can be used for batch processing purposes. All important options are available in command line mode as well. When providing command line options, the application does not wait for manual user input. All command line operations will be performed in exactly the order they are passed. So, for example issuing a program command before a project has been opened will cause the program command to fail.

Examples

The example batchfile below will cause J-Flash SPI to perform the following operations:

  1. Open project C:\Projects\Default.jflash
  2. Open bin file C:\Data\data.bin and set start address to 0x100000
  3. Perform "Auto" operation in J-Flash (by default this performs erase, program, verify)
  4. Close J-Flash SPI

The return value will be checked and in case of an error message will be displayed. Adapt the example according to the requirements of your project.

@ECHO OFF

ECHO Open a project and data file, start auto processing and exit
JFlashSPI.exe -openprjC:\Projects\Default.jflash -openC:\Data\data.bin,0x100000 -auto -exit
IF ERRORLEVEL 1 goto ERROR

goto END

:ERROR
ECHO J-Flash SPI: Error!
pause

:END
Starting J-Flash minimized

Adapt this example call to start J-Flash SPI minimized:

start /min /wait "J-Flash" "JFlashSPI.exe" -openprjC:\Projects\Default.jflash \
-openC:\Data\data.bin,0x100000 -auto -exit


Note:
Every call of JFlashSPI.exe has to be completed with the -exit option, otherwise the execution of the batch file stops and the following commands will not be processed.

Programming multiple targets in parallel

J-Flash SPI Project settings dialog - General - SN selection

In order to program multiple targets in parallel using J-Flash SPI, the following is needed:
Multiple J-Flash SPI projects, each configured to connect to a specific J-Link / Flasher (emulator to connect to is selected by serial number).
The easiest way is to setup the appropriate project once and then make multiple copies of this project. Now modify the Connection type setting in each project, in order to let J-Flash SPI connect to the different programmers as shown in the screenshot on the right: Find below a small sample which shows how to program multiple targets in parallel:

@ECHO OFF

ECHO Open first project which is configured to connect to the first J-Link.
ECHO Open data file, start auto processing and exit
open JFlashSPI.exe -openprjC:\Projects\Project01.jflash -openC:\Data\data.bin,
0x100000 -auto -exit
IF ERRORLEVEL 1 goto ERROR

ECHO Open second project which is configured to connect to the second J-Link.
ECHO Open data file, start auto processing and exit
open JFlashSPI.exe -openprjC:\Projects\Project02.jflash -openC:\Data\data.bin,
0x100000 -auto -exit
IF ERRORLEVEL 1 goto ERROR

ECHO Open third project which is configured to connect to the third J-Link.
ECHO Open data file, start auto processing and exit
open JFlashSPI.exe -openprjC:\Projects\Project03.jflash -openC:\Data\data.bin,
0x100000 -auto -exit
IF ERRORLEVEL 1 goto ERROR

goto END

:ERROR
ECHO J-Flash SPI: Error!
pause

:END


Note:
Every call of JFlashSPI.exe has to be completed with the -exit option, otherwise the execution of the batch file stops and the following commands will not be processed.

Creating a new J-Flash SPI project

Creating a new project for J-Flash is pretty simple. In the following, all necessary steps to create a project file are explained.

  1. Select File -> New Project to create a new project with default settings.
  2. Open the Project Settings context menu. Select Options -> Project Settings to open the Project settings dialog and select the type of connection to J-Link.
    JFlashSPI ProjectSettings General.PNG

  3. Define the SPI communication speed. The default settings work without any problem for most targets, but to achieve the last quantum of performance, manual tuning may be necessary.
    JFlashSPI ProjectSettings Setup.PNG

  4. Open the Flash and either select Automatically detect SPI flash or manually enter the flash parameters.

  5. Save the project (File -> Save Project).

Custom Command Sequences

J-Flash SPI supports sending custom command sequences, which may be different for different SPI flashes (e.g. program OTP, program security register, etc...), via the SPI interface. Due to the generic syntax, this feature can be used to implement any kind of required command sequence. The sequence is stored in the J-Flash SPI project file (*.jflash) and therefore it can be included in automated production environments without any problems and be used with the command line version of J-Flash SPI as well.
The custom command sequence can be configured in the Setup tab of the J-Flash project settings as part of the Init / Exit Steps which allow to enter custom sequences using a pre-defined list of operations. The following list shows all valid commands which can be used:

Command Value0 Value1 Description
Delay Delay in ms -- Waits a given time
Activate CS -- -- Sets the CS signal low
Deactivate CS -- -- Sets the CS signal high
Write data NumByte(s) ByteStream separated by commas (hex) Sends a number of bytes via the SPI interface to the SPI. (e.g.: 9F,13,CA)
Var Read Data OffInVarBuffer NumByte(s) max. 16 bytes Reads the specified number of bytes via the SPI interface into the VarBuffer which is 16 bytes in size.
Var Write Data OffInVarBuffer NumByte(s) max. 16 bytes Writes the specified number of bytes via the SPI interface from the VarBuffer (filled via Var Read).
Var AND ByteIndex Value (hex) Logical AND combination of the internal var buffer at the specified index with a given value.
Var OR ByteIndex Value (hex) Logical OR combination of the internal var buffer at the specified index with a given value.
Var XOR ByteIndex Value (hex) Logical XOR combination of the internal var buffer at the specified index with a given value.

Init / Exit steps

The init sequence will be performed as part of the connect sequence, for example to disable security, while the exit sequence will be executed after programming, for example to enable the security in order to secure the SPI flash.

Example

The example below demonstrates how to use the custom command sequence feature to implement a read-modify-write security register on the Winbond W25Q128FVSIG SPI flash using the init steps. To make sure that the output of the example is exactly the same, the sample erases the security register to have defined values.

Step #0 to Step#2: Set Write Enable
Step #3 to Step#6: Erase security register to have a defined values (0xFF)
Step #7 to Step#11: Read 16 byte security register into Var buffer
Step #12 to Step#19: Modify the data in the Var buffer
Step #20 to Step#22: Set Write Enable
Step #23 to Step#27: Program security register with values from Var buffer
Step #28 to Step#32: Read back security register to verify successful programming

# Action Value0 Value1 Comment
0 Activate CS -- -- Activate CS
1 Write Data 1 06 Send command: Write Enable
2 Deactivate CS -- -- Deactivate CS
3 Activate CS -- -- Activate CS
4 Write Data 4 44,00,10,00 Send command: Erase Security Register 1
5 Deactivate CS -- -- Deactivate CS
6 Delay 200ms -- Wait until security register 1 has been erased
7 Activate CS -- -- Activate CS
8 Write Data 4 48,00,10,00 Send Read Security Register: 1b command + 3b addr
9 Write Data 1 FF Send 8 dummy clocks
10 Var Read Data 0 16 Read actual security register data (16 byte) into Varbuffer[0]
11 Deactivate CS -- -- Deactivate CS
12 Var AND 0 0x00 Set byte 0 to 0x00 using Var AND
13 Var OR 0 0x12 Set byte 0 to 0x12 using Var OR
14 Var AND 6 0x00 Set byte 6 to 0x00 using Var AND
15 Var OR 6 0x12 Set byte 6 to 0xAB using Var OR
16 Var AND 12 0x00 Set byte 12 to 0x00 using Var AND
17 Var OR 12 0x12 Set byte 12 to 0xCC using Var OR
18 Var AND 15 0x00 Set byte 15 to 0x00 using Var AND
19 Var OR 15 0x12 Set byte 15 to 0x4E using Var OR
20 Activate CS -- -- Activate CS
21 Write Data 1 06 Send command: Write Enable
22 Deactivate CS -- -- Deactivate CS
23 Activate CS -- -- Activate CS
24 Write Data 4 42,00,10,00 Send command: Program Security Register 1
25 Var Write Data 0 16 Send data: Program sec reg 1_1
26 Deactivate CS -- -- Deactivate CS
27 Delay 200ms -- Wait until security register 1 has been erased
28 Activate CS -- -- Activate CS
29 Write Data 4 48,00,10,00 Send Read Security Register: 1b command + 3b addr
30 Write Data 1 FF Send 8 dummy clocks
31 Var Read Data 0 16 Read actual security register data (16 byte) into Varbuffer[0]
32 Deactivate CS -- -- Deactivate CS

J-Flash SPI Command Line Version

As the Init / Exit Steps are stored in the J-Flash project file, which is evaluated in the command line version of J-Flash SPI too, the custom command sequence feature can be used under Linux / MAC, as well. The project can be either created using the GUI version of J-Flash SPI or by editing the *.jflash project, manually. The expected format of the custom command sequences in the J-Flash project file is described below.

J-Flash project layout

Basically, the custom sequence is separated into different steps where each step contains the fields as in the table below. Some commands require to pass parameter to it. They are stored in Value0 and Value1 as described in the table below.

Step Description
ExitStepX_Action = "$Action$" Any action as described in the table below.
ExitStepX_Comment = "$Comment$" User can specify any comment here. This field is optional and not taken into account.
ExitStepX_Value0 = "$Value0$" Value depends on the action. See table below
ExitStepX_Value1 = "$Value1$" Value depends on the action. See table below

The number of exit steps needs to be specified right behind the ExitStep sequence with the line "NumExitSteps = <NumExitSteps>" (see example below).

Actions Parameter Description
Activate CS none Set CS signal low
Deactivate CS none Set CS signal high
Write data Value0=NumBytes
Value1[x]=ByteStream
max. NumBytes is 16
Send a number of bytes via the SPI interface to the SPI.
Please note, that the number of bytes has to be specified right behind Value1 in square brackets
(e.g.: ExitStep4_Value1[3] = 0x44,0x00,0x10)
Delay Value0=Delay in ms Waits a given time

Below is a small example excerpt from a J-Flash project, which shows a example sequence to erase sector 0 of the SPI flash using the 0xD8 command. Further examples can be found in the installation directory of the J-Link software and documentation package.

[CPU]
//
// Set write enable
//
ExitStep0_Action = "Activate CS"
ExitStep0_Value0 = 0x00000000
ExitStep0_Value1 = 0x00000000
ExitStep1_Action = "Write data"
ExitStep1_Comment = "Set write enable"
ExitStep1_Value0 = 1
ExitStep1_Value1[1] = 0x06
ExitStep2_Action = "Deactivate CS"
ExitStep2_Comment = "Deactivate CS"
ExitStep2_Value0 = 0x00000000
ExitStep2_Value1 = 0x00000000
//
// Erase sector 0
//
ExitStep3_Action = "Activate CS"
ExitStep3_Comment = "Activate CS"
ExitStep3_Value0 = 0x00000000
ExitStep3_Value1 = 0x00000000
ExitStep4_Action = "Write data"
ExitStep4_Comment = "Set write enable"
ExitStep4_Value0 = 4
ExitStep4_Value1[4] = 0xD8,0x00,0x00,0x00
ExitStep5_Action = "Deactivate CS"
ExitStep5_Comment = "Deactivate CS"
ExitStep5_Value0 = 0x00000000
ExitStep5_Value1 = 0x00000000
//
// Wait until sector has been erased
//
ExitStep6_Action = "Delay"
ExitStep6_Comment = "Wait until sector has been erased"
ExitStep6_Value0 = 0x00000080
ExitStep6_Value1 = 0x00000000
NumExitSteps = 7

How to use quad mode

TBD

How to configure quad mode

Note:
  • Not all J-Link / Flasher / ... models support the QSPI interface (4 data lines), but some only support traditional SPI. For an overview about which model and hardware version support QSPI, please refer to the model overview wiki article

In order to configure or setup quad mode in J-Flash SPI, some flash chip-specific information needs to be gathered.

  1. Quad Mode Enable Sequence
  2. Quad Read Data Command
    • Command code
    • Address transfer mode
    • Number of dummy cycles
  3. Quad Page Program Command
    • Command code
    • Address transfer mode

Usually, all of the above information can be found in the flash chip's datasheet.

Quad mode initialization

Quad Mode Enable Sequence for a Spansion S25FL512S flash

Most flash chips need to be put into a "quad mode" or similar before data can be written or read in quad mode.
In J-Flash SPI, the procedure which enables this mode is referred to as "Quad Mode Enable Sequence".
In a J-Flash SPI project, this sequence can be configured similar to the init/exit steps, by defining a series of custom steps inside the "Quad Mode Enable Sequence" table in the "Flash" tab of the J-Flash project settings. An example for a Quad Mode Enable Sequence can be found in the screenshot pictured on the right.
The pictured sequence enables quad mode for a Spansion S25FL512S flash chip by doing the following:

  1. Read the configuration register (RDCR command) and store it in a temporary buffer on the host
  2. Check if the QUAD bit is set (bit position 1)
  3. If the QUAD bit is already set, quad mode is already enabled and we are done
  4. If the QUAD bit in is not set, set it in the temporary host-buffer (TmpBuf[1] &= (1 << 1))
  5. Read the status register 1 (RDSR1 command)
  6. Write the status register 1 and the (adjusted) configuration register
  7. Wait for the register writes to finish

The series of steps that are required to put a flash chip into the desired quad mode may look very different for other flash chips, because this sequence is completely flash-specific and not standardized at all.
Note:
Some flash chips also support a mode called "Quad I/O" mode or similar. This mode makes the flash chip assume that any SPI communication happens in quad mode, meaning that sending any command (not just page program or read data) happens in quad mode.
Currently, this type of "Quad I/O" mode is not supported by J-Flash SPI and Flasher. Make sure that this mode is not accidentally enabled.


Quad Read Data Command

Reading data from a flash in quad mode can be achieved by using a SPI command which behaves the same as the "single" SPI read data command,
except for the fact that the read data is sent to the host on four lines instead of just one, increasing the data transfer speed by a factor of 4.
Information about a quad read data command can be found in the flash chip's datasheet. Usually, the command is referred to as "quad read data", "data read quad", "read quad out", or similar.

In the J-Flash SPI project settings, the Quad Read Data Command code needs to be configured (ReadDataQuad field), as well as the address transfer mode for quad page program.
The address transfer mode setting determines if the address bytes that are sent to the flash are sent in quad mode (4 data lines in parallel) or in single mode (1 data line). This settings needs to be configured correctly, otherwise proper function cannot be guaranteed.

For the Spansion S25FL512S flash, the Quad Read Data Command code is 0x6C and the address is transferred in single mode.

Dummy cycles

When reading data from the target flash chip in quad mode, a specific number of so called "dummy cycles" or "latency cycles" may be sent to the flash chip before receiving actual data. The number of required dummy cycles depends on the flash chip and may vary depending on the current flash configuration (e.g. configuration register contents), SPI clock frequency, operation mode, etc...

For the Spansion S25FL512S flash, the number of required dummy cycles for the "read quad out" command at a SPI clock frequency of 50MHz is 8.

Quad Page Program Command

Programming a flash page in quad mode can be achieved by using a SPI command which behaves the same as the "single" SPI page program command,
except for the fact that the page data is sent to the flash chip on four lines instead of just one, increasing the data transfer speed by a factor of 4.
Information about a quad page program command can be found in the flash chip's datasheet. Usually, the command is referred to as "quad page program", "pape program quad", or similar.

In the J-Flash SPI project settings, the Quad Page Program Command code needs to be configured (WritePageQuad field), as well as the address transfer mode for quad page program.
The address transfer mode setting determines if the address bytes that are sent to the flash are sent in quad mode (4 data lines in parallel) or in single mode (1 data line). This settings needs to be configured correctly, otherwise proper function cannot be guaranteed.

For the Spansion S25FL512S flash, the Quad Page Program Command code is 0x34 and the address is transferred in single mode.

Device specifics

This section gives some additional information about specific devices.

SPI flashes with multiple erase commands

Some SPI flashes support multiple erase commands that allow to erase different units on the flash. For example some flashes provide a sector erase (erase 4 KiB units) and a block erase (erase 16 KiB or 64 KiB units) command. In general, it is up to the user which command to use, as the EraseSector command can be overridden by the user. When manually changing the SectorErase command in the Options -> Project settings... -> Flash tab, make sure that the SectorSize parameter matches the command being used

Target systems

Programmable flash devices

In general, all kinds of SPI flash can be programmed. Since all flash parameters are configurable, also flashes with non-standard command sets can be programmed.

Performance

The following section lists programming performance for various SPI flash devices.

Performance values

In direct programming mode (J-Link directly connects to the pins of the SPI flash), the programming speed is mainly limited by the SPI communication speed, the USB speed of J-Link (if a Full-Speed or Hi-Speed based J-Link is used) and the maximum programming speed of the flash itself.
For most SPI flash devices, in direct programming mode speeds of >= 50 KiB/s can be achieved.

Background information

This section provides some background information about specific parts of the J-Flash SPI software.

SPI interface connection

For direct SPI flash programming, J-Link needs to be wired to the SPI flash in a specific way. For more information about the pinout for the J-Link SPI target interface, please refer to The J-Link User Guide. The minimum pins that need to be connected, are: VTref, GND, SPI-CLK, MOSI, MISO. If other components on the target hardware need to be kept in reset while programming the SPI flash (e.g. a CPU etc.), nRESET also needs to be connected.

Troubleshooting

Target system has no power

Meaning:
J-Link could not measure the target (flash) reference voltage on pin 1 of its connector.
Remedy:
The target interface of J-Link works with level shifters to be as flexible as possible. Therefore, the reference I/O voltage the flash is working with also needs to be connected to pin 1 of the J-Link connector.

Programming / Erasing failed

Meaning:
The SPI communication speed may be too high for the given signal quality.
Remedy:
Try again with a slower speed. If it still fails, check the quality of the SPI signals.

Failed to verify Flash ID

Meaning:
J-Link could not verify the ID of the connected flash.
Remedy:
Check the Flash ID entered in the flash parameters dialog, for correctness.