J-Link flash programming
Example sequence
The standard programming procedure for a device that uses the SEGGER Flashloader. This procedure is used for flash breakpoints and the loadfile command. Note that this procedure may differ depending on the applied configuration of the J-Link DLL:
- Handle Before Flash Programming: The J-Link script file function HandleBeforeFlashProg() is called.
- Flash Prepare: The J-Link script file function FLASH_Prepare() is called.
- Prepare: The function SEGGER_FL_Prepare() of the flashloader is called.
- Data Comparison: The data to be programmed is compared with the actual data in flash.
- Blank Check: The sectors to be programmed are blank-checked with the SEGGER_FL_CheckBlank() function.
- Sector Erase: All sectors that are not blank are erased with SEGGER_FL_Erase().
- Programming: All sectors are programmed using the SEGGER_FL_Program() function.
- Verification: The flash is then verified using L2-verify.
- Restore: The function SEGGER_FL_Restore() of the flashloader is called.
- Flash Restore: The J-Link script file function FLASH_Restore() is called.
- Steps 2–10 are repeated for every flash bank that is programmed.
- Handle After Flash Programming: The J-Link script file function HandleAfterFlashProg() is called.
Steps 2–10 are loader-specific and therefore executed for every flash bank that is programmed.
Steps 1 and 12 are device-specific and executed once per programming procedure.
Programming functions
Loader Script File
The loader script file can be specified once for every flash loader.
For already supported devices the loader script file cannot be specified manually.
For usage with the J-Link DSK, the loader script can be specified in the XML-tag LoaderInfo.
Flash Prepare
The loader J-Link script file function FLASH_Prepare() is called. This optional step prepares the flash for programming operations.
Flash Restore
The loader J-Link script file function FLASH_Restore() is called. This optional step restores the flash.
Device Script File
The device script file inherits device specific handling.
For usage and selection of custom script files see Using J-Link script files.
Handle Before Flash Programming
The device J-Link script file function HandleBeforeFlashProg() is called. This is an optional step that is executed once at the beginning of the programming procedure.
Handle After Flash Programming
The device J-Link script file function HandleAfterFlashProg() is called. This is an optional step that is executed once at the end of the programming procedure.
SEGGER Flashloader
The SEGGER Flash Loader (SFL) is part of the J-Link Device Support Kit (DSK) and allows users to add flash programming support for a new device on their own.
For more information see: SEGGER_Flash_Loader.
Prepare
The function SEGGER_FL_Prepare() of the flashloader is called to initialize the flash programming process.
Data Comparison
The data to be programmed is compared with the actual data in flash. Sectors that already match the data are skipped and will not be modified. This method uses either SEGGER_FL_CalcCRC() or SEGGER_FL_Read() depending on the compare configuration.
Blank Check
The sectors to be programmed are blank-checked using the SEGGER_FL_CheckBlank() function to ensure they are ready for programming. This method can be skipped using the blank check configuration.
Sector Erase
All sectors that are not blank are erased using SEGGER_FL_Erase() to prepare them for new data.
Programming
All sectors are programmed using the SEGGER_FL_Program() function to write the new data.
Verification
The flash is verified using L2-verify. This procedure can be configured. See: #Configuring_Verification_Levels_and_Methods. Depending on the flashloader and configuration, SEGGER_FL_CalcCRC(), SEGGER_FL_Read() or SEGGER_FL_Verify() is called for this process.
Restore
The function SEGGER_FL_Restore() of the flashloader is called to complete the programming process.
Verification methods
There are different verification methods and levels of verification available for J-Link. In the following, the available configurations are explained.
L1-verify
The level-1 verification is performed immediately after programming a chunk of data into flash. Due to necessary handling for some modern MCUs (read not allowed in certain states), it was superseded by L2 verification. It is therefore deprecated and only rarely used.
L2-verify
The level-2 verification is performed after all data has been programmed. It is performed over all data that has been programmed. The L2-verify can be configured to be performed via different methods, which are explained in the following:
- Read-back: The data is read back and compared against the data that was programmed.
- CRC: A CRC over the data in flash is calculated by the flash algo, and this CRC is sent back to the PC software to compare it against the CRC of the data to be programmed. This way of verification is much faster than "read-back" because not all data from flash must be transmitted over the debug interface and USB/IP to the PC for comparison.
CRC is much faster than reading back all data and gives a very good security to detect errors. It is the default for L2-verify.
Configuration
Configuring Verification Levels and Methods
Verification levels can be enabled or disabled.
The following command strings are available for configuring L1 and L2 verification:
The method used for L2 verification can be configured via the J-Link Control Panel.
The following methods are available for L2 verification:
Configuring blank check
The following command strings are available for configuring blank check:
Configuring compare
The following command strings are available for configuring the compare process:
Configuring restore
The following command strings are available for configuring the restore process:
