cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0 Bootloader – Flash Erase Command via FDCAN Doesn't Erase Flash to 0xFF

AKG123
Associate II

 

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:

 

bash
 
ERASE command received! Flash Erased. FLASH[0x08008000] = 0x20024000 FLASH[0x08008004] = 0x08008859 FLASH[0x08008008] = 0x08008845 FLASH[0x0800800C] = 0x08008847
? 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!

2 REPLIES 2
SirineST
ST Employee

Hello @AKG123 

At first glance, it seems your application is using the FDCAN2 instance. However, according to AN2606 (Table 102, page 244), only the FDCAN1 instance supports bootloader communication. Could you please try using FDCAN1 to see if it resolves the issue?

With regards

 

If your question is answered, please close this topic by clicking "Accept as Solution"

Indeed it does:

/**
  * @brief FDCAN2 Initialization Function
  * @PAram None
  * @retval None
  */
static void MX_FDCAN2_Init(void)
{
  /* USER CODE BEGIN FDCAN2_Init 0 */
  /* USER CODE END FDCAN2_Init 0 */
  /* USER CODE BEGIN FDCAN2_Init 1 */
  /* USER CODE END FDCAN2_Init 1 */

  hfdcan2.Instance = FDCAN2;
A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.