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 in the code. After linking and flashing the .elf, the LED does not blink anymore, although I receive neither warnings nor errors. My idea was to compare the working .elf file with my non-working .elf file. I used arm-none-eabi-objdump
and readelf -a
, but I quickly learned that I have no way yet to assess the differences and therefore understand, what I did wrong. What are good ways/practices of comparing the .elf-files? Should I have a look at the sections, at functions, at bss-data, … I guess I am a bit overwhelmed right now.
If necessary: This is how I call arm-none-eabi-gcc
:
arm-none-eabi-gcc -Wall -g3 -O0 -Wl,-Map=debug_link_custom.map -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
And this is my linker-script:
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
}