你好研究员,我困了,需要一些帮助与NVM程序闪存写页。我在
论坛里发现了一些代码,我必须修改一下,以适应我的需要。现在模拟器里一切都很好。我可以擦除闪光灯页面并给它写。我必须写600字节。因此不止一行。据我所知,PIC32 MX中的行是512字节。我用最后两个程序Flash页面为我的用户闪存空间。我的用户Flash空间开始于0x9D01E000,结束于0x9D01FFFF。这应该是2×4096字节。我还保留了链接器脚本问题:当我写一行时,只有第一个128字节被写入一行。其余的行(80H-200小时)仍然是FFH。这是我使用的代码:MycPy((空*)PaBufff,(空虚*)用户闪存,sieZof(PaBufff));NVMyErasePoad((空*)UsFlash页面);……(NUBYTESLUT & GT;ByTeTyRoWig Simple)NyBestTestOrreTeToRoWo= BytEythRoWig大小;否则NuBestTestOWRITETROW= NuByTestLead;//从PaBufff写入512个字节(一个NVM行)。总是写一整行。//NvMyWrrrDeWORE((空洞*)(UsFlash页面+ RoRunnIn PaulBufff),(空虚*)PaBufff);/*原始*/Unt8Itt Res=NVMyWrdReWORE((空洞*)(UsFlash页面+ RoRunnIn PaulBufff),(空*)PaBuffff+RooRunnIn PaulBufff);= 0)返回Res;NuByTestLeop-= NuByTestOWrrTeToRoW;RooRunnIn PosiWoReTeToRoW;}和未签名的int nvMyWrdReWORE(无效*地址,空隙*数据){un签署int Res=0;未签名int SaveDeSt.;SaveDeStase=d int)地址和0x1FFFFFF;NVMSRCADDR=((未签名int)数据和0x1FFFFFF);RES=NVMME解锁(NvMyOptuthOpRead Err.Read);*一些帮助或提示将非常感谢。非常感谢,安德烈亚斯。
以上来自于百度翻译
以下为原文
Hello Fellows,
Im stuck and need some help with NVM Program Flash write page. I found some code here in the forum, which I had to modify a little bit to suit my needs. Now in simulator everything works well. I can erase the flash page and write to it. I have to write 600bytes. Hence more than a row. According to my knowledge a row is 512 bytes in PIC32MX. I use the last two program flash pages for my user flash space. My user flash space starts at 0x9D01E000 and ends at 0x9D01FFFF. This should be 2*4096bytes. I also reserve that in the linker script
Problem: When I write a row only the first 128byte are written of a row. The rest of the row (80h-200h) remains all FFh.
Here is the code I use:
memcpy((void *)pageBuff, (void *)userFlashPage, sizeof(pageBuff));
NVM_ErasePage((void *)userFlashPage);
...
while (numBytesLeft)
{
if (numBytesLeft > BYTE_ROW_SIZE)
numBytesToWriteToRow = BYTE_ROW_SIZE;
else
numBytesToWriteToRow = numBytesLeft;
// Write 512 bytes (one NVM row) from pageBuff. Writes a whole row always.
//NVM_WriteRow((void *)(userFlashPage + rowIndexInPageBuff), (void*)pageBuff); /* Original */
uint8_t res = NVM_WriteRow((void *)(userFlashPage + rowIndexInPageBuff), (void*)pageBuff + rowIndexInPageBuff);
if (res != 0)
return res;
numBytesLeft -= numBytesToWriteToRow;
rowIndexInPageBuff += numBytesToWriteToRow;
}
and
unsigned int NVM_WriteRow (void* address, void* data)
{
unsigned int res = 0;
unsigned int saved_state;
saved_state = __buil
tin_get_isr_state();
__builtin_disable_interrupts();
NVMADDR = ((unsigned int) address & 0x1FFFFFFF);
NVMSRCADDR = ((unsigned int) data & 0x1FFFFFFF);
res = NVM_Unlock(NVM_OPERATION_WRITE_ROW);
__builtin_set_isr_state(saved_state); /* Set back to what was before. */
return res;
}
Some help or hints would be very appreciated. Thank you very much.
Andreas