semf
stm32flash.h
Go to the documentation of this file.
1
10#ifndef SEMF_HARDWAREABSTRACTION_STM32_STM32FLASH_H_
11#define SEMF_HARDWAREABSTRACTION_STM32_STM32FLASH_H_
12
14
15#if defined(STM32) && defined(HAL_FLASH_MODULE_ENABLED)
17namespace semf
18{
25class Stm32Flash : public app::Flash
26{
27public:
29 enum class ErrorCode : uint8_t
30 {
31 Write_IsBusy = 0,
32 Write_DataIsNullptr,
33 Write_DataSizeIsZero,
34 Write_DataNot8ByteAligned,
35 Write_DataNot4ByteAligned,
36 Write_DataNot2ByteAligned,
37 Write_HalError,
38 Write_HalBusy,
39 Write_HalTimeout,
40 Read_IsBusy = 0,
41 Read_BufferIsNullptr,
42 Read_BufferSizeIsZero,
43 Erase_IsBusy,
44 Erase_SectorOutOfBounds,
45 Erase_IsHalError,
46 Erase_IsHalBusy,
47 Erase_IsHalTimeout,
48 Isr_HalError,
49 Isr_HalBusy,
50 Isr_HalTimeout,
51 IsrError_InterruptError
52 };
53
61 Stm32Flash(uint16_t size, uint32_t voltageRange, uint32_t bank);
67 Stm32Flash(uint16_t size, uint32_t bank);
72 explicit Stm32Flash(uint16_t size);
73 explicit Stm32Flash(const Stm32Flash& other) = delete;
74 virtual ~Stm32Flash() = default;
75
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;
111 static void isr();
116 static void isrError();
117
118protected:
123 uint16_t size() const;
124
125private:
126 void write();
127
128 static Stm32Flash* m_flash;
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;
144};
145} /* namespace semf */
146#endif
147#endif /* SEMF_HARDWAREABSTRACTION_STM32_STM32FLASH_H_ */
ClassID
Semf class IDs.
Definition: error.h:28
This Class is for read and write data in the internal flash from the Stm32.
Definition: stm32flash.h:26
void erase(size_t sector, size_t numOfSectors=1) override
Erase sector(s).
Definition: stm32flash.cpp:145
virtual ~Stm32Flash()=default
uint16_t size() const
Returns the size of the flash in kBytes.
Definition: stm32flash.cpp:390
void write(uint32_t address, const uint8_t data[], size_t dataSize) override
Writes data into the storage.
Definition: stm32flash.cpp:55
void read(uint32_t address, uint8_t buffer[], size_t bufferSize) override
Reads data from the storage into a given read buffer.
Definition: stm32flash.cpp:86
static void isr()
This function must be called from isr.
Definition: stm32flash.cpp:288
static void isrError()
This function is call from isr when an error has occurred.
Definition: stm32flash.cpp:382
Stm32Flash(uint16_t size, uint32_t voltageRange, uint32_t bank)
Constructor.
Definition: stm32flash.cpp:31
bool isBusy() const override
Returns if the storage is busy reading, writing or e.g. erasing.
Definition: stm32flash.cpp:205
Stm32Flash(const Stm32Flash &other)=delete
Interface for flash storage.
Definition: flash.h:24
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.