Content originally posted in LPCWare by BPC on Wed Jan 23 09:31:15 MST 2013
Hello Everyone,
I am migrating from the LPC1343 to the LPC1347. Everything has been smooth so far, but I ran into a snag in implementing "Auto ISP" or ISP from user code using command 57. I have taken the LPC1343 example, and based on the User Manual for the LPC1347, it appears these function should be cross compatible. Below is the function I am using.
[COLOR=blue]/* This data must be global so it is not read from the stack */
typedef void (*IAP)(uint32_t [], uint32_t []);
IAP iap_entry = (IAP)0x1fff1ff1;
uint32_t command[5], result[4];[/COLOR]
[COLOR=blue][/COLOR]
[COLOR=blue]void ReinvokeISP(void)
{
/* make sure USB clock is turned on before calling ISP */
LPC_SYSCON->SYSAHBCLKCTRL |= 0x04000;
/* make sure 32-bit Timer 1 is turned on before calling ISP */
LPC_SYSCON->SYSAHBCLKCTRL |= 0x00400;
/* make sure GPIO clock is turned on before calling ISP */
LPC_SYSCON->SYSAHBCLKCTRL |= 0x00040;
/* make sure IO configuration clock is turned on before calling ISP */
LPC_SYSCON->SYSAHBCLKCTRL |= 0x10000;
/* make sure AHB clock divider is 1:1 */
LPC_SYSCON->SYSAHBCLKDIV = 1;[/COLOR]
[COLOR=blue] /* Send Reinvoke ISP command to ISP entry point*/
command[0] = 57;[/COLOR]
[COLOR=blue] /* Set stack pointer to ROM value (reset default) This must be the last
piece of code executed before calling ISP, because most C expressions
and function returns will fail after the stack pointer is changed. */
__set_MSP(*((uint32_t *)0x1FFF0000)); /* inline asm function */[/COLOR]
[COLOR=blue] /* Enter ISP. We call "iap_entry" to enter ISP because the ISP entry is done
through the same command interface as IAP. */
iap_entry(command, result);
// Not supposed to come back!
}[/COLOR]
Prior to calling this function, I disable the SYSTICK timer and interrupt.
Once iap_entry is executed, "nothing" happens, except the debugger "disconnects" as it should. I cannot get the Mass Storage Device to pop up on my computer as it did with the LPC1343. I have the "Soft USB Connection" circuit implemented on my board with an LED to show if the USB is connected, once iap_entry is executed, this LED turns off (as it should), but never turns back on.
I have tried doing a soft disconnect using pUsbApi->hw->Connect(hUsb, 0); prior to calling ReinvokeISP();. I also tried a USB reset pUsbApi->hw->Reset(hUsb); prior to calling ReinvokeISP();.
Any help would be much appreciated.
Thank you.