cancel
Showing results for 
Search instead for 
Did you mean: 

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

LehuW
Associate III

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

 

 

11 REPLIES 11

For now, the external loader does not support any memory only flashes an LED on PD2. Please see the attached files.

The target memory is W25Q series connected via QSPI.
I have done Erase, Read, Write, MemoryMappedMode tests and everything works fine. The tests were done normally from the main loop without using external loader.

For now, the main problem is to run the external loader.
When the external loader functions will be started correctly I will insert W25Q support code into them.

 

Current config and versions:

STM32G491RE  (FLASH=512k, RAM=112k)

STM32CubeIDE Version: 1.14.0  Build: 19471_20231121_1200

I am using the debugger included in STM32CubeIDE. In the debugger configuration -> add external loader (the path to the loader is set).

I also made tests with STM32CubeProgrammer v.2.18.0 - external loader also does not work.

 

I also tried to use this loader: https://github.com/cturvey/stm32extldr/tree/main/g4_w25q128

This is the exact hardware configuration as mine, but also does not start.

I think it is also because the wrong sequence of programming.

 

 

LehuW
Associate III

I have updated STM32CubeIDE to Version: 1.17.0
The same problem still occurs. ST-Link does not load external loader into RAM before calling Init() / Erase() / Write() function.

 

