cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I am doing a project with the stm32G431 micro controller with arm processor. I am trying to figure out how to write and read from flash memory correctly but I cant figure it out.

Ide p.11
Associate II

# I am willing to pay for a couple of hours help. I have some experience with micro controller but not enough to understand from the reference manual.

7 REPLIES 7
Imen Ezzine
ST Employee

Hi Ide p.1,

I can advise you to take a look at the STM32CubeG4. You will find different examples for the stm32G431 that can help you get started with your device and to be inspired for making your own projects.

I hope this help!

-Imen

Ide p.11
Associate II

Hi,

I have stmCubeIde and STM32CubeMonitor. I have done small projects but I am stuck specifically on writing and reading from flash memory.

ARM has a flat memory map, i.e. FLASH is mapped in the same way as RAM, so you can access it in the same way as you access FLASH.

Actually, most Cortex-M C compilers allocate variables qualified as const into FLASH, so if you have such variable, you already read from it.

Writing means erasing first, in pages; and then writing usually word-wise. This is in detail explained in Flash program and erase operations, Flash main memory erase sequences and Flash main memory programming sequences subchapters of the FLASH chapter in RM. Read them thoroughly, try to implement it, and if anything did not work as you though, come back with questions.

JW

Ide p.11
Associate II

Hi,

Thank you.

I was able to write and read from the flash memory. I verified with debugging and looking at the memory map, I wrote to 0x08002000. But after relaunching and checking if it is still there, it seems it was reset to random values. My project is taking values from sensors and calibrating and saving the calibration to flash so next time I Launch the program I can use the values saved in flash, here when I relaunch the code it resets the memory map. Can someone help and understand how to fix?

Thanks

> it was reset to random values

What is "relaunching"?

How do you write? From the program?

Can't be that your programming/debugging environment (what do you use?) writes to that area, too?

JW

I mean by relaunching is that I run a debug session again, I am aware that might cause the reset but I can't be sure, what way can I check that?

I write from the main.c, I am attaching pictures of the erasing,writing and reading procedure.

All this program does is try to write and read to that memory so it is unlikely that my prgram writes to that memory. So maybe the environment writes to it and erases it but how can I be sure? Or how can I know where to write so it will remain there.0693W000003QXbnQAG.png0693W000003QXbiQAG.png

What's this, CubeIDE?

How do you define FLASH_USER_START_ADDR?

Observe mapfile. Is there any mention of the area you are writing to? If not, it may be OK.

Show the memory you are writing into, after the write, and after the "relaunch".

JW