Skip to main content
Visitor
Question

STM32G0B1KC change dual/single bank option by code

I am faced with a flash erase issue at page 126 on a 256k device (STM32G0B1KCU7), although the writing at this location works well (but only one time, of course). It seems to be related to the dual/single bank option.
I've seen a clue in the "STM320B1RE cannot erase page 127 on 256k version" topic.
But changing the bank mode with SetupSTM32CubeProgrammer in production is not an option.
What code should I add to my application to change this bank option?
Many thanks in advance for any help.

3 replies

TDK

I am faced with a flash erase issue at page 126 on a 256k device

If the goal is to erase the page, there is no need to change the dual bank option.

What is the flash erase issue? Show the relevant code. What dual bank mode are you in at the time?

"If you feel a post has answered your question, please click ""Accept as Solution""."
PhilippeDAuthor
Visitor

Thanks for the quick answer.

I want to store some parameters in flash
The writing in flash works well, at both page 63 or page 126
The read-back from flash is ok too.
But the erase works only on the the evaluation board NUCLEO-G0B1RE at both pages.
On the final product, build around a STM32G0B1KCU7, the erase process has absolutely no effect at page 126.
I have also written extra code (not shown here) to trap any error (!HAL_OK or PageError). But there ain't any.
The flash remains programmed with my data. At page 63, it works fine.

This is the code in use for both projects (eval-board and final product)
Tested for both page 63 and then page 126

void myFLASH_Erase_Page(uint32_t Page)
{
FLASH_EraseInitTypeDef EraseInitStruct;
uint32_t PageError;

HAL_FLASH_Unlock();

EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Page = Page; // in this case = 126
EraseInitStruct.NbPages = 1;
EraseInitStruct.Banks = FLASH_BANK_1;

HAL_FLASHEx_Erase(&EraseInitStruct, &PageError);

HAL_FLASH_Lock();

} // End void myFLASH_Erase_Page(uint32_t Page)
//-----------------------------------------------------------------------------

Additional info:
STM32CubeIde Version 2.2.0
In the STM32G0B1KCUX_RAM.ld and STM32G0B1KCUX_FLASH.ld:
MEMORY
{
  RAM    (xrw)    : ORIGIN = 0x20000000,   LENGTH = 144K
  FLASH  (rx)    : ORIGIN = 0x8000000,   LENGTH = 256K
}

Thanks a lot. Philippe.

TDK

You still don’t mention what mode you are in. Are you in dual bank mode or single bank? The DUAL_BANK option byte governs this and can be checked in STM32CubeProgrammer.

The STM32G0B1KCU7 only has 64 pages of flash in each bank in dual bank mode. The nucleo board has 128. While the flash may be physically present, it is not tested and is not supported by HAL. The NUCLEO-G0B1RE has twice as much flash.

What addresses are you writing and checking to see if they erase?

"If you feel a post has answered your question, please click ""Accept as Solution""."