2024-01-18 06:49 AM
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).
I assume there is something i need to change in the STM32G4XX files as well, because DBANK is always defiend:
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
2024-06-19 03:49 AM
Hello @filvas
To erase in single bank mode on an STM32G4 platform, you should follow these steps:
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.
Execute the code from SRAM or use the bootloader to avoid reading corrupted data from the Flash when the memory organization is changed.
If any secure Flash protection is enabled, it must be disabled.
Disable the instruction cache if it is enabled.
Clear the DBANK option bit and all WRP write protection by following the user option modification and option bytes loader procedure.
Once the option byte loading (OBL) is done with DBANK=0, perform a mass erase.
Start a new programming of code in 128 bits mode with DBANK=0 memory mapping.
Set the new secure protection if needed.