Skip to main content
unsigned_char_array
Lead III
January 20, 2023
Solved

Flashing elf file in internal + external memory in STM32CubeIde

  • January 20, 2023
  • 9 replies
  • 7850 views

I've successfully created a custom flash loader for the STM32H7A3ZIT6Q with the MT25TL256 dual-quad NOR FLASH. I can erase, program and read the external memory in STM32CubeProgrammer with a dummy file. Flashing an elf file with external flash data fails.

Memory mapping also works in my STM32CubeIDE project. The project has some dummy data in the external flash section. It shows up in the Build Analyzer. I can export the external memory section to a bin file, which I can manually flash with STM32CubeProgrammer. If I debug my application I can see the dummy variable is correctly initialized and in the right location.

I use the following post-build command to export my bin file:

arm-none-eabi-objcopy.exe -O binary --only-section=.textqspi "${BuildArtifactFileBaseName}.elf" textqspi.bin

I've added my flash loader to a new launch file and I get the following output:

STMicroelectronics ST-LINK GDB server. Version 7.1.0
Copyright (c) 2022, STMicroelectronics. All rights reserved.
 
Starting server with the following options:
 Persistent Mode : Disabled
 Logging Level : 1
 Listen Port Number : 61234
 Status Refresh Delay : 15s
 Verbose Mode : Disabled
 SWD Debug : Enabled
 
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Failed to initialize external memory

STM32CubeProgrogrammer gives the following error if I select external flash column on the right before clicking on Start Programming:

16:52:39:365 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
 16:52:39:844 : Memory Programming ...
 16:52:39:844 : Opening and parsing file: IDE-Prothese-base.elf
 16:52:39:854 : File : IDE-Prothese-base.elf
 16:52:39:854 : Size : 1.81 MB 
 16:52:39:854 : Address : 0x08000000 
 16:52:39:854 : Erasing Segment <0> Address <0x08000000> Size <1901070>Bytes
 16:52:39:854 : Erasing memory corresponding to segment 0:
 16:52:39:854 : Memory erase...
 16:52:39:856 : halt ap 0 
 16:52:39:856 : w ap 0 reg 15 PC (0x24000000) 
 16:52:39:856 : w ap 0 reg 17 MSP (0x24000500) 
 16:52:39:856 : w ap 0 reg 16 xPSR (0x01000000) 
 16:52:39:859 : w ap 0 @0x24001140 0x00000200 bytes Data 0x00000000
 16:52:39:859 : w ap 0 @0x24000000 0x00000004 bytes Data 0x0000BE00
 16:52:39:861 : w ap 0 @0x24000004 0x00000D10 bytes Data 0x8F4FF3BF
 16:52:39:861 : Erasing internal memory sectors [0 232]
 16:52:39:861 : Init flashloader...
 16:52:39:861 : halt ap 0 
 16:52:39:862 : w ap 0 reg 0 R0 0x00000001
 16:52:39:863 : w ap 0 reg 1 R1 0x00000000
 16:52:39:863 : w ap 0 reg 2 R2 0x00000000
 16:52:39:864 : w ap 0 reg 3 R3 0x00000000
 16:52:39:864 : w ap 0 reg 4 R4 0x00000000
 16:52:39:864 : w ap 0 reg 5 R5 0x00000000
 16:52:39:864 : w ap 0 reg 6 R6 0x00000000
 16:52:39:864 : w ap 0 reg 7 R7 0x00000000
 16:52:39:864 : w ap 0 reg 8 R8 0x00000000
 16:52:39:864 : w ap 0 reg 9 R9 0x00000000
 16:52:39:864 : w ap 0 reg 10 R10 0x00000000
 16:52:39:864 : w ap 0 reg 11 R11 0x00000000
 16:52:39:865 : w ap 0 reg 12 R12 0x00000000
 16:52:39:865 : w ap 0 reg 13 SP 0x00000000
 16:52:39:865 : w ap 0 reg 14 LR 0x24000001
 16:52:39:866 : w ap 0 reg 15 PC 0x2400000B
 16:52:39:866 : w ap 0 reg 16 xPSR 0x01000000
 16:52:39:866 : w ap 0 reg 17 MSP 0x24001110
 16:52:39:866 : w ap 0 reg 18 PSP 0x00000000
 16:52:39:866 : run ap 0 
 16:52:39:866 : halt ap 0 
 16:52:39:866 : r ap 0 reg 0 R0 0x00000001
 16:52:39:866 : Loader sector erase...
 16:52:39:867 : w ap 0 reg 0 R0 0x08000000
 16:52:39:867 : w ap 0 reg 1 R1 0x081D0000
 16:52:39:867 : w ap 0 reg 2 R2 0x00000002
 16:52:39:868 : w ap 0 reg 3 R3 0x00000000
 16:52:39:868 : w ap 0 reg 4 R4 0x00000000
 16:52:39:868 : w ap 0 reg 5 R5 0x00000000
 16:52:39:868 : w ap 0 reg 6 R6 0x00000000
 16:52:39:869 : w ap 0 reg 7 R7 0x00000000
 16:52:39:869 : w ap 0 reg 8 R8 0x00000000
 16:52:39:869 : w ap 0 reg 9 R9 0x00000000
 16:52:39:869 : w ap 0 reg 10 R10 0x00000000
 16:52:39:869 : w ap 0 reg 11 R11 0x00000000
 16:52:39:869 : w ap 0 reg 12 R12 0x00000000
 16:52:39:869 : w ap 0 reg 13 SP 0x00000000
 16:52:39:870 : w ap 0 reg 14 LR 0x24000001
 16:52:39:870 : w ap 0 reg 15 PC 0x2400086B
 16:52:39:870 : w ap 0 reg 16 xPSR 0x01000000
 16:52:39:870 : w ap 0 reg 17 MSP 0x24001110
 16:52:39:870 : w ap 0 reg 18 PSP 0x00000000
 16:52:39:870 : run ap 0 
 16:52:40:417 : halt ap 0 
 16:52:40:417 : r ap 0 reg 0 R0 0x00000000
 16:52:40:418 : r ap 0 reg 16 xPSR 0x80000003
 16:52:40:418 : Error: failed to erase memory
 16:52:40:441 : Error: failed to erase memory
 16:52:40:441 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
 16:52:41:411 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
 16:52:42:417 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
 16:52:43:421 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091

