标题:
stm32f4 内部flash存储数据问题(2)
[打印本页]
作者:
yuyang911220
时间:
2014-9-26 18:47
标题:
stm32f4 内部flash存储数据问题(2)
参考Demo中的例子,将FLASH的页的其实地址(基地址)可定义如下:
这里的flash的在编程钱如果这一个地址已经写过了请先擦除这个地址,因为现在stm32f4的的flash分为11个部分,每个擦除是按照每个部分一起擦除,因为这你的对每个快的做一个缓冲区才行。
我的代码如下:
void get_from_flash(void)
{
delay_ms(2);
OwnFlashReady(0x08008000,getflashdata_buf,100);
// SPI_FLASH_BufferRead(getflashdata_buf, 0x000000, 100); //??????
// SPI_FLASH_ChipErase();//????flash????????
memmove(&RTU_Basedata_Only,&getflashdata_buf[0],18);
memmove(&BaseData01,&getflashdata_buf[18],21);
memmove(&gx_options01[0],&getflashdata_buf[39],60);
}
void OwnFlashSave(uint32_t save_addr,uint8_t *p,uint16_t number)
{
uint32_t StartSector,EndSector,i, save_addr_temp;
StartSector = GetSector(save_addr);
EndSector = GetSector(save_addr+number);
save_addr_temp = save_addr;
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
//????flash
for (i = StartSector; i<=EndSector; i += 8)
{
while (FLASH_EraseSector(i, VoltageRange_3) != FLASH_COMPLETE)
{
}
} //????????????×÷?????????????????????í?ó??
while (save_addr < number+save_addr_temp)
{
if (FLASH_ProgramByte(save_addr, *p++) == FLASH_COMPLETE)
{
save_addr = save_addr + 1;
}
else
{
while (1)
{
}
}
}
FLASH_Lock();
}
// void OwnFlashErasure()
void OwnFlashReady(uint32_t read_addr,uint8_t * read_buf,uint16_t read_number)
{
uint32_t Address_ready;
Address_ready = read_addr;
while (Address_ready < read_addr+read_number)
{
*read_buf++ = (*(__IO uint8_t*)Address_ready);
Address_ready = Address_ready + 1;
}
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0