5.3 Interrupts

The current implementation of the bootloader does not use interrupts. If the bootloader is more complex, it can require usage of interrupts.

After Reset, the default vector table location is at the start of the APPCODE section. The peripheral interrupts can be used in the bootloader code by relocating the interrupt vector table at the start of the BOOT section. That is done by setting the IVSEL bit in the CPUINT.CTRLA register:

void relocating_vector_table_example(void) 
{ 
    // Set the Interrupt Vector Select bit,
    // read-modify-write to preserve other configured bits 
    _PROTECTED_WRITE(CPUINT.CTRLA, (CPUINT.CTRLA | CPUINT_IVSEL_bm)); 
    //Enable global interrupts 
    sei(); 
}
Note:
  • If interrupts are used in the bootloader, the linker directive -nostartfiles must not be used.
  • If the interrupt vector location was changed to the start of the BOOT section, it needs to be changed back to the start of the APPCODE section before entering the main application.