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
23class CH32Flash : public Flash
24{
25 public:
29 CH32Flash(const FlashSector* sectors, size_t sector_count, size_t start_sector);
33 CH32Flash(const FlashSector* sectors, size_t sector_count)
34 : CH32Flash(sectors, sector_count, sector_count - 1)
35 {
36 }
37
38 ErrorCode Erase(size_t offset, size_t size) override;
39 ErrorCode Write(size_t offset, ConstRawData data) override;
40
41 static constexpr size_t MinWriteSize()
42 {
43 return 2;
44 }
45
46 static constexpr uint32_t PageSize()
47 {
48 return 256;
49 }
50
51 private:
52 const FlashSector* sectors_;
53 uint32_t base_address_;
54 size_t sector_count_;
55
56 bool IsInRange(uint32_t addr, size_t size) const;
57 static inline void ClearFlashFlagsOnce();
58};
59
60} // namespace LibXR
CH32 闪存驱动实现 / CH32 flash driver implementation.
static constexpr size_t MinWriteSize()
最小写入粒度(半字) / Minimum write size (half-word)
static constexpr uint32_t PageSize()
Page erase size in fast erase mode / 快速擦除页大小
CH32Flash(const FlashSector *sectors, size_t sector_count, size_t start_sector)
构造闪存对象 / Construct flash object
ErrorCode Erase(size_t offset, size_t size) override
Erases a section of the flash memory. 擦除闪存的指定区域。
CH32Flash(const FlashSector *sectors, size_t sector_count)
构造并使用默认起始扇区 / Construct with default start sector
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 命名空间
Definition ch32_can.hpp:14
闪存扇区描述 / Flash sector descriptor
uint32_t size
扇区大小(字节) / Sector size in bytes
uint32_t address
扇区起始地址 / Sector base address