转来的,参考一下
stm32 flash模拟eeprom读写操作
int main(void)
{
u32 a,b,c;
Stm32_Clock_Init(9); //系统时钟设置
delay_init(72); //延时初始化
uart_init(72,9600); //串口初始化
LED_Init(); //初始化与LED连接的硬件接口
a=3;b=4;c=5; //初始化变量;
//Flash_Init();
FLASH_Unlock(); //开锁;
a = FLASH_ProgramWord_R(0x0800f000); //再次打印 0x0800f000
printf("%d@\n",a);
b = FLASH_ProgramWord_R(0x0800f004); //再次打印 0x0800f004
printf("%d#\n",b);
c = FLASH_ProgramWord_R(0x0800f008); //再次打印 0x0800f008
printf("%d$\n",c);
//a=3;b=4;c=5;
//初始化变量;
a=a+5;
b=b+5;
c=c+5;
FLASH_ProgramWord(0x0800f000,a); //写 0x0800f000
//delay_ms(100);
FLASH_ProgramWord(0x0800f004,b); //写 0x0800f004
//delay_ms(100);
FLASH_ProgramWord(0x0800f008,c); //写 0x0800f008
//delay_ms(100);
//FLASH_EnableWriteProtection(FLASH_WRProt_Pages60to63);//写保护
a= 0;b=0;c=0;
a = FLASH_ProgramWord_R(0x0800f000); //再次打印 0x0800f000
printf("%d@\n",a);
b = FLASH_ProgramWord_R(0x0800f004); //再次打印 0x0800f004
printf("%d#\n",b);
c = FLASH_ProgramWord_R(0x0800f008); //再次打印 0x0800f008
printf("%d$\n",c);
------------------------------------------------------------
打印结果:
4@
4#
4$
4@
4#
4$
复位以后还是这个结果。
4@
4#
4$
4@
4#
4$
掉电没有保存。请问掉电保存还要加什么条件吗?写进去以后不就行了吗? |