2025-06-15 9:39 PM - last edited on 2025-06-16 3:14 AM by Andrew Neil
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.
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).
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”.
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.
? 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:
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!
2025-06-16 2:56 AM
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
2025-06-16 3:13 AM
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;