I have a custom bootloader that was designed for the KL16 and I have ported it to the K20. I used Processor Expert (KDS) to design both versions of the code. My bootloader is at address 0x0000 and the application is at 0x3000.
The code in the bootloader that actually does the jump is:
void Execute_JumpToApplication( void )
{
__DI();
SCB_VTOR = (uint32_t)APPLIC_BASE_ADDR;
uint32_t startup;
startup = ((uint32_t*)APPLIC_BASE_ADDR)[0];
__set_SP(startup);
startup = ((uint32_t*)APPLIC_BASE_ADDR)[1];
((void(*)(void))startup)();
}
When I load my application with a debugger, interrupts are enabled correctly. When I transfer control from my bootloader, interrupts do not appear to be enabled. Even my timer interrupt does not work. Here is the initialization code from Cpu.c. I have commented most of the initialization functions. Only TI1_Init() and BitsIOLdd1_Init() remain. All of my interrupt code was set to priority 8. Any suggestions with how to proceed?
void PE_low_level_init(void)
{
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/* Initialization of the SIM module */
/* Initialization of the RCM module */
/* RCM_RPFW: RSTFLTSEL=0 */
RCM_RPFW &= (uint8_t)~(uint8_t)(RCM_RPFW_RSTFLTSEL(0x1F));
/* RCM_RPFC: RSTFLTSS=0,RSTFLTSRW=0 */
RCM_RPFC &= (uint8_t)~(uint8_t)(
RCM_RPFC_RSTFLTSS_MASK |
RCM_RPFC_RSTFLTSRW(0x03)
);
/* Initialization of the FTFL_FlashConfig module */
/* Initialization of the PMC module */
/* PMC_REGSC: ACKISO=0,BGBE=0 */
PMC_REGSC &= (uint8_t)~(uint8_t)(
PMC_REGSC_ACKISO_MASK |
PMC_REGSC_BGBE_MASK
);
/* PMC_LVDSC1: LVDACK=1,LVDIE=0,LVDRE=1,LVDV=0 */
PMC_LVDSC1 = (uint8_t)((PMC_LVDSC1 & (uint8_t)~(uint8_t)(
PMC_LVDSC1_LVDIE_MASK |
PMC_LVDSC1_LVDV(0x03)
)) | (uint8_t)(
PMC_LVDSC1_LVDACK_MASK |
PMC_LVDSC1_LVDRE_MASK
));
/* PMC_LVDSC2: LVWACK=1,LVWIE=0,LVWV=0 */
PMC_LVDSC2 = (uint8_t)((PMC_LVDSC2 & (uint8_t)~(uint8_t)(
PMC_LVDSC2_LVWIE_MASK |
PMC_LVDSC2_LVWV(0x03)
)) | (uint8_t)(
PMC_LVDSC2_LVWACK_MASK
));
/* SMC_PMPROT: ??=0,??=0,AVLP=0,??=0,ALLS=0,??=0,AVLLS=0,??=0 */
SMC_PMPROT = 0x00U; /* Setup Power mode protection register */
/* Common initialization of the CPU registers */
/* NVICIP8: PRI8=0 */
NVICIP8 = NVIC_IP_PRI8(0x00);
/* GPIOD_PDDR: PDD&=~0x40 */
GPIOD_PDDR &= (uint32_t)~(uint32_t)(GPIO_PDDR_PDD(0x40));
/* ### Asynchro serial "DebugUART" init code ... */
//DebugUART_Init();
/* ### InternalI2C "Vpi" init code ... */
//Vpi_Init();
/* ### BitIO_LDD "BitIoLdd1" component auto initialization. Auto initialization feature can be disabled by component property "Auto initialization". */
//(void)BitIoLdd1_Init(NULL);
/* ### IntFLASH "FLASH" init code ... */
//FLASH_Init();
/* ### GPIO_LDD "BitsIoLdd1" component auto initialization. Auto initialization feature can be disabled by component property "Auto initialization". */
(void)BitsIoLdd1_Init(NULL);
/* ### BitIO_LDD "BitIoLdd2" component auto initialization. Auto initialization feature can be disabled by component property "Auto initialization". */
//(void)BitIoLdd2_Init(NULL);
/* ### BitIO_LDD "BitIoLdd3" component auto initialization. Auto initialization feature can be disabled by component property "Auto initialization". */
//(void)BitIoLdd3_Init(NULL);
/* ### BitIO_LDD "BitIoLdd4" component auto initialization. Auto initialization feature can be disabled by component property "Auto initialization". */
//(void)BitIoLdd4_Init(NULL);
/* ### ExtInt_LDD "ExtIntLdd1" component auto initialization. Auto initialization feature can be disabled by component property "Auto initialization". */
//(void)ExtIntLdd1_Init(NULL);
/* ### ADC "TempADC" init code ... */
//TempADC_Init();
/* ### SPIMaster_LDD "SPI_LDD" component auto initialization. Auto initialization feature can be disabled by component property "Auto initialization". */
//(void)SPI_LDD_Init(NULL);
/* ### TimerInt_LDD "TI1" component auto initialization. Auto initialization feature can be disabled by component property "Auto initialization". */
(void)TI1_Init(NULL);
/* Enable interrupts of the given priority level */
__set_BASEPRI(0U);
}
So I’ve tried both __EI() and __enable_interrupt() at the end of low_level_init and neither work
So I added an __EI() statement at the end of Cpu.c but that did not fix the problem. I thought that the __set_BASEPRI statement enabled the interrupts??
No, BASEPRI only sets the base priority of interrupts to be masked, see https://mcuoneclipse.com/2016/08/14/arm-cortex-m-interrupts-and-freertos-part-1/
Erich