I've tried different versions of STM32CubeIDE. 1.11.0 and 1.10.0. Both cannot flash my elf file.

How do I get STM32CubeIDE to flash my elf file in external memory too?

This topic has been closed for replies.
Best answer by unsigned_char_array

I have a workaround.

In the linker file I no longer put the external flash after the internal flash:

.textqspi :
 {
 . = ALIGN(4);
 _qspi_start = .; /* create a global symbol at qspi start */
 *(.textqspi) /* .textqspi sections */
 *(.textqspi*) /* .textqspi* sections */
 . = ALIGN(4);
 _qspi_end = .; /* define a global symbols at end of textqspi */
 
 } >QSPI
 /*>QSPI AT> FLASH this didn't work!*/

This changed my elf file from:

Program Headers:
 Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
 LOAD 0x010000 0x08000000 0x08000000 0x002ac 0x002ac R 0x10000
 LOAD 0x020000 0x90000000 0x080002ac 0x00014 0x00014 R 0x10000
 LOAD 0x0202c0 0x080002c0 0x080002c0 0x114240 0x114240 RWE 0x10000
 LOAD 0x140000 0x24000000 0x08114500 0x004e8 0x004e8 RW 0x10000
 LOAD 0x140500 0x24000500 0x081149e8 0x00026 0x00026 RW 0x10000
 LOAD 0x140528 0x24000528 0x08114a0e 0xbb800 0xc8328 RW 0x10000
 LOAD 0x008850 0x240c8850 0x081d020e 0x00000 0x00600 RW 0x10000

to

