#include <stdint.h> #include "stm32f4xx.h"
/* 定义EEPROM首地址 / #define EEPROM_START_ADDRESS ((uint32_t)0x08080000) / 定义EEPROM页大小 */ #define EEPROM_PAGE_SIZE ((uint32_t)FLASH_PAGE_SIZE)
/* 函数声明 */ void EEPROM_WriteWord(uint32_t address, uint32_t data); uint32_t EEPROM_ReadWord(uint32_t address);
int main(void) { /* 初始化系统时钟等设置 */
/* 解锁Flash并且使能Flash预编程操作 */
FLASH_Unlock();
FLASH_PrefetchBufferCmd(ENABLE);
/* 清除所有待写入的页 */
uint32_t eraseCounter = 0;
uint32_t nbOfPages = 0;
uint32_t PageError = 0;
FLASH_EraseInitTypeDef eraseInitStruct;
eraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
eraseInitStruct.PageAddress = EEPROM_START_ADDRESS;
eraseInitStruct.NbPages = 1;
HAL_FLASHEx_Erase(&eraseInitStruct, &a