External loader for STM32WL5: code is not loaded in ram
Hello,
I'm trying to develop a custom external loader for STM32WL5 device, in a custom board using SPI flash memory Winbond W25Q80DV.
In the past I've already developed external loaders successfully for other MCUs and boards.
I again followed the steps described by official documentation, hints on this forum, examples in folder bin/ExternalLoader of CubeProgrammer: I set up a new project with CubeIDE, compiled, created .stldr file and copied it in ExternalLoader folder. If I debug the project everything is ok. Besides, opening CubeProgrammer, I correctly see my new external loader in external loader list and information provided are correct.
The problem is that when I try to read from the SPI flash mapped address (set to 0x9000 0000 in this case) using CubeProgrammer, the procedure fails. Selecting Verbosity level 3, I can see these messages:
11:11:37:994 : UR connection mode is defined with the HWrst reset mode
11:11:38:061 : ST-LINK SN : 54FF69066685495419301687
11:11:38:062 : ST-LINK FW : V2J43S7
11:11:38:062 : Board : --
11:11:38:062 : Voltage : 3.22V
11:11:38:062 : SWD freq : 4000 KHz
11:11:38:062 : Connect mode: Normal
11:11:38:062 : Reset mode : Hardware reset
11:11:38:062 : Device ID : 0x497
11:11:38:063 : Revision ID : Rev Y
11:11:38:063 : Reading data...
11:11:38:063 : r ap 0 @0x1FFF7550 0x00000004 bytes Data 0x0000FFFF
11:11:38:063 : Reading data...
11:11:38:063 : r ap 0 @0x1FFF7550 0x00000004 bytes Data 0x0000FFFF
11:11:38:063 : Database: Config 1 is active.
11:11:38:063 : r ap 0 @0x1FFF73F8 0x00000004 bytes Data 0x38100002
11:11:38:064 : r ap 0 @0x1FFF73FC 0x00000004 bytes Data 0x46AFDBD1
11:11:38:064 : flash loader C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer3\bin/FlashLoader/0x497.stldr is loaded
11:11:38:064 : Debug in Low Power mode is not supported for this device.
11:11:38:064 : r ap 0 @0x1FFF73F8 0x00000004 bytes Data 0x38100002
11:11:38:064 : r ap 0 @0x1FFF73FC 0x00000004 bytes Data 0x46AFDBD1
11:11:38:064 : Reading data...
11:11:38:064 : r ap 0 @0x1FFF75E0 0x00000004 bytes Data 0xFFFF0100
11:11:38:064 : r ap 0 @0x1FFF3EFE 0x00000004 bytes Data 0x008800C4
11:11:38:333 : r ap 0 @0x1FFF73F8 0x00000004 bytes Data 0x38100002
11:11:38:334 : r ap 0 @0x1FFF73FC 0x00000004 bytes Data 0x46AFDBD1
11:11:38:334 : r ap 0 @0x1FFF3EFE 0x00000004 bytes Data 0x008800C4
11:11:38:334 : Selected loader: C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer3\bin/ExternalLoader/W25Q80DV_Term_Redox.stldr
11:11:38:334 : Selected loader: C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer3\bin/ExternalLoader/W25Q80DV_Term_Redox.stldr
11:11:38:334 : External loader C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer3\bin/ExternalLoader/W25Q80DV_Term_Redox.stldr is loaded
11:11:38:334 : UPLOADING OPTION BYTES DATA ...
11:11:38:334 : Bank : 0x00
11:11:38:334 : Address : 0x58004020
11:11:38:334 : Size : 96 Bytes
11:11:38:334 : Reading data...
11:11:38:334 : r ap 0 @0x58004020 0x00000060 bytes Data 0x3BFFF0AA
11:11:38:335 : Bank : 0x01
11:11:38:335 : Address : 0x58004080
11:11:38:335 : Size : 8 Bytes
11:11:38:335 : Reading data...
11:11:38:335 : r ap 0 @0x58004080 0x00000008 bytes Data 0x80FF00FF
11:11:38:335 : UPLOADING OPTION BYTES DATA ...
11:11:38:336 : Bank : 0x00
11:11:38:336 : Address : 0x58004020
11:11:38:336 : Size : 96 Bytes
11:11:38:336 : Reading data...
11:11:38:336 : r ap 0 @0x58004020 0x00000060 bytes Data 0x3BFFF0AA
11:11:38:336 : Bank : 0x01
11:11:38:336 : Address : 0x58004080
11:11:38:336 : Size : 8 Bytes
11:11:38:336 : Reading data...
11:11:38:337 : r ap 0 @0x58004080 0x00000008 bytes Data 0x80FF00FF
11:11:38:337 : r ap 0 @0x1FFF73F8 0x00000004 bytes Data 0x38100002
11:11:38:337 : r ap 0 @0x1FFF73FC 0x00000004 bytes Data 0x46AFDBD1
11:11:38:337 : r ap 0 @0x1FFF3EFE 0x00000004 bytes Data 0x008800C4
11:11:38:337 : UPLOADING ...
11:11:38:337 : Size : 1024 Bytes
11:11:38:337 : Address : 0x90000000
11:11:38:337 : Read progress:
11:11:38:337 : Reading data...
11:11:38:337 : halt ap 0
11:11:38:338 : w ap 0 reg 15 PC (0x20000000)
11:11:38:338 : w ap 0 reg 17 MSP (0x20000500)
11:11:38:338 : w ap 0 reg 16 xPSR (0x01000000)
11:11:38:339 : Loader read...
11:11:38:339 : Init flashloader...
11:11:38:340 : halt ap 0
11:11:38:340 : w ap 0 reg 0 R0 0x00000000
11:11:38:340 : w ap 0 reg 1 R1 0x00000000
11:11:38:341 : w ap 0 reg 2 R2 0x00000000
11:11:38:341 : w ap 0 reg 3 R3 0x00000000
11:11:38:342 : w ap 0 reg 4 R4 0x00000000
11:11:38:342 : w ap 0 reg 5 R5 0x00000000
11:11:38:343 : w ap 0 reg 6 R6 0x00000000
11:11:38:343 : w ap 0 reg 7 R7 0x00000000
11:11:38:343 : w ap 0 reg 8 R8 0x00000000
11:11:38:343 : w ap 0 reg 9 R9 0x00000000
11:11:38:343 : w ap 0 reg 10 R10 0x00000000
11:11:38:343 : w ap 0 reg 11 R11 0x00000000
11:11:38:343 : w ap 0 reg 12 R12 0x00000000
11:11:38:344 : w ap 0 reg 13 SP 0x00000000
11:11:38:344 : w ap 0 reg 14 LR 0x00000000
11:11:38:344 : w ap 0 reg 15 PC 0x20000009
11:11:38:344 : w ap 0 reg 16 xPSR 0x01000000
11:11:38:344 : w ap 0 reg 17 MSP 0x00000000
11:11:38:344 : w ap 0 reg 18 PSP 0x00000000
As you can see, after the step
11:11:38:338 : w ap 0 reg 15 PC (0x20000000)
11:11:38:338 : w ap 0 reg 17 MSP (0x20000500)
11:11:38:338 : w ap 0 reg 16 xPSR (0x01000000)
a step is missing where the code is actually loaded in MCU ram at address 0x2000 0004.
If I try to select other external loaders in the list, those, for example, developed for STM32H7 MCUs, the result is the same.
Instead, for a few other loaders, for example N25Q256A_STM32L476G-EVAL loader, the code loading step is actually done (in red):
11:20:26:349 : w ap 0 reg 15 PC (0x20000000)
11:20:26:349 : w ap 0 reg 17 MSP (0x20000500)
11:20:26:349 : w ap 0 reg 16 xPSR (0x01000000)
11:20:26:354 : w ap 0 @0x20001680 : 0x00000200 bytes, Data 0x00000000...
11:20:26:354 : w ap 0 @0x20000000 : 0x00000004 bytes, Data 0x0000BE00...
11:20:26:392 : w ap 0 @0x20000004 : 0x00001258 bytes, Data 0xB085B500...
11:20:26:392 : Loader read...
11:20:26:392 : Init flashloader...
I've done another test: if I try to use the CubeProgrammer software with another board equipped with STM32H735 MCU, regardless of the external loader selected, the code is ALWAYS loaded in ram.
I'm asking for your help and hints.
Anybody knows the reason of this weird behaviour?
Am I missing anything or making some mistakes?
Thank you very much.
