我在获取 PIC32MX795F512L 工作的引导加载程序时遇到问题。
我基于微芯片网站上的示例代码。
这是我应该写入内存的代码部分,到目前为止我已经验证了引导加载程序(解析十六进制文件很好,数据到达这一点但没有写入内存):
#define NVMOP_WORD_PGM 0x4001
// Write the data into flash.
Result = NVMemWriteWord(ProgAddress, WrData);
// Assert on error. This must be caught during debug phase.
if(Result != 0)
{
ASSERT(Result==0);
}
UINT NVMemWriteWord(void* address, UINT data)
{
UINT res;
NVMADDR = KVA_TO_PA((unsigned int)address);
// Load data into NVMDATA register
NVMDATA = data;
// Unlock and Write Word
res = NVMemOperation(NVMOP_WORD_PGM);
return res;
}
UINT __attribute__((nomips16)) NVMemOperation(UINT nvmop)
{
int int_status;
int susp;
// Disable DMA & Disable Interrupts
#ifdef _DMAC
int_status = INTDisableInterrupts();
susp = DmaSuspend();
#else
int_status = INTDisableInterrupts();
#endif // _DMAC
// Enable Flash Write/Erase Operations
NVMCON = nvmop;//NVMCON_WREN | nvmop;
// Data sheet prescribes 6us delay for LVD to become stable.
// To be on the safer side, we shall set 7us delay.
delay_us(7);
NVMKEY = 0xAA996655;
NVMKEY = 0x556699AA;
NVMCONSET = NVMCON_WR;
// Wait for WR bit to clear
while(NVMCON & 0x8000);//NVMCON_WR);
// Disable Flash Write/Erase operations
NVMCONCLR = NVMCON_WREN;
// Enable DMA & Enable Interrupts
#ifdef _DMAC
DmaResume(susp);
INTRestoreInterrupts(int_status);
#else
INTRestoreInterrupts(int_status);
#endif // _DMAC
// Return Error Status
return(NVMemIsError());
}
正在加载的程序地址示例为:0x9D033358,数据为 2403000E
配置位在代码中设置,如下所示:
地址设置
1FC02FF0 FCFFFFFF
1FC02FF4 FFF8FFDF
1FC02FF8 FF69CC5B
1FC02FFC 7FFFFFFF
无法告诉您所有位的作用,但闪存位设置为可写并且代码保护已禁用。