#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不可以執行。