FlashBrushHAL.h 3.4 KB
#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