Skip to main content
Visitor II
November 15, 2024
Question

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

  • November 15, 2024
  • 6 replies
  • 5671 views

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

 


Your other thread showed a major confusion between what is a "microcontroller", and what is a "board" - so edited for clarity.

    This topic has been closed for replies.

    6 replies

    Visitor II
    November 15, 2024

    (duplicate thread - merged)

     

    hello i am using stm32f429i-disc1 microcontroller board i want flash code (eeprom) for storing biomatric data

    Super User
    November 15, 2024

    You mean you want to use the Flash for non-volatile data storage - "emulating" EEPROM?

    For that, ST provide the STSW-STM32066 software pack, EEPROM emulation in STM32F40x/STM32F41x microcontrollers:

    https://www.st.com/en/embedded-software/stsw-stm32066.html

    See Application Note AN3969EEPROM emulation in STM32F40x/STM32F41x microcontrollers for details:

    https://www.st.com/en/embedded-software/stsw-stm32066.html#documentation

     

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

    With that knowledge, you could adapt to your own needs; eg, see:
    https://community.st.com/t5/stm32-mcus-embedded-software/eeprom-emulation-virtual-addresses/m-p/675964/highlight/true#M47888

    and follow the link.

     

    PS:

     


    @syedhashmiraza wrote:

    for storing biometric data


    The nature of the data really makes no difference - it's all just data !

    Visitor II
    November 15, 2024

    yes i want to store data in Flash for non-volatile data storage - "emulating" EEPROM i want one refrernce or example code for stm32f429i-disc1

    Visitor II
    November 15, 2024

    is STSW-STM32066  code work for stm32f4219i-disc1?

    Visitor II
    November 16, 2024

    (merged from duplicate thread)

     

    hello iam using srm32f429i-disc1 microcontroller board and i want refrence code for emulated eeprom 

    Visitor II
    November 16, 2024

    I think you have to use the STM32 HAL library. 

    Visitor II
    November 16, 2024

    yes iam using HAL library

    Visitor II
    November 18, 2024

    Hello,

    I want to read and write string in eeprom  this is my code but in this code string is not storing in eeprom

     

    #include "main.h"
    #include <stdio.h>
    
    /** @addtogroup EEPROM_Emulation
    * @{
    */
    
    
    /* Private typedef -----------------------------------------------------------*/
    /* Private define ------------------------------------------------------------*/
    /* Private macro -------------------------------------------------------------*/
    /* Private variables ---------------------------------------------------------*/
    
    
    /* Virtual address defined by the user: 0xFFFF value is prohibited */
    
    uint16_t VirtAddVarTab[NB_OF_VAR] = {0x5555, 0x6666, 0x7777};
    
    uint16_t VarDataTab[NB_OF_VAR] = {0, 0, 0};
    
    uint16_t VarValue,VarDataTmp = 0;
    
    /* Private function prototypes -----------------------------------------------*/
    static void SystemClock_Config(void);
    static void Error_Handler(void);
    
    /* Private functions ---------------------------------------------------------*/
    
    /**
    * @brief Main program.
    * None
    * @retval None
    */
    
    //char writeString[] = "Hello Hashmi";
    char readString[64]={0};
    
    
    int main(void)
    {
    	/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    	HAL_Init();
    
    	/* Configure the system clock to 180 MHz */
    	SystemClock_Config();
    
    	/* Unlock the Flash Program Erase controller */
    	HAL_FLASH_Unlock();
    
    	/* Configure LED3 */
    	BSP_LED_Init(LED3);
    
    	/* EEPROM Init */
    	if( EE_Init() != EE_OK)
    	{
    		Error_Handler();
    	}
    
    	if((EE_ReadVariable(VirtAddVarTab[0], &readString[0])) != HAL_OK)
    	{
    		Error_Handler();
    	}
    	while(1)
    	{
    		char writeString[] = "Hello";
    		for (int i = 0; i < sizeof(writeString); i++)
    		{
    			if (EE_WriteVariable(VirtAddVarTab[0] + i, (uint16_t*)&writeString[i]) != HAL_OK)
    			{
    				Error_Handler();
    			}
    		}
    	}
    }
    

     

     

     

    Technical Moderator
    November 18, 2024

    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.

    Visitor II
    November 25, 2024

    Again, please stop creating multiple threads on the same topic. Merged into original Thread.


     

    hello in this code not storing string after power cut and poer on in eeprom not storing and in this code how to use printf?

     

     

    /* Includes ------------------------------------------------------------------*/
    #include "main.h"
    #include <stdio.h>
    
    /** @addtogroup EEPROM_Emulation
    * @{
    */
    
    /* Private typedef -----------------------------------------------------------*/
    /* Private define ------------------------------------------------------------*/
    /* Private macro -------------------------------------------------------------*/
    /* Private variables ---------------------------------------------------------*/
    
    /* Virtual address defined by the user: 0xFFFF value is prohibited */
    uint16_t VirtAddVarTab[NB_OF_VAR] = {0x5555, 0x6666, 0x7777};
    uint16_t VarDataTab[NB_OF_VAR] = {0, 0, 0};
    
    uint16_t VarValue,VarDataTmp = 0;
    
    /* Private function prototypes -----------------------------------------------*/
    static void SystemClock_Config(void);
    static void Error_Handler(void);
    
    /* Private functions ---------------------------------------------------------*/
    
    /**
    * @brief Main program.
    * None
    * @retval None
    */
    
    //char writeString[] = "Hello Hashmi";
    char readString[64]={0};
    
    int main(void)
    {
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();
    
    /* Configure the system clock to 180 MHz */
    SystemClock_Config();
    
    /* Unlock the Flash Program Erase controller */
    HAL_FLASH_Unlock();
    
    /* Configure LED3 */
    BSP_LED_Init(LED3);
    
    /* EEPROM Init */
    if( EE_Init() != EE_OK)
    {
    Error_Handler();
    }
    
    if (EE_ReadVariable(VirtAddVarTab[0], &VarDataTmp) != HAL_OK)
    {
    Error_Handler();
    }
    
    char writeString[] = "Hello";
    for (int i = 0; i < sizeof(writeString); i++)
    {
    uint16_t charToWrite = (uint16_t)writeString[i];
    
    // Pass the value, not the pointer
    if (EE_WriteVariable(VirtAddVarTab[0] + i, charToWrite) != HAL_OK)
    {
    Error_Handler();
    }
    }
    
    //printf("hello");
    }
    
    static void SystemClock_Config(void)
    {
    RCC_ClkInitTypeDef RCC_ClkInitStruct;
    RCC_OscInitTypeDef RCC_OscInitStruct;
    HAL_StatusTypeDef ret = HAL_OK;
    
    /* Enable Power Control clock */
    __HAL_RCC_PWR_CLK_ENABLE();
    
    /* The voltage scaling allows optimizing the power consumption when the device is
    clocked below the maximum system frequency, to update the voltage scaling value
    regarding system frequency refer to product datasheet. */
    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
    
    /* Enable HSE Oscillator and activate PLL with HSE as source */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
    RCC_OscInitStruct.PLL.PLLM = 8;
    RCC_OscInitStruct.PLL.PLLN = 360;
    RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
    RCC_OscInitStruct.PLL.PLLQ = 7;
    HAL_RCC_OscConfig(&RCC_OscInitStruct);
    ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
    if(ret != HAL_OK)
    {
    while(1) { ; }
    }
    
    /* Activate the Over-Drive mode */
    HAL_PWREx_EnableOverDrive();
    
    /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
    clocks dividers */
    RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
    ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
    if(ret != HAL_OK)
    {
    while(1) { ; }
    }
    }
    
    /**
    * @brief This function is executed in case of error occurrence.
    * None
    * @retval None
    */
    static void Error_Handler(void)
    {
    while(1)
    {
    
    /* Toggle LED3 fast */
    BSP_LED_Toggle(LED3);
    HAL_Delay(40);
    }
    }
    
    #ifdef USE_FULL_ASSERT
    /**
    * @brief Reports the name of the source file and the source line number
    * where the assert_param error has occurred.
    * file: pointer to the source file name
    * line: assert_param error line source number
    * @retval None
    */
    void assert_failed(uint8_t* file, uint32_t line)
    {
    /* User can add his own implementation to report the file name and line number,
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
    
    /* Infinite loop */
    while (1)
    {
    }
    }
    #endif
    
    /**
    * @}
    */

     

    Technical Moderator
    November 25, 2024

    Hello @syedhashmiraza ,

    Please review tips on posting a thread in this community, especially for the following points:

    - Title: "store" does not mean anything in the title needs to be short (not tooo short) and concise.

    - Posting a code: you need to use </> button to paste your code.

    - Part number: always state the FULL Part Number of the product used.

    +

    1- "hello in this code not storing string after power cut and poer on in eeprom not storing and in this code how to use printf?" -> not clear what do you mean by that. Need to elaborate more.

    2- The thread subject is not related to CubeIDE usage but to the product usage -> To be moved to STM32 MCUs Products forum board.

    Thank you for your understanding.

    Technical Moderator
    November 25, 2024

    You posted again the same question in a new thread which I moved to the forum archive.

    Please don't duplicate threads! and keep the discussion in the same conversation until you solve your issue or you have another question.

    Any further duplication will be moved to the archive.

    Thank you for your understanding.