高中生
最后登录1970-1-1
在线时间 小时
注册时间2018-8-17
|
楼主 |
发表于 2018-9-7 15:47:43
|
显示全部楼层
八戒 发表于 2018-9-4 17:06
你好 有两个地方不明白,问一下
1、
int InternalFlash_Write(uint32_t Address,uint32_t *Data,uint8_t ...
int InternalFlash_Write(uint32_t Address,uint32_t *Data,uint8_t length)
{
uint32_t EraseCounter = 0x00; //记录要擦除多少页
uint32_t NbrOfPage = 0x00; //记录写入多少页
uint8_t i=0;
FLASH_Status FLASHStatus = FLASH_COMPLETE; //记录每次擦除的结果
TestStatus MemoryProgramStatus = PASSED;//记录整个测试结果
/* 解锁 */
FLASH_Unlock();
/* 计算要擦除多少页 */
NbrOfPage = (WRITE_END_ADDR - WRITE_START_ADDR) / FLASH_PAGE_SIZE;
/* 清空所有标志位 */
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
/* 按页擦除*/
for(EraseCounter = 0; (EraseCounter < NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++)
{
FLASHStatus = FLASH_ErasePage(WRITE_START_ADDR + (FLASH_PAGE_SIZE * EraseCounter));
}
/* 向内部FLASH写入数据 */
//Address = WRITE_START_ADDR;
while((Address < WRITE_END_ADDR) && (FLASHStatus == FLASH_COMPLETE))
{
FLASHStatus = FLASH_ProgramWord(Address,Data);
i++;
Address = Address + 4;
}
FLASH_Lock();
/* 检查写入的数据是否正确 */
i=0;
while((Address < WRITE_END_ADDR) && (MemoryProgramStatus != FAILED))
{
if((*(__IO uint32_t*) Address) != Data)
{
MemoryProgramStatus = FAILED;
}
i++;
Address += 4;
}
return MemoryProgramStatus;
}
void InternalFlash_Read(uint32_t addr,uint8_t *p,uint16_t Byte_Num)
{
uint8_t i=0;
TestStatus MemoryProgramStatus = PASSED;//记录整个测试结果
while((addr < WRITE_END_ADDR) && (MemoryProgramStatus != FAILED))
{
p=(*(__IO uint8_t*) addr);
i++;
addr++;
}
}
不知道是否粘贴错误,这是我又在程序上复制了一份,你说的那两个问题不存在 |
|