I've been trying to implement ISP Reinvoke function for some time now and I've run into problem. My function looks like this:
void IAP_ReinvokeISP(void)
{
SCB->VTOR = 0;
volatile unsigned int command[5] = {0};
volatile unsigned int result[4] = {0};
LPC_SYSCTL->SYSAHBCLKCTRL |= 0x14440;
LPC_SYSCTL->SYSAHBCLKDIV = 1;
//Prepare the command array
command[0] = 57;
//Chip_GPIO_SetPinState(LPC_GPIO, 2, 16, 1);
//Initialize the storage state machine
init_msdstate();
//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(*((unsigned int*)0x00000000));
//Invoke IAP call...
iap_ent((unsigned int *)command, (unsigned int *)result);
}
I've put some variables as volatile even though they shouldn't be optimized whatsoever because they are in function yet I can't get it to open mass storage device. Turning optimization off works well but I need it as my code is fairly big and I would like it to be more compact.
P.S. Before this function I turn off all interrupts except for USB handling