cancel
Showing results for 
Search instead for 
Did you mean: 

Use STM32F4 flash for non-volatile data storage (eeprom)

syedhashmiraza
Associate II

hello i am using stm32f429i-disc1 microcontroller in this how to generate flash code (eeprom)

22 REPLIES 22

@syedhashmiraza wrote:

this code is not build in stm32cubeide


how did you download from GitHub?

It's important to use git clone --recursive - the Zip download won't work:

https://community.st.com/t5/stm32-mcus/downloading-stm32cube-packages-from-github-correctly/ta-p/725288

 

Hello @syedhashmiraza 

Please don't duplicate the same subject on multiple threads. 

This thread will be merged with the previous one.

Thank you for your understanding.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@syedhashmiraza wrote:

this is my code but in this code string is not storing in eeprom


So you got it to build? Well done!

How do you determine that the string is not being stored?

Is it storing anything at all ?

Did you run the demo? Did that work?

Did you study the Application Note, which describes what this code does, and how to use it?

AndrewNeil_0-1731928988327.png

https://www.st.com/resource/en/application_note/an3969-eeprom-emulation-in-stm32f40xstm32f41x-microcontrollers-stmicroelectronics.pdf#page=13

As that description says, the EE_WriteVariable() function updates a Virtual Variable in the emulated EEPROM.

See also the documentation in the source code itself:

/**
* @brief Writes/updates variable data in EEPROM.
* @param VirtAddress: Variable virtual address
* @param Data: 16 bit data to be written
* @retval Success or error status:
* - FLASH_COMPLETE: on success
* - PAGE_FULL: if valid page is full
* - NO_VALID_PAGE: if no valid page was found
* - Flash error code: on write Flash error
*/

So that's writing 16-bit data - or two characters at once.

You will need something like:

 

char writeString[] = "Hello";
int string_idx = 0;  // Index to characters in the string
int eeprom_idx;      // Index to Virtual Variables in the emulated EEPROM
for( eeprom_idx = 0; i < strlen(writeString)/2; eeprom_idx++ )
{
   if( EE_WriteVariable( VirtAddVarTab[0] + eeprom_idx, (uint16_t*)&writeString[string_idx ]) != HAL_OK)
   {
      Error_Handler();
   }
   string_idx += 2;
}

 

 

In general, you will have to also cope with

  1. Odd number of characters in the string
  2. Having enough Virtual Variables for the length of the string.

In both cases, you are lucky so far that this happens to be OK.

 

As I said initially:

"It may not exactly suit your requirements, but it does show how to use the STM32F4 Flash for data storage."

It certainly isn't great for saving strings ...