cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G491 does not start from RAM (in debug mode) - External loader problem

LehuW
Associate

Hi,

I am working on an external loader for STM32G491.
For STM32F4 series microcontroller, everything works fine, but STM32G491 does not work.
I observed that the external loader program is loaded into RAM, but does not execute.
I did some tests with running the program from RAM in debug mode.
I observed that if the FLASH memory is erased then the program loaded into RAM does not want to start (see image below).


If there is any previous running program in FLASH memory, then loading the test program into RAM and running it with the debugger works fine.
For STM32F4 series microcontroller, I can always run the program from RAM ( also for deleted FLASH memory - which seems to be normal).

The problem with the external loader is that the debugger initially deletes the processor's FLASH memory, then using the external loader to erase the external memory, but the external loader no longer works, because the FLASH memory is deleted.

I use CubeIDE Version: 1.14.0  &  HAL library

 

LehuW_1-1734817470428.png

 

 

 Start of the linker file:

 

/* Entry Point */
ENTRY(Init)

/* Generate 2 segment for Loader code and device info */
PHDRS {Loader PT_LOAD ; SgInfo PT_LOAD ; }

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM);    /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x200 ;      /* required amount of heap  */
_Min_Stack_Size = 0x400 ; /* required amount of stack */

/* Specify the memory areas */
MEMORY
{
RAM (xrw)      : ORIGIN = 0x20000004, LENGTH = 112K
}

 

 

 

What did I miss?
Any ideas?

 

Best regards,

Lehu

 

 

10 REPLIES 10
Saket_Om
ST Employee

Hello @LehuW 

Could you share with us the source code please? 

Is the code in internal flash initialize the external flash?

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

I did some additional tests.

I think the main problem is on the side of the ST-LINK programmer.
I have a log of the programming process.

At the beginning the FLASH memory of the processor is erased - address 0x8000000.
From address 0x20000004 the debugger loads 0x000007A0 bytes of the loader with which it will erase the internal FLASH memory.
Next sets PC 0x20000005 and starts the erase procedure.
Next proceeds to erase the external flash memory.

Next loader starts to erase external mamory.  (Erasing Segment <1> Address <0x90000000> Size <37>Bytes)

Sets PC 0x200006C1 and starts erasing.

But what is at address 0x200006C1 ?
The external loader has not been loaded.

From .map file we know that the Init() function of the external loader is at address 0x200006C1 (.text.Init 0x00000000200006c0 0x88 ./Core/Src/Loader_Src.o), but it has not been loaded.

