I want to learn about programming an STM32 without ready-made startup-code and linking to improve my understanding of these crucial steps and to not be dependent on automatic code generation by ST. The tool-chain I am using is arm-none-eabi-gcc. Currently I am running into problems creating my own linker-script.
I created a project via STM32Cube which blinks an LED on my board. I could verify that the code works with the linker-script provided by ST. Now, I am only replacing the linker-script without changing anything else about the project and the LED does not blink, although I receive neither warnings nor errors. My idea was to compare the linking results via readelf -a
, but I quickly learned that I have no way yet to assess the differences and therefore understand, what I did wrong. I want to avoid to just look into the ST-provided linker-script since I hope the learnings will by higher by evaluating differences in the linking results. Besides readelf, are there tools or methods that you could recommend to overcome the obstacle?
My current linker-code is still rudimentary and looks like the following:
ENTRY(reset_handler)
MEMORY
{
FLASH (RX) : ORIGIN = 0x08000000, LENGTH = 32k,
SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 10k
}
SECTIONS
{
. = ORIGIN(FLASH);
.init_vec :
{
KEEP(*(.init_vec))
. = ALIGN(4);
} >FLASH
.text :
{
*(.text)
. = ALIGN(4);
} >FLASH
.rodata :
{
*(.rodata)
. = ALIGN(4);
} >FLASH
.data :
{
*(.data)
. = ALIGN(4);
} >FLASH
.bss :
{
__bss_start__ = .;
*(.bss)
. = ALIGN(4);
__bss_end__ = .;
} >SRAM
}
The command I am calling to link looks like this:
arm-none-eabi-gcc -Wall -g3 -O0 -mcpu=cortex-m3 -mfloat-abi=soft -mthumb --specs=nosys.specs -fstack-usage -T link_custom.ld -I Core/Inc -I Drivers/STM32F1xx_HAL_Driver/Inc -I Drivers/CMSIS/Device/ST/STM32F1xx/Include -I Drivers/CMSIS/Include -I Drivers/CMSIS/Device/Include startup_custom.c interrupt_handlers.c Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c Core/Src/system_stm32f1xx.c Core/Src/main.c -o blinky_custom_link.elf