From 1d99b1ed8493554835670eb6df7bf5340d9c4423 Mon Sep 17 00:00:00 2001 From: Kenneth Bell Date: Fri, 1 Jul 2022 17:06:08 +0100 Subject: [PATCH] boards: add Challenger RP2040 LoRa --- Makefile | 2 + README.md | 3 +- src/machine/board_badger2040.go | 28 ++++++ src/machine/board_challenger_rp2040.go | 119 +++++++++++++++++++++++++ src/machine/board_feather_rp2040.go | 37 ++++++++ src/machine/board_macropad-rp2040.go | 28 ++++++ src/machine/board_nano-rp2040.go | 28 ++++++ src/machine/board_pico.go | 37 ++++++++ src/machine/board_thingplus_rp2040.go | 28 ++++++ src/machine/board_xiao-rp2040.go | 28 ++++++ src/machine/machine_rp2040.go | 33 ------- targets/challenger-rp2040.json | 11 +++ 12 files changed, 348 insertions(+), 34 deletions(-) create mode 100644 src/machine/board_challenger_rp2040.go create mode 100644 targets/challenger-rp2040.json diff --git a/Makefile b/Makefile index a9f950bf..4c11e99a 100644 --- a/Makefile +++ b/Makefile @@ -569,6 +569,8 @@ endif @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=xiao-rp2040 examples/blinky1 @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=challenger-rp2040 examples/blinky1 + @$(MD5SUM) test.hex # test pwm $(TINYGO) build -size short -o test.hex -target=itsybitsy-m0 examples/pwm @$(MD5SUM) test.hex diff --git a/README.md b/README.md index 834567f3..3fa607b9 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ See the [getting started instructions](https://tinygo.org/getting-started/) for You can compile TinyGo programs for microcontrollers, WebAssembly and Linux. -The following 87 microcontroller boards are currently supported: +The following 88 microcontroller boards are currently supported: * [Adafruit Circuit Playground Bluefruit](https://www.adafruit.com/product/4333) * [Adafruit Circuit Playground Express](https://www.adafruit.com/product/3333) @@ -89,6 +89,7 @@ The following 87 microcontroller boards are currently supported: * [ESP8266 - d1mini](https://www.espressif.com/en/products/socs/esp8266) * [ESP8266 - NodeMCU](https://www.espressif.com/en/products/socs/esp8266) * [Game Boy Advance](https://en.wikipedia.org/wiki/Game_Boy_Advance) +* [iLabs Challenger RP2040 LoRa](https://ilabs.se/product/challenger-rp2040-lora/) * [M5Stack](https://docs.m5stack.com/en/core/basic) * [M5Stack Core2](https://shop.m5stack.com/products/m5stack-core2-esp32-iot-development-kit) * [M5Stamp C3](https://docs.m5stack.com/en/core/stamp_c3) diff --git a/src/machine/board_badger2040.go b/src/machine/board_badger2040.go index d2b41122..2619af36 100644 --- a/src/machine/board_badger2040.go +++ b/src/machine/board_badger2040.go @@ -9,6 +9,11 @@ // package machine +import ( + "device/rp" + "runtime/interrupt" +) + const ( LED Pin = GPIO25 @@ -79,3 +84,26 @@ var ( usb_VID uint16 = 0x2e8a usb_PID uint16 = 0x0003 ) + +// UART pins +const ( + UART0_TX_PIN = GPIO0 + UART0_RX_PIN = GPIO1 + UART_TX_PIN = UART0_TX_PIN + UART_RX_PIN = UART0_RX_PIN +) + +// UART on the RP2040 +var ( + UART0 = &_UART0 + _UART0 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART0, + } +) + +var DefaultUART = UART0 + +func init() { + UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt) +} diff --git a/src/machine/board_challenger_rp2040.go b/src/machine/board_challenger_rp2040.go new file mode 100644 index 00000000..daae745f --- /dev/null +++ b/src/machine/board_challenger_rp2040.go @@ -0,0 +1,119 @@ +//go:build challenger_rp2040 +// +build challenger_rp2040 + +package machine + +import ( + "device/rp" + "runtime/interrupt" +) + +const ( + LED = GPIO24 + + // Onboard crystal oscillator frequency, in MHz. + xoscFreq = 12 // MHz +) + +// GPIO Pins +const ( + D5 = GPIO2 + D6 = GPIO3 + D9 = GPIO4 + D10 = GPIO5 + D11 = GPIO6 + D12 = GPIO7 + D13 = GPIO8 +) + +// Analog pins +const ( + A0 = ADC0 + A1 = ADC1 + A2 = ADC2 + A3 = ADC3 +) + +// I2C Pins. +const ( + I2C0_SDA_PIN = GPIO24 + I2C0_SCL_PIN = GPIO25 + + I2C1_SDA_PIN = GPIO2 + I2C1_SCL_PIN = GPIO3 + + SDA_PIN = I2C1_SDA_PIN + SCL_PIN = I2C1_SCL_PIN +) + +// SPI default pins +const ( + // Default Serial Clock Bus 0 for SPI communications + SPI0_SCK_PIN = GPIO22 + // Default Serial Out Bus 0 for SPI communications + SPI0_SDO_PIN = GPIO23 // Tx + // Default Serial In Bus 0 for SPI communications + SPI0_SDI_PIN = GPIO20 // Rx + + // Default Serial Clock Bus 1 for SPI communications + SPI1_SCK_PIN = GPIO10 + // Default Serial Out Bus 1 for SPI communications + SPI1_SDO_PIN = GPIO11 // Tx + // Default Serial In Bus 1 for SPI communications + SPI1_SDI_PIN = GPIO12 // Rx +) + +// LoRa default pins +const ( + LORA_CS = GPIO9 + LORA_SCK = GPIO10 + LORA_SDO = GPIO11 + LORA_SDI = GPIO12 + LORA_RESET = GPIO13 + LORA_DIO0 = GPIO14 + LORA_DIO1 = GPIO15 + LORA_DIO2 = GPIO18 +) + +// UART pins +const ( + UART0_TX_PIN = GPIO16 + UART0_RX_PIN = GPIO17 + UART1_TX_PIN = GPIO4 + UART1_RX_PIN = GPIO5 + UART_TX_PIN = UART0_TX_PIN + UART_RX_PIN = UART0_RX_PIN +) + +// UART on the RP2040 +var ( + UART0 = &_UART0 + _UART0 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART0, + } + + UART1 = &_UART1 + _UART1 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART1, + } +) + +var DefaultUART = UART0 + +func init() { + UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt) + UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt) +} + +// USB identifiers +const ( + usb_STRING_PRODUCT = "Challenger 2040 LoRa" + usb_STRING_MANUFACTURER = "iLabs" +) + +var ( + usb_VID uint16 = 0x2e8a + usb_PID uint16 = 0x1023 +) diff --git a/src/machine/board_feather_rp2040.go b/src/machine/board_feather_rp2040.go index 4ac5ce38..04991d2e 100644 --- a/src/machine/board_feather_rp2040.go +++ b/src/machine/board_feather_rp2040.go @@ -3,6 +3,11 @@ package machine +import ( + "device/rp" + "runtime/interrupt" +) + const ( LED = GPIO13 @@ -61,6 +66,38 @@ const ( SPI1_SDI_PIN = GPIO12 // Rx ) +// UART pins +const ( + UART0_TX_PIN = GPIO0 + UART0_RX_PIN = GPIO1 + UART1_TX_PIN = GPIO8 + UART1_RX_PIN = GPIO9 + UART_TX_PIN = UART0_TX_PIN + UART_RX_PIN = UART0_RX_PIN +) + +// UART on the RP2040 +var ( + UART0 = &_UART0 + _UART0 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART0, + } + + UART1 = &_UART1 + _UART1 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART1, + } +) + +var DefaultUART = UART0 + +func init() { + UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt) + UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt) +} + // USB identifiers const ( usb_STRING_PRODUCT = "Feather RP2040" diff --git a/src/machine/board_macropad-rp2040.go b/src/machine/board_macropad-rp2040.go index ec03418a..916b94a4 100644 --- a/src/machine/board_macropad-rp2040.go +++ b/src/machine/board_macropad-rp2040.go @@ -3,6 +3,11 @@ package machine +import ( + "device/rp" + "runtime/interrupt" +) + const ( NeopixelCount = 12 @@ -65,6 +70,29 @@ const ( SPI0_SDI_PIN = 31 // not pinned out ) +// UART pins +const ( + UART0_TX_PIN = GPIO0 + UART0_RX_PIN = GPIO1 + UART_TX_PIN = UART0_TX_PIN + UART_RX_PIN = UART0_RX_PIN +) + +// UART on the RP2040 +var ( + UART0 = &_UART0 + _UART0 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART0, + } +) + +var DefaultUART = UART0 + +func init() { + UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt) +} + // USB identifiers const ( usb_STRING_PRODUCT = "MacroPad RP2040" diff --git a/src/machine/board_nano-rp2040.go b/src/machine/board_nano-rp2040.go index 1e30ca67..11dab88e 100644 --- a/src/machine/board_nano-rp2040.go +++ b/src/machine/board_nano-rp2040.go @@ -13,6 +13,11 @@ // package machine +import ( + "device/rp" + "runtime/interrupt" +) + // Digital Pins const ( D2 Pin = GPIO25 @@ -104,3 +109,26 @@ var ( usb_VID uint16 = 0x2341 usb_PID uint16 = 0x005e ) + +// UART pins +const ( + UART0_TX_PIN = GPIO0 + UART0_RX_PIN = GPIO1 + UART_TX_PIN = UART0_TX_PIN + UART_RX_PIN = UART0_RX_PIN +) + +// UART on the RP2040 +var ( + UART0 = &_UART0 + _UART0 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART0, + } +) + +var DefaultUART = UART0 + +func init() { + UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt) +} diff --git a/src/machine/board_pico.go b/src/machine/board_pico.go index f7356fcf..25e3551d 100644 --- a/src/machine/board_pico.go +++ b/src/machine/board_pico.go @@ -3,6 +3,11 @@ package machine +import ( + "device/rp" + "runtime/interrupt" +) + // GPIO pins const ( GP0 Pin = GPIO0 @@ -65,6 +70,38 @@ const ( SPI1_SDI_PIN = GPIO12 // Rx ) +// UART pins +const ( + UART0_TX_PIN = GPIO0 + UART0_RX_PIN = GPIO1 + UART1_TX_PIN = GPIO8 + UART1_RX_PIN = GPIO9 + UART_TX_PIN = UART0_TX_PIN + UART_RX_PIN = UART0_RX_PIN +) + +// UART on the RP2040 +var ( + UART0 = &_UART0 + _UART0 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART0, + } + + UART1 = &_UART1 + _UART1 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART1, + } +) + +var DefaultUART = UART0 + +func init() { + UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt) + UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt) +} + // USB identifiers const ( usb_STRING_PRODUCT = "Pico" diff --git a/src/machine/board_thingplus_rp2040.go b/src/machine/board_thingplus_rp2040.go index 8967f6b2..10fa5cc7 100644 --- a/src/machine/board_thingplus_rp2040.go +++ b/src/machine/board_thingplus_rp2040.go @@ -3,6 +3,11 @@ package machine +import ( + "device/rp" + "runtime/interrupt" +) + const ( LED = GPIO25 @@ -80,6 +85,29 @@ const ( SPI1_SDI_PIN = GPIO12 // Rx ) +// UART pins +const ( + UART0_TX_PIN = GPIO0 + UART0_RX_PIN = GPIO1 + UART_TX_PIN = UART0_TX_PIN + UART_RX_PIN = UART0_RX_PIN +) + +// UART on the RP2040 +var ( + UART0 = &_UART0 + _UART0 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART0, + } +) + +var DefaultUART = UART0 + +func init() { + UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt) +} + // USB identifiers const ( usb_STRING_PRODUCT = "Thing Plus RP2040" diff --git a/src/machine/board_xiao-rp2040.go b/src/machine/board_xiao-rp2040.go index 88fcc774..420319bd 100644 --- a/src/machine/board_xiao-rp2040.go +++ b/src/machine/board_xiao-rp2040.go @@ -9,6 +9,11 @@ // package machine +import ( + "device/rp" + "runtime/interrupt" +) + // Digital Pins const ( D0 Pin = GPIO26 @@ -67,6 +72,29 @@ const ( xoscFreq = 12 // MHz ) +// UART pins +const ( + UART0_TX_PIN = GPIO0 + UART0_RX_PIN = GPIO1 + UART_TX_PIN = UART0_TX_PIN + UART_RX_PIN = UART0_RX_PIN +) + +// UART on the RP2040 +var ( + UART0 = &_UART0 + _UART0 = UART{ + Buffer: NewRingBuffer(), + Bus: rp.UART0, + } +) + +var DefaultUART = UART0 + +func init() { + UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt) +} + // USB CDC identifiers const ( usb_STRING_PRODUCT = "XIAO RP2040" diff --git a/src/machine/machine_rp2040.go b/src/machine/machine_rp2040.go index 4b18368e..e74789fe 100644 --- a/src/machine/machine_rp2040.go +++ b/src/machine/machine_rp2040.go @@ -5,7 +5,6 @@ package machine import ( "device/rp" - "runtime/interrupt" ) const deviceName = rp.Device @@ -91,38 +90,6 @@ func lightSleep(ticks uint64) { timer.lightSleep(ticks) } -// UART pins -const ( - UART_TX_PIN = UART0_TX_PIN - UART_RX_PIN = UART0_RX_PIN - UART0_TX_PIN = GPIO0 - UART0_RX_PIN = GPIO1 - UART1_TX_PIN = GPIO8 - UART1_RX_PIN = GPIO9 -) - -// UART on the RP2040 -var ( - UART0 = &_UART0 - _UART0 = UART{ - Buffer: NewRingBuffer(), - Bus: rp.UART0, - } - - UART1 = &_UART1 - _UART1 = UART{ - Buffer: NewRingBuffer(), - Bus: rp.UART1, - } -) - -var DefaultUART = UART0 - -func init() { - UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt) - UART1.Interrupt = interrupt.New(rp.IRQ_UART1_IRQ, _UART1.handleInterrupt) -} - // CurrentCore returns the core number the call was made from. func CurrentCore() int { return int(rp.SIO.CPUID.Get()) diff --git a/targets/challenger-rp2040.json b/targets/challenger-rp2040.json new file mode 100644 index 00000000..d7ade643 --- /dev/null +++ b/targets/challenger-rp2040.json @@ -0,0 +1,11 @@ +{ + "inherits": [ + "rp2040" + ], + "serial": "uart", + "build-tags": ["challenger_rp2040"], + "linkerscript": "targets/feather-rp2040.ld", + "extra-files": [ + "targets/feather-rp2040-boot-stage2.S" + ] +}