Debugging a Custom Flash Loader
Technical Note 201118
Architectures:
Arm
Component:
debugger
Updated:
12/10/2020 10:14 AM
Introduction
Creating a custom flash loader can be a tricky process, because it is difficult to debug flash loader activity the usual way. (See Technical Note 200214 on how to log flash loader activity). This Technical Note shows an alternative way of debugging a flash loader under development.
For more information about developing custom flash loaders, see also the Flash Loader Development Guide in $TOOLKIT_DIR$\doc\FlashLoaderGuide.ENU.pdf
.
Discussion
During development of a custom flash loader, it is possible to use semihosting printf to debug flash loader activity. The general idea is to:
- Build a flash loader project with semihosting
printf
- Configure the application project to produce a Terminal I/O log file
Instructions
In this example, an STM32F429II-ACA board is used with an I-jet debug probe.
Build a flash loader project with semihosting printf
- Open the flash loader workspace from
$TOOLKIT_DIR$\src\flashloader
(in this example fromST\FlashSTM32F4xx
) - Select the correct configuration (in this example
FlashSTM32F4xxRAM192K_Dual
) - Confirm that Project > Options > General Options > Library Configuration > stdout/stderr: Via semihosting is selected.
- Add a call to
__iar_data_init3
and aprintf
statement at the beginning of theFlashInit
function, like this:
__iar_data_init3(); // Required to initialize .bss parallelism = 1; blankcheck = 0; printf("Hello! World\n\n"); printf("image_size:%d\n\n", image_size);
- If you get a linker error [Lp005]: placement includes a mix of sections with content and sections without content, you need to modify the linker configuration file:
* Comment out the linesdo not initialize { zi }
ordo not initialize { section .bss }
.
* Add a lineinitialize by copy { readwrite }
if not already there. - Build and replace the flash loader .out file in
$TOOLKIT_DIR$\config\flashloader
(In this example in the ST folder)
Configure the application project to produce a Terminal I/O log file
The flash loader printf output will not be visible in the Terminal I/O window. However, it will be logged in the Terminal I/O log file.
- Open the STM32F429II-ACA LightEffects project from Help > Information Center > Example Projects.
- Temporarily change the debugger driver to Simulator just in case the debug session cannot be launched with I-jet or other hardware debug probes (because of problems with the custom flash loader): Project > Options > Debugger > Setup>Driver: Simulator
- Start a debug session by choosing Project > Download and Debug
- Enable the Terminal I/O log file by choosing Debug > Logging > Set Terminal I/O Log File
- Exit the debug session, and change the debugger driver back to I-jet: Project > Options > Debugger > Setup>Driver: I-jet
- Start a new debug session by choosing Project > Download and Debug
- Flash loader printf output is now recorded in the Terminal I/O log file.
Conclusion
For debugging and logging details of custom flash loader development, semihosting printf and the Terminal I/O log file are useful.
All product names are trademarks or registered trademarks of their respective owners.