cancel
Showing results for 
Search instead for 
Did you mean: 

Flashing elf file in internal + external memory in STM32CubeIde

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?

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.
1 ACCEPTED SOLUTION

Accepted Solutions

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

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.

View solution in original post

9 REPLIES 9

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
Up vote any posts that you find helpful, it shows what's working..

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.

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.

The STM32 Cube Programmer log shows the erase of 0x08000000 .. 0x081D0000 failing (1.9 MB)

If it is conflicting with your External loader, then perhaps review that, but the log doesn't indicate it is involved, and the internal erase is failing.

The 0xD10 size downloaded to RAM matches the \bin\Flashloader\0x480.stldr for the H7A3

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I read somewhere on this forum that the internal flash loader could cause problems. So I changed my 0x480.stldr loader to a version that was attached to some post. I think this was an older version. It could be that I broke it. But I'm not sure if I changed it for STM32CubeProgrammer or STM32CubeIDE. I'll have to check Monday when I'm in the office again.

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.

0x480.stldr is not the issue, I've put the previous one back (file CRC32: EEC21F52). Flashing internal flash is fine, no issues. It only occurs when I try to flash internal + external.

STM32CubeProgrammer flashing elf file:

09:57:53:977 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
09:57:54:979 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
09:57:55:100 : Memory Programming ...
09:57:55:100 : Opening and parsing file: IDE-Prothese-base.elf
09:57:55:111 :   File          : IDE-Prothese-base.elf
09:57:55:111 :   Size          : 1.81 MB 
09:57:55:111 :   Address       : 0x08000000 
09:57:55:111 : Erasing Segment <0> Address <0x08000000> Size <1901078>Bytes
09:57:55:111 : Erasing memory corresponding to segment 0:
09:57:55:111 : Memory erase...
09:57:55:115 : halt ap 0 
09:57:55:115 : w ap 0 reg 15 PC   (0x24000000)  
09:57:55:115 : w ap 0 reg 17 MSP  (0x24000500)  
09:57:55:115 : w ap 0 reg 16 xPSR (0x01000000)  
09:57:55:115 : w ap 0 @0x24001140 0x00000200 bytes Data 0x00000000
09:57:55:116 : w ap 0 @0x24000000 0x00000004 bytes Data 0x0000BE00
09:57:55:119 : w ap 0 @0x24000004 0x00000D10 bytes Data 0x8F4FF3BF
09:57:55:119 : Erasing internal memory sectors [0 232]
09:57:55:119 : Init flashloader...
09:57:55:119 : halt ap 0 
09:57:55:119 : w ap 0 reg 0 R0   0x00000001
09:57:55:119 : w ap 0 reg 1 R1   0x00000000
09:57:55:119 : w ap 0 reg 2 R2   0x00000000
09:57:55:122 : w ap 0 reg 3 R3   0x00000000
09:57:55:123 : w ap 0 reg 4 R4   0x00000000
09:57:55:124 : w ap 0 reg 5 R5   0x00000000
09:57:55:125 : w ap 0 reg 6 R6   0x00000000
09:57:55:125 : w ap 0 reg 7 R7   0x00000000
09:57:55:125 : w ap 0 reg 8 R8   0x00000000
09:57:55:125 : w ap 0 reg 9 R9   0x00000000
09:57:55:125 : w ap 0 reg 10 R10  0x00000000
09:57:55:125 : w ap 0 reg 11 R11  0x00000000
09:57:55:125 : w ap 0 reg 12 R12  0x00000000
09:57:55:125 : w ap 0 reg 13 SP   0x00000000
09:57:55:125 : w ap 0 reg 14 LR   0x24000001
09:57:55:125 : w ap 0 reg 15 PC   0x2400000B
09:57:55:125 : w ap 0 reg 16 xPSR 0x01000000
09:57:55:125 : w ap 0 reg 17 MSP  0x24001110
09:57:55:125 : w ap 0 reg 18 PSP  0x00000000
09:57:55:125 : run ap 0 
09:57:55:126 : halt ap 0 
09:57:55:126 : r ap 0 reg 0 R0   0x00000001
09:57:55:126 : Loader sector erase...
09:57:55:126 : w ap 0 reg 0 R0   0x08000000
09:57:55:126 : w ap 0 reg 1 R1   0x081D0000
09:57:55:126 : w ap 0 reg 2 R2   0x00000002
09:57:55:126 : w ap 0 reg 3 R3   0x00000000
09:57:55:127 : w ap 0 reg 4 R4   0x00000000
09:57:55:127 : w ap 0 reg 5 R5   0x00000000
09:57:55:127 : w ap 0 reg 6 R6   0x00000000
09:57:55:127 : w ap 0 reg 7 R7   0x00000000
09:57:55:127 : w ap 0 reg 8 R8   0x00000000
09:57:55:127 : w ap 0 reg 9 R9   0x00000000
09:57:55:127 : w ap 0 reg 10 R10  0x00000000
09:57:55:127 : w ap 0 reg 11 R11  0x00000000
09:57:55:128 : w ap 0 reg 12 R12  0x00000000
09:57:55:129 : w ap 0 reg 13 SP   0x00000000
09:57:55:130 : w ap 0 reg 14 LR   0x24000001
09:57:55:131 : w ap 0 reg 15 PC   0x2400086B
09:57:55:132 : w ap 0 reg 16 xPSR 0x01000000
09:57:55:133 : w ap 0 reg 17 MSP  0x24001110
09:57:55:133 : w ap 0 reg 18 PSP  0x00000000
09:57:55:133 : run ap 0 
09:57:55:670 : halt ap 0 
09:57:55:671 : r ap 0 reg 0 R0   0x00000001
09:57:55:671 : erase: 0553ms
09:57:55:671 : Download in Progress:
09:57:55:671 :   Size          : 1901088 Bytes
09:57:55:671 :   Address       : 0x08000000 
09:57:55:671 : Buffer program...
09:57:55:671 : halt ap 0 
09:57:55:671 : w ap 0 reg 15 PC   (0x24000000)  
09:57:55:671 : w ap 0 reg 17 MSP  (0x24000500)  
09:57:55:671 : w ap 0 reg 16 xPSR (0x01000000)  
09:57:55:671 : w ap 0 @0x24001140 0x00000200 bytes Data 0x00000000
09:57:55:671 : w ap 0 @0x24000000 0x00000004 bytes Data 0x0000BE00
09:57:55:672 : w ap 0 @0x24000004 0x00000D10 bytes Data 0x8F4FF3BF
09:57:55:673 : Loader write range...
09:57:56:279 : w ap 0 @0x24001140 0x0007F600 bytes Data 0x24100000
09:57:56:280 : W B1 in RAM @0x24001140 size 0x0007F600 : 0608ms
09:57:56:280 : Init flashloader...
09:57:56:282 : halt ap 0 
09:57:56:283 : w ap 0 reg 0 R0   0x00000001
09:57:56:283 : w ap 0 reg 1 R1   0x00000000
09:57:56:283 : w ap 0 reg 2 R2   0x00000000
09:57:56:283 : w ap 0 reg 3 R3   0x00000000
09:57:56:283 : w ap 0 reg 4 R4   0x00000000
09:57:56:283 : w ap 0 reg 5 R5   0x00000000
09:57:56:283 : w ap 0 reg 6 R6   0x00000000
09:57:56:283 : w ap 0 reg 7 R7   0x00000000
09:57:56:283 : w ap 0 reg 8 R8   0x00000000
09:57:56:284 : w ap 0 reg 9 R9   0x00000000
09:57:56:284 : w ap 0 reg 10 R10  0x00000000
09:57:56:284 : w ap 0 reg 11 R11  0x00000000
09:57:56:285 : w ap 0 reg 12 R12  0x00000000
09:57:56:285 : w ap 0 reg 13 SP   0x00000000
09:57:56:285 : w ap 0 reg 14 LR   0x24000001
09:57:56:285 : w ap 0 reg 15 PC   0x2400000B
09:57:56:287 : w ap 0 reg 16 xPSR 0x01000000
09:57:56:288 : w ap 0 reg 17 MSP  0x24001110
09:57:56:289 : w ap 0 reg 18 PSP  0x00000000
09:57:56:289 : run ap 0 
09:57:56:290 : halt ap 0 
09:57:56:291 : r ap 0 reg 0 R0   0x00000001
09:57:56:291 : w ap 0 reg 0 R0   0x08000000
09:57:56:291 : w ap 0 reg 1 R1   0x0007F600
09:57:56:291 : w ap 0 reg 2 R2   0x24001140
09:57:56:291 : w ap 0 reg 3 R3   0x00000002
09:57:56:291 : w ap 0 reg 4 R4   0x00000000
09:57:56:291 : w ap 0 reg 5 R5   0x00000000
09:57:56:292 : w ap 0 reg 6 R6   0x00000000
09:57:56:292 : w ap 0 reg 7 R7   0x00000000
09:57:56:292 : w ap 0 reg 8 R8   0x00000000
09:57:56:292 : w ap 0 reg 9 R9   0x00000000
09:57:56:295 : w ap 0 reg 10 R10  0x00000000
09:57:56:295 : w ap 0 reg 11 R11  0x00000000
09:57:56:295 : w ap 0 reg 12 R12  0x00000000
09:57:56:296 : w ap 0 reg 13 SP   0x00000000
09:57:56:296 : w ap 0 reg 14 LR   0x24000001
09:57:56:297 : w ap 0 reg 15 PC   0x24000079
09:57:56:297 : w ap 0 reg 16 xPSR 0x01000000
09:57:56:298 : w ap 0 reg 17 MSP  0x24001110
09:57:56:298 : w ap 0 reg 18 PSP  0x00000000
09:57:56:298 : run ap 0 
09:57:56:895 : w ap 0 @0x24080740 0x0007F600 bytes Data 0x39D231D2
09:57:56:895 : W B2 in RAM @0x24080740 size 0x0007F600: 0616ms
09:57:56:959 : r ap 0 reg 0 R0   0x00000001
09:57:56:959 : Wait W B1 in Flash @0x08000000 size 0x0007F600: 0064ms
09:57:56:961 : w ap 0 reg 0 R0   0x0807F600
09:57:56:961 : w ap 0 reg 1 R1   0x0007F600
09:57:56:961 : w ap 0 reg 2 R2   0x24080740
09:57:56:961 : w ap 0 reg 3 R3   0x00000002
09:57:56:961 : w ap 0 reg 4 R4   0x00000000
09:57:56:961 : w ap 0 reg 5 R5   0x00000000
09:57:56:962 : w ap 0 reg 6 R6   0x00000000
09:57:56:962 : w ap 0 reg 7 R7   0x00000000
09:57:56:963 : w ap 0 reg 8 R8   0x00000000
09:57:56:963 : w ap 0 reg 9 R9   0x00000000
09:57:56:963 : w ap 0 reg 10 R10  0x00000000
09:57:56:964 : w ap 0 reg 11 R11  0x00000000
09:57:56:964 : w ap 0 reg 12 R12  0x00000000
09:57:56:964 : w ap 0 reg 13 SP   0x00000000
09:57:56:964 : w ap 0 reg 14 LR   0x24000001
09:57:56:965 : w ap 0 reg 15 PC   0x24000079
09:57:56:965 : w ap 0 reg 16 xPSR 0x01000000
09:57:56:965 : w ap 0 reg 17 MSP  0x24001110
09:57:56:965 : w ap 0 reg 18 PSP  0x00000000
09:57:56:965 : run ap 0 
09:57:57:462 : w ap 0 @0x24001140 0x00068B20 bytes Data 0xFFFFFFFF
09:57:57:462 : W B1 in RAM @0x24001140 size 0x00068B20 : 0499ms
09:57:57:465 : halt ap 0 
09:57:57:465 : r ap 0 reg 0 R0   0x00000001
09:57:57:465 : Wait W B2 in flash @0x0807F600 size 0x0007F600: 0001ms
09:57:57:465 : w ap 0 reg 0 R0   0x080FEC00
09:57:57:465 : w ap 0 reg 1 R1   0x00068B20
09:57:57:466 : w ap 0 reg 2 R2   0x24001140
09:57:57:466 : w ap 0 reg 3 R3   0x00000002
09:57:57:466 : w ap 0 reg 4 R4   0x00000000
09:57:57:466 : w ap 0 reg 5 R5   0x00000000
09:57:57:467 : w ap 0 reg 6 R6   0x00000000
09:57:57:467 : w ap 0 reg 7 R7   0x00000000
09:57:57:468 : w ap 0 reg 8 R8   0x00000000
09:57:57:469 : w ap 0 reg 9 R9   0x00000000
09:57:57:469 : w ap 0 reg 10 R10  0x00000000
09:57:57:469 : w ap 0 reg 11 R11  0x00000000
09:57:57:470 : w ap 0 reg 12 R12  0x00000000
09:57:57:470 : w ap 0 reg 13 SP   0x00000000
09:57:57:470 : w ap 0 reg 14 LR   0x24000001
09:57:57:470 : w ap 0 reg 15 PC   0x24000079
09:57:57:470 : w ap 0 reg 16 xPSR 0x01000000
09:57:57:470 : w ap 0 reg 17 MSP  0x24001110
09:57:57:471 : w ap 0 reg 18 PSP  0x00000000
09:57:57:471 : run ap 0 
09:57:57:962 : w ap 0 @0x24069C60 0x00068B00 bytes Data 0x00000000
09:57:57:962 : W B2 in RAM @0x24080740 size 0x00068B00: 0499ms
09:57:57:996 : r ap 0 reg 0 R0   0x00000001
09:57:57:996 : Wait W B1 in Flash @0x080FEC00 size 0x00068B20: 0034ms
09:57:57:997 : w ap 0 reg 0 R0   0x08167720
09:57:57:997 : w ap 0 reg 1 R1   0x00068B00
09:57:57:997 : w ap 0 reg 2 R2   0x24069C60
09:57:57:997 : w ap 0 reg 3 R3   0x00000002
09:57:57:997 : w ap 0 reg 4 R4   0x00000000
09:57:57:999 : w ap 0 reg 5 R5   0x00000000
09:57:57:999 : w ap 0 reg 6 R6   0x00000000
09:57:57:999 : w ap 0 reg 7 R7   0x00000000
09:57:57:999 : w ap 0 reg 8 R8   0x00000000
09:57:58:000 : w ap 0 reg 9 R9   0x00000000
09:57:58:001 : w ap 0 reg 10 R10  0x00000000
09:57:58:001 : w ap 0 reg 11 R11  0x00000000
09:57:58:001 : w ap 0 reg 12 R12  0x00000000
09:57:58:001 : w ap 0 reg 13 SP   0x00000000
09:57:58:001 : w ap 0 reg 14 LR   0x24000001
09:57:58:001 : w ap 0 reg 15 PC   0x24000079
09:57:58:005 : w ap 0 reg 16 xPSR 0x01000000
09:57:58:006 : w ap 0 reg 17 MSP  0x24001110
09:57:58:006 : w ap 0 reg 18 PSP  0x00000000
09:57:58:007 : run ap 0 
09:57:58:562 : r ap 0 reg 0 R0   0x00000001
09:57:58:562 : Write elapsed time: 2891ms
09:57:58:562 : Segment[0] downloaded successfully
09:57:58:562 : File download complete
09:57:58:572 : Time elapsed during download operation: 00:00:03.451
09:57:58:574 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
09:57:59:569 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
09:58:00:575 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091

