0

我正在尝试对 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)

擦除和数据写入似乎已经奏效。有什么建议是什么原因造成的?

此代码适用于另一个应用程序。

4

1 回答 1

0

你覆盖哪个内存块?那里有什么数据?您是否不会覆盖加载程序使用的某些函数或某些中断处理程序,这些函数可能会在您编写时出现?

于 2014-02-22T08:50:46.727 回答