semf
semf::Stm32Flash Class Reference

This Class is for read and write data in the internal flash from the Stm32. More...

#include <stm32flash.h>

Inheritance diagram for semf::Stm32Flash:
Inheritance graph
Collaboration diagram for semf::Stm32Flash:
Collaboration graph

Public Types

enum class  ErrorCode : uint8_t {
  Write_IsBusy = 0 , Write_DataIsNullptr , Write_DataSizeIsZero , Write_DataNot8ByteAligned ,
  Write_DataNot4ByteAligned , Write_DataNot2ByteAligned , Write_HalError , Write_HalBusy ,
  Write_HalTimeout , Read_IsBusy = 0 , Read_BufferIsNullptr , Read_BufferSizeIsZero ,
  Erase_IsBusy , Erase_SectorOutOfBounds , Erase_IsHalError , Erase_IsHalBusy ,
  Erase_IsHalTimeout , Isr_HalError , Isr_HalBusy , Isr_HalTimeout ,
  IsrError_InterruptError
}
 

Public Member Functions

 Stm32Flash (uint16_t size, uint32_t voltageRange, uint32_t bank)
 Constructor. More...
 
 Stm32Flash (uint16_t size, uint32_t bank)
 Constructor. More...
 
 Stm32Flash (uint16_t size)
 Constructor. More...
 
 Stm32Flash (const Stm32Flash &other)=delete
 
virtual ~Stm32Flash ()=default
 
void write (uint32_t address, const uint8_t data[], size_t dataSize) override
 Writes data into the storage. More...
 
void read (uint32_t address, uint8_t buffer[], size_t bufferSize) override
 Reads data from the storage into a given read buffer. More...
 
void erase (size_t sector, size_t numOfSectors=1) override
 Erase sector(s). More...
 
bool isBusy () const override
 Returns if the storage is busy reading, writing or e.g. erasing. More...
 
- Public Member Functions inherited from semf::app::Flash
virtual ~Flash ()=default
 
virtual void erase (size_t sector, size_t numOfSectors=1)=0
 Erase sector(s). More...
 
virtual size_t sector (uint32_t address) const =0
 Return in which sector an address is located. More...
 
virtual uint32_t address (size_t sector) const =0
 Return on which address a sector starts. More...
 
virtual size_t sectorSize (size_t sector) const =0
 Return the size of a sector in bytes. More...
 
virtual size_t numberOfSectors () const =0
 Return the number/amount of sectors of a flash memory. More...
 
- Public Member Functions inherited from semf::app::Storage
virtual ~Storage ()=default
 
virtual void write (uint32_t address, const uint8_t data[], size_t dataSize)=0
 Writes data into the storage. More...
 
virtual void read (uint32_t address, uint8_t buffer[], size_t bufferSize)=0
 Reads data from the storage into a given read buffer. More...
 
virtual bool isBusy () const =0
 Returns if the storage is busy reading, writing or e.g. erasing. More...
 

Static Public Member Functions

static void isr ()
 This function must be called from isr. More...
 
static void isrError ()
 This function is call from isr when an error has occurred. More...
 

Protected Member Functions

uint16_t size () const
 Returns the size of the flash in kBytes. More...
 

Additional Inherited Members

- Public Attributes inherited from semf::app::Flash
Signal erased
 
- Public Attributes inherited from semf::app::Storage
Signal dataAvailable
 
Signal dataWritten
 
Signal< Errorerror
 

Detailed Description

This Class is for read and write data in the internal flash from the Stm32.

Attention
To use this class, the flash interrupt must be activated. In addition, the semfStm32FlashIsr() function must be called in the FLASH_IRQHandler() function after HAL_FLASH_IRQHandler() has been called.

Definition at line 25 of file stm32flash.h.

Member Enumeration Documentation

◆ ErrorCode

enum class semf::Stm32Flash::ErrorCode : uint8_t
strong

Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring).

Enumerator
Write_IsBusy 
Write_DataIsNullptr 
Write_DataSizeIsZero 
Write_DataNot8ByteAligned 
Write_DataNot4ByteAligned 
Write_DataNot2ByteAligned 
Write_HalError 
Write_HalBusy 
Write_HalTimeout 
Read_IsBusy 
Read_BufferIsNullptr 
Read_BufferSizeIsZero 
Erase_IsBusy 
Erase_SectorOutOfBounds 
Erase_IsHalError 
Erase_IsHalBusy 
Erase_IsHalTimeout 
Isr_HalError 
Isr_HalBusy 
Isr_HalTimeout 
IsrError_InterruptError 

Definition at line 29 of file stm32flash.h.

Constructor & Destructor Documentation

◆ Stm32Flash() [1/4]

semf::Stm32Flash::Stm32Flash ( uint16_t  size,
uint32_t  voltageRange,
uint32_t  bank 
)