[6.621] spawnCubeProgrammer():  18:39:39:779 Memory Programming ...
[6.621] spawnCubeProgrammer():  18:39:39:779 Opening and parsing file: ST-LINK_GDB_server_a05132.srec
[6.621] spawnCubeProgrammer():  18:39:39:780   File          : ST-LINK_GDB_server_a05132.srec
[6.621] spawnCubeProgrammer():  18:39:39:780   Size          : 7.56 KB 
[6.621] spawnCubeProgrammer():  18:39:39:780   Address       : 0x08000000 
[6.621] spawnCubeProgrammer():  18:39:39:780 
[6.621] spawnCubeProgrammer():  
[6.621] spawnCubeProgrammer():  18:39:39:780 Erasing Segment <0> Address <0x08000000> Size <7708>Bytes
[6.621] spawnCubeProgrammer():  18:39:39:780 Erasing memory corresponding to segment 0:
[6.621] spawnCubeProgrammer():  18:39:39:780 Memory Erase via FlashLoader!
[6.621] spawnCubeProgrammer():  18:39:39:780 Memory erase...
[6.621] spawnCubeProgrammer():  18:39:39:782 halt ap 0 
[6.621] spawnCubeProgrammer():  18:39:39:782 w ap 0 reg 15 PC   (0x20000000)  
[6.621] spawnCubeProgrammer():  18:39:39:782 w ap 0 reg 17 MSP  (0x20000500)  
[6.621] spawnCubeProgrammer():  18:39:39:783 w ap 0 reg 16 xPSR (0x01000000)  
[6.621] spawnCubeProgrammer():  18:39:39:785 w ap 0 @0x20000BE0 : 0x00000200 bytes, Data 0x00000000...
[6.621] spawnCubeProgrammer():  18:39:39:785 w ap 0 @0x20000000 : 0x00000004 bytes, Data 0x0000BE00...
[6.621] spawnCubeProgrammer():  18:39:39:787 w ap 0 @0x20000004 : 0x000007A0 bytes, Data 0xF000B580...
[6.621] spawnCubeProgrammer():  18:39:39:789 Erasing internal memory sectors [0 3]
[6.621] spawnCubeProgrammer():  18:39:39:789 Init flashloader...
[6.621] spawnCubeProgrammer():  18:39:39:790 halt ap 0 
[6.621] spawnCubeProgrammer():  18:39:39:790 w ap 0 reg 0 R0   0x00000001
[6.621] spawnCubeProgrammer():  18:39:39:790 w ap 0 reg 1 R1   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:790 w ap 0 reg 2 R2   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:790 w ap 0 reg 3 R3   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:790 w ap 0 reg 4 R4   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:791 w ap 0 reg 5 R5   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:791 w ap 0 reg 6 R6   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:791 w ap 0 reg 7 R7   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:792 w ap 0 reg 8 R8   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:792 w ap 0 reg 9 R9   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:792 w ap 0 reg 10 R10  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:792 w ap 0 reg 11 R11  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:792 w ap 0 reg 12 R12  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:793 w ap 0 reg 13 SP   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:793 w ap 0 reg 14 LR   0x20000001
[6.621] spawnCubeProgrammer():  18:39:39:793 w ap 0 reg 15 PC   0x20000005
[6.621] spawnCubeProgrammer():  18:39:39:793 w ap 0 reg 16 xPSR 0x01000000
[6.621] spawnCubeProgrammer():  18:39:39:793 w ap 0 reg 17 MSP  0x20000BA0
[6.621] spawnCubeProgrammer():  18:39:39:793 w ap 0 reg 18 PSP  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:793 run ap 0 
[6.621] spawnCubeProgrammer():  18:39:39:794 halt ap 0 
[6.621] spawnCubeProgrammer():  18:39:39:794 r ap 0 reg 0 R0   0x00000001
[6.621] spawnCubeProgrammer():  18:39:39:794 Loader sector erase...
[6.621] spawnCubeProgrammer():  18:39:39:794 w ap 0 reg 0 R0   0x08000000
[6.621] spawnCubeProgrammer():  18:39:39:795 w ap 0 reg 1 R1   0x08001800
[6.621] spawnCubeProgrammer():  18:39:39:795 w ap 0 reg 2 R2   0x00000002
[6.621] spawnCubeProgrammer():  18:39:39:795 w ap 0 reg 3 R3   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:795 w ap 0 reg 4 R4   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:795 w ap 0 reg 5 R5   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:796 w ap 0 reg 6 R6   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:796 w ap 0 reg 7 R7   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:796 w ap 0 reg 8 R8   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:796 w ap 0 reg 9 R9   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:797 w ap 0 reg 10 R10  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:797 w ap 0 reg 11 R11  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:797 w ap 0 reg 12 R12  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:797 w ap 0 reg 13 SP   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:797 w ap 0 reg 14 LR   0x20000001
[6.621] spawnCubeProgrammer():  18:39:39:798 w ap 0 reg 15 PC   0x2000038B
[6.621] spawnCubeProgrammer():  18:39:39:798 w ap 0 reg 16 xPSR 0x01000000
[6.621] spawnCubeProgrammer():  18:39:39:798 w ap 0 reg 17 MSP  0x20000BA0
[6.621] spawnCubeProgrammer():  18:39:39:798 w ap 0 reg 18 PSP  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:798 run ap 0 
[6.621] spawnCubeProgrammer():  18:39:39:886 halt ap 0 
[6.621] spawnCubeProgrammer():  18:39:39:886 r ap 0 reg 0 R0   0x00000001
[6.621] spawnCubeProgrammer():  18:39:39:886 erase: 0106ms
[6.621] spawnCubeProgrammer():  18:39:39:886 Erasing Segment <1> Address <0x90000000> Size <37>Bytes
[6.621] spawnCubeProgrammer():  18:39:39:886 Erasing memory corresponding to segment 1:
[6.621] spawnCubeProgrammer():  18:39:39:886 Memory Erase via FlashLoader!
[6.621] spawnCubeProgrammer():  18:39:39:886 Memory erase...
[6.621] spawnCubeProgrammer():  18:39:39:888 halt ap 0 
[6.621] spawnCubeProgrammer():  18:39:39:888 w ap 0 reg 15 PC   (0x20000000)  
[6.621] spawnCubeProgrammer():  18:39:39:889 w ap 0 reg 17 MSP  (0x20000500)  
[6.621] spawnCubeProgrammer():  18:39:39:889 w ap 0 reg 16 xPSR (0x01000000)  
[6.621] spawnCubeProgrammer():  18:39:39:889 Erasing external memory sectors [0 4]
[6.621] spawnCubeProgrammer():  18:39:39:889 Init flashloader...
[6.621] spawnCubeProgrammer():  18:39:39:889 halt ap 0 
[6.621] spawnCubeProgrammer():  18:39:39:890 w ap 0 reg 0 R0   0x00000001
[6.621] spawnCubeProgrammer():  18:39:39:890 w ap 0 reg 1 R1   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:890 w ap 0 reg 2 R2   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:890 w ap 0 reg 3 R3   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:890 w ap 0 reg 4 R4   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:891 w ap 0 reg 5 R5   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:891 w ap 0 reg 6 R6   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:891 w ap 0 reg 7 R7   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:891 w ap 0 reg 8 R8   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:891 w ap 0 reg 9 R9   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:892 w ap 0 reg 10 R10  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:892 w ap 0 reg 11 R11  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:892 w ap 0 reg 12 R12  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:892 w ap 0 reg 13 SP   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:892 w ap 0 reg 14 LR   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:892 w ap 0 reg 15 PC   0x200006C1
[6.621] spawnCubeProgrammer():  18:39:39:893 w ap 0 reg 16 xPSR 0x01000000
[6.621] spawnCubeProgrammer():  18:39:39:894 w ap 0 reg 17 MSP  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:894 w ap 0 reg 18 PSP  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:894 run ap 0 
[6.621] spawnCubeProgrammer():  18:39:39:894 halt ap 0 

 

