FlashBrushHAL.h
3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef _C17MAKE_EEPRON_HAL_H_
#define _C17MAKE_EEPRON_HAL_H_
// _______ ___ _______ _______ __ __ _______ ______ __ __ _______ __ __
// | || | | _ || || | | | | _ || _ | | | | || || | | |
// | ___|| | | |_| || _____|| |_| | | |_| || | || | | | || _____|| |_| |
// | |___ | | | || |_____ | | | || |_||_ | |_| || |_____ | |
// | ___|| |___ | ||_____ || | | _ | | __ || ||_____ || |
// | | | || _ | _____| || _ | | |_| || | | || | _____| || _ |
// |___| |_______||__| |__||_______||__| |__| |_______||___| |_||_______||_______||__| |__|
// STM32F405 ONLY Flash Simula EEPROM
// #include "eepromHAL_Config.h"
#include "stm32f4xx.h"
#include "stm32f4xx_hal_flash.h"
#include "stm32f4xx_hal_flash_ex.h" //Flash Erase
// STM32F405 Store Sector Location
//
// Sector 0 : 0x08000000
// Sector 1 : 0x08004000
// Sector 2 : 0x08008000
// Sector 3 : 0x0800c000
// Sector 4 : 0x08010000
// Sector 5 : 0x08020000
// Sector 6 : 0x08040000
// Sector 7 : 0x08060000
// Sector 8 : 0x08080000
// Sector 9 : 0x080a0000
// Sector 10 : 0x080c0000
// Sector 11 : 0x080e0000 <-- F405RGT6 Last Sector
// 0x08100000
typedef __IO uint32_t vu32;
typedef __IO uint16_t vu16;
typedef __IO uint8_t vu8;
typedef __I uint32_t vuc32;
typedef __I uint16_t vuc16;
typedef __I uint8_t vuc8;
// 状态/返回值枚举
enum {
FLASHBRUSH_STA_OK = 0,
FLASHBRUSH_STA_INPUTERR,
FLASHBRUSH_STA_ERASE_ERR,
FLASHBRUSH_STA_WRCTRL_ERR,
FLASHBRUSH_STA_WRING_ERR
};
// 编程单位
#define FLASHBRUSH_TYPEPROGRAM_BYTE 0x00000000U /*!< Program byte (8-bit) at a specified address */
#define FLASHBRUSH_TYPEPROGRAM_HALFWORD 0x00000001U /*!< Program a half-word (16-bit) at a specified address */
#define FLASHBRUSH_TYPEPROGRAM_WORD 0x00000002U /*!< Program a word (32-bit) at a specified address */
// Modify it only when grafting
#define FLASHBRUSH_BASE_ADDR (uint32_t)0x08000000
#define FLASHBRUSH_BASE_ADDR_END (uint32_t)0x080FFFFF
/**
* @brief 以单个字节读取Flash
* @param addr 读取地址
* @return
*/
uint8_t FlashBrush_ReadBtye(uint32_t addr);
/**
* @brief 以半字读取Flash
* @param addr 读取地址
* @return
*/
uint16_t FlashBrush_ReadHalfWord(uint32_t addr);
/**
* @brief 以字读取Flash
* @param addr 读取地址
* @return
*/
uint32_t FlashBrush_ReadWord(uint32_t addr);
/**
* @brief 单个扇区的擦除
* @param startAddress 将擦除该地址所在的扇区
* @return
*/
uint32_t FlashBrush_EraseSingleSector(uint32_t startAddress);
/**
* @brief flash无检查写入,根据提供数据的长度和类型将数据写入flash
* @param typeprogram 输入数据(data)的类型,该参数决定每次flash 编程操作的大小,值需要为 FLASHBRUSH_TYPEPROGRAM_x 中的一个
* @param startADDR 写入flash的地址
* @param data 需要写入的数据,为void*类型,将根据typeprogram参数强制转换该数据
* @param data_len 需要写入数据的长度,为数据的实际长度;若输入数据为uint32[16],则该参数为16;若输入数据为uint8[10],则该参数为10
* @return
*/
uint32_t FlashBrush_Program_Direct( uint32_t typeprogram , uint32_t startADDR , void* data , uint32_t data_len );
#endif