libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
ch32_flash.hpp
1#pragma once
2
3#include <cstdint>
4#include <cstring>
5
6#include "flash.hpp"
7#include "libxr_def.hpp"
8#include "libxr_type.hpp"
9#include DEF2STR(LIBXR_CH32_CONFIG_FILE)
10
11namespace LibXR
12{
13
14struct FlashSector
15{
16 uint32_t address; // 扇区起始地址
17 uint32_t size; // 扇区大小
18};
19
20class CH32Flash : public Flash
21{
22 public:
23 CH32Flash(const FlashSector* sectors, size_t sector_count, size_t start_sector);
24 CH32Flash(const FlashSector* sectors, size_t sector_count)
25 : CH32Flash(sectors, sector_count, sector_count - 1)
26 {
27 }
28
29 ErrorCode Erase(size_t offset, size_t size) override;
30 ErrorCode Write(size_t offset, ConstRawData data) override;
31
32 static constexpr size_t MinWriteSize() { return 2; } // 普通编程:半字
33
34 static constexpr uint32_t PageSize() { return 256; } // 快速页擦除:256字节
35
36 private:
37 const FlashSector* sectors_;
38 uint32_t base_address_;
39 size_t sector_count_;
40
41 bool IsInRange(uint32_t addr, size_t size) const;
42 static inline void ClearFlashFlagsOnce();
43};
44
45} // namespace LibXR
ErrorCode Erase(size_t offset, size_t size) override
Erases a section of the flash memory. 擦除闪存的指定区域。
ErrorCode Write(size_t offset, ConstRawData data) override
Writes data to the flash memory. 向闪存写入数据。
常量原始数据封装类。 A class for encapsulating constant raw data.
Abstract base class representing a flash memory interface. 抽象基类,表示闪存接口。
Definition flash.hpp:19
LibXR 命名空间
STM32Flash 通用类,构造时传入扇区列表,自动判断编程粒度。