2024-10-23 03:51 AM
Hello,
I'm encountering a problem with the STM32G0B0 (also applicable to the STM32G0B1RE) when using flash memory in single bank mode.
My application requires single bank mode, but when I use the erase function to erase pages (from both bank 1 and bank 2), it erases the wrong page.
using the "FLASH_EraseProgram" example provided on the STM32CubeFw with the updates below:
#define ADDR_FLASH_PAGE_128 ((uint32_t)0x08040000) /* Base @ of Page 128, 2 Kbytes */
#define ADDR_FLASH_PAGE_129 ((uint32_t)0x08040800) /* Base @ of Page 129, 2 Kbytes */
#define ADDR_FLASH_PAGE_130 ((uint32_t)0x08041000) /* Base @ of Page 130, 2 Kbytes */
#define ADDR_FLASH_PAGE_131 ((uint32_t)0x08041800) /* Base @ of Page 131, 2 Kbytes */
#define FLASH_USER_START_ADDR ADDR_FLASH_PAGE_126 /* Start @ of user Flash area */
#define FLASH_USER_END_ADDR (ADDR_FLASH_PAGE_131 + FLASH_PAGE_SIZE - 1) /* End @ of user Flash area */
/**
* @brief Gets the page of a given address
* @PAram Addr: Address of the FLASH Memory
* @retval The page of a given address
*/
static uint32_t GetPage(uint32_t Addr)
{
uint32_t page = 0;
/* Single Bank Mode */
page = (Addr - FLASH_BASE) / FLASH_PAGE_SIZE;
return page;
}
/**
* @brief Gets the bank of a given address
* @PAram Addr: Address of the FLASH Memory
* @retval The bank of a given address
*/
static uint32_t GetBank(uint32_t Addr)
{
return FLASH_BANK_1;
}
When I attempt to erase page 128 (the first page in bank 2), it instead erases page 0 (the first page in bank 1, which contains the application binary).
However, if I split the erase operation into two parts, first erasing the pages in bank 1, then erasing the pages in bank 2 and update the GetPage and GetBank functions as follows, the erase function works properly (as it does in dual bank mode):
/**
* @brief Gets the page of a given address
* @PAram Addr: Address of the FLASH Memory
* @retval The page of a given address
*/
static uint32_t GetPage(uint32_t Addr)
{
uint32_t page = 0;
if (Addr < (FLASH_BASE + FLASH_BANK_SIZE))
{
/* Bank 1 */
page = (Addr - FLASH_BASE) / FLASH_PAGE_SIZE;
}
else
{
/* Bank 2 */
page = (Addr - (FLASH_BASE + FLASH_BANK_SIZE)) / FLASH_PAGE_SIZE;
}
return page;
}
/**
* @brief Gets the bank of a given address
* @PAram Addr: Address of the FLASH Memory
* @retval The bank of a given address
*/
static uint32_t GetBank(uint32_t Addr)
{
if (Addr < (FLASH_BASE + FLASH_BANK_SIZE))
return FLASH_BANK_1;
else
return FLASH_BANK_2;
}
Is there any way to handle the flash properly in single bank mode without splitting the erase operation? Any suggestions or insights into this issue would be greatly appreciated.
Thank you in advance.
2024-10-25 08:23 AM
Hello @Comelit_HEBM
I reported your request internally and will get back to you as soon as possible.
Internal ticket number: 194852 (This is an internal tracking number and is not accessible or usable by customers).