cancel
Showing results for 
Search instead for 
Did you mean: 

I wish to store data in the flash memory of my STM32G030C8T6 microcontroller. The issue I am facing is that my data is not being stored in contiguous memory banks, but rather the banks are being skipped, as seen from the image.

YBend.1
Associate III

0693W00000Y8sbDQAR.pngI have written a small driver code for the same to store different types of data types to a memory location.

The link to my code is: Yadnik1/Eeprom-Emulation-driver-STM32 (github.com)

and I have taken reference from here: STM32/FLASH_PROGRAM/F1 SERIES at master ·

Reference Blog: How to Program Flash memory in STM32 » ControllersTech

The available code was for STM32F103C8T6 microcontroller, and I had to make some changes to the code for my g0 series MCU.

It would be very helpful if someone can please tell me what mistake I am making.

Thank you very much!!!

12 REPLIES 12
gbm
Lead III

G0 require the Flash memory to be written in units of 64-bit words - check the manual. You cannot write it by words (32-bit), only in pairs.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
YBend.1
Associate III

Thanks gbm,

Thanks for pointing the problem out. Any changes you could please suggest in my code for incorporating this change.

Javier1
Principal

you hardcoded a bunch of 8s and 4s , im sure you skipped/swapped one of those

0693W00000Y8tGVQAZ.png

we dont need to firmware by ourselves, lets talk
YBend.1
Associate III

Thanks a lot Javier for pointing that out,

What should the values be according to you, in place of 8?

Beacuse

uint32_t EndPageAdress = StartPageAddress + numberofwords*4;

and

StartPageAddress += 8;

are yielding the same result.

I am not saying the value shouldnt be 8/4, i meant if those numbers are harcoded like that there is usually a big chance you messed up some.

we dont need to firmware by ourselves, lets talk

Okay Javier got it,

But I tried multiple values that made sense, but I am getting the same error.

Any other suggestions?

YBend.1
Associate III

@gbm​ ,

Can you please tell me how I can inculcate the change you are suggesting into my code.

Thanks.

gbm
Lead III

Look at the EraseInitStruct.Page = statements in your code, one after another. They don't seem to be correct.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
YBend.1
Associate III

Thanks @gbm​ ,

I think I have got where the issue is.

I am doing:

EraseInitStruct.Page = StartPage;

EraseInitStruct.NbPages = ((EndPage - StartPage)/(FLASH_PAGE_SIZE)) +1;

whereas in the example code it is

EraseInitStruct.PageAddress = StartPage; EraseInitStruct.NbPages = ((EndPage - StartPage)/FLASH_PAGE_SIZE) +1;

Most probably this is causing the issue.

The definition of Page is: Initial Flash page to erase when page erase is enabled. This parameter must be a value between 0 and (FLASH_PAGE_NB - 1)

and that of PageAddress is: Initial FLASH page address to erase when mass erase is disabled. This parameter must be a number between Min Data = 0x08000000 and Max_Data = FLASH_BANKx_END (x = 1 or 2 depending on devices).

Can you please suggest an alternative to be used for PageAdress for g0 series, as I am not able to identify what the correct variable alternative to PageAdress could be.

Thanks!!!