#include "flash.h"
//功能:向第四扇区写数据
void Flash_Init(void) { uint32_t data[64] = {0};//64字 uint32_t i=0; for(i=0;i<64;i++) { data[i] = 0x00100000 +i; } //解除写保护 FLASH_Unlock(); //清除上一次出现的错误码 FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_OPERR|FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR|FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); //擦除第4号扇区,每次擦除一个字(32bit) if(FLASH_EraseSector(FLASH_Sector_4, VoltageRange_3) != FLASH_COMPLETE) { printf("flash erase error!\r\n"); while(1); } for(i=0;i<64;i++) { //在4号扇区写内容 if (FLASH_ProgramWord(0x08010000+4*i, data[i]) != FLASH_COMPLETE) { printf("flash program error!\r\n"); } } //打开写保护 FLASH_Lock(); //读取数据 for(i=0;i<64;i++) { printf("0x%08X ", *(volatile unsigned int *)(0x08010000+4*i) ); } }