STM32 core 3.0.1-dev
Arduino core for STM32 based boards: API reference
← STM32duino documentation
Loading...
Searching...
No Matches
stm32_eeprom.c File Reference

Provides emulated eeprom from flash. More...

#include "stm32_eeprom.h"
#include "stm32yyxx_ll_utils.h"
#include <string.h>
#include <stdbool.h>

Macros

#define EEPROM_FLASH_PAGE_NUMBER   ((uint32_t)(((LL_GetFlashSize() * 1024) / FLASH_PAGE_SIZE) - 1))
 Flash bank used for the EEPROM emulation.
 
#define FLASH_BASE_ADDRESS   ((uint32_t)((FLASH_END + 1) - FLASH_PAGE_SIZE))
 Address of the last byte of the flash area used for the EEPROM emulation.
 

Functions

uint8_t eeprom_read_byte (const uint32_t pos)
 Read a byte from the emulated EEPROM (flash).
 
void eeprom_write_byte (uint32_t pos, uint8_t value)
 Write a byte to the emulated EEPROM (flash).
 
uint8_t eeprom_buffered_read_byte (const uint32_t pos)
 Read a byte from the EEPROM buffer, flash is not read.
 
void eeprom_buffered_write_byte (uint32_t pos, uint8_t value)
 Write a byte to the EEPROM buffer, flash is not updated.
 
void eeprom_buffer_fill (void)
 Copy the data from flash into the EEPROM buffer.
 
void eeprom_buffer_flush (void)
 Write the EEPROM buffer content into flash.
 
 HAL_FLASH_Lock ()
 

Variables

static uint8_t eeprom_buffer [E2END+1] = {0}
 RAM copy of the emulated EEPROM, 8 bytes aligned for the flash programming.
 

Detailed Description

Provides emulated eeprom from flash.

Attention

Copyright (c) 2016-2021, STMicroelectronics All rights reserved.

This software component is licensed by ST under BSD 3-Clause license, the "License"; You may not use this file except in compliance with the License. You may obtain a copy of the License at: opensource.org/licenses/BSD-3-Clause

Macro Definition Documentation

◆ EEPROM_FLASH_PAGE_NUMBER

#define EEPROM_FLASH_PAGE_NUMBER   ((uint32_t)(((LL_GetFlashSize() * 1024) / FLASH_PAGE_SIZE) - 1))

Flash bank used for the EEPROM emulation.

Can be overridden before including this file.

Flash sector used for the EEPROM emulation. Can be overridden before including this file.

Flash page number used for the EEPROM emulation. Can be overridden before including this file.

◆ FLASH_BASE_ADDRESS

#define FLASH_BASE_ADDRESS   ((uint32_t)((FLASH_END + 1) - FLASH_PAGE_SIZE))

Address of the last byte of the flash area used for the EEPROM emulation.

Can be overridden.

Start address of the flash area used for the EEPROM emulation. Can be overridden.

By default, use the last page of the flash to store data in order to prevent overwriting program data.

Function Documentation

◆ eeprom_buffer_fill()

void eeprom_buffer_fill ( )

Copy the data from flash into the EEPROM buffer.

Note
Any pending change in the buffer which was not flushed is overwritten.

◆ eeprom_buffer_flush()

void eeprom_buffer_flush ( )

Write the EEPROM buffer content into flash.

Note
Use it after eeprom_buffered_write_byte() to make the changes persistent.

◆ eeprom_buffered_read_byte()

uint8_t eeprom_buffered_read_byte ( const uint32_t  pos)

Read a byte from the EEPROM buffer, flash is not read.

Parameters
posAddress to read.
Returns
Data read from the EEPROM buffer.

◆ eeprom_buffered_write_byte()

void eeprom_buffered_write_byte ( uint32_t  pos,
uint8_t  value 
)

Write a byte to the EEPROM buffer, flash is not updated.

Parameters
posAddress to write.
valueValue to write.

◆ eeprom_read_byte()

uint8_t eeprom_read_byte ( const uint32_t  pos)

Read a byte from the emulated EEPROM (flash).

With a real data EEPROM, pos is a relative address and 0 is returned if it is out of range. Otherwise the flash content is first copied into the EEPROM buffer.

Parameters
posAddress to read.
Returns
Data read from EEPROM.

◆ eeprom_write_byte()

void eeprom_write_byte ( uint32_t  pos,
uint8_t  value 
)

Write a byte to the emulated EEPROM (flash).

With a real data EEPROM, pos is a relative address and the write is ignored if it is out of range. Otherwise the byte is written to the EEPROM buffer, then the whole buffer is written into flash.

Parameters
posAddress to write.
valueValue to write.