我正在尝试对 PIC32MX360F512L 上的内部闪存块进行编程和验证。我有一个功能可以一次擦除、编程和验证一个 4096 字节的块。当我运行它时,该函数挂起试图验证第一个字节。
BOOL Loader_ProgramFlashBlock(unsigned long int adr, unsigned int *p )
{
unsigned long int CurrentAddress;
unsigned long int PageEndAddress;
unsigned int *pData;
unsigned int nvmResult;
// Calculate the beginning and ending addresses of the page.
CurrentAddress = adr;
PageEndAddress = CurrentAddress + FLASH_BLOCK_SIZE;
pData = (unsigned int *)p;
// Check to see if the page has been erased
{
// If not, erase the page & log track it
nvmResult = NVMErasePage((void *)CurrentAddress);
if (nvmResult != 0)
{
// Error erasing Flash page
return FALSE;
}
}
// Program the block to Flash
while (CurrentAddress < PageEndAddress)
{
if ( NVMWriteWord( (void *)CurrentAddress, *pData ) != FALSE )
{
// Error Writing Flash
return FALSE;
}
pData++;
CurrentAddress += sizeof(unsigned int);
}
// Verify that the block was written correctly
// (This check will identify writes to a Flash block that was not fully erased.)
CurrentAddress = adr;
pData = (unsigned int *)p;
while (CurrentAddress < PageEndAddress)
{
// Compare buffer contents to Flash contents
if (*((unsigned int *)PA_TO_KVA1(CurrentAddress)) != *pData)
{
// Flash and buffer did not match.
return FALSE;
}
pData++;
CurrentAddress += sizeof(unsigned int);
}
return TRUE;
} // Loader_ProgramFlashBlock
该函数挂起试图验证该行的闪存的第一个字:
if (*((unsigned int *)PA_TO_KVA1(CurrentAddress)) != *pData)
擦除和数据写入似乎已经奏效。有什么建议是什么原因造成的?
此代码适用于另一个应用程序。