Adding Support for New Devices
- 1 Creating a flash algorithm using SEGGER Embedded Studio
- 1.1 Debug Configurations
- 1.2 Included files
- 1.3 Embedded Studio Template Projects
- 1.4 Step-By-Step Instruction
- 1.5 Frequently Asked Questions
- 1.6 Troubleshoot
- 1.7 Frequently Problems
- 2 Using a Precompiled Flashloader
This article describes how to add support for new devices / flash banks to the J-Link DLL so that they can be used with any J-Link DLL based application like for example J-Flash, J-Link Commander, IDEs, etc...This article assumes that there is already a basic understanding of the method of adding new devices using the Open Flashloader concept. If this is not the case, we recommend to read the Open Flashloader chapter in the J-Link User Manual (UM08001). In general, there are two possibilities to add support for a new device:
- Use a pre-compiled flash loader
- Compile / create the flash loader on your own
- Using Keil uVision (a license is required, no trial available; Supports Cortex-M, only)
- SEGGER Embedded Studio (can be evaluated without license; Supports Cortex-M and Cortex-A/R)
How to create a flash loader on your own using Embedded Studio is described below.
Creating a flash algorithm using SEGGER Embedded Studio
This article describes how to create a flash loader using the template projects (Cortex-M and Cortex-A/R) for SEGGER Embedded Studio.
The example project contains two debug configurations:
This configuration allows to debug the flash algorithm in Embedded Studio. The configuration includes a main.c containing the typical function call order, executed by the J-Link DLL during flash programming. The optimization level for this configuration is set to "none".
This configuration does not allow debugging but creates the output elf file which can be referenced from within the JLinkDevices.xml file as "Loader". The optimization level is set to 3 (highest).
|FlashDev.c||Flash device description for the ST STM32F205RC|
|FlashOS.h||Function prototypes, definitions and structures|
|FlashPrg.c||Flash algorithm itself (e.g. ProgramPage(), EraseSector()|
|main.c||Flash algorithm debug code (used by debug configuration, only)|
| Cortex-M startup code (used by debug configuration, only) |
Cortex-A/R startup code (used by debug configuration, only)
|MemoryMap.xml||Memory map of the ST STM32F205RC|
|Placement_debug.xml||Debug configuration section placement file.|
|Placement_release.xml||Release configuration section placement file.|
| Initialization file for Cortex-M (used by debug configuration, only)|
Initialization file for Cortex-A/R(used by debug configuration, only)
Embedded Studio Template Projects
The template projects below have been tested with SEGGER Embedded Studio V3.10.
- File:OpenFlashLoader CortexM Template EmbeddedStudio.zip
- File:OpenFlashLoader CortexAR Template EmbeddedStudio.zip
This step-by-step instruction explains how to create your own flash loader using the template projects for Embedded Studio and how to use add a new flash bank for an existing or new device to the J-Link DLL, so that it can be used from within any application using the DLL.
- Adapt the template project
- FlashDev.c: Modify the FlashDevice structure according to your device
- FlashPrg.c: Implement the flash routines Init(), UnInit(), EraseSector() and ProgramPage()
- MemoryMap.xml: Enter RAM base address and RAM size
- main.c: Make sure that the define _FLASH_BASE_ADDR defines the correct flash base address
- Test the debug configuration
- Connect the target to the J-Link and the J-Link to the PC
- Switch to the Debug configuration in Embedded Studio (Build -> Set Active Build Configuration -> Debug)
- Build the project by pressing F7
- Start the debug session by pressing F5
- PC should be halted at main. Now debug the flash algorithm and make sure that it behaves as expected.
- Build the flash loader using the release configuration
- Switch to the Release configuration in Embedded Studio (Build -> Set Active Build Configuration -> Release)
- Build the project by pressing F7 --> The flash loader file can be found here: $PROJ_DIR$\Output\Release\Exe\*.elf
- Create or adapt the JLinkDevices.xml (described in the J-Link User Manual (UM08001)).
- Place the JLinkDevices.xml file at the correct location (described in the J-Link User Manual (UM08001)).
Now you can select and use the created or adapted device which uses the new flash bank in any J-Link DLL based application (e.g. J-Link Commander / IDE / ...).
Frequently Asked Questions
In which order does the J-Link DLL call the function during flash programming?
Memory is accessed so it has to be initialized during Init() so that it can be memory mapped accessed here. If it is not initialized correctly, the read access may results in confusing the MCU.
This section provides assistance in case of issues pops up when using custom added flash bank. The section assumes that the functionality has been verified using the debug configuration in Embedded Studio.
- Get the latest version of the template project
- Follow the Step-By-Step instructions expect of 2.1 FlashPrg.c --> Functions should not contain any code that accesses any SFRs
- Build the flash loader using the release configuration
- Perform a flash download using J-Link Commander. Flash download should report an error during verify
- Implement EraseSector() and retry the flash download test. J-Link Commander should still report verify failed but effected flash memory region should be empty. If not, check EraseSector().
- Implement ProgramPage() and retry the flash download test. Expected result: Test reports O.K. --> Programmed successfully. If not, check ProgramPage() code.
PC has unexpected value after flash download
This error may have different root causes:
- Watchdog is enabled but not fed in the flash loader functions. This may result in a watchdog timeout pops up during RAMCode execution. The behavior is different but usually a reset will be triggered.
- Accessing not enabled / clocked special function registers / peripherals
- Accessing invalid memory regions (reserved)
- The Init() code has to make sure that the (Q)SPI pins as well as the (Q)SPI controller are configured so that the flash can be memory mapped (read) accessed. This is necessary as the J-Link DLL reads the data before programming to check if flash content does already match. This can be validated by setting the compare method in J-Link Commander to "skip" (exec SetCompareMode 0). Now start flash download. J-Link Commander should report a verify error but the flash should be memmory mapped accessible from now. If not, check the Init() code.
Using a Precompiled Flashloader
- Make sure that J-Link software V6.16f or later is installed:
- Browse to the installation of the J-Link software package.
You should now see JFlash.exe, JLinkDevices.xml, ...
- Open JLinkDevices.xml in a text editor and add the device entry at the beginning, right after the <Database> opening tag.
- Copy the flashloader file, referenced in the JLinkDevices.xml entry, into the same directory where also the JLinkDevices.xml is located (in this example ST_STM32F7xxxx_2MB_DualBank.elf).
- Start JFlash.exe (or any other application which supports J-Link) and select the device
<!-- This entry will overwrite the existing device entry in the J-Link software, so that a custom flash algorithm is used for the internal flash --> <ChipInfo Vendor="ST" Name="STM32F767ZI" Core="JLINK_CORE_CORTEX_M7" /> <FlashBankInfo Name="Internes Flash" BaseAddr="0x08000000" MaxSize="0x00200000 " Loader="ST_STM32F7xxxx_2MB_DualBank.elf" LoaderType="FLASH_ALGO_TYPE_OPEN" /> </Device>