cancel
Showing results for 
Search instead for 
Did you mean: 

How to erase pages on bank 2 on stm32g4?

Rafael Bachmann
Associate II

I was trying to erase some flash pages on an stm32g474re nucleo (and on a custom board with the stm32g474veh3).

The flash pages are all on flash bank 2, because i read in the reference manual that flash bank 2 can be written while code is running from bank 1.

However, erasing pages in the second bank (by setting 'Banks' of the FLASH_EraseInitTypeDef to FLASH_BANK_2) has no effect.

In the example given in https://www.st.com/en/embedded-software/stm32cubeg4.html, (STM32Cube_FW_G4_V1.1.0/Projects/NUCLEO-G474RE/Examples/FLASH/FLASH_EraseProgram), there is a function defined called

uint32_t GetBank(uint32_t Addr)

which just returns FLASH_BANK_1.

This does not make sense to me, isn't flash bank 2 the one bank where erasing or writing makes sense?

Greetings,

Rafael

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

The flash in the STM32G4 can be run in either single bank or dual bank mode. (Because why not make it as confusing as possible?)

Is your FLASH_OPTR_DBANK macro defined to enable dual bank mode?

The example you're pointing to runs in single bank mode, so all memory is bank 1.

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

View solution in original post

6 REPLIES 6
TDK
Guru

The flash in the STM32G4 can be run in either single bank or dual bank mode. (Because why not make it as confusing as possible?)

Is your FLASH_OPTR_DBANK macro defined to enable dual bank mode?

The example you're pointing to runs in single bank mode, so all memory is bank 1.

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

Hello @Community member​ ,

You are right, the second bank in the STM32G4-Flash presentation is typo mistake.

In RM0440 is correct and it should be 0x0804 0000 - 0x0804 07FF.

I will raise this internally for correction.

Best Regards,

Imen

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

Just noticed that you also got it wrong in the Youtube video of the presentation...

Hmm, are you sure that this example really uses single bank mode? Because dual bank is the default and the example also defines pages as 2 KB, not 4 KB as in single bank mode.

So did they maybe just implement the GetBank() incorrectly?

Best regards,

Anguel

RBach.1
Associate II

For what its worth, see here: https://github.com/barafael/g4-dual-bank-example