0
我正在編程並驗證PIC32MX360F512L上的一個內部閃存塊。我有一個功能,一次擦除,編程和驗證一個4096字節塊。當我運行它時,函數掛起嘗試驗證第一個字節。通過軟件Progam PIC32內部閃存
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
功能掛起試圖驗證閃存的第一個字在該行:
如果(!*((unsigned int類型*)PA_TO_KVA1(CurrentAddress))= * pData所)
擦除和數據寫入似乎已經工作。任何建議是什麼導致這個?
此代碼可用於其他應用程序。
我正在從應用程序中寫入新的引導加載程序。中斷被禁用。 –
確保您的閃存未被鎖定以供讀取 – kirill