[6.855] spawnCubeProgrammer():  21:21:18:438 Memory Programming ...
[6.855] spawnCubeProgrammer():  21:21:18:438   File          : ST-LINK_GDB_server_a04544.srec
[6.855] spawnCubeProgrammer():  21:21:18:438   Size          : 5.98 KB 
[6.855] spawnCubeProgrammer():  21:21:18:438   Address       : 0x08000000 
[6.855] spawnCubeProgrammer():  21:21:18:438 
[6.855] spawnCubeProgrammer():  
[6.855] spawnCubeProgrammer():  21:21:18:439 Erasing Segment <0> Address <0x08000000> Size <5788>Bytes
[6.855] spawnCubeProgrammer():  21:21:18:439 Erasing memory corresponding to segment 0:
[6.855] spawnCubeProgrammer():  21:21:18:439 r ap 0 @0x40022040 0x00000004 bytes Data 0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:439 Memory Erase via FlashLoader!
[6.855] spawnCubeProgrammer():  21:21:18:439 Memory erase...
[6.855] spawnCubeProgrammer():  21:21:18:442 halt ap 0 
[6.855] spawnCubeProgrammer():  21:21:18:442 w ap 0 reg 15 PC   (0x20000000)  
[6.855] spawnCubeProgrammer():  21:21:18:442 w ap 0 reg 17 MSP  (0x20000500)  
[6.855] spawnCubeProgrammer():  21:21:18:443 w ap 0 reg 16 xPSR (0x01000000)  
[6.855] spawnCubeProgrammer():  21:21:18:448 w ap 0 @0x20000BE0 : 0x00000200 bytes, Data 0x00000000...
[6.855] spawnCubeProgrammer():  21:21:18:448 w ap 0 @0x20000000 : 0x00000004 bytes, Data 0x0000BE00...
[6.855] spawnCubeProgrammer():  21:21:18:460 w ap 0 @0x20000004 : 0x000007A0 bytes, Data 0xF000B580...
[6.855] spawnCubeProgrammer():  21:21:18:460 Erasing internal memory sectors [0 2]
[6.855] spawnCubeProgrammer():  21:21:18:460 Init flashloader...
[6.855] spawnCubeProgrammer():  21:21:18:461 halt ap 0 
[6.855] spawnCubeProgrammer():  21:21:18:461 w ap 0 reg 0 R0   0x00000001
[6.855] spawnCubeProgrammer():  21:21:18:461 w ap 0 reg 1 R1   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:462 w ap 0 reg 2 R2   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:462 w ap 0 reg 3 R3   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:463 w ap 0 reg 4 R4   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:464 w ap 0 reg 5 R5   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:464 w ap 0 reg 6 R6   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:464 w ap 0 reg 7 R7   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:465 w ap 0 reg 8 R8   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:465 w ap 0 reg 9 R9   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:465 w ap 0 reg 10 R10  0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:467 w ap 0 reg 11 R11  0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:467 w ap 0 reg 12 R12  0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:467 w ap 0 reg 13 SP   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:468 w ap 0 reg 14 LR   0x20000001
[6.855] spawnCubeProgrammer():  21:21:18:468 w ap 0 reg 15 PC   0x20000005
[6.855] spawnCubeProgrammer():  21:21:18:468 w ap 0 reg 16 xPSR 0x01000000
[6.855] spawnCubeProgrammer():  21:21:18:469 w ap 0 reg 17 MSP  0x20000BA0
[6.855] spawnCubeProgrammer():  21:21:18:469 w ap 0 reg 18 PSP  0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:469 run ap 0 
[6.855] spawnCubeProgrammer():  21:21:18:470 halt ap 0 
[6.855] spawnCubeProgrammer():  21:21:18:470 r ap 0 reg 0 R0   0x00000001
[6.855] spawnCubeProgrammer():  21:21:18:470 Loader sector erase...
[6.855] spawnCubeProgrammer():  21:21:18:471 w ap 0 reg 0 R0   0x08000000
[6.855] spawnCubeProgrammer():  21:21:18:471 w ap 0 reg 1 R1   0x08001000
[6.855] spawnCubeProgrammer():  21:21:18:472 w ap 0 reg 2 R2   0x00000002
[6.855] spawnCubeProgrammer():  21:21:18:473 w ap 0 reg 3 R3   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:473 w ap 0 reg 4 R4   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:473 w ap 0 reg 5 R5   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:474 w ap 0 reg 6 R6   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:475 w ap 0 reg 7 R7   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:475 w ap 0 reg 8 R8   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:476 w ap 0 reg 9 R9   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:476 w ap 0 reg 10 R10  0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:477 w ap 0 reg 11 R11  0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:477 w ap 0 reg 12 R12  0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:478 w ap 0 reg 13 SP   0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:479 w ap 0 reg 14 LR   0x20000001
[6.855] spawnCubeProgrammer():  21:21:18:479 w ap 0 reg 15 PC   0x2000038B
[6.855] spawnCubeProgrammer():  21:21:18:479 w ap 0 reg 16 xPSR 0x01000000
[6.855] spawnCubeProgrammer():  21:21:18:480 w ap 0 reg 17 MSP  0x20000BA0
[6.855] spawnCubeProgrammer():  21:21:18:480 w ap 0 reg 18 PSP  0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:480 run ap 0 
[6.855] spawnCubeProgrammer():  21:21:18:547 halt ap 0 
[6.855] spawnCubeProgrammer():  21:21:18:548 r ap 0 reg 0 R0   0x00000001
[6.855] spawnCubeProgrammer():  21:21:18:548 erase: 0108ms
[6.855] spawnCubeProgrammer():  21:21:18:548 Erasing Segment <1> Address <0x90000000> Size <335>Bytes
[6.855] spawnCubeProgrammer():  21:21:18:548 Erasing memory corresponding to segment 1:
[6.855] spawnCubeProgrammer():  21:21:18:548 r ap 0 @0x40022040 0x00000004 bytes Data 0x00000000
[6.855] spawnCubeProgrammer():  21:21:18:548 Memory Erase via FlashLoader!
[6.855] spawnCubeProgrammer():  21:21:18:548 Memory erase...
[6.855] spawnCubeProgrammer():  21:21:18:552 halt ap 0 
[6.855] spawnCubeProgrammer():  21:21:18:552 w ap 0 reg 15 PC   (0x20000000)  
[6.855] spawnCubeProgrammer():  21:21:18:553 w ap 0 reg 17 MSP  (0x20000500)  
[6.855] spawnCubeProgrammer():  21:21:18:553 w ap 0 reg 16 xPSR (0x01000000)  
[6.855] spawnCubeProgrammer():  21:21:18:554 Erasing external memory sectors [0 1]
[6.855] spawnCubeProgrammer():  21:21:18:554 Init flashloader...
[6.855] spawnCubeProgrammer():  21:21:18:554 halt ap 0 
[6.855] spawnCubeProgrammer():  21:21:18:555 w ap 0 reg 0 R0   0x00000001
[6.856] spawnCubeProgrammer():  21:21:18:555 w ap 0 reg 1 R1   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:556 w ap 0 reg 2 R2   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:556 w ap 0 reg 3 R3   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:557 w ap 0 reg 4 R4   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:557 w ap 0 reg 5 R5   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:558 w ap 0 reg 6 R6   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:558 w ap 0 reg 7 R7   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:559 w ap 0 reg 8 R8   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:559 w ap 0 reg 9 R9   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:560 w ap 0 reg 10 R10  0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:561 w ap 0 reg 11 R11  0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:561 w ap 0 reg 12 R12  0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:562 w ap 0 reg 13 SP   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:562 w ap 0 reg 14 LR   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:563 w ap 0 reg 15 PC   0x200006C1
[6.856] spawnCubeProgrammer():  21:21:18:563 w ap 0 reg 16 xPSR 0x01000000
[6.856] spawnCubeProgrammer():  21:21:18:564 w ap 0 reg 17 MSP  0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:564 w ap 0 reg 18 PSP  0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:564 run ap 0 
[6.856] spawnCubeProgrammer():  21:21:18:565 halt ap 0 
[6.856] spawnCubeProgrammer():  21:21:18:566 r ap 0 reg 0 R0   0x00000001
[6.856] spawnCubeProgrammer():  21:21:18:566 Loader sector erase...
[6.856] spawnCubeProgrammer():  21:21:18:566 w ap 0 reg 0 R0   0x90000000
[6.856] spawnCubeProgrammer():  21:21:18:567 w ap 0 reg 1 R1   0x90000100
[6.856] spawnCubeProgrammer():  21:21:18:568 w ap 0 reg 2 R2   0x00000002
[6.856] spawnCubeProgrammer():  21:21:18:568 w ap 0 reg 3 R3   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:568 w ap 0 reg 4 R4   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:570 w ap 0 reg 5 R5   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:570 w ap 0 reg 6 R6   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:571 w ap 0 reg 7 R7   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:571 w ap 0 reg 8 R8   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:572 w ap 0 reg 9 R9   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:572 w ap 0 reg 10 R10  0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:573 w ap 0 reg 11 R11  0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:573 w ap 0 reg 12 R12  0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:574 w ap 0 reg 13 SP   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:574 w ap 0 reg 14 LR   0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:575 w ap 0 reg 15 PC   0x200007B5
[6.856] spawnCubeProgrammer():  21:21:18:575 w ap 0 reg 16 xPSR 0x01000000
[6.856] spawnCubeProgrammer():  21:21:18:576 w ap 0 reg 17 MSP  0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:576 w ap 0 reg 18 PSP  0x00000000
[6.856] spawnCubeProgrammer():  21:21:18:576 run ap 0 
[6.856] spawnCubeProgrammer():  21:21:18:577 halt ap 0 
[6.856] spawnCubeProgrammer():  21:21:18:577 r ap 0 reg 0 R0   0x000000FF
[6.856] spawnCubeProgrammer():  21:21:18:578 r ap 0 reg 16 xPSR 0x21000000
[6.856] spawnCubeProgrammer():  21:21:18:578 Error: failed to erase memory
[6.856] spawnCubeProgrammer():  21:21:18:578 
[6.856] spawnCubeProgrammer():  
[6.856] spawnCubeProgrammer():  21:21:18:578 Error: failed to erase memory
[6.856] spawnCubeProgrammer():   ------ Switching context ----- 

 

Any ideas on how to solve this problem?