Program Headers:
 Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
 LOAD 0x010000 0x08000000 0x08000000 0x002ac 0x002ac R 0x10000
 LOAD 0x020000 0x90000000 0x080002ac 0x00014 0x00014 R 0x10000
 LOAD 0x0202c0 0x080002c0 0x080002c0 0x114240 0x114240 RWE 0x10000
 LOAD 0x140000 0x24000000 0x08114500 0x004e8 0x004e8 RW 0x10000
 LOAD 0x140500 0x24000500 0x081149e8 0x00026 0x00026 RW 0x10000
 LOAD 0x140528 0x24000528 0x08114a0e 0xbb800 0xc8328 RW 0x10000
 LOAD 0x008850 0x240c8850 0x081d020e 0x00000 0x00600 RW 0x10000

In my launch file I added the external flash loader and set initialize to disable. I can now flash the elf file with STM32CubeProgrammer and I can debug, but not flash the external flash, in STM32CubeIDE.

I get the following error in STM32CubeIDE:

STMicroelectronics ST-LINK GDB server. Version 7.1.0
Copyright (c) 2022, STMicroelectronics. All rights reserved.
 
Starting server with the following options:
 Persistent Mode : Disabled
 Logging Level : 1
 Listen Port Number : 61234
 Status Refresh Delay : 15s
 Verbose Mode : Disabled
 SWD Debug : Enabled
 
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Failed to initialize external memory
 -------------------------------------------------------------------
 STM32CubeProgrammer v2.12.0 
 -------------------------------------------------------------------
 
 
 
Log output file: C:\Users\user\AppData\Local\Temp\STM32CubeProgrammer_a09844.log
ST-LINK SN : 003000493438510734313939
ST-LINK FW : V3J10M3B5S1
Board : STLINK-V3SET
Voltage : 3.32V
SWD freq : 24000 KHz
Connect mode: Under Reset
Reset mode : Hardware reset
Device ID : 0x480
Revision ID : --
Device name : STM32H7A/B
Flash size : 2 MBytes
Device type : MCU
Device CPU : Cortex-M7
BL Version : 0x91
 
 
 
Memory Programming ...
Opening and parsing file: ST-LINK_GDB_server_a09844.srec
 File : ST-LINK_GDB_server_a09844.srec
 Size : 1.81 MB 
 Address : 0x08000000 
 
 
Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 232]
Erasing memory corresponding to segment 1:
Erasing external memory sector 0
Download in Progress:
 
 
File download complete
Time elapsed during download operation: 00:00:03.561
 
 
 
Verifying ...
 
 
 
 
Download verified successfully 
 
 
Failed to initialize external memory!
Failed to reinitialize device
Shutting down...
Exit.

So it kind of works, but, I wish there is a way to get it working properly.

EDIT: I just discovered it works in STM32CubeIDE. With external memory initialize set to disable it will flash it anyway. But it will crash when I enable it. I don't understand the logic of it, but it works! Somehow there are occasional read errors with the flash chip so I reduced the clock speed from 70MHz to 56MHz

9 replies

unsigned_char_array
Lead III
January 20, 2023

Yes. That's what I did. I added the flash loader to the launch file. I have Enable and Init checked.

"Kudo posts if you have the same problem and kudo replies if the solution works.Click ""Accept as Solution"" if a reply solved your problem. If no solution was posted please answer with your own."
Tesla DeLorean
Guru
January 20, 2023

Seems to be failing on the INTERNAL memory erase.

Would perhaps suspect power supply, or VCAP pins/capacitors.

Any of the memory read/write protected?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
unsigned_char_array
Lead III
January 20, 2023

Hmm. That's odd. STM32CubeIDE can flash the internal FLASH without any issues and so can STM32CubeProgrammer if I don't select external FLASH. Nothing is locked or protected. We have several of our PCBs and they run without any issues, so power problems are unlikely.

"Kudo posts if you have the same problem and kudo replies if the solution works.Click ""Accept as Solution"" if a reply solved your problem. If no solution was posted please answer with your own."