Skip to main content
Bs.1
Associate III
October 22, 2020
Question

How to store data on non erasable memory of controller during run time.

  • October 22, 2020
  • 5 replies
  • 1865 views

I am using STM32L442KC part number...And i want to store the 16 byte of data on non erasable memory of controller during runtime...Can i get any reference how to store the data in microcontroller memory???

This topic has been closed for replies.

5 replies

Tesla DeLorean
Guru
October 22, 2020

Which OPT bytes would these be?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Bs.1
Bs.1Author
Associate III
October 27, 2020

The exact option byte/address has not been decided yet...the actual requirement is during runtime client system is going to send one string to my system and i have to store that string at non erasable memory to use afterward for further processing....I am stuck with how to store that received data in internal non erasable memory...

I found some API during search EEPROM_WriteData(), EEPROM_ReadData().... but stuck at how to generate the related API or middleware..

TDK
October 22, 2020

You can use the EEProm emulation software, or you can roll your own solution:

https://www.st.com/resource/en/application_note/dm00311483-eeprom-emulation-techniques-and-software-for-stm32-microcontrollers-stmicroelectronics.pdf

You need to erase the flash page and program your data each time you want to change it.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Bs.1
Bs.1Author
Associate III
October 24, 2020

Hi TDK,

Thanks for your reply...

I have downloaded the EEProm emulation software(X-CUBE-EEPROM_V2.0.0). But in that there are so many files found in project folder of my targeted microcontroller.

I am stuck up with how to use that files in my actual code....

if any reference for how to use this files will be very helpful for me....

TDK
October 27, 2020

I don't use the EEPROM emulation software myself. I do have the same thing working on a few projects, but with my own code. I would imagine the code works on a STM32L442KC with few changes, but I'm guessing here.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Bs.1
Bs.1Author
Associate III
October 28, 2020

Have you written on internal EEPROM in your code??if yes, how you have did this?? So that i can try the same logic in my code.

I am using STM32L442KC with AES functionality used in it...

TDK
October 28, 2020
HAL_FLASH_Program will write to flash. You need to erase the page before writing. That's the basics.
I don't want to share anything other than very basic code because that ends up as more work for me.
"If you feel a post has answered your question, please click ""Accept as Solution""."
TDK
November 8, 2020

There are multiple issues here:

You need to erase the flash page before writing, as stated earlier. That's just how FLASH works. Its not random-access memory.

The address 0x8000001 is in the first page of flash and is very likely being used by your program. Overwriting it will likely prevent your code from working. Typically people use the last page in flash to write user data.

You are writing a double-word value to a non double-word aligned address. I didn't check, but my guess is this is not allowed. If you only need to write a byte, write a byte.

> can I read that data using particular API..?

STM32CubeProgrammer can show you the current state of the flash memory.

Here is an example for the F4 family that you can use as a guide. The code for an L4 chip should be very similar.

https://github.com/STMicroelectronics/STM32CubeF4/blob/a86ecaa2fb63029596ba7dabadab2d9c2c139560/Projects/STM32446E-Nucleo/Applications/EEPROM/EEPROM_Emulation/readme.txt

"If you feel a post has answered your question, please click ""Accept as Solution""."
Bs.1
Bs.1Author
Associate III
November 10, 2020

Thank you very much for your valuable guidance..

I have tried with the last pages addresses...

i.e 0x08010000

 HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, 0x08010000, 65);

And i can able to successfully write on that address. And also able to read that location..

its works fine.

Only the issue is unable to erase or overwrite that location.

I tried with the API void FLASH_PageErase(uint32_t Page, uint32_t Banks)

i.e page is 63 & bank is 1.

FLASH_PageErase(63, 1);

TDK
November 10, 2020

> 0x08010000

> FLASH_PageErase(63, 1);

Why do you think 0x08010000 is in page 63?

2kB per page. 0x10000/2048 = 32, so that's the start of page 32.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Bs.1
Bs.1Author
Associate III
November 17, 2020

Hi....

Yes, its page 32...

I was my mistake, i have wrtten it as page 63..

I have corrected it page 32. still unable to erase the location.