Search code examples
debuggingstm32iar

Debug STM32L151xD with or without "Use Flash Loader" IAR


I'm came across a strange behavior while debugging various firmware on the STM32L151xD using IAR 6.50.6.

I've found out that flashing a FW with Use Flash Loader checked everything goes smooth. After that, if I try to flash on the same device another FW with Use Flash Loader unchecked, the flashing process goes smooth but I can't debug and IAR shows a series of verify error like

Verify error at address 0x08000000, target byte: 0xD0, byte in file: 0xC8 

I know that the flash loader read the application binary image from the host, unpack the image, and write the image to flash memory.

What happens if I check/uncheck on IAR and try to debug?


Solution

  • The unobtrusive Use Flash Loader option has a major impact on how an application is programmed into the target device:

    • If Use Flash Loader is checked, the IAR debugger loads a tiny flash loader application into the RAM of the target MCU which then in turn is able to program the user application into the target flash. The flash loader application is typically implemented specifically for a MCU device family (like STM32L1), because each device (family) has it's specific way on how the flash memory needs to be programmed (unlock mechanism, timing, etc.). The IAR workbench ships with a large collection of flash loaders for all supported devices. Refer to chapter Flash loaders in the IAR C-SPY Debugging Guide for a more detailed description of the flash loader mechanism.

    • If Use Flash Loader is unchecked, the IAR debugger instead relies on the debugging probe to be able to program the target MCU's flash memory. It depends on the specific debug probe (driver), whether it is able to program a specific device. From my experience the popular Segger J-Link debug probes are able to program nearly all ST STM32 MCU devices without Use Flash Loader, while the IAR i-Jet debug probes lack this ability - to name just two probes.

    Unfortunately, the IAR EWARM debugger does not issue a warning (or error) message, when the configured debug probe is not able to program the specific target MCU. Instead it seems to assume that programming succeeded. Only if the option Verify download has been enabled, the debugger will check whether the user application has been successfully flashed to the target.

    In your case verification of the download fails with a blank device, because your debug probe is apparently not able to program the target MCU flash memory without a flash loader. You need to enable the Use Flash Loader for the debug probe in all your projects.