my code here:
void _init(void) {return;}
int main(void)
{
/* STM32F2xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure the system clock to 64 MHz */
SystemClock_Config();
/* Enable CRC clock */
__CRC_CLK_ENABLE();
Example_Status = 1;
Example_Status = 2;
Example_Status = 3;
.....
and my gdb on my stm32 using stlink-texane are as follow:
(gdb) s
main () at main.c:74
74 __CRC_CLK_ENABLE();
(gdb) s
77 Example_Status = 3;
(gdb) p Example_status
No symbol "Example_status" in current context.
(gdb) p Example_Status
$1 = 139640994
(gdb) n
74 __CRC_CLK_ENABLE();
(gdb) n
77 Example_Status = 3;
(gdb) n
183 Example_Status = ExampleECCKeyGenSignVerif();
(gdb) p Example_Status
$2 = 139640994
i am wondering why the Example_Status outcome not = 3 ?
and the storage of the variable are
arm-none-eabi-objdump --syms main.o | grep Example_Status
00000000 l d .bss.Example_Status 00000000 .bss.Example_Status
00000000 g O .bss.Example_Status 00000004 Example_Status
and my linker file are here:
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20010000; /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x000;; /* required amount of heap */
_Min_Stack_Size = 0x000;; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}
This is my first linux project, i would appreicate if someone can help~
thanks
Edited for adding "disassemble /m"
75 Example_Status = 1;
0x080002ac <+24>: and.w r3, r3, #33554432 ; 0x2000000
0x080002b0 <+28>: cmp r3, #0
---Type <return> to continue, or q <return> to quit---
76 Example_Status = 2;
0x080002b2 <+30>: beq.n 0x80002a8 <main+20>
0x080002b4 <+32>: ldr r3, [pc, #60] ; (0x80002f4 <main+96>)
0x080002b6 <+34>: movw r2, #1795 ; 0x703
77 Example_Status = 3;
0x080002b8 <+36>: strb r3, [r0, #8]
0x080002ba <+38>: str r2, [r3, #0]
0x080002bc <+40>: ldr r2, [pc, #44] ; (0x80002ec <main+88>)
//
(gdb) n
75 Example_Status = 1;
(gdb) n
76 Example_Status = 2;
(gdb) p Example_Status
$1 = 140166176
(gdb) s
When compiling, and you want reliable debugging, do not compile with optimization-level higher than 0:
gcc -O0 mycode.c -o mycode.o -c
Related
I am writing a project with STM32H7. The project contains RTC, SPI, USART, SD Card, timers, and I2C.
In order to have more RAM, I have brought the data and bss to RAM_D1.
I did this by changing the linker file.
As next steps I want to implement Ethernet. However, I realized that in order for Ethernet to work, I need to only use RAM_D1.
The problem is when I bring the heap and stack to RAM_D1, the project stops working.
Can someone please help?
I include the linker script before and after bringing everything to RAM_D1.
Thank you in advance for your help.
I include the linker files before and after change below.
Before changing, everything works at this stage:
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20020000; /* 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 = 0x8000; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 2048K
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM_D1 AT> FLASH
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM_D1
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >DTCMRAM
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}
After changing the RAM section for heap and stack, at this stage the program stops working
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20020000; /* 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 = 0x8000; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 2048K
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM_D1 AT> FLASH
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM_D1
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >RAM_D1
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}
Your help is greatly appreciated, thank you in advance.
Your _estack variable (which is end of RAM address) is still set to 0x2002000, which is DTCRAM location + it's size (128K). To get everything working, change your _estack variable to this:
_estack = 0x24080000; /* end of RAM */
What is Address of D1 Memory + it's size (512K). (0x24000000 + (512 * 1024))
I'm working on a Nucleo-F767zi board (stm32F767ZIT6U MCU) with custom bootloader and application in Atollic TrueSTUDIO. I have working bootloader and application. I have started both separately without errors. But when I try to run application from bootloader I have hard_fault in application. Image of application is correct (address, size and check code of image are valid) before I jump. I would appreciate for any idea of what I should pay attention and remake.
part of bootloader code:
int boot_main(void)
{
// Reset of all peripherals, Initializes the Flash interface and the Systick.
HAL_Init();
// Configure the system clock
SystemClock_Config();
// bootloader
if (isBootFlag() || checkMainAppWithSign()) {
//HAL_DeInit();
startMainApp();
}
// Initialize all configured peripherals
MX_GPIO_Init();
MX_ETH_Init();
MX_USART3_UART_Init();
MX_USB_DEVICE_Init();
createTask(&sysTaskControlBlock, threadTaskSystem, NULL, tskIDLE_PRIORITY + 3, bufferTaskSystem, sizemas(bufferTaskSystem), "SystemTask");
// Start scheduler */
osKernelStart();
// We should never get here as control is now taken by the scheduler
// Infinite loop
while (1) {
}
}
void startMainApp(void)
{
uint32_t mainAppAddr;
mainAppAddr = (uint32_t)Flash_Get_Starting_Address(FLASH_SPACE_APPLICATION);
__disable_irq();
typedef void(*pMainApp)(void);
pMainApp mainApplication;
mainApplication = (pMainApp)(mainAppAddr + 4);
__set_MSP(*(uint32_t*)mainAppAddr);
SCB->VTOR = mainAppAddr;
mainApplication();
}
bootloader linker script:
/* Entry Point */
ENTRY(Boot_Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20080000; /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
/* Single bank mode */
FLASH_LOADER(rx) : ORIGIN = 0x08000000, LENGTH = 96K /* 32K * 3 sectors*/
FLASH_SIGN(rx) : ORIGIN = 0x08000000 + 96K, LENGTH = 32K /* 32K * 1 sector*/
FLASH_USER_DATA(rx) : ORIGIN = 0x08000000 + 96K + 32K, LENGTH = 128K /* 128K * 1 sector*/
FLASH_MAIN_APP(rx) : ORIGIN = 0x08000000 + 128K + 128K, LENGTH = 512K /* 256K * 2 sector*/
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
SRAM1 (xrw) : ORIGIN = 0x20020000, LENGTH = 368K - 32
SRAM1_FLAG (xrw): ORIGIN = 0x20020000 + 368K - 32, LENGTH = 32
SRAM2 (xrw) : ORIGIN = 0x2007C000, LENGTH = 16K
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
}
REGION_ALIAS("FLASH", FLASH_LOADER)
__flash_sign__ = ORIGIN(FLASH_SIGN);
__flash_sign_end__ = __flash_user_data__ + LENGTH(FLASH_SIGN);
__flash_user_data__ = ORIGIN(FLASH_USER_DATA);
__flash_user_data_end__ = __flash_user_data__ + LENGTH(FLASH_USER_DATA);
__flash_main_app__ = ORIGIN(FLASH_MAIN_APP);
__flash_main_app_end__ = __flash_main_app__ + LENGTH(FLASH_MAIN_APP);
__ram_bootflag__ = ORIGIN(SRAM1_FLAG);
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >SRAM1 AT> FLASH
_sidtcmram = LOADADDR(.dtcmram);
/* DTCMRAM section
*
* IMPORTANT NOTE!
* If initialized variables will be placed in this section,
* the startup code needs to be modified to copy the init-values.
*/
.dtcmram :
{
. = ALIGN(4);
_sdtcmram = .; /* create a global symbol at dtcmram start */
*(.dtcmram)
*(.dtcmram*)
. = ALIGN(4);
_edtcmram = .; /* create a global symbol at dtcmram end */
} >DTCMRAM AT> FLASH
_sisram2 = LOADADDR(.sram2);
/* SRAM2 section
*
* IMPORTANT NOTE!
* If initialized variables will be placed in this section,
* the startup code needs to be modified to copy the init-values.
*/
.sram2 :
{
. = ALIGN(4);
_ssram2 = .; /* create a global symbol at sram2 start */
*(.sram2)
*(.sram2*)
. = ALIGN(4);
_esram2 = .; /* create a global symbol at sram2 end */
} >SRAM2 AT> FLASH
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >SRAM1
/* User_heap_stack section, used to check that there is enough SRAM1 left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >SRAM1
/* MEMORY_bank1 section, code must be located here explicitly */
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
.memory_b1_text :
{
*(.mb1text) /* .mb1text sections (code) */
*(.mb1text*) /* .mb1text* sections (code) */
*(.mb1rodata) /* read-only data (constants) */
*(.mb1rodata*)
} >MEMORY_B1
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}
application linker script:
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20080000; /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
/* Single bank mode */
FLASH_LOADER(rx) : ORIGIN = 0x08000000, LENGTH = 96K /* 32K * 3 sectors*/
FLASH_SIGN(rx) : ORIGIN = 0x08000000 + 96K, LENGTH = 32K /* 32K * 1 sector*/
FLASH_USER_DATA(rx) : ORIGIN = 0x08000000 + 96K + 32K, LENGTH = 128K /* 128K * 1 sector*/
FLASH_MAIN_APP(rx) : ORIGIN = 0x08000000 + 128K + 128K, LENGTH = 512K /* 256K * 2 sector*/
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
SRAM1 (xrw) : ORIGIN = 0x20020000, LENGTH = 368K - 32
SRAM1_FLAG (xrw): ORIGIN = 0x20020000 + 368K - 32, LENGTH = 32
SRAM2 (xrw) : ORIGIN = 0x2007C000, LENGTH = 16K
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
}
REGION_ALIAS("FLASH", FLASH_MAIN_APP)
__flash_sign__ = ORIGIN(FLASH_SIGN);
__flash_sign_end__ = __flash_user_data__ + LENGTH(FLASH_SIGN);
__flash_user_data__ = ORIGIN(FLASH_USER_DATA);
__flash_user_data_end__ = __flash_user_data__ + LENGTH(FLASH_USER_DATA);
__flash_main_app__ = ORIGIN(FLASH_MAIN_APP);
__flash_main_app_end__ = __flash_main_app__ + LENGTH(FLASH_MAIN_APP);
__ram_bootflag__ = ORIGIN(SRAM1_FLAG);
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >SRAM1 AT> FLASH
_sidtcmram = LOADADDR(.dtcmram);
/* DTCMRAM section
*
* IMPORTANT NOTE!
* If initialized variables will be placed in this section,
* the startup code needs to be modified to copy the init-values.
*/
.dtcmram :
{
. = ALIGN(4);
_sdtcmram = .; /* create a global symbol at dtcmram start */
*(.dtcmram)
*(.dtcmram*)
. = ALIGN(4);
_edtcmram = .; /* create a global symbol at dtcmram end */
} >DTCMRAM AT> FLASH
_sisram2 = LOADADDR(.sram2);
/* SRAM2 section
*
* IMPORTANT NOTE!
* If initialized variables will be placed in this section,
* the startup code needs to be modified to copy the init-values.
*/
.sram2 :
{
. = ALIGN(4);
_ssram2 = .; /* create a global symbol at sram2 start */
*(.sram2)
*(.sram2*)
. = ALIGN(4);
_esram2 = .; /* create a global symbol at sram2 end */
} >SRAM2 AT> FLASH
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >SRAM1
/* User_heap_stack section, used to check that there is enough SRAM1 left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >SRAM1
/* MEMORY_bank1 section, code must be located here explicitly */
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
.memory_b1_text :
{
*(.mb1text) /* .mb1text sections (code) */
*(.mb1text*) /* .mb1text* sections (code) */
*(.mb1rodata) /* read-only data (constants) */
*(.mb1rodata*)
} >MEMORY_B1
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}
I found my error. Thanks to Fiddling Bits who gave me useful hint.
Working code for my application:
void startMainApp(void)
{
typedef void(*pMainApp)(void);
pMainApp mainApplication;
uint32_t mainAppAddr = (uint32_t)Flash_Get_Starting_Address(FLASH_SPACE_APPLICATION);
uint32_t mainAppStack = (uint32_t)*((uint32_t*)mainAppAddr);
mainApplication = (pMainApp)*(uint32_t*)(mainAppAddr + 4); // Corrected!!!
__disable_irq();
__set_MSP(mainAppStack);
SCB->VTOR = mainAppAddr;
__enable_irq();
mainApplication();
}
I'm tyring to write micropython code in STM32F779I. I get while running the app without running any code stack smashing detected.
Here is my memory layout
/* Highest address of the user mode stack */
_estack = 0x20080000; /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x1000; /* required amount of heap */
_Min_Stack_Size = 0x2000; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
SRAM1 (xrw) : ORIGIN = 0x20020000, LENGTH = 368K
SRAM2 (xrw) : ORIGIN = 0x2007C000, LENGTH = 16K
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
}
main_stack_base = _estack;
/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
/* used by the startup code to wipe memory */
ccmram_start = ORIGIN(SRAM1);
ccmram_end = ORIGIN(SRAM1) + 4;
/* used by the startup code to wipe memory */
sram_start = ORIGIN(SRAM1);
sram_end = ORIGIN(SRAM1) + LENGTH(SRAM1);
_ram_start = sram_start;
_ram_end = sram_end;
_codelen = LENGTH(FLASH);
_flash_start = ORIGIN(FLASH);
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
_estack = ORIGIN(SRAM1) + LENGTH(SRAM1) - 8;
_sstack = _estack; /* tunable */
_heap_start = _ebss;
_heap_end = _sstack;
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >SRAM1 AT> FLASH
_sidtcmram = LOADADDR(.dtcmram);
/* DTCMRAM section
*
* IMPORTANT NOTE!
* If initialized variables will be placed in this section,
* the startup code needs to be modified to copy the init-values.
*/
.dtcmram :
{
. = ALIGN(4);
_sdtcmram = .; /* create a global symbol at dtcmram start */
*(.dtcmram)
*(.dtcmram*)
. = ALIGN(4);
_edtcmram = .; /* create a global symbol at dtcmram end */
} >DTCMRAM AT> FLASH
_sisram2 = LOADADDR(.sram2);
/* SRAM2 section
*
* IMPORTANT NOTE!
* If initialized variables will be placed in this section,
* the startup code needs to be modified to copy the init-values.
*/
.sram2 :
{
. = ALIGN(4);
_ssram2 = .; /* create a global symbol at sram2 start */
*(.sram2)
*(.sram2*)
. = ALIGN(4);
_esram2 = .; /* create a global symbol at sram2 end */
} >SRAM2 AT> FLASH
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >SRAM1
/* User_heap_stack section, used to check that there is enough SRAM1 left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >SRAM1
/* MEMORY_bank1 section, code must be located here explicitly */
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
.memory_b1_text :
{
*(.mb1text) /* .mb1text sections (code) */
*(.mb1text*) /* .mb1text* sections (code) */
*(.mb1rodata) /* read-only data (constants) */
*(.mb1rodata*)
} >MEMORY_B1
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}
and Here is how I run micropython:
mp_stack_set_top(&_estack);
mp_stack_set_limit((char *)&_estack - (char *)&_heap_end - 1024);
// GC init
//printf("CORE: Starting GC\n");
gc_init(&_heap_start, &_heap_end);
// Interpreter init
//printf("CORE: Starting interpreter\n");
mp_init();
mp_obj_list_init(mp_sys_argv, 0);
mp_obj_list_init(mp_sys_path, 0);
mp_obj_list_append(
mp_sys_path,
MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
// Execute the main script
//printf("CORE: Executing main script\n");
pyexec_frozen_module("boot.py");
The stack limit is negative, because &_estack and &_heap_end have the same value.
There is this line in the linker script
_sstack = _estack;
and two lines down
_heap_end = _sstack;
When the following expression is evaluated
mp_stack_set_limit((char *)&_estack - (char *)&_heap_end - 1024);
it gives -1024 as a result. There is no way one could get stack usage below that.
Set a reasonable size in mp_stack_set_limit().
I run command:
arm-none-eabi-gcc -T STM32F100XB_FLASH.ld -o main.elf main.c lcd.c c2b.c startup_stm32f100xb.s system_stm32f10x.c stm32f10x_gpio.c stm32f10x_rcc.c -specs=nosys.specs
but got error like this
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/bin/ld:STM32F100XB_FLASH.ld:1: syntax error
collect2: error: ld returned 1 exit status
syntax error in this file(STM32F100XB_FLASH):
0
/* Entry Point */
ENTRY(Reset_Handler)
0
/* Highest address of the user mode stack */
_estack = 0x20001FFF; /* end of RAM */
0
/* 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 */
0
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K
}
0
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
0
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
0
KEEP (*(.init))
KEEP (*(.fini))
0
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
0
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
0
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
0
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
0
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
0
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
0
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH
0
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
0
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
0
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >RAM
0
0
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
0
.ARM.attributes 0 : { *(.ARM.attributes) }
}
Thas Linker script file publish by st.com in STM32Cube_FW_F1_V1.4.0.zip firmware file for STMCUBEMX ( I extracted that and find some file including STM32F100XB_FLASH.ld)
but when change linker script file with other one not official! compile and link successfully.
arm-none-eabi-gcc -T stm32f100.ld -o main.elf main.c lcd.c c2b.c startup_stm32f100xb.s system_stm32f10x.c stm32f10x_gpio.c stm32f10x_rcc.c -specs=nosys.specs
and the stm32f100.ld file:
/*
Linker script for STM32F10x_128K_8K
modified from
http://www.codesourcery.com/archives/arm-gnu/msg02972.html
http://communities.mentor.com/community/cs/archives/arm-gnu/msg02972.html
*/
/*
There will be a link error if there is not this amount of RAM free at the
end.
*/
_Minimum_Stack_Size = 256;
ENTRY(Reset_Handler)
/* Memory Spaces Definitions */
MEMORY
{
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 8K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
}
__ram_start__ = ORIGIN(RAM);
__ram_size__ = LENGTH(RAM);
__ram_end__ = __ram_start__ + __ram_size__;
_estack = __ram_end__;
/* highest address of the user mode stack */
PROVIDE ( _Stack_Limit = _estack - _Minimum_Stack_Size );
/* Sections Definitions */
SECTIONS
{
.text :
{
KEEP(*(.isr_vector)) /* Startup code */
*(.text) /* code */
*(.text.*) /* remaining code */
*(.rodata) /* read-only data (constants) */
*(.rodata.*)
*(.glue_7)
*(.glue_7t)
*(.vfp11_veneer)
*(.v4_bx)
*(.ARM.extab* .gnu.linkonce.armextab.*)
} >FLASH
/* for exception handling/unwind - some Newlib functions (in
common with C++ and STDC++) use this. */
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
__exidx_end = .;
. = ALIGN(4);
_etext = .;
/* This is used by the startup in order to initialize the .data secion
*/
_sidata = _etext;
/* This is the initialized data section
The program executes knowing that the data is in the RAM
but the loader puts the initial values in the FLASH (inidata).
It is one task of the startup to copy the initial values from FLASH to
RAM. */
.data : AT ( _sidata )
{
. = ALIGN(4);
/* This is used by the startup in order to initialize the .data
secion */
_sdata = . ;
*(.data)
*(.data.*)
. = ALIGN(4);
/* This is used by the startup in order to initialize the .data
secion */
_edata = . ;
} >RAM
/* This is the uninitialized data section */
.bss :
{
. = ALIGN(4);
/* This is used by the startup in order to initialize the .bss
secion */
_sbss = .;
__bss_start__ = _sbss;
*(.bss)
*(.bss.*)
*(COMMON)
. = ALIGN(4);
/* This is used by the startup in order to initialize the .bss
secion */
_ebss = . ;
__bss_end__ = _ebss;
} >RAM
PROVIDE ( end = _ebss );
PROVIDE ( _end = _ebss );
PROVIDE ( _exit = _ebss );
PROVIDE (_stackend = ORIGIN(RAM) + LENGTH(RAM) - _Minimum_Stack_Size);
/* This is the user stack section
This is just to check that there is enough RAM left for the User mode
stack
It should generate an error if it's full.
*/
._usrstack :
{
. = ALIGN(4);
_susrstack = . ;
. = . + _Minimum_Stack_Size ;
. = ALIGN(4);
_eusrstack = . ;
} >RAM
/* after that it's only debugging information. */
/* remove the debugging information from the standard libraries */
/*
DISCARD :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
*/
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
}
Whats wrong with STM32F100XB_FLASH.ld???
All the zeroes that you have at the beginning of lines are wrong and that's what ld is telling you.
0 <-- error
/* Entry Point */
ENTRY(Reset_Handler)
0 <-- error
/* Highest address of the user mode stack */
_estack = 0x20001FFF; /* end of RAM */
0 <-- error
/* 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 */
0 <-- error
...
The file in the package is indeed broken, as are all the files from this folder (Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/linker/). My suggestion would be to use any of the files from the Projects/ folder and just change the values of flash/ram addresses and sizes to match your device (you can take them from the file which is broken).
If you just take this one - Projects/STM32VL-Discovery/Examples/ADC/ADC_Regular_injected_groups/TrueSTUDIO/STM32VL-Discovery/STM32F100VB_FLASH.ld - then you won't need to change anything, as the sizes and addresses are OK for your device (assuming it's a device with 128kB of flash and 8kB of RAM).
I made my own bootloader for an STM32L1 board.
My algorithm is simple :
- first, I erase the memory I need to write my new program on my flash.
- then, I write 4 bytes per 4 bytes my new program ( I receive it from the USART of the board)
then i push the RESET button of my card, and nothing happens ...
My new program should blink a LED but nothing happens and I d'ont understand why ...
Do i have to write my own RESET function?
Here is my code if you want to give a try.
void BootLoader(void) {
//clear all ITs
USART_ITConfig_boot( USART1, USART_IT_RXNE, 0);
uint32_t start_adr, end_adr;
uint8_t status, i;
uint8_t buffer[4096];
uint8_t sizeRcv[2];
uint16_t tailleSector = 0x1000;
uint32_t adr;
uint8_t nbSector = 0;
//size fixée en dur
uint16_t k = 0;
uint8_t size1 = 0;
uint8_t size2 = 0;
uint16_t sizeBin = 0;
//taille sector
uint16_t tailleSecteurDec = 4096;
SendString_boot("BOOTLOADER ON.....\r\n", USART2);
//adress
//First Sector
start_adr = WRITE_START_ADDR;
end_adr = start_adr + tailleSector;
//erasing flags
FLASH_ClearFlag_boot(
FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
| FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR
| FLASH_FLAG_OPTVERRUSR | FLASH_FLAG_RDERR);
FLASH_Unlock_boot();
sizeBin = 51400;
nbSector = (uint8_t) (sizeBin / tailleSecteurDec) + 1;
if(nbSector > 30){
SendString_boot("cannot overrite memory : too much sectors used\r\n",USART2);
}
for (i = 0; i <= (127 - 1); i++) {
if(end_adr < 0x0808FFFF){
status = Flash_Erase(start_adr, end_adr);
start_adr = end_adr;
end_adr = end_adr + tailleSector;
SendString_boot(" ERASING SECTOR DONE \r\n", USART2);
}
else{
SendString_boot("END OF FLASH MEMORY\r\n", USART2);
}
}
SendString_boot("ERASING COMPLETE\r\n", USART2);
start_adr = WRITE_START_ADDR;
//receive frames
adr = WRITE_START_ADDR;
do {
SendString_boot("ACK_READY", USART1);
SendString_boot("ACK_READY\r\n", USART2);
//receive 32 bytes
if (sizeBin - k > 4096)
Receive_Data_boot(buffer, 4096);
else
Receive_Data_boot(buffer, sizeBin - k);
//write 32 bytes in memory
if (sizeBin - k > 4096)
status = Flash_Write(adr, buffer, 4096);
else
status = Flash_Write(adr, buffer, sizeBin - k);
//on check si on ecrit bien au bon endroit
//increment cpt
k = k + 4096;
adr = adr + 0x1000;
i++;
//check CRC
//TODO
SendString_boot("...FLASH DONE ON ", USART2);
SendString_boot("\r\n", USART2);
SendString_boot(" SECTOR DONE \r\n", USART2);
} while (k < sizeBin);
SendString_boot("END", USART1);
SendString_boot("ACK_END\r\n", USART2);
FLASH_Lock_boot();
}
The linker script is:
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20014000; /* end of 96K 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
{
BOOT (rx) : ORIGIN = 0x0801E000, LENGTH = 8K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K-8K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 80K
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
*(.RamFunc) /* .RamFunc sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >RAM
/* MEMORY_bank1 section, code must be located here explicitly */
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
.memory_b1_text :
{
*(.mb1text) /* .mb1text sections (code) */
*(.mb1text*) /* .mb1text* sections (code) */
*(.mb1rodata) /* read-only data (constants) */
*(.mb1rodata*)
} >MEMORY_B1
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.bootsection :
{
. = ALIGN(4);
KEEP(*(.bootsection)) /* Bootloader code */
. = ALIGN(4);
} >BOOT
.ARM.attributes 0 : { *(.ARM.attributes) }
}
Receive_data_boot code :
void Receive_Data_boot(uint8_t * buffer, int size) {
uint16_t i = 0;
do {
buffer[i] = Uart2ReadChar_boot();
i++;
} while (i < size);
}
uint8_t Uart2ReadChar_boot(void) {
while(USART_GetFlagStatus_boot(USART1, USART_FLAG_RXNE) == 0);
return USART_ReceiveData_boot(USART1);
}
uint16_t USART_ReceiveData_boot(USART_TypeDef_boot* USARTx)
{
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH_BOOT(USARTx));
SendChar_boot((uint8_t)USARTx->DR,USART1);
/* Receive Data */
return ((uint16_t)(USARTx->DR & (uint16_t)0x01FF));
}
To start your new program from FLASH after RESET the following conditions must be satisfied:
Written image contains correct Reset_Handler which will be executed after POR. Typically this is defined in startup.S and ended with something like:
bl SystemInit
bl main
bx lr
Pin BOOT0 of your processor must be set 0.
Example.
From startup.S:
.section .isr_vector,"a",%progbits
.type g_pfnVectors, %object
.size g_pfnVectors, .-g_pfnVectors
g_pfnVectors:
.word _estack
.word Reset_Handler
.word NMI_Handler
.word HardFault_Handler
...
From program assembly listing:
08008fd8 <Reset_Handler>:
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
8008fd8: 2100 movs r1, #0
From hex-file:
:020000040800F2
:1000000000000220D98F0008F9070008FD0700084A
Note address 0x08008fd9 in hex file (:1000000000000220D98F0008F9070008FD0700084A) that match Reset_Handler with LSB set (Thumb2-mode).