Skip to main content
Associate III
November 15, 2024
Question

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

  • November 15, 2024
  • 30 replies
  • 5783 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.

30 replies

Associate III
November 15, 2024

(duplicate thread - merged)

 

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

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

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate III
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

Associate III
November 15, 2024

is STSW-STM32066  code work for stm32f4219i-disc1?

Associate III
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. 

Associate III
November 16, 2024

yes iam using HAL library

Associate III
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();
			}
		}
	}
}

 

 

 

mƎALLEm
ST 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.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Associate III
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

/**
* @}
*/

 

Andrew Neil
Super User
November 25, 2024

@syedhashmiraza wrote:

hello in this code not storing string after power cut and poer on in eeprom not storing and in this code 


That code seems to be unchanged from your earlier post:

https://community.st.com/t5/stm32-mcus-products/use-stm32f4-flash-for-non-volatile-data-storage-eeprom/m-p/743983/highlight/true#M266531

I asked you questions about that, and pointed out some issues here:

https://community.st.com/t5/stm32-mcus-products/use-stm32f4-flash-for-non-volatile-data-storage-eeprom/m-p/744136/highlight/true#M266554

 


@syedhashmiraza wrote:

how to use printf?


That's an entirely separate question.

  1. First, you need to get basic, direct UART output working:
    https://wiki.st.com/stm32mcu/wiki/Getting_started_with_UART

  2. Then - and only then - you can redirect printf to your working UART output:
    https://community.st.com/t5/stm32-mcus/how-to-redirect-the-printf-function-to-a-uart-for-debug-messages/ta-p/49865 

https://community.st.com/t5/stm32-mcus-embedded-software/how-to-redirect-the-printf-function-to-a-uart-for-debug-messages/m-p/740284/highlight/true#M56711

Of course, having got the basic UART output working, you may find that you don't really need printf ...

If you have further questions about that, it is a separate question - so do start a new thread for it.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate III
November 25, 2024

hello in this code iam storing string but  after power cut string is not storing in eeprom and how can i use printf for stm32f429i-disc1 for this code 

 

 

 

</* 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

/**
* @}
*/>

 

 

mƎALLEm
ST 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.

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