我根据官方例程修改的,测试时全部写入20,但读出来为0,应该是写入进去了。查了几遍没查到错误,麻烦帮我看一眼。
void FLASH_Eraser()
{
/* Clear pending flags (if any) */
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
/* Get the number of the start and end sectors */
StartSector = GetSector(FLASH_USER_START_ADDR);
EndSector = GetSector(FLASH_USER_END_ADDR);
for (SectorCounter = StartSector; SectorCounter < EndSector; SectorCounter += 8)
{
/* Device voltage range supposed to be [2.7V to 3.6V], the opera
tion will
be done by word */
if (FLASH_EraseSector(SectorCounter, VoltageRange_3) != FLASH_COMPLETE)
{
/* Error occurred while sector erase.
User can add here some code to deal with this error */
while (1);
}
}
}
void FLASH_Write(aCm *Buf)
{
tPriint32 Value=20;
// float * Ptr=(float*)Buf;
FLASH_Unlock();
FLASH_Eraser();
Address = FLASH_USER_START_ADDR;
while (Address < FLASH_USER_END_ADDR)
{
if (FLASH_ProgramWord(Address,Value) == FLASH_COMPLETE)
{
Address = Address + 4;
}
else
{
while (1);
}
}
FLASH_Lock();
}
tPriint32 data32=5;
void FLASH_Read(aCm *Buf)
{
tPriint32 *Ptr=(tPriint32*)Buf;
Address = FLASH_USER_START_ADDR;
while (Address < FLASH_USER_END_ADDR)
{
data32 = *(__IO uint32_t*)Address;
Address = Address + 4;
}
}
程序写入时没有停在while(1)处,说明已经写入进去了,但不知道为什么读出来是0
char* ptr = NULL
ptr = ADD_START
循环体
printf(%x , *ptr);
ptr++;
这是基本思路,你可以参考参考
一周热门 更多>