SAMD51 sercom handling

Hi all,

I am trying to understand the IRQ handling in Serial in SAMD51 chip. When I look at the different variants(SparkFun and Adafruit), I noticed in SAMD51 its:

void SERCOM2_0_Handler()
{
  Serial1.IrqHandler();
}
void SERCOM2_1_Handler()
{
  Serial1.IrqHandler();
}
void SERCOM2_2_Handler()
{
  Serial1.IrqHandler();
}
void SERCOM2_3_Handler()
{
  Serial1.IrqHandler();
}

whereas in SAMD21 its:

void SERCOM0_Handler()
{
  Serial1.IrqHandler();
}

Can anyone please explain the difference? Thanks in advance.

Hi razor101,

The SERCOM peripheral on the SAMD51 and SAMD21 generates a number of interrupts, such as DRE (DataRegister Empty), TXC (Transmit Complete) and RXC (Receive Complete), to name just three of the most commonly used.

The SAMD21's SERCOMx module has only a single Interrupt Service Routine (ISR) called SERCOMx_Handler(), therefore within the ISR it's necessary to test each of the interrupt flags to find which interrupt has occured when the handler function is called.

The SAMD51's SERCOMx module on the other hand has separate ISR's for each interrupt, with the ISR number relating to the position of the interrupt in the Interrupt Flag (INTFLAG) register, for example SERCOM2_0_Handler() is called for DRE, SERCOM2_1_Handler() is called for TXC and SERCOM2_2_Handler() for RXC, etc.... Having serparate ISRs for each interrupt flag removes the need test which interrupt has occured within the handler function, thereby providing the SAMD51 with a small speed optimisation over the SAMD21.

Thank you very much MartinL. That explanation makes perfect sense :slight_smile: