WITC
WITC

Reputation: 329

Differences in STM32 Flash Content Between .elf and .bin on STM32 Affecting CRC Calculation

I am working with an STM32 microcontroller and uploading both .elf and .bin files of the same compiled program to the flash memory. However, I have noticed differences in the flash content when reading it back. Specifically, when I upload the .bin file, there is an area in the flash that reads as 0xFFFFFFFF, whereas the same area reads as 0x00000000 when I upload the .elf file.

While this doesn't seem to affect the program execution, I need to calculate the CRC over the entire flash content, and this discrepancy is causing issues with the calculation.

I am uploading the bin file using the debug mode, but I am not sure how it works. When I open the bin file itself, it seems that 0x00000000 is already present at that specific location. However, after uploading and reading it back, I see 0xFFFFFFFF.

I have tried adding FILL(0x00) in my linker script to fill empty spaces with zeros when generating the .bin file, but it doesn't seem to have worked. Here is the relevant part of my linker script:

.isr_vector :
{
  . = ALIGN(4);
  KEEP(*(.isr_vector)) /* Startup code */
  . = ALIGN(4);
  FILL(0x00)
} >FLASH_APP1

Upvotes: 1

Views: 360

Answers (1)

pfmaggi
pfmaggi

Reputation: 6496

elf stands for Executable and Linkable Format, it is not the correct format to flash a binary to the STM32. You need some kind of "binary image" with absolute address that maps your STM32 vector table and memory map.

My suggestion is to follow a getting started guide like this to understand how to setup your linker script / memory map.

Upvotes: 1

Related Questions