sam: simplify definition of SERCOM UART peripherals

Instead of defining them separately for each board, define them once in
the chip definition and later simply use &sercomUART1 etc. to refer to
them. This is simpler and less error-prone.

I found two bugs while working on this:

  - The P1AM-100 board mixed SERCOM 5 and SERCOM 3. It looks like SERCOM
    5 was intended, based on the used pins.
  - The Adafruit Matrix Portal appears to have configured the wrong
    interrupt.

Unfortunately, I can't test these fixes. However, they make it clear
that such a change is important to avoid bugs.

I tested this commit on the PyBadge and the Circuit Playground Express.
This commit is contained in:
Ayke van Laethem
2021-10-15 21:20:45 +02:00
committed by Ron Evans
parent 478dd3a28d
commit e50885a6f2
35 changed files with 156 additions and 402 deletions
+4 -32
View File
@@ -4,7 +4,6 @@ package machine
import (
"device/sam"
"runtime/interrupt"
)
// Definition for compatibility, but not used
@@ -240,45 +239,18 @@ var (
// UART on the SAM E54 Xplained Pro
var (
// Extension Header EXT1
UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: sam.SERCOM0_USART_INT,
SERCOM: 0,
}
UART1 = &sercomUSART0
// Extension Header EXT2
UART2 = &_UART2
_UART2 = UART{
Buffer: NewRingBuffer(),
Bus: sam.SERCOM5_USART_INT,
SERCOM: 5,
}
UART2 = &sercomUSART5
// Extension Header EXT3
UART3 = &_UART3
_UART3 = UART{
Buffer: NewRingBuffer(),
Bus: sam.SERCOM1_USART_INT,
SERCOM: 1,
}
UART3 = &sercomUSART1
// EDBG Virtual COM Port
UART4 = &_UART4
_UART4 = UART{
Buffer: NewRingBuffer(),
Bus: sam.SERCOM2_USART_INT,
SERCOM: 2,
}
UART4 = &sercomUSART2
)
func init() {
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, _UART1.handleInterrupt)
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, _UART2.handleInterrupt)
UART3.Interrupt = interrupt.New(sam.IRQ_SERCOM1_2, _UART3.handleInterrupt)
UART4.Interrupt = interrupt.New(sam.IRQ_SERCOM2_2, _UART4.handleInterrupt)
}
// I2C on the SAM E54 Xplained Pro
var (
// Extension Header EXT1