Skip to main content
BMcK
Associate II
August 30, 2021
Question

STM32G4 flash write/erase

  • August 30, 2021
  • 16 replies
  • 6202 views

I'm quite confused. The RM0440 states: "Note that read-while-write capability (or RWW) is only supported when the dual-bank architecture is active. This enables programming or erasing one bank while executing code from the other bank." Okay, for me, it means that if a single bank option is selected then it is impossible to write/erase flash executing user code at all. Correct? Then programming and/or erasing flash is possible only for category 3 devices (G431 is out of the picture immediately). The next step is to verify if dual bank mode is selected, then to deal with the page in the alternative to the user code bank.

I wrote a simple example code doing exactly that, but it is inconsistent: sometimes works as expected, mostly does not. I do not use Cube but direct access to the registers. What is wrong with my logic and where should I pay more attention.

Thanks in advance.

This topic has been closed for replies.

16 replies

Bubbles
ST Employee
August 30, 2021

Hello @BMcK​ ,

the usual practice in single bank device is to set the linker to place the functions that write/erase the Flash in SRAM. That way the code can execute even when the Flash is being manipulated.

J.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
BMcK
BMcKAuthor
Associate II
August 30, 2021

Thank you for the reply.

Basically, you're saying that my understanding is correct.

Could you please point me to a GCC example(I'm a Keil user) of how to locate my flash access functions in SRAM. My guess is that they should be located in some dedicated section, and this section should be located in SRAM.

Bubbles
ST Employee
August 30, 2021

0693W00000DldFuQAJ.pngEasiest is to open source file options using right mouse button and set SRAM as memory assignment for code. For finer adjustments you need to build your own scatter file.

J.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
BMcK
BMcKAuthor
Associate II
September 1, 2021

PS: the reason my simple example code didn't reliably work was... the Nucleo board I was using did NOT have a boot pin jumper installed while option bytes were changed from the default and that was causing me to get into ROM bootloader...

It is so hard to catch a black cat in a dark room that's not there.