Content originally posted in LPCWare by Lea on Sat Feb 13 00:24:55 MST 2016
I am using a LPCA 11C24 and flash new firmware over the primary CANopen bootloader.
My user app process a command to start the reinvoke function. But this causes a crash. I read in other posts that it is important to turn PLL off, set timer value to it defaults., so I modiy my ipa_reinvoke methode
<code >
/**
* @brief Prepare an invoke µC to call isp-command reinvoke
*/
void iap_reinvoke_bootloader(void)
{
static uint32_t cmd[5] = {IAP_REINVOKE_ISP_CMD,0,0,0,0};
static uint32_t result[4];
cmd[0] = IAP_REINVOKE_ISP_CMD;// reinvoke ISP command
__disable_irq();
// make sure 32-bit timer 1 is turned on before calling ISP
LPC_SYSCTL->SYSAHBCLKCTRL |= 0x00400;
//Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_CT32B1);
// make sure GPIO clock is turned on before calling ISP
LPC_SYSCTL->SYSAHBCLKCTRL |= 0x00040;
//Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_GPIO);
// make sure IO configuration clock is turned on before calling ISP
LPC_SYSCTL->SYSAHBCLKCTRL |= 0x10000;
//Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
// AHB clock divider must 1:1
LPC_SYSCTL->SYSAHBCLKDIV = 1;
//Chip_Clock_SetSysClockDiv(1);
// disabele PLL
LPC_SYSCTL->MAINCLKSEL = 0;// enable IRQ oscillator
LPC_SYSCTL->MAINCLKUEN = 0x01;// update MLCK clock source
LPC_SYSCTL->MAINCLKUEN = 0x00;// toggle update register
LPC_SYSCTL->MAINCLKUEN = 0x01;
while (!(LPC_SYSCTL->MAINCLKUEN & 0x01))// wait until updated
;
// reset the stack pointer to point to the top of the stack minus 32 byte for IAP
// for LPC11Cxx where top of RAM (8kB) is 0x1000_2000: MSP = (0x1000_20000 - 0x20 = 0x1000_1FE0)
//__set_MSP((uint32_t)0x100001FE0);
//__set_MSP((uint32_t)0x100002000);
/* Set stack pointer to ROM value (reset default) */
__set_MSP(*((uint32_t *) 0x100001FE0));
// the cortex M0 needs to synchronize the CPU cache
__ISB();
Chip_GPIO_SetPinDIROutput(LPC_GPIO, 0, 3);
Chip_GPIO_SetPinOutLow(LPC_GPIO, 0, 3);
Chip_GPIO_SetPinDIROutput(LPC_GPIO, 0, 1);
Chip_GPIO_SetPinOutLow(LPC_GPIO, 0, 1);
iap_entry(cmd, result);
}
<\code>
Does anyone have a tip for me, what am I doing wrong?