2025-04-22 1:45 PM - last edited on 2025-04-23 6:06 AM by Amel NASRI
I’m using the Class B Flash self‑test on an STM32F407. My post‑build step injects CRCs with:
STM32_Programmer_CLI -sl Firmware.elf 0x08000000 0x08100000 0x400
I Inspected the CRC of the first section via
arm-none-eabi-objdump -s -j "CRCs area" Firmware.elf | head -n2
After this I re‑computed the CRC to verify which method it used. I used srec_cat and I used the following method:
arm-none-eabi-objcopy -O binary Firmware.elf full_flash.bin
dd if=full_flash.bin of=region.bin bs=1 count=1024
srec_cat region.bin -Binary \
-CRC32_Little_Endian 0x400 \
-crop 0x400 0x404 \
-output - -binary \
| hexdump -e '1/4 "CRC32: 0x%08X\n"'
After this I figured out that the CRC checksum stored in the memory for the first 0x400 section matched with the srec_cat output.
However at runtime, when STL_SCH_RunFlashTM() (compiled with both -DSTL_SW_CRC and without it) computes the CRC over the exact same 0x400 bytes which is different than the expected value. As a result, StlFlashStatus returns STL_Failed I end up in the FailSafe_Handler with error code 13.
Key finding:
The built‑in STM32F4 CRC peripheral has no bit reflections, initial bit is 0xFFFFFFFF, no final XOR. Whereas -CRC32_Little_endian (same as STM_Programmer_CLI) uses reflected input and output, consistent with the standard CRC-32 definition. A final XOR of 0xFFFFFFFF is applied always injects the reflected CRC32 (input+output bit‑reversal), so the two algorithms cannot match on F4 hardware.
The whole method of CRC calculation seems unusual to me. Maybe it's my lack of knowledge too. Any guidance or best‑practice example for aligning the runtime CRC with the CLI‑injected table on STM32F4 would be greatly appreciated.
2025-04-22 2:17 PM
srecord does have the STM32-specific CRC implemented, see it's manual.
JW
2025-04-22 3:11 PM - edited 2025-04-22 3:11 PM
>>The whole method of CRC calculation seems unusual to me.
The HW is super awkward, it does 32-bit word level processing, reads the words small-endian and then processes left-ward with the high order bit first.
Most online calculators will choke if fed bytes in memory order.
https://github.com/cturvey/RandomNinjaChef/blob/main/stm32crc.c
2025-04-23 5:25 AM
Hey @waclawek.jan , yes I've seen that too and tried it. It results in a different checksum from what is stored in the CRCs area of the memory. Which leads me to believe that STM_Programmer_CLI uses -CRC32_Little_Endian configurations (which is different than STM32F407's hardware CRC engine).
2025-04-23 5:37 AM
In X-Cube-ClassB-F4, all the safety functions including the checksum calculation function is under STL_Lib.a library. According to the documentation, all I know is that the flash test STL_SCH_RunFlashTM() calls the CRC calculation function CRC_Handle_32_HW(). I don't have the visibility of what's inside. It likely calls the HAL function to calculate the CRC but I don't know.
The issue is it's a pre-certified library and I shouldn't modify any core logic. That's why wanted to figure out if anyone in the community faced similar issues or not.
Maybe an ST employee can answer this? @Petr Sladecek @Amel NASRI