Constructor.

Parameters
sizeFlash size in kBytes.
voltageRangeOperating voltage range. See microcontroller user manual for HAL and LL drivers in flash extension driver section.
bankFlash bank which is used.

Definition at line 31 of file stm32flash.cpp.

◆ Stm32Flash() [2/4]

semf::Stm32Flash::Stm32Flash ( uint16_t  size,
uint32_t  bank 
)

Constructor.

Parameters
sizeFlash size in kBytes.
bankFlash bank which is used.

Definition at line 39 of file stm32flash.cpp.

◆ Stm32Flash() [3/4]

semf::Stm32Flash::Stm32Flash ( uint16_t  size)
explicit

Constructor.

Parameters
sizeFlash size in kBytes.

Definition at line 47 of file stm32flash.cpp.

◆ Stm32Flash() [4/4]

semf::Stm32Flash::Stm32Flash ( const Stm32Flash other)
explicitdelete

◆ ~Stm32Flash()

virtual semf::Stm32Flash::~Stm32Flash ( )
virtualdefault
Here is the call graph for this function:

Member Function Documentation

◆ erase()

void semf::Stm32Flash::erase ( size_t  sector,
size_t  numOfSectors = 1 
)
overridevirtual

Erase sector(s).

Parameters
sectorThe numerical order of the targeted sector.
numOfSectorsAmount of sectors to be erased.
Exceptions
Erase_IsBusyIf this is busy
Erase_SectorOutOfBoundsIf sector does not exist
Erase_IsHalErrorIf the ST-HAL returns hal error.
Erase_IsHalBusyIf the ST-HAL returns hal busy.
Erase_IsHalTimeoutIf the ST-HAL returns hal timeout.

Implements semf::app::Flash.

Definition at line 145 of file stm32flash.cpp.

Here is the call graph for this function:

◆ isBusy()

bool semf::Stm32Flash::isBusy ( ) const
overridevirtual

Returns if the storage is busy reading, writing or e.g. erasing.

Returns
true for busy, otherwise false.

Implements semf::app::Storage.

Definition at line 205 of file stm32flash.cpp.

◆ isr()

void semf::Stm32Flash::isr ( )
static

This function must be called from isr.

Exceptions
Isr_HalErrorIf the ST-HAL returns hal error.
Isr_HalBusyIf the ST-HAL returns hal busy.
Isr_HalTimeoutIf the ST-HAL returns hal timeout.

Definition at line 288 of file stm32flash.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isrError()

void semf::Stm32Flash::isrError ( )
static

This function is call from isr when an error has occurred.

Exceptions
IsrError_InterruptErrorIf a unexpected error occurres.

Definition at line 382 of file stm32flash.cpp.

Here is the caller graph for this function:

◆ read()

void semf::Stm32Flash::read ( uint32_t  address,
uint8_t  buffer[],
size_t  bufferSize 
)
overridevirtual

Reads data from the storage into a given read buffer.

  • dataAvailable signal will be emitted for all data are read.
  • error signal will be emitted if an error occurred.
Parameters
addressThe address from which the data will be read.
bufferPointer at which the read data is stored.
bufferSizeSize of the data to be read in bytes.
Exceptions
Read_IsBusyIf this is busy.
Read_BufferIsNullptrIf buffer is a nullptr
Read_BufferSizeIsZeroIf bufferSize is zero.

Implements semf::app::Storage.

Definition at line 86 of file stm32flash.cpp.

Here is the call graph for this function:

◆ size()

uint16_t semf::Stm32Flash::size ( ) const
protected

Returns the size of the flash in kBytes.

Returns
Flash size.

Definition at line 390 of file stm32flash.cpp.

◆ write()

void semf::Stm32Flash::write ( uint32_t  address,
const uint8_t  data[],
size_t  dataSize 
)
overridevirtual

Writes data into the storage.

  • dataWritten signal will be emitted for all data are written.
  • error signal will be emitted if an error occurred.
Parameters
addressThe address where the data will be written to.
dataPointer to the data to be written.
dataSizeSize of data to be written in bytes.
Exceptions
Write_IsBusyIf this is busy.
Write_DataIsNullptrIf data is a nullptr.
Write_DataSizeIsZeroIf dataSize is zero.
Write_DataNot4ByteAlignedIf the dataSize is not a multiple of 4 (only STM32L0)
Write_DataNot2byteAlignedIf the dataSize is not a multiple of 2 (only STM32F1 & STM32F3)
Write_HalErrorIf the ST-HAL returns hal error.
Write_HalBusyIf the ST-HAL returns hal busy.
Write_HalTimeoutIf the ST-HAL returns hal timeout.

Implements semf::app::Storage.

Definition at line 55 of file stm32flash.cpp.

Here is the call graph for this function:
Here is the caller graph for this function: