#include "bat32g137.h"
#include "EventRecorder.h" // Keil.ARM Compiler::Compiler:Event Recorder
#include "flash.h"
#include "stdio.h"
// 512字节一个 页面
#define FLASH_TEST_START_ADDR (8*1024)
#define DATA_FLASH_TEST_START_ADDR (0x0500000+512)
static char write_buff[] = {0xAA,0x55,0x12,0x56};
int main(void)
{
SystemCoreClockUpdate();
EventRecorderInitialize(0,0);
EventRecorderStart();
// flash写入
EraseSector(FLASH_TEST_START_ADDR);
ProgramPage(FLASH_TEST_START_ADDR,sizeof(write_buff),(void*)write_buff);
uint8_t *paddr = (void*)(volatile const uint8_t*)FLASH_TEST_START_ADDR;
for(char i = 0;i < sizeof(write_buff);i++)
printf("paddr[%d] = 0x%02x\n",i,paddr[i]);
{
// dataflash写入
EraseSector(DATA_FLASH_TEST_START_ADDR);
ProgramPage(DATA_FLASH_TEST_START_ADDR,sizeof(write_buff),(void*)write_buff);
uint8_t *paddr = (void*)(volatile const uint8_t*)DATA_FLASH_TEST_START_ADDR;
for(char i = 0;i < sizeof(write_buff);i++)
printf("paddr[%d] = 0x%02x\n",i,paddr[i]);
}
while(1)
{
}
}



测试擦写速度很快只需要4ms.类似的单片机都是几十ms的擦除时间。

特别注意这个是512字节一个页面。操作flash区域和dataflash区域只是地址不同而已其他都一样。flash区域可以执行程序,dataflash不可以执行。
2225

被折叠的 条评论
为什么被折叠?



