cancel
Showing results for 
Search instead for 
Did you mean: 

Can't flash erase on "Single bank mode" (STM32G4)

filvas
Associate

Hi!
I have no problem with writing, reading, or erasing with dual mode, but erase stops working as soon as I change the DBANK option byte to "Single bank mode" (Uncheck it).

filvas_0-1705587380408.png

I assume there is something i need to change in the STM32G4XX files as well, because DBANK is always defiend:

filvas_0-1705588493883.png

I have tried to search on my own, but have not found any solution. Out of the 2 relevant hits I found online, one did not work and the other seems to be unverified and not easy to test

This is my code, which simply calls "stm32g4xx_hal_flash.c" and "stm32g4xx_hal_flash_ex.c" functions

 

 

 

 

if(HAL_FLASH_Unlock() == HAL_OK)
{   
    uint32_t PageError;
    if(HAL_FLASHEx_Erase(&pEraseInit, &PageError) != HAL_OK)
    {
        HAL_FLASH_GetError();
    } 
    while(HAL_FLASH_Lock() != HAL_OK);
}

 

 

 

 

 Anyone have any suggestion?

Thank you in advance

1 REPLY 1
Saket_Om
ST Employee

Hello @filvas 

 

To erase in single bank mode on an STM32G4 platform, you should follow these steps:

  1. Ensure that the DBANK option bit is cleared to enable single bank mode. This can be done using the STM32CubeProgrammer tool by navigating to OB (Option Bytes) and then to User Configuration to check the DBANK setting.

  2. Execute the code from SRAM or use the bootloader to avoid reading corrupted data from the Flash when the memory organization is changed.

  3. If any secure Flash protection is enabled, it must be disabled.

  4. Disable the instruction cache if it is enabled.

  5. Clear the DBANK option bit and all WRP write protection by following the user option modification and option bytes loader procedure.

  6. Once the option byte loading (OBL) is done with DBANK=0, perform a mass erase.

  7. Start a new programming of code in 128 bits mode with DBANK=0 memory mapping.

  8. Set the new secure protection if needed.

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

Thanks
Omar