If I do the same test for the STM32F4 processor after erase the internal FLASH memory the external loader is loaded into RAM and then the external memory is erased - lines 73...78 below.

 

[19.541] spawnCubeProgrammer():  18:19:31:154 Memory Programming ...
[19.541] spawnCubeProgrammer():  18:19:31:154 Opening and parsing file: ST-LINK_GDB_server_a11700.srec
[19.541] spawnCubeProgrammer():  18:19:31:155   File          : ST-LINK_GDB_server_a11700.srec
[19.541] spawnCubeProgrammer():  18:19:31:155   Size          : 30.91 KB 
[19.541] spawnCubeProgrammer():  18:19:31:155   Address       : 0x08000000 
[19.541] spawnCubeProgrammer():  18:19:31:155 
[19.541] spawnCubeProgrammer():  
[19.541] spawnCubeProgrammer():  18:19:31:155 Erasing Segment <0> Address <0x08000000> Size <31612>Bytes
[19.541] spawnCubeProgrammer():  18:19:31:155 Erasing memory corresponding to segment 0:
[19.541] spawnCubeProgrammer():  18:19:31:156 Memory Erase via FlashLoader!
[19.541] spawnCubeProgrammer():  18:19:31:156 Memory erase...
[19.541] spawnCubeProgrammer():  18:19:31:159 halt ap 0 
[19.541] spawnCubeProgrammer():  18:19:31:159 w ap 0 reg 15 PC   (0x20000000)  
[19.541] spawnCubeProgrammer():  18:19:31:159 w ap 0 reg 17 MSP  (0x20000500)  
[19.541] spawnCubeProgrammer():  18:19:31:160 w ap 0 reg 16 xPSR (0x01000000)  
[19.541] spawnCubeProgrammer():  18:19:31:164 w ap 0 @0x20001160 : 0x00000200 bytes, Data 0x00000000...
[19.541] spawnCubeProgrammer():  18:19:31:165 w ap 0 @0x20000000 : 0x00000004 bytes, Data 0x0000BE00...
[19.541] spawnCubeProgrammer():  18:19:31:188 w ap 0 @0x20000004 : 0x00000D38 bytes, Data 0xF000B580...
[19.541] spawnCubeProgrammer():  18:19:31:191 Erasing internal memory sectors [0 1]
[19.541] spawnCubeProgrammer():  18:19:31:191 Init flashloader...
[19.541] spawnCubeProgrammer():  18:19:31:192 halt ap 0 
[19.541] spawnCubeProgrammer():  18:19:31:194 w ap 0 reg 0 R0   0x00000001
[19.541] spawnCubeProgrammer():  18:19:31:195 w ap 0 reg 1 R1   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:196 w ap 0 reg 2 R2   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:197 w ap 0 reg 3 R3   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:198 w ap 0 reg 4 R4   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:199 w ap 0 reg 5 R5   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:200 w ap 0 reg 6 R6   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:201 w ap 0 reg 7 R7   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:202 w ap 0 reg 8 R8   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:203 w ap 0 reg 9 R9   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:204 w ap 0 reg 10 R10  0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:205 w ap 0 reg 11 R11  0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:206 w ap 0 reg 12 R12  0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:207 w ap 0 reg 13 SP   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:207 w ap 0 reg 14 LR   0x20000001
[19.541] spawnCubeProgrammer():  18:19:31:208 w ap 0 reg 15 PC   0x20000005
[19.541] spawnCubeProgrammer():  18:19:31:208 w ap 0 reg 16 xPSR 0x01000000
[19.541] spawnCubeProgrammer():  18:19:31:209 w ap 0 reg 17 MSP  0x20001138
[19.541] spawnCubeProgrammer():  18:19:31:210 w ap 0 reg 18 PSP  0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:210 run ap 0 
[19.541] spawnCubeProgrammer():  18:19:31:212 halt ap 0 
[19.541] spawnCubeProgrammer():  18:19:31:212 r ap 0 reg 0 R0   0x00000001
[19.541] spawnCubeProgrammer():  18:19:31:212 Loader sector erase...
[19.541] spawnCubeProgrammer():  18:19:31:214 w ap 0 reg 0 R0   0x08000000
[19.541] spawnCubeProgrammer():  18:19:31:214 w ap 0 reg 1 R1   0x08004000
[19.541] spawnCubeProgrammer():  18:19:31:215 w ap 0 reg 2 R2   0x00000002
[19.541] spawnCubeProgrammer():  18:19:31:216 w ap 0 reg 3 R3   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:217 w ap 0 reg 4 R4   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:217 w ap 0 reg 5 R5   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:218 w ap 0 reg 6 R6   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:219 w ap 0 reg 7 R7   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:220 w ap 0 reg 8 R8   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:220 w ap 0 reg 9 R9   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:221 w ap 0 reg 10 R10  0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:222 w ap 0 reg 11 R11  0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:223 w ap 0 reg 12 R12  0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:223 w ap 0 reg 13 SP   0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:224 w ap 0 reg 14 LR   0x20000001
[19.541] spawnCubeProgrammer():  18:19:31:225 w ap 0 reg 15 PC   0x2000022B
[19.541] spawnCubeProgrammer():  18:19:31:225 w ap 0 reg 16 xPSR 0x01000000
[19.541] spawnCubeProgrammer():  18:19:31:226 w ap 0 reg 17 MSP  0x20001138
[19.541] spawnCubeProgrammer():  18:19:31:227 w ap 0 reg 18 PSP  0x00000000
[19.541] spawnCubeProgrammer():  18:19:31:227 run ap 0 
[19.541] spawnCubeProgrammer():  18:19:31:768 halt ap 0 
[19.541] spawnCubeProgrammer():  18:19:31:768 r ap 0 reg 0 R0   0x00000001
[19.541] spawnCubeProgrammer():  18:19:31:768 erase: 0612ms
[19.541] spawnCubeProgrammer():  18:19:31:768 Erasing Segment <1> Address <0x70000000> Size <37>Bytes
[19.541] spawnCubeProgrammer():  18:19:31:769 Erasing memory corresponding to segment 1:
[19.541] spawnCubeProgrammer():  18:19:31:769 Memory Erase via FlashLoader!
[19.541] spawnCubeProgrammer():  18:19:31:769 Memory erase...
[19.541] spawnCubeProgrammer():  18:19:31:771 halt ap 0 
[19.541] spawnCubeProgrammer():  18:19:31:771 w ap 0 reg 15 PC   (0x20000000)  
[19.541] spawnCubeProgrammer():  18:19:31:772 w ap 0 reg 17 MSP  (0x20000500)  
[19.541] spawnCubeProgrammer():  18:19:31:772 w ap 0 reg 16 xPSR (0x01000000)  
[19.541] spawnCubeProgrammer():  18:19:31:776 w ap 0 @0x20008340 : 0x00000200 bytes, Data 0x00000000...
[19.541] spawnCubeProgrammer():  18:19:31:776 w ap 0 @0x20000000 : 0x00000004 bytes, Data 0x0000BE00...
[19.541] spawnCubeProgrammer():  18:19:32:001 w ap 0 @0x20000004 : 0x00007F18 bytes, Data 0x00000000...
[19.541] spawnCubeProgrammer():  18:19:32:001 Erasing external memory sectors [0 4]
[19.541] spawnCubeProgrammer():  18:19:32:001 Init flashloader...
[19.541] spawnCubeProgrammer():  18:19:32:002 halt ap 0 
[19.541] spawnCubeProgrammer():  18:19:32:003 w ap 0 reg 0 R0   0x00000001
[19.541] spawnCubeProgrammer():  18:19:32:004 w ap 0 reg 1 R1   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:005 w ap 0 reg 2 R2   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:006 w ap 0 reg 3 R3   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:007 w ap 0 reg 4 R4   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:008 w ap 0 reg 5 R5   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:008 w ap 0 reg 6 R6   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:009 w ap 0 reg 7 R7   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:009 w ap 0 reg 8 R8   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:010 w ap 0 reg 9 R9   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:012 w ap 0 reg 10 R10  0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:012 w ap 0 reg 11 R11  0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:012 w ap 0 reg 12 R12  0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:014 w ap 0 reg 13 SP   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:014 w ap 0 reg 14 LR   0x20000001
[19.541] spawnCubeProgrammer():  18:19:32:015 w ap 0 reg 15 PC   0x20000991
[19.541] spawnCubeProgrammer():  18:19:32:017 w ap 0 reg 16 xPSR 0x01000000
[19.541] spawnCubeProgrammer():  18:19:32:017 w ap 0 reg 17 MSP  0x20008318
[19.541] spawnCubeProgrammer():  18:19:32:017 w ap 0 reg 18 PSP  0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:018 run ap 0 
[19.541] spawnCubeProgrammer():  18:19:33:791 halt ap 0 

 

 

 

