Teste semf



The main function of this module is to emulate the EEPROM behavior on a flash memory, where single byte(s) can be read, written or erased; what is not allowed by the flash memory, because erasing is done over a whole page or even sector.


In order to create an EepromEmulation object, a bunch of input parameters must be passed to its constructor: Reference to the Flash object, addresses of two flash pages (used to emulate the EEPROM), size of a Flash page in bytes and number of entries to be stored in the EEPROM emulator.

The input pages/sectors MUST have the same size.
An entry has a maximum size of 4 bytes, and the maximum number of entries is size of a flash page divided by 8 N(max) = pageSize [bytes]/8 [bytes].
In the following example, we consider the hardware flash memory of stm32f4 microcontroller, which is already defined in semf library. The main goal of this class is to link the interface of the semf library with the hardware abstraction layer of the microcontroller.
Stm32f4 microcontroller is provided with a main flash memory of 12 sectors with different sizes as shown in the figure below.
Please configure the linker script to avoid double used sectors by the program data and the logged data.

#include "HardwareAbstraction/Stm32/stm32f4flash.h"
#include "Components/Storage/EepromEmulation/eepromemulation.h"

// 100 entries are going to be stored in the EEPROM emulator.
static constexpr uint32_t kEntriesNumber 100;
semf::Stm32F4Flash internalFlash;  
semf::EepromEmulation emulator(internalFlash, 
	internalFlash.sector(0) /*address of sector 0*/, 
	internalFlash.sector(1) /*address of sector 1*/,
	internalFlash.sectorSize(0) /*sector size in bytes*/, 



// read 5 data entries at address 10 in the EEPROM emulator. 
uint32_t dataReadEeprom[5] = {0};
emulator.read(10, dataReadEeprom, 5);

// slot, which is invoked by 'dataAvailable'-signal from EEPROM emulator object.
void onEntriesRead()
	// do something

// writes 2 entries to start address 0
uint32_t dataWrittenEeprom[2] = {1, 2};
emulator.write(0, dataWrittenEeprom, 2);
// slot, which is invoked by 'dataWritten'-signal from EEPROM emulator object.
void onEntriesWritten()
	// do something
// slot, which is invoked by 'readyInitialized'-signal from EEPROM emulator object.
void onEepromInitialized()
	// initialization done

zurück zur Dokumentation