打开标准库
源码---
int main(void)
{
uint32_t d;
Led_init();
key_init();
/* 初始化串口1波特率为115200bps,若发送/接收数据有乱码,请检查PLL */
usart1_init(115200);
printf("this is flash test\r\n");
/* 解锁FLASH(闪存)*/
FLASH_Unlock();
/* 擦除扇区4(如果不擦除将不可再写入数据) */
if(FLASH_EraseSector(FLASH_Sector_4, VoltageRange_3) != FLASH_COMPLETE)
{
printf("FLASH_EraseSector error\r\n");
while(1);
}
/* 向扇区4首地址写入0x12345678 */
if(FLASH_ProgramWord(0x8010000,0xAABBCCDD)!= FLASH_COMPLETE)
{
printf("FLASH_ProgramWord error\r\n");
while(1);
}
/* 不再需要修改数据,则锁定闪存 */
FLASH_Lock();
d = *(__IO uint32_t*)0x8010000;
printf("read addr at 0x8010000 is 0x%08X\r\n",d);
while(1)
{
}
}