This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

IAP call when running RTOS

Hi,

I'm trying to use the IAP routine to change the active flash bank on an LPC4357 with uVision V5.15. The application uses the Ethernet Network interface and the CMSIS-RTOS RTX. Does anyone know the correct way to disable interrupts before calling the IAP routines and then how to re-enable the interrupts? The code ends up in the HardFault Handler after the eth_thread starts running again.

uint8_t IAP_SetBootFlashBank(uint8_t bankNum)
{

uint32_t command[6], result[5];
uint32_t interrupts[8];
uint32_t i;
//disable interrupts
SysTick->CTRL &= ~(SysTick_CTRL_TICKINT_Msk);
for (i=0;i<8;i++)
{

interrupts[i]=NVIC->ISER[i];

NVIC->ICER[i]=interrupts[i];

NVIC->ICPR[i]=interrupts[i];

}
__disable_irq();
command[0]=49;
command[1]=0;
command[2]=0;
command[3]=0;
iap_entry(command, result); //initialise IAP
command[0]=50;
command[1]=0;
command[2]=0;
command[3]=0;
iap_entry(command, result); //prepare sector 0, bank 0 for write
command[0]=50;
command[1]=0;
command[2]=0;
command[3]=1;
iap_entry(command, result); //prepare sector 0, bank 1 for write
command[0] = 60;
command[1] = bankNum;
command[2] = SystemCoreClock / 1000;
iap_entry(command, result);
//re-enable interrupts
__enable_irq();
for (i=0;i<8;i++)
{

NVIC->ISER[i]=interrupts[i];
}

SysTick->VAL = 0;
SysTick->CTRL |= (SysTick_CTRL_TICKINT_Msk);
return result[0];
}