After this no external flash was programmed. STM32CubeProgrammer doesn't flash external flash from elf file! I can flash a seperate bin file.

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.

Bin file flashing

10:06:59:467 : Error: Connection to target must be established before performing file download operation.
10:07:02:276 : ST-LINK SN  : 003000493438510734313939
10:07:02:276 : ST-LINK FW  : V3J10M3B5S1
10:07:02:277 : Board       : STLINK-V3SET
10:07:02:277 : Voltage     : 3.28V
10:07:02:281 : SWD freq    : 24000 KHz
10:07:02:282 : Connect mode: Normal
10:07:02:282 : Reset mode  : Software reset
10:07:02:283 : Device ID   : 0x480
10:07:02:284 : Revision ID : --
10:07:02:288 : Buffer program...
10:07:02:288 : w ap 0 @0x580244F4 0x00000004 bytes Data 0x00000002
10:07:02:288 : Reading data...
10:07:02:288 : r ap 0 @0x08FFF80C 0x00000004 bytes Data 0x00060800
10:07:02:288 : Buffer program...
10:07:02:289 : w ap 0 @0x580244F4 0x00000004 bytes Data 0x00000002
10:07:02:289 : Reading data...
10:07:02:289 : r ap 0 @0x08FFF80C 0x00000004 bytes Data 0x00060800
10:07:02:289 : Buffer program...
10:07:02:289 : w ap 0 @0x580244F4 0x00000004 bytes Data 0x00000002
10:07:02:289 : Reading data...
10:07:02:290 : r ap 0 @0x58000528 0x00000004 bytes Data 0x00000000
10:07:02:290 : Database: Config 0 is active.
10:07:02:290 : flash loader C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin/FlashLoader/0x480.stldr is loaded
10:07:02:290 : Debug in Low Power mode is not supported for this device.
10:07:02:290 : Reading data...
10:07:02:291 : r ap 0 @0x08FFF80C 0x00000004 bytes Data 0x00060800
10:07:02:291 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
10:07:02:370 : Selected loader: C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin/ExternalLoader/STM32H7A3ZIT6Q_MT25TL256.stldr
10:07:02:370 : Selected loader: C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin/ExternalLoader/STM32H7A3ZIT6Q_MT25TL256.stldr
10:07:02:370 : External loader C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin/ExternalLoader/STM32H7A3ZIT6Q_MT25TL256.stldr is loaded
10:07:02:370 : Selected loader: C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin/ExternalLoader/STM32H7A3ZIT6Q_MT25TL256.stldr
10:07:02:370 : External loader C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin/ExternalLoader/STM32H7A3ZIT6Q_MT25TL256.stldr is loaded
10:07:02:370 : UPLOADING OPTION BYTES DATA ...
10:07:02:370 :   Bank          : 0x00
10:07:02:370 :   Address       : 0x5200201c
10:07:02:370 :   Size          : 308 Bytes
10:07:02:370 : Reading data...
10:07:02:370 : r ap 0 @0x5200201C 0x00000134 bytes Data 0x0006AAD0
10:07:02:370 : UPLOADING OPTION BYTES DATA ...
10:07:02:371 :   Bank          : 0x00
10:07:02:371 :   Address       : 0x5200201c
10:07:02:371 :   Size          : 308 Bytes
10:07:02:371 : Reading data...
10:07:02:371 : r ap 0 @0x5200201C 0x00000134 bytes Data 0x0006AAD0
10:07:02:371 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
10:07:02:371 : UPLOADING ...
10:07:02:371 :   Size          : 1024 Bytes
10:07:02:371 :   Address       : 0x90000000
10:07:02:371 : Read progress:
10:07:02:371 : Reading data...
10:07:02:371 : halt ap 0 
10:07:02:371 : w ap 0 reg 15 PC   (0x24000000)  
10:07:02:371 : w ap 0 reg 17 MSP  (0x24000500)  
10:07:02:371 : w ap 0 reg 16 xPSR (0x01000000)  
10:07:02:371 : w ap 0 @0x24003E20 0x00000200 bytes Data 0x00000000
10:07:02:371 : w ap 0 @0x24000000 0x00000004 bytes Data 0x0000BE00
10:07:02:381 : w ap 0 @0x24000004 0x000039E8 bytes Data 0x00000000
10:07:02:381 : Init flashloader...
10:07:02:381 : halt ap 0 
10:07:02:381 : w ap 0 reg 0 R0   0x00000000
10:07:02:381 : w ap 0 reg 1 R1   0x00000000
10:07:02:382 : w ap 0 reg 2 R2   0x00000000
10:07:02:382 : w ap 0 reg 3 R3   0x00000000
10:07:02:382 : w ap 0 reg 4 R4   0x00000000
10:07:02:383 : w ap 0 reg 5 R5   0x00000000
10:07:02:383 : w ap 0 reg 6 R6   0x00000000
10:07:02:383 : w ap 0 reg 7 R7   0x00000000
10:07:02:383 : w ap 0 reg 8 R8   0x00000000
10:07:02:384 : w ap 0 reg 9 R9   0x00000000
10:07:02:384 : w ap 0 reg 10 R10  0x00000000
10:07:02:384 : w ap 0 reg 11 R11  0x00000000
10:07:02:384 : w ap 0 reg 12 R12  0x00000000
10:07:02:384 : w ap 0 reg 13 SP   0x00000000
10:07:02:385 : w ap 0 reg 14 LR   0x24000001
10:07:02:385 : w ap 0 reg 15 PC   0x2400071D
10:07:02:385 : w ap 0 reg 16 xPSR 0x01000000
10:07:02:385 : w ap 0 reg 17 MSP  0x24003DE8
10:07:02:385 : w ap 0 reg 18 PSP  0x00000000
10:07:02:386 : run ap 0 
10:07:02:388 : halt ap 0 
10:07:02:389 : r ap 0 reg 0 R0   0x00000001
10:07:02:392 : r ap 0 @0x90000000 0x00000400 bytes Data 0x00000000
10:07:02:392 : Data read successfully
10:07:02:392 : Time elapsed during the read operation is: 00:00:00.032
10:07:02:393 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
10:07:03:396 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
10:07:04:404 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
10:07:05:410 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
10:07:06:417 : r ap 0 @0x1FF13FFE 0x00000004 bytes Data 0xFFFF0091
10:07:07:091 : Disconnected
10:07:07:091 : Disconnected from device.

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.

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

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.