10#ifndef SEMF_HARDWAREABSTRACTION_STM32_STM32FLASH_H_
11#define SEMF_HARDWAREABSTRACTION_STM32_STM32FLASH_H_
15#if defined(STM32) && defined(HAL_FLASH_MODULE_ENABLED)
34 Write_DataNot8ByteAligned,
35 Write_DataNot4ByteAligned,
36 Write_DataNot2ByteAligned,
42 Read_BufferSizeIsZero,
44 Erase_SectorOutOfBounds,
51 IsrError_InterruptError
87 void write(uint32_t
address,
const uint8_t data[],
size_t dataSize)
override;
94 void read(uint32_t
address, uint8_t buffer[],
size_t bufferSize)
override;
103 void erase(
size_t sector,
size_t numOfSectors = 1)
override;
104 bool isBusy()
const override;
123 uint16_t
size()
const;
129 const uint32_t m_voltageRange;
130 const uint16_t m_size;
131 const uint32_t m_bank;
132 bool m_isBusy =
false;
133 bool m_eraseIsRunning =
false;
134 uint32_t m_numOfSecotrsToErase = 0;
135 size_t m_bytesToWrite = 0;
136 uint8_t* m_dataWrite =
nullptr;
137 size_t m_addressWrite = 0;
138 uint32_t m_addressRead = 0;
139 uint8_t* m_dataRead =
nullptr;
140 size_t m_sizeRead = 0;
141 bool m_readIsPending =
false;
142 bool m_dataAvailablePending =
false;
143 static constexpr Error::ClassID kSemfClassId = Error::ClassID::Stm32Flash;
This Class is for read and write data in the internal flash from the Stm32.
void erase(size_t sector, size_t numOfSectors=1) override
Erase sector(s).
virtual ~Stm32Flash()=default
uint16_t size() const
Returns the size of the flash in kBytes.
void write(uint32_t address, const uint8_t data[], size_t dataSize) override
Writes data into the storage.
void read(uint32_t address, uint8_t buffer[], size_t bufferSize) override
Reads data from the storage into a given read buffer.
static void isr()
This function must be called from isr.
static void isrError()
This function is call from isr when an error has occurred.
Stm32Flash(uint16_t size, uint32_t voltageRange, uint32_t bank)
Constructor.
bool isBusy() const override
Returns if the storage is busy reading, writing or e.g. erasing.
Stm32Flash(const Stm32Flash &other)=delete
Interface for flash storage.
virtual uint32_t address(size_t sector) const =0
Return on which address a sector starts.
virtual size_t sector(uint32_t address) const =0
Return in which sector an address is located.