STM32G0 Bootloader – Flash Erase Command via FDCAN Doesn't Erase Flash to 0xFF
Hello ST Community,
I'm working with the STM32G0B1CCT6 microcontroller and implementing a custom bootloader located at the beginning of flash memory. The bootloader handles firmware updates over FDCAN.
:wrench:Flash Layout:
Bootloader start address: 0x08000000
Application start address: 0x08008000
Total flash: 256 KB
Flash page size: 2 KB
In my bootloader code, I handle a specific FDCAN message with ID 0x555 as a signal to erase the entire application area (from 0x08008000 to 0x080FFFFF).
:white_heavy_check_mark:What works:
The bootloader receives the erase command correctly from FDCAN.
It calls HAL_FLASHEx_Erase() and returns HAL_OK.
The UART debug log confirms the erase was “successful”.
:cross_mark:The problem:
After erasing, when I read back the flash content at address 0x08008000, I still see the previous application data (e.g., 0x20024000, 0x08008859, etc.), not 0xFFFFFFFF as expected.
:magnifying_glass_tilted_left:Debug output example:
? Waiting for FDCAN ERASE command (ID=0x555)...
? ERASE command received!
? Flash Erased.
FLASH[0x08008000] = 0x20024000
FLASH[0x08008004] = 0x08008859
FLASH[0x08008008] = 0x08008845
FLASH[0x0800800C] = 0x08008847
I have already checked the Option Bytes using STM32CubeProgrammer:
:counterclockwise_arrows_button:My Question:
Why does the application flash area not get fully erased (all bytes to 0xFF) even though HAL_FLASHEx_Erase() returns success?
Is there something specific I need to configure for STM32G0B1CCT6 to allow proper flash erasure?
I’ve attached my bootloader code and debug output for reference.
Any help is appreciated. Thank you!
