Skip to main content
YBend.1
Associate III
Jan 23, 2023 6:17 AM UTC
Question

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.

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!!!

This topic has been closed for replies.

12 replies

gbm
Super User
Jan 23, 2023 7:16 AM UTC

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
YBend.1Author
Associate III
Jan 23, 2023 8:10 AM UTC

Thanks gbm,

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

Javier1
Principal
Jan 23, 2023 8:21 AM UTC

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

0693W00000Y8tGVQAZ.png

hit me up in https://www.linkedin.com/in/javiermuñoz/
YBend.1
YBend.1Author
Associate III
Jan 23, 2023 8:41 AM UTC

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.

Javier1
Principal
Jan 23, 2023 9:23 AM UTC

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.

hit me up in https://www.linkedin.com/in/javiermuñoz/
YBend.1
YBend.1Author
Associate III
Jan 23, 2023 10:12 AM UTC

Okay Javier got it,

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

Any other suggestions?

YBend.1
YBend.1Author
Associate III
Jan 23, 2023 11:01 AM UTC

@gbm​ ,

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

Thanks.

gbm
Super User
Jan 23, 2023 11:21 AM UTC

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
YBend.1Author
Associate III
Jan 23, 2023 1:45 PM UTC

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!!!

gbm
Super User
Jan 23, 2023 1:52 PM UTC

In the code above, you've set .Page twice and you didn't set .NbPages or PageAddress at all. Read the docs, look at the examples, then write your code. I do not use HAL, so I can't help here.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
YBend.1
YBend.1Author
Associate III
Jan 24, 2023 9:07 AM UTC

Thanks @gbm​ .

I will go through the documentation and if I am yet stuck I will ask with the HAL tag in the forum, since the issue seems to have been identified.

gbm
Super User
Jan 24, 2023 10:25 AM UTC

There is no issue, it's just you are not passing the required parameters.

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