How can I fix this?

 

 

 

>>How can I fix this?

Remove the Internal Flash content from your External Application?

The linker script for that is evidently describing FLASH content at 0x08000000

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

The problem is that the debugger/programmer/ST-LINK does not load the external loader into RAM before calling the Init(), SectorErase(), Write() functions.  (Or, I'm wrong).

From .map file I know that the Init() function of the external loader is at address 0x200006C1. ST-LINK try to run this function (line 27 of the log below). But I think the external loader functions are not loaded in to ram. 

If I compare it with the procedure that ST-LINK performs for STM32F4, the operation of loading the external loader into RAM is missing. Please see the log for STM32F4 (lines (10..12).

 

 

Log for STM32G4

[6.621] spawnCubeProgrammer():  18:39:39:886 Erasing Segment <1> Address <0x90000000> Size <37>Bytes
[6.621] spawnCubeProgrammer():  18:39:39:886 Erasing memory corresponding to segment 1:
[6.621] spawnCubeProgrammer():  18:39:39:886 Memory Erase via FlashLoader!
[6.621] spawnCubeProgrammer():  18:39:39:886 Memory erase...
[6.621] spawnCubeProgrammer():  18:39:39:888 halt ap 0 
[6.621] spawnCubeProgrammer():  18:39:39:888 w ap 0 reg 15 PC   (0x20000000)  
[6.621] spawnCubeProgrammer():  18:39:39:889 w ap 0 reg 17 MSP  (0x20000500)  
[6.621] spawnCubeProgrammer():  18:39:39:889 w ap 0 reg 16 xPSR (0x01000000)  
[6.621] spawnCubeProgrammer():  18:39:39:889 Erasing external memory sectors [0 4]
[6.621] spawnCubeProgrammer():  18:39:39:889 Init flashloader...
[6.621] spawnCubeProgrammer():  18:39:39:889 halt ap 0 
[6.621] spawnCubeProgrammer():  18:39:39:890 w ap 0 reg 0 R0   0x00000001
[6.621] spawnCubeProgrammer():  18:39:39:890 w ap 0 reg 1 R1   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:890 w ap 0 reg 2 R2   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:890 w ap 0 reg 3 R3   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:890 w ap 0 reg 4 R4   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:891 w ap 0 reg 5 R5   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:891 w ap 0 reg 6 R6   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:891 w ap 0 reg 7 R7   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:891 w ap 0 reg 8 R8   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:891 w ap 0 reg 9 R9   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:892 w ap 0 reg 10 R10  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:892 w ap 0 reg 11 R11  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:892 w ap 0 reg 12 R12  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:892 w ap 0 reg 13 SP   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:892 w ap 0 reg 14 LR   0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:892 w ap 0 reg 15 PC   0x200006C1
[6.621] spawnCubeProgrammer():  18:39:39:893 w ap 0 reg 16 xPSR 0x01000000
[6.621] spawnCubeProgrammer():  18:39:39:894 w ap 0 reg 17 MSP  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:894 w ap 0 reg 18 PSP  0x00000000
[6.621] spawnCubeProgrammer():  18:39:39:894 run ap 0 

 

 

If I do it on STM32F4 the same procedure looks like this:

[19.541] spawnCubeProgrammer():  18:19:31:768 Erasing Segment <1> Address <0x70000000> Size <37>Bytes
[19.541] spawnCubeProgrammer():  18:19:31:769 Erasing memory corresponding to segment 1:
[19.541] spawnCubeProgrammer():  18:19:31:769 Memory Erase via FlashLoader!
[19.541] spawnCubeProgrammer():  18:19:31:769 Memory erase...
[19.541] spawnCubeProgrammer():  18:19:31:771 halt ap 0 
[19.541] spawnCubeProgrammer():  18:19:31:771 w ap 0 reg 15 PC   (0x20000000)  
[19.541] spawnCubeProgrammer():  18:19:31:772 w ap 0 reg 17 MSP  (0x20000500)  
[19.541] spawnCubeProgrammer():  18:19:31:772 w ap 0 reg 16 xPSR (0x01000000)  
[19.541] spawnCubeProgrammer():  18:19:31:776 w ap 0 @0x20008340 : 0x00000200 bytes, Data 0x00000000...
[19.541] spawnCubeProgrammer():  18:19:31:776 w ap 0 @0x20000000 : 0x00000004 bytes, Data 0x0000BE00...
[19.541] spawnCubeProgrammer():  18:19:32:001 w ap 0 @0x20000004 : 0x00007F18 bytes, Data 0x00000000...
[19.541] spawnCubeProgrammer():  18:19:32:001 Erasing external memory sectors [0 4]
[19.541] spawnCubeProgrammer():  18:19:32:001 Init flashloader...
[19.541] spawnCubeProgrammer():  18:19:32:002 halt ap 0 
[19.541] spawnCubeProgrammer():  18:19:32:003 w ap 0 reg 0 R0   0x00000001
[19.541] spawnCubeProgrammer():  18:19:32:004 w ap 0 reg 1 R1   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:005 w ap 0 reg 2 R2   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:006 w ap 0 reg 3 R3   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:007 w ap 0 reg 4 R4   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:008 w ap 0 reg 5 R5   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:008 w ap 0 reg 6 R6   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:009 w ap 0 reg 7 R7   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:009 w ap 0 reg 8 R8   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:010 w ap 0 reg 9 R9   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:012 w ap 0 reg 10 R10  0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:012 w ap 0 reg 11 R11  0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:012 w ap 0 reg 12 R12  0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:014 w ap 0 reg 13 SP   0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:014 w ap 0 reg 14 LR   0x20000001
[19.541] spawnCubeProgrammer():  18:19:32:015 w ap 0 reg 15 PC   0x20000991
[19.541] spawnCubeProgrammer():  18:19:32:017 w ap 0 reg 16 xPSR 0x01000000
[19.541] spawnCubeProgrammer():  18:19:32:017 w ap 0 reg 17 MSP  0x20008318
[19.541] spawnCubeProgrammer():  18:19:32:017 w ap 0 reg 18 PSP  0x00000000
[19.541] spawnCubeProgrammer():  18:19:32:018 run ap 0 
[19.541] spawnCubeProgrammer():  18:19:33:791 halt ap 0 

 

If I'm not wrong, these three lines (10..12 from previous listing) are responsible for loading the external loader into RAM. But I don't see a similar operation for the STM32G4.

[19.541] spawnCubeProgrammer():  18:19:31:776 w ap 0 @0x20008340 : 0x00000200 bytes, Data 0x00000000...
[19.541] spawnCubeProgrammer():  18:19:31:776 w ap 0 @0x20000000 : 0x00000004 bytes, Data 0x0000BE00...
[19.541] spawnCubeProgrammer():  18:19:32:001 w ap 0 @0x20000004 : 0x00007F18 bytes, Data 0x00000000...

 

The questions are:
1. Is the external loader loaded into RAM for the STM32G4 version ?
2. If it is not loaded then how to fix it ?
3. Or maybe it's a completely different error and I'm not seeing something.

 

 

It should load into RAM, but the form/format of the .ELF/.STLDR needs to be consistent with expectations.

Suggest you zip and attach the .STLDR

C:\STM32Cube\STM32CubeProgrammer_v2.18.0\bin\ExternalLoader>C:\Keil528\ARM\ARMCC\bin\fromelf.exe -csd MT25QL512ABB_STM32G474E-EVAL.stldr
========================================================================
** ELF Header Information

    File Name: MT25QL512ABB_STM32G474E-EVAL.stldr

    Machine class: ELFCLASS32 (32-bit)
    Data encoding: ELFDATA2LSB (Little endian)
    Header version: EV_CURRENT (Current version)
    Operating System ABI: none
    ABI Version: 0
    File Type: ET_EXEC (Executable) (2)
    Machine: EM_ARM (ARM)

    Image Entry point: 0x2000000f
    Flags: None (0x05000000)

    ARM ELF revision: 5 (ABI version 2)

    Conforms to Base float procedure-call standard

    Header size: 52 bytes (0x34)
    Program header entry size: 32 bytes (0x20)
    Section header entry size: 40 bytes (0x28)

    Program header entries: 2
    Section header entries: 20

    Program header offset: 177748 (0x0002b654)
    Section header offset: 177812 (0x0002b694)

    Section header string table index: 1
========================================================================
** Program header #0 (PT_LOAD) [PF_R]
    Size : 200 bytes
    Virtual address: 0x00000000 (Alignment 4)
====================================
** Program header #1 (PT_LOAD) [PF_X + PF_W + PF_R]
    Size : 12916 bytes
    Virtual address: 0x20000004 (Alignment 4)
========================================================================
...
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Sorry for the confusion, I forgot to write that the problem with starting the program from RAM has been solved.
The problem was due to a bad VTOR setting.
And an error in the linker
RAM (xrw) : ORIGIN = 0x20000004, LENGTH = 112K
It should be
RAM (xrw) : ORIGIN = 0x20000004, LENGTH = 112K-4

 

 

However, there is still a problem with the external loader.

I attach the external loader file.
Tesla DeLorean could You please check if it is consistent with expectations.

Thank you in advance.

I have done an additional test.
In the bodies of the Init(), SectorErase(), Write() functions, I placed code that flashes an LED. Now if any external loader function is called by ST-LINK I know it because the LED flashes.

What did I observe?
For STM32F4 during the program loading procedure the functions Init(), SectorErase(), Write() are called .

When I use the external loader with STM32G4 none of these functions are called.

When in the Debug Config options I checkbox Initialize True (for STM32G4 ), then the Init() function is executed only once right after clicking the Debug icon.

This confirms what I see in ST-LINK's logs.
When Initialize True is checked right after clicking Debug ST-LINK loads the external loader into RAM. Next runs the Init() function.
Next ST-LINK loads into RAM its own program to erase the internal FLASH memory. After deleting the internal FLASH memory, it calls the external loader's Init() function. But the external loader is no longer in RAM because it has been overwritten.

Before using the external loader, ST-LINK should reload it into RAM.
It does this for the STM32F4, but it doesn't do it for the STM32G4 (see previous logs).

I tried to get around this problem.
My idea was to locate the external loader in the RAM outside the address used by the ST-LINK loader. So that ST-LINK would not overwrite the external loader.
But it doesn't work. I don't know why yet, but probably during the erase/programming sequence the CPU is reset, or the RAM is reset.

 

 

 

Yeah, not sure what's going on there, a lot of clutter in the file, a lot of start-up code that's not connected to the entry points, but issue with it not loading/running would be more of a Cube Programmer sequencing issue. Using 2.18 ?

@Aziz BRIGUI 

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

GPIO/LED on PD2 ?

What memory device? On what pins?

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