cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with Flash Erase in Single Bank Mode on STM32G0B0

Comelit_HEBM
Associate

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 bank 2 user pages address in main.h

 

#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 */

 

  • Update "FLASH_USER_START_ADDR" and "FLASH_USER_END_ADDR"

 

#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 */

 

  • Update GetPage and GetBank:

 

/**
  * @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.

 

 

 

 

 

 

 

 

 

 

 

1 REPLY 1
Saket_Om
ST Employee

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).

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

Thanks
Omar