We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
The IAP is driving me crazy. When I single step my code using ulink it works, but when I just let it run the micro reboots itself and the IAP hasn't worked. I've read the manual, AN10256, searched the forums and looked at the sample code.
Here's my code:
ErrorCode_t writeBufToOneFlashSector(uint8_t secNum) { BOOL good = TRUE; ErrorCode_t retCode = ERR_NO_ERROR; unsigned int enables; BOOL pllStat; // Disable interrupts during erase and write operations // Keep a copy of what was enabled enables = VICIntEnable; command[0] = IAP_PrepareSectors; command[1] = (uint32_t)secNum; command[2] = (uint32_t)secNum; waitTXComplete(); pauseTX(TRUE); pllStat = usePLL(FALSE); iap_entry(command, result); good = (BOOL)(IAP_CMD_SUCCESS == result[0]); if(!good) { usePLL(pllStat); retCode = ERR_IAP_ERASE_PREPARE | ERR_NUM_USED; errVal = (ParamType)result[0]; } else { command[0] = IAP_EraseSectors; command[1] = (uint32_t)secNum; command[2] = (uint32_t)secNum; command[3] = XTAL_OSC_KHZ; // Disable interrupts during erase VICIntEnable = 0; iap_entry(command, result); VICIntEnable = enables; good = (BOOL)(IAP_CMD_SUCCESS == result[0]); if(!good) { usePLL(pllStat); retCode = ERR_IAP_ERASE | ERR_NUM_USED; errVal = (ParamType)result[0]; } } // See about doing the write if(good) { command[0] = IAP_PrepareSectors; command[1] = (uint32_t)secNum; command[2] = (uint32_t)secNum; iap_entry(command, result); good = (BOOL)(IAP_CMD_SUCCESS == result[0]); if(!good) { usePLL(pllStat); retCode = ERR_IAP_WRITE_PREPARE | ERR_NUM_USED; errVal = (ParamType)result[0]; } } // Ready to write at last if(good) { command[0] = IAP_CopyRAMtoFlash; command[1] = SectorStartAddr[secNum]; command[2] = (unsigned int)nvBuf; command[3] = FLASH_NV_PAGE_SIZE8; command[4] = XTAL_OSC_KHZ; // Disable interrupts during erase VICIntEnable = 0; iap_entry(command, result); usePLL(pllStat); VICIntEnable = enables; good = (BOOL)(IAP_CMD_SUCCESS == result[0]); if(!good) { retCode = ERR_IAP_WRITE | ERR_NUM_USED; errVal = (ParamType)result[0]; } } pauseTX(FALSE); return retCode; }
Hi Oliver,
Please refer to:
UM10120 LPC2131/2/4/6/8 User manual Rev. 02 - 25 July 2006 User manual LPC213x
www.standardics.nxp.com/.../user.manual.lpc2131.lpc2132.lpc2134.lpc2136.lpc2138.pdf
Page 242, Table 223. Flash sectors in LPC2131, LPC2132, LPC2134, LPC2136 and LPC2138
0 4 0X0000 0000 - 0X0000 0FFF + + + + + [del] 7 4 0X0000 7000 - 0X0000 7FFF + + + + + 8 32 0x0000 8000 - 0X0000 FFFF + + + + [del] 21 32 0x0007 0000 - 0X0007 7FFF + 22 4 0x0007 8000 - 0X0007 8FFF + [del] 26 4 0x0007 C000 - 0X0007 CFFF +
It seems that, you don't have any 8K sectors.
I found something improper in the source code of the below URL.
http://www.keil.com/download/docs/298.asp
And, what I used was from somewhere like "C:\Keil\ARM\Boards\Keil\MCB2100\IAP"; it worked.
I had to provide a correct get_secnum() function to this example. After some checks and tests, it worked.
(Not so sure about how to integrate this IAP example to a project.)
You're right. I was confusing myself as I actually use 4k byte sectors.
So, do you still encounter the IAP problem?
Bad of it to not generate an error about incorrect parameter.
God, this is soooo frustrating. After I fixed the sector calculation algorithm, the example IAP project appears to work. I can't say that it works with 100% confidence because you can only observe it's behaviour with the debugger, and I know the debugger makes a difference. Anyway, the next step is obviously to add my code, piece by piece, until I figure out what breaks it. The problem now is that the ULink seems to have stopped working, as it keeps reporting that it can't stop the target. I remember this happening to me before, and I had to use Flashmagic to recover the target, but that doesn't seem to do the trick now. Flashmagic claims to reprogram the target, but the ULink still doesn't work.
Have you done a full chip erase with Flash Magic?
try this: * reduce JTAG clock speed. * disable "cache code", "cache memory" in driver setup menu.