Hi,I try to debug my code in ram.but after searching on the web for a
long time,I still can't figure it out.I use Sourcery G++ Lite Edition
,openocd and jlink on ubuntu 10.04.for the flash run,it work well.the
MCU is STM32F103VE
I download the start up code and link script from the web.I modify the
link script to something like this:
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >RAM
/* for some STRx devices, the beginning of the startup code is
stored in the .flashtext section, which goes to FLASH */
.flashtext :
{
. = ALIGN(4);
*(.flashtext) /* Startup code */
. = ALIGN(4);
} >RAM
/* the program code is stored in the .text section, which goes to
Flash */
.text :
{
. = ALIGN(4);
*(.text .text.* .gnu.linkonce.t.*)
*(.plt)
*(.gnu.warning)
*(.glue_7t) *(.glue_7) *(.vfp11_veneer)
*(.ARM.extab* .gnu.linkonce.armextab.*)
*(.gcc_except_table)
} >RAM
please help.
and sorry for my poor English.
So far I have not tested "RAM-debugging" with STM32 controllers so these are just some hints which might be helpful: - In the Makefile there is a variable RUN_MODE which is set to FLASH_RUN in the file in the archiv. Set it to RAM_RUN. The stetting is later used to select the linker-script. Look into the output of make all and verify that the *_RAM linker-script is used. The content of RUN_MODE is also passed as a preprocessor definition so #ifdef RAM_RUN or #ifdef FLASH_RUN can be used in the source-code. - SystemInit_ExtMemCtl() is called in the reset handler, usually SystemInit should do. Initialisation of the external memory interface can be enabled by a preprocessor define (see system_stm32*.c). Since initialization of the external memory interface can be enabled in SystemInit() it might be better to call SystemInit in the reset-handler. This may not cause a problem but it might be better to use the method intended by the STM library-developers until everything starts up as expected. - I did not check every line in the linker-script for RAM but it looks o.k. - Since the .data output-section is already at the correct location it is o.k. to wrap the first for-loop (copy data seg initializers...) with #ifdef FLASH_RUN/#endif - MSP is already set in the reset-handler-function so there should be no need to add something for this. - Since the interrupt-vector-table is also in RAM and not at the default location the the beginning of the flash-memory area the location has do be configured in SCB's VTOR register before any interrupt is enabled. See function NVIC_SetVectorTable in misc.c. Call could be done in the reset-handler. - Since the core should start run the code in RAM, the debuggering-software should set the program-counter (PC) to the reset-handler's address. This can be done with OpenOCD just before a "resume".
Thank you very much for you reply I will try it later and report what I get. Thanks again.
Thank you Martin By following you instruction ,I finaly made it work ! 1.Modify the link script to put all the sections in ram 2.Set RUN_MODE to RAM_RUN in Makefile and make sure the linker link with the ram-run-link-script 3.Change the Reset_Handler to:
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
4.Change __Init_Data to:
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
5.Use the following openocd command:
1 | |
2 | |
3 | |
4 | |
5 | |
Guest
#4676305
I did test with STM32F103C8T6 ($3 chinese board, known as blue pill). The only thing I had to do is to write my linker script to put everything in RAM, then: 1. Put the jumpers at BOOT0 & BOOT1 pins to boot from RAM. 3. Debug via configured Eclipse+GDB+OpenOCD. No code changes are necessary. The .elf contains all necessary sections so GDB is able to load the sections in RAM:
1 | |
Then (in gdb) we connect to a running OpenOCD to load program into RAM:
1 | |
2 | |
3 | |
The output from 'load' looks like:
1 | |
2 | |
3 | |
4 | |
5 | |
You see that I defined vectors in separate section. Even the code for loading stack pointer is unnecessary (it saves 4 bytes of RAM in my case - for return address of reset handler), because my linker has the beginning of stack at end of the RAM which is by default after reset. For eclipse there are no special settings - "load image" & "load symbols" are checked, everything works out of the box.
Reply
Please log in before posting.