From 0c880ec44c3199cebbdf3611eba331d5b683afdd Mon Sep 17 00:00:00 2001 From: sago35 Date: Fri, 5 Jun 2020 15:14:31 +0900 Subject: [PATCH] Standardize SAMD51 UART settings (#1155) * machine/samd51: standardize samd51 uart settings --- src/machine/board_feather-m4.go | 22 +------- src/machine/board_feather-m4_baremetal.go | 43 +++++++++++++++ src/machine/board_itsybitsy-m4.go | 25 +-------- src/machine/board_itsybitsy-m4_baremetal.go | 43 +++++++++++++++ src/machine/board_metro-m4-airlift.go | 37 ++----------- .../board_metro-m4-airlift_baremetal.go | 52 +++++++++++++++++++ src/machine/board_pybadge.go | 33 +----------- src/machine/board_pybadge_baremetal.go | 51 ++++++++++++++++++ src/machine/board_pyportal.go | 29 ++--------- src/machine/board_pyportal_baremetal.go | 37 +++++++++++++ src/machine/machine_atsamd51.go | 20 ------- 11 files changed, 238 insertions(+), 154 deletions(-) create mode 100644 src/machine/board_feather-m4_baremetal.go create mode 100644 src/machine/board_itsybitsy-m4_baremetal.go create mode 100644 src/machine/board_metro-m4-airlift_baremetal.go create mode 100644 src/machine/board_pybadge_baremetal.go create mode 100644 src/machine/board_pyportal_baremetal.go diff --git a/src/machine/board_feather-m4.go b/src/machine/board_feather-m4.go index fee8c2e4..511834e2 100644 --- a/src/machine/board_feather-m4.go +++ b/src/machine/board_feather-m4.go @@ -1,9 +1,7 @@ -// +build sam,atsamd51,feather_m4 +// +build feather_m4 package machine -import "device/sam" - // used to reset into bootloader const RESET_MAGIC_VALUE = 0xf01669ef @@ -47,13 +45,11 @@ const ( USBCDC_DP_PIN = PA25 ) -// UART1 pins const ( UART_TX_PIN = D1 UART_RX_PIN = D0 ) -// UART2 pins const ( UART2_TX_PIN = A4 UART2_RX_PIN = A5 @@ -65,14 +61,6 @@ const ( SCL_PIN = D21 // SCL: SERCOM2/PAD[1] ) -// I2C on the Feather M4. -var ( - I2C0 = I2C{ - Bus: sam.SERCOM2_I2CM, - SERCOM: 2, - } -) - // SPI pins const ( SPI0_SCK_PIN = D25 // SCK: SERCOM1/PAD[1] @@ -80,14 +68,6 @@ const ( SPI0_MISO_PIN = D23 // MISO: SERCOM1/PAD[2] ) -// SPI on the Feather M4. -var ( - SPI0 = SPI{ - Bus: sam.SERCOM1_SPIM, - SERCOM: 1, - } -) - // USB CDC identifiers const ( usb_STRING_PRODUCT = "Adafruit Feather M4" diff --git a/src/machine/board_feather-m4_baremetal.go b/src/machine/board_feather-m4_baremetal.go new file mode 100644 index 00000000..84921739 --- /dev/null +++ b/src/machine/board_feather-m4_baremetal.go @@ -0,0 +1,43 @@ +// +build sam,atsamd51,feather_m4 + +package machine + +import ( + "device/sam" + "runtime/interrupt" +) + +var ( + UART1 = UART{ + Buffer: NewRingBuffer(), + Bus: sam.SERCOM5_USART_INT, + SERCOM: 5, + } + + UART2 = UART{ + Buffer: NewRingBuffer(), + Bus: sam.SERCOM0_USART_INT, + SERCOM: 0, + } +) + +func init() { + UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, UART1.handleInterrupt) + UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART2.handleInterrupt) +} + +// I2C on the Feather M4. +var ( + I2C0 = I2C{ + Bus: sam.SERCOM2_I2CM, + SERCOM: 2, + } +) + +// SPI on the Feather M4. +var ( + SPI0 = SPI{ + Bus: sam.SERCOM1_SPIM, + SERCOM: 1, + } +) diff --git a/src/machine/board_itsybitsy-m4.go b/src/machine/board_itsybitsy-m4.go index c6d3390b..43c9a4ba 100644 --- a/src/machine/board_itsybitsy-m4.go +++ b/src/machine/board_itsybitsy-m4.go @@ -1,9 +1,7 @@ -// +build sam,atsamd51,itsybitsy_m4 +// +build itsybitsy_m4 package machine -import "device/sam" - // used to reset into bootloader const RESET_MAGIC_VALUE = 0xf01669ef @@ -51,30 +49,17 @@ const ( UART_RX_PIN = D0 ) -// UART1 var is on SERCOM3, defined in atsamd51.go - -// UART2 pins const ( UART2_TX_PIN = A4 UART2_RX_PIN = D2 ) -// UART2 var is on SERCOM0, defined in atsamd51.go - // I2C pins const ( SDA_PIN = PA12 // SDA: SERCOM2/PAD[0] SCL_PIN = PA13 // SCL: SERCOM2/PAD[1] ) -// I2C on the ItsyBitsy M4. -var ( - I2C0 = I2C{ - Bus: sam.SERCOM2_I2CM, - SERCOM: 2, - } -) - // SPI pins const ( SPI0_SCK_PIN = PA01 // SCK: SERCOM1/PAD[1] @@ -82,14 +67,6 @@ const ( SPI0_MISO_PIN = PB23 // MISO: SERCOM1/PAD[3] ) -// SPI on the ItsyBitsy M4. -var ( - SPI0 = SPI{ - Bus: sam.SERCOM1_SPIM, - SERCOM: 1, - } -) - // USB CDC identifiers const ( usb_STRING_PRODUCT = "Adafruit ItsyBitsy M4" diff --git a/src/machine/board_itsybitsy-m4_baremetal.go b/src/machine/board_itsybitsy-m4_baremetal.go new file mode 100644 index 00000000..88097bca --- /dev/null +++ b/src/machine/board_itsybitsy-m4_baremetal.go @@ -0,0 +1,43 @@ +// +build sam,atsamd51,itsybitsy_m4 + +package machine + +import ( + "device/sam" + "runtime/interrupt" +) + +var ( + UART1 = UART{ + Buffer: NewRingBuffer(), + Bus: sam.SERCOM3_USART_INT, + SERCOM: 3, + } + + UART2 = UART{ + Buffer: NewRingBuffer(), + Bus: sam.SERCOM0_USART_INT, + SERCOM: 0, + } +) + +func init() { + UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM3_2, UART1.handleInterrupt) + UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART2.handleInterrupt) +} + +// I2C on the ItsyBitsy M4. +var ( + I2C0 = I2C{ + Bus: sam.SERCOM2_I2CM, + SERCOM: 2, + } +) + +// SPI on the ItsyBitsy M4. +var ( + SPI0 = SPI{ + Bus: sam.SERCOM1_SPIM, + SERCOM: 1, + } +) diff --git a/src/machine/board_metro-m4-airlift.go b/src/machine/board_metro-m4-airlift.go index a62c4c24..c1f49a19 100644 --- a/src/machine/board_metro-m4-airlift.go +++ b/src/machine/board_metro-m4-airlift.go @@ -1,9 +1,7 @@ -// +build sam,atsamd51,metro_m4_airlift +// +build metro_m4_airlift package machine -import "device/sam" - // used to reset into bootloader const RESET_MAGIC_VALUE = 0xf01669ef @@ -53,7 +51,10 @@ const ( UART_RX_PIN = D0 ) -// Note: UART1 is on SERCOM3, defined in machine_atsamd51.go +const ( + UART2_TX_PIN = PA04 + UART2_RX_PIN = PA07 +) const ( NINA_CS = PA15 @@ -66,23 +67,12 @@ const ( NINA_RTS = PB23 ) -// UART2 is on SERCOM0, defined in machine_atsamd51.go, and connects to the -// onboard ESP32-WROOM chip. - // I2C pins const ( SDA_PIN = PB02 // SDA: SERCOM5/PAD[0] SCL_PIN = PB03 // SCL: SERCOM5/PAD[1] ) -// I2C on the Metro M4. -var ( - I2C0 = I2C{ - Bus: sam.SERCOM5_I2CM, - SERCOM: 5, - } -) - // SPI pins const ( SPI0_SCK_PIN = PA13 // SCK: SERCOM2/PAD[1] @@ -94,29 +84,12 @@ const ( NINA_SCK = SPI0_SCK_PIN ) -// SPI on the Metro M4. -var ( - SPI0 = SPI{ - Bus: sam.SERCOM2_SPIM, - SERCOM: 2, - } - NINA_SPI = SPI0 -) - const ( SPI1_SCK_PIN = D12 // MISO: SERCOM1/PAD[1] SPI1_MOSI_PIN = D11 // MOSI: SERCOM1/PAD[3] SPI1_MISO_PIN = D13 // SCK: SERCOM1/PAD[0] ) -// SPI1 on the Metro M4 on pins 11,12,13 -var ( - SPI1 = SPI{ - Bus: sam.SERCOM1_SPIM, - SERCOM: 1, - } -) - // USB CDC identifiers const ( usb_STRING_PRODUCT = "Adafruit Metro M4 Airlift Lite" diff --git a/src/machine/board_metro-m4-airlift_baremetal.go b/src/machine/board_metro-m4-airlift_baremetal.go new file mode 100644 index 00000000..b04f13cc --- /dev/null +++ b/src/machine/board_metro-m4-airlift_baremetal.go @@ -0,0 +1,52 @@ +// +build sam,atsamd51,metro_m4_airlift + +package machine + +import ( + "device/sam" + "runtime/interrupt" +) + +var ( + UART1 = UART{ + Buffer: NewRingBuffer(), + Bus: sam.SERCOM3_USART_INT, + SERCOM: 3, + } + + UART2 = UART{ + Buffer: NewRingBuffer(), + Bus: sam.SERCOM0_USART_INT, + SERCOM: 0, + } +) + +func init() { + UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM3_2, UART1.handleInterrupt) + UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART2.handleInterrupt) +} + +// I2C on the Metro M4. +var ( + I2C0 = I2C{ + Bus: sam.SERCOM5_I2CM, + SERCOM: 5, + } +) + +// SPI on the Metro M4. +var ( + SPI0 = SPI{ + Bus: sam.SERCOM2_SPIM, + SERCOM: 2, + } + NINA_SPI = SPI0 +) + +// SPI1 on the Metro M4 on pins 11,12,13 +var ( + SPI1 = SPI{ + Bus: sam.SERCOM1_SPIM, + SERCOM: 1, + } +) diff --git a/src/machine/board_pybadge.go b/src/machine/board_pybadge.go index 84ccb7ba..2b830197 100644 --- a/src/machine/board_pybadge.go +++ b/src/machine/board_pybadge.go @@ -1,9 +1,7 @@ -// +build sam,atsamd51,pybadge +// +build pybadge package machine -import "device/sam" - // used to reset into bootloader const RESET_MAGIC_VALUE = 0xf01669ef @@ -80,30 +78,17 @@ const ( UART_RX_PIN = D0 ) -// UART1 var is on SERCOM3, defined in atsamd51.go - -// UART2 pins const ( UART2_TX_PIN = A4 UART2_RX_PIN = A5 ) -// UART2 var is on SERCOM0, defined in atsamd51.go - // I2C pins const ( SDA_PIN = PA12 // SDA: SERCOM2/PAD[0] SCL_PIN = PA13 // SCL: SERCOM2/PAD[1] ) -// I2C on the ItsyBitsy M4. -var ( - I2C0 = I2C{ - Bus: sam.SERCOM2_I2CM, - SERCOM: 2, - } -) - // SPI pins const ( SPI0_SCK_PIN = PA17 // SCK: SERCOM1/PAD[1] @@ -111,14 +96,6 @@ const ( SPI0_MISO_PIN = PB22 // MISO: SERCOM1/PAD[2] ) -// SPI on the PyBadge. -var ( - SPI0 = SPI{ - Bus: sam.SERCOM1_SPIM, - SERCOM: 1, - } -) - // TFT SPI pins const ( SPI1_SCK_PIN = PB13 // SCK: SERCOM4/PAD[1] @@ -126,14 +103,6 @@ const ( SPI1_MISO_PIN = NoPin ) -// TFT SPI on the PyBadge. -var ( - SPI1 = SPI{ - Bus: sam.SERCOM4_SPIM, - SERCOM: 4, - } -) - // USB CDC identifiers const ( usb_STRING_PRODUCT = "Adafruit pyBadge M4" diff --git a/src/machine/board_pybadge_baremetal.go b/src/machine/board_pybadge_baremetal.go new file mode 100644 index 00000000..e3fd82e6 --- /dev/null +++ b/src/machine/board_pybadge_baremetal.go @@ -0,0 +1,51 @@ +// +build sam,atsamd51,pybadge + +package machine + +import ( + "device/sam" + "runtime/interrupt" +) + +var ( + UART1 = UART{ + Buffer: NewRingBuffer(), + Bus: sam.SERCOM5_USART_INT, + SERCOM: 5, + } + + UART2 = UART{ + Buffer: NewRingBuffer(), + Bus: sam.SERCOM0_USART_INT, + SERCOM: 0, + } +) + +func init() { + UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, UART1.handleInterrupt) + UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART2.handleInterrupt) +} + +// I2C on the ItsyBitsy M4. +var ( + I2C0 = I2C{ + Bus: sam.SERCOM2_I2CM, + SERCOM: 2, + } +) + +// SPI on the PyBadge. +var ( + SPI0 = SPI{ + Bus: sam.SERCOM1_SPIM, + SERCOM: 1, + } +) + +// TFT SPI on the PyBadge. +var ( + SPI1 = SPI{ + Bus: sam.SERCOM4_SPIM, + SERCOM: 4, + } +) diff --git a/src/machine/board_pyportal.go b/src/machine/board_pyportal.go index 7000631e..2eaf0b88 100644 --- a/src/machine/board_pyportal.go +++ b/src/machine/board_pyportal.go @@ -1,11 +1,7 @@ -// +build sam,atsamd51,pyportal +// +build pyportal package machine -import ( - "device/sam" -) - // used to reset into bootloader const RESET_MAGIC_VALUE = 0xf01669ef @@ -104,10 +100,10 @@ const ( USBCDC_DP_PIN = PA25 ) -// TODO: add configuration for UART on SERCOM4 that is connected to TX/RX of ESP32 +// UART1 aka NINA_TX/NINA_RX const ( - UART_TX_PIN = NoPin - UART_RX_PIN = NoPin + UART_TX_PIN = D1 + UART_RX_PIN = D0 ) // I2C pins @@ -116,14 +112,6 @@ const ( SCL_PIN = PB03 // SCL: SERCOM2/PAD[1] ) -// I2C on the PyPortal. -var ( - I2C0 = I2C{ - Bus: sam.SERCOM5_I2CM, - SERCOM: 5, - } -) - // SPI pins const ( SPI0_SCK_PIN = PA13 // SCK: SERCOM1/PAD[1] @@ -135,15 +123,6 @@ const ( NINA_SCK = SPI0_SCK_PIN ) -// SPI on the PyPortal. -var ( - SPI0 = SPI{ - Bus: sam.SERCOM2_SPIM, - SERCOM: 2, - } - NINA_SPI = SPI0 -) - // USB CDC identifiers const ( usb_STRING_PRODUCT = "Adafruit PyPortal M4" diff --git a/src/machine/board_pyportal_baremetal.go b/src/machine/board_pyportal_baremetal.go new file mode 100644 index 00000000..24ce6d38 --- /dev/null +++ b/src/machine/board_pyportal_baremetal.go @@ -0,0 +1,37 @@ +// +build sam,atsamd51,pyportal + +package machine + +import ( + "device/sam" + "runtime/interrupt" +) + +var ( + UART1 = UART{ + Buffer: NewRingBuffer(), + Bus: sam.SERCOM4_USART_INT, + SERCOM: 4, + } +) + +func init() { + UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM4_2, UART1.handleInterrupt) +} + +// I2C on the PyPortal. +var ( + I2C0 = I2C{ + Bus: sam.SERCOM5_I2CM, + SERCOM: 5, + } +) + +// SPI on the PyPortal. +var ( + SPI0 = SPI{ + Bus: sam.SERCOM2_SPIM, + SERCOM: 2, + } + NINA_SPI = SPI0 +) diff --git a/src/machine/machine_atsamd51.go b/src/machine/machine_atsamd51.go index 042b90d9..7008590b 100644 --- a/src/machine/machine_atsamd51.go +++ b/src/machine/machine_atsamd51.go @@ -903,28 +903,8 @@ type UART struct { var ( // UART0 is actually a USB CDC interface. UART0 = USBCDC{Buffer: NewRingBuffer()} - - // The first hardware serial port on the SAMD51. Uses the SERCOM3 interface. - UART1 = UART{ - Buffer: NewRingBuffer(), - Bus: sam.SERCOM3_USART_INT, - SERCOM: 3, - } - - // The second hardware serial port on the SAMD51. Uses the SERCOM0 interface. - UART2 = UART{ - Buffer: NewRingBuffer(), - Bus: sam.SERCOM0_USART_INT, - SERCOM: 0, - } ) -func init() { - // Register RXC interrupts. - UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM3_2, UART1.handleInterrupt) - UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART2.handleInterrupt) -} - const ( sampleRate16X = 16 lsbFirst = 1