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.

 

 

 

 

 

 

 

 

 

 

 

2 REPLIES 2
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
TOUNI.1
ST Employee

Hello @Comelit_HEBM,

Thank you for your contribution. You are absolutely right about this point.

Actually, the point you raised has already been addressed internally. A new revision of the reference manual will be published with all the necessary information regarding the operation of the G0 512K devices in single/dual FLASH banks mode. Here are some points to mention that are related to your issue:

  • The 512K Flash bank device always operate in dual-bank mode. (The DUAL_BANK option byte (OB) has no effect).
  • The nSWAP_BANK and DUAL_BANK settings are not considered for page erasing.
  • For page erasing, nSWAP_BANK is not considered.Page erasing is always linked to the physical bank, which explains why, when you attempted to erase page 128 (the first page in bank 2), page 0 of bank 1 was erased.
  • The page number ranges from 0 to 127 per bank. (The FLASH_CR_PNB bit can hold values from 0x00 to 0x7F, not from 0x00 to 0x17F.

All this information will be included in the next revision of the reference manual.

 

Thank you again for your contribution. If you have any further questions or need additional assistance, please do not hesitate to reach out.

Best regards,