2023-01-22 10:17 PM
I 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!!!
2023-01-22 11:16 PM
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.
2023-01-23 12:10 AM
Thanks gbm,
Thanks for pointing the problem out. Any changes you could please suggest in my code for incorporating this change.
2023-01-23 12:21 AM
you hardcoded a bunch of 8s and 4s , im sure you skipped/swapped one of those
2023-01-23 12:41 AM
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.
2023-01-23 01:23 AM
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.
2023-01-23 02:12 AM
Okay Javier got it,
But I tried multiple values that made sense, but I am getting the same error.
Any other suggestions?
2023-01-23 03:01 AM
@gbm ,
Can you please tell me how I can inculcate the change you are suggesting into my code.
Thanks.
2023-01-23 03:21 AM
Look at the EraseInitStruct.Page = statements in your code, one after another. They don't seem to be correct.
2023-01-23 05:45 AM
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!!!