diff --git a/Makefile b/Makefile index e5e72d0f..bbb00fb6 100644 --- a/Makefile +++ b/Makefile @@ -349,6 +349,8 @@ smoketest: @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=feather-m4-can examples/caninterrupt @$(MD5SUM) test.hex + $(TINYGO) build -size short -o test.hex -target=arduino-nano33 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/src/examples/echo/echo.go b/src/examples/echo/echo.go index 97a5dc4c..be129dd0 100644 --- a/src/examples/echo/echo.go +++ b/src/examples/echo/echo.go @@ -9,7 +9,7 @@ import ( // change these to test a different UART or pins if available var ( - uart = machine.UART0 + uart = machine.Serial tx = machine.UART_TX_PIN rx = machine.UART_RX_PIN ) diff --git a/src/machine/board_arduino_mkr1000.go b/src/machine/board_arduino_mkr1000.go index e4605942..863faeeb 100644 --- a/src/machine/board_arduino_mkr1000.go +++ b/src/machine/board_arduino_mkr1000.go @@ -47,7 +47,9 @@ const ( LED = D6 ) -// UART0 aka USBCDC pins +var Serial = USB + +// USBCDC pins const ( USBCDC_DM_PIN Pin = PA24 USBCDC_DP_PIN Pin = PA25 diff --git a/src/machine/board_arduino_nano33.go b/src/machine/board_arduino_nano33.go index 81aa815c..606f5e63 100644 --- a/src/machine/board_arduino_nano33.go +++ b/src/machine/board_arduino_nano33.go @@ -46,7 +46,7 @@ const ( LED = D13 ) -// UART0 aka USBCDC pins +// USBCDC pins const ( USBCDC_DM_PIN Pin = PA24 USBCDC_DP_PIN Pin = PA25 diff --git a/src/machine/board_arduino_zero.go b/src/machine/board_arduino_zero.go index 651eea82..773515c9 100644 --- a/src/machine/board_arduino_zero.go +++ b/src/machine/board_arduino_zero.go @@ -35,6 +35,8 @@ const ( LED3 Pin = PB03 // RX LED ) +var Serial = USB + // ADC pins const ( AREF Pin = PA03 diff --git a/src/machine/board_atsamd21.go b/src/machine/board_atsamd21.go index 3b11b452..800c4cb3 100644 --- a/src/machine/board_atsamd21.go +++ b/src/machine/board_atsamd21.go @@ -74,3 +74,5 @@ const ( PB30 Pin = 62 PB31 Pin = 63 ) + +var Serial = USB diff --git a/src/machine/board_atsame54-xpro.go b/src/machine/board_atsame54-xpro.go index a70ab7b0..01ae282c 100644 --- a/src/machine/board_atsame54-xpro.go +++ b/src/machine/board_atsame54-xpro.go @@ -15,6 +15,8 @@ const ( BUTTON = PB31 ) +var Serial = USB + const ( // https://ww1.microchip.com/downloads/en/DeviceDoc/70005321A.pdf @@ -152,7 +154,7 @@ const ( PIN_USB_ID = PC19 ) -// UART0 aka USBCDC pins +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/board_bluepill.go b/src/machine/board_bluepill.go index 4aece086..480aa19e 100644 --- a/src/machine/board_bluepill.go +++ b/src/machine/board_bluepill.go @@ -50,6 +50,8 @@ const ( LED = PC13 ) +var Serial = UART1 + // UART pins const ( UART_TX_PIN = PA9 @@ -60,22 +62,21 @@ const ( var ( // USART1 is the first hardware serial port on the STM32. - // Both UART0 and UART1 refer to USART1. - UART0 = &_UART0 - _UART0 = UART{ + UART1 = &_UART1 + _UART1 = UART{ Buffer: NewRingBuffer(), Bus: stm32.USART1, } - UART1 = &_UART1 - _UART1 = UART{ + UART2 = &_UART2 + _UART2 = UART{ Buffer: NewRingBuffer(), Bus: stm32.USART2, } ) func init() { - UART0.Interrupt = interrupt.New(stm32.IRQ_USART1, _UART0.handleInterrupt) - UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt) + UART1.Interrupt = interrupt.New(stm32.IRQ_USART1, _UART1.handleInterrupt) + UART2.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART2.handleInterrupt) } // SPI pins diff --git a/src/machine/board_circuitplay_bluefruit.go b/src/machine/board_circuitplay_bluefruit.go index 0a78ca5e..ccb2e3c1 100644 --- a/src/machine/board_circuitplay_bluefruit.go +++ b/src/machine/board_circuitplay_bluefruit.go @@ -56,10 +56,7 @@ const ( UART_RX_PIN = P0_30 // PORTB ) -// UART0 is the USB device -var ( - UART0 = USB -) +var Serial = USB // I2C pins const ( diff --git a/src/machine/board_clue_alpha.go b/src/machine/board_clue_alpha.go index a6c8807b..89f82056 100644 --- a/src/machine/board_clue_alpha.go +++ b/src/machine/board_clue_alpha.go @@ -103,9 +103,9 @@ const ( UART_TX_PIN = D1 ) -// UART0 is the USB device +// Serial is the USB device var ( - UART0 = USB + Serial = USB ) // I2C pins diff --git a/src/machine/board_esp32-coreboard-v2.go b/src/machine/board_esp32-coreboard-v2.go index 0145fe4e..b1d61d87 100644 --- a/src/machine/board_esp32-coreboard-v2.go +++ b/src/machine/board_esp32-coreboard-v2.go @@ -68,6 +68,8 @@ const ( ADC3 Pin = IO39 ) +var Serial = UART0 + // UART0 pins const ( UART_TX_PIN = IO1 diff --git a/src/machine/board_feather-m0.go b/src/machine/board_feather-m0.go index f0f72ea7..b09c4371 100644 --- a/src/machine/board_feather-m0.go +++ b/src/machine/board_feather-m0.go @@ -42,7 +42,7 @@ const ( LED = D13 ) -// UART0 aka USBCDC pins +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/board_feather-m4-can.go b/src/machine/board_feather-m4-can.go index 5ad3cd15..d5750f96 100644 --- a/src/machine/board_feather-m4-can.go +++ b/src/machine/board_feather-m4-can.go @@ -46,7 +46,9 @@ const ( NEOPIXELS = D8 ) -// UART0 aka USBCDC pins +var Serial = USB + +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/board_feather-m4.go b/src/machine/board_feather-m4.go index bec23fc8..251da721 100644 --- a/src/machine/board_feather-m4.go +++ b/src/machine/board_feather-m4.go @@ -39,7 +39,9 @@ const ( LED = D13 ) -// UART0 aka USBCDC pins +var Serial = USB + +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/board_feather-nrf52840.go b/src/machine/board_feather-nrf52840.go index f353a3b7..2c6e8465 100644 --- a/src/machine/board_feather-nrf52840.go +++ b/src/machine/board_feather-nrf52840.go @@ -75,9 +75,9 @@ const ( UART_TX_PIN = D1 ) -// UART0 is the USB device +// Serial is the USB device var ( - UART0 = USB + Serial = USB ) // I2C pins diff --git a/src/machine/board_feather-stm32f405.go b/src/machine/board_feather-stm32f405.go index f55572ff..e5e8d4b7 100644 --- a/src/machine/board_feather-stm32f405.go +++ b/src/machine/board_feather-stm32f405.go @@ -140,7 +140,7 @@ var ( TxAltFuncSelector: AF7_USART1_2_3, RxAltFuncSelector: AF7_USART1_2_3, } - UART0 = UART1 + Serial = UART1 ) func initUART() { diff --git a/src/machine/board_grandcentral-m4.go b/src/machine/board_grandcentral-m4.go index fdd09ecd..6d42034d 100644 --- a/src/machine/board_grandcentral-m4.go +++ b/src/machine/board_grandcentral-m4.go @@ -141,6 +141,8 @@ const ( NEOPIXEL = NEOPIXEL_PIN ) +var Serial = USB + // UART pins const ( UART1_RX_PIN = D0 // (PB25) diff --git a/src/machine/board_hifive1b.go b/src/machine/board_hifive1b.go index 10fd4a9f..7ce225cc 100644 --- a/src/machine/board_hifive1b.go +++ b/src/machine/board_hifive1b.go @@ -35,6 +35,8 @@ const ( LED_BLUE = P21 ) +var Serial = UART0 + const ( // TODO: figure out the pin numbers for these. UART_TX_PIN = D1 diff --git a/src/machine/board_itsybitsy-m0.go b/src/machine/board_itsybitsy-m0.go index a4161429..bd0272d4 100644 --- a/src/machine/board_itsybitsy-m0.go +++ b/src/machine/board_itsybitsy-m0.go @@ -42,7 +42,7 @@ const ( LED = D13 ) -// UART0 aka USBCDC pins +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/board_itsybitsy-m4.go b/src/machine/board_itsybitsy-m4.go index 5fef841c..282f9087 100644 --- a/src/machine/board_itsybitsy-m4.go +++ b/src/machine/board_itsybitsy-m4.go @@ -37,7 +37,9 @@ const ( LED = D13 ) -// UART0 aka USBCDC pins +var Serial = USB + +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/board_itsybitsy-nrf52840.go b/src/machine/board_itsybitsy-nrf52840.go index e61be006..64aeed50 100644 --- a/src/machine/board_itsybitsy-nrf52840.go +++ b/src/machine/board_itsybitsy-nrf52840.go @@ -70,9 +70,9 @@ const ( UART_TX_PIN = D1 ) -// UART0 is the USB device +// Serial is the USB device var ( - UART0 = USB + Serial = USB ) // I2C pins diff --git a/src/machine/board_lgt92.go b/src/machine/board_lgt92.go index 81fe2220..97e1fa2a 100644 --- a/src/machine/board_lgt92.go +++ b/src/machine/board_lgt92.go @@ -54,6 +54,8 @@ const ( I2C0_SDA_PIN = PA10 ) +var Serial = UART0 + var ( // Console UART (LPUSART1) diff --git a/src/machine/board_maixbit.go b/src/machine/board_maixbit.go index 718a46e4..766054d0 100644 --- a/src/machine/board_maixbit.go +++ b/src/machine/board_maixbit.go @@ -52,6 +52,8 @@ const ( LED_BLUE = D14 ) +var Serial = UART0 + // Default pins for UARTHS. const ( UART_TX_PIN = D5 diff --git a/src/machine/board_metro-m4-airlift.go b/src/machine/board_metro-m4-airlift.go index 5d12dd73..5665a081 100644 --- a/src/machine/board_metro-m4-airlift.go +++ b/src/machine/board_metro-m4-airlift.go @@ -40,7 +40,9 @@ const ( LED = D13 ) -// UART0 aka USBCDC pins +var Serial = USB + +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/board_microbit-v2.go b/src/machine/board_microbit-v2.go index 9d42bd49..a034e2ef 100644 --- a/src/machine/board_microbit-v2.go +++ b/src/machine/board_microbit-v2.go @@ -12,6 +12,8 @@ const ( BUTTONB Pin = P11 ) +var Serial = UART0 + // UART pins const ( UART_TX_PIN Pin = P34 diff --git a/src/machine/board_microbit.go b/src/machine/board_microbit.go index a606ad86..5b0ac2bf 100644 --- a/src/machine/board_microbit.go +++ b/src/machine/board_microbit.go @@ -12,6 +12,8 @@ const ( BUTTONB Pin = 26 ) +var Serial = UART0 + // UART pins const ( UART_TX_PIN Pin = 24 diff --git a/src/machine/board_nicenano.go b/src/machine/board_nicenano.go index 0a79fad3..213fdb33 100644 --- a/src/machine/board_nicenano.go +++ b/src/machine/board_nicenano.go @@ -54,9 +54,9 @@ const ( UART_TX_PIN = P0_08 ) -// UART0 is the USB device +// Serial is the USB device var ( - UART0 = USB + Serial = USB ) // I2C pins diff --git a/src/machine/board_nodemcu.go b/src/machine/board_nodemcu.go index f9f1af4f..4177f80c 100644 --- a/src/machine/board_nodemcu.go +++ b/src/machine/board_nodemcu.go @@ -20,6 +20,8 @@ const ( // Onboard blue LED (on the AI-Thinker module). const LED = D4 +var Serial = UART0 + // SPI pins const ( SPI0_SCK_PIN = D5 diff --git a/src/machine/board_nrf52840-mdk-usb-dongle.go b/src/machine/board_nrf52840-mdk-usb-dongle.go index 45d175ff..e4923f4e 100644 --- a/src/machine/board_nrf52840-mdk-usb-dongle.go +++ b/src/machine/board_nrf52840-mdk-usb-dongle.go @@ -23,10 +23,8 @@ const ( UART_RX_PIN Pin = NoPin ) -// UART0 is the USB device -var ( - UART0 = USB -) +// Serial is the USB device +var Serial = USB // I2C pins (unused) const ( diff --git a/src/machine/board_nrf52840-mdk.go b/src/machine/board_nrf52840-mdk.go index 19c6cbfd..d9dc4130 100644 --- a/src/machine/board_nrf52840-mdk.go +++ b/src/machine/board_nrf52840-mdk.go @@ -18,10 +18,8 @@ const ( UART_RX_PIN Pin = 19 ) -// UART0 is the USB device -var ( - UART0 = USB -) +// Serial is the USB device +var Serial = USB // I2C pins (unused) const ( diff --git a/src/machine/board_nucleof103rb.go b/src/machine/board_nucleof103rb.go index 0efdd5d8..89ce8449 100644 --- a/src/machine/board_nucleof103rb.go +++ b/src/machine/board_nucleof103rb.go @@ -99,17 +99,16 @@ const ( var ( // USART2 is the hardware serial port connected to the onboard ST-LINK // debugger to be exposed as virtual COM port over USB on Nucleo boards. - // Both UART0 and UART1 refer to USART2. - UART0 = &_UART0 - _UART0 = UART{ + UART2 = &_UART2 + _UART2 = UART{ Buffer: NewRingBuffer(), Bus: stm32.USART2, } - UART2 = UART0 + Serial = UART2 ) func init() { - UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt) + UART2.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART2.handleInterrupt) } // SPI pins diff --git a/src/machine/board_nucleof722ze.go b/src/machine/board_nucleof722ze.go index 4c1a2cd2..003e8fc7 100644 --- a/src/machine/board_nucleof722ze.go +++ b/src/machine/board_nucleof722ze.go @@ -31,19 +31,18 @@ const ( var ( // USART3 is the hardware serial port connected to the onboard ST-LINK // debugger to be exposed as virtual COM port over USB on Nucleo boards. - // Both UART0 and UART1 refer to USART2. - UART0 = &_UART0 - _UART0 = UART{ + UART1 = &_UART1 + _UART1 = UART{ Buffer: NewRingBuffer(), Bus: stm32.USART3, TxAltFuncSelector: UART_ALT_FN, RxAltFuncSelector: UART_ALT_FN, } - UART1 = UART0 + Serial = UART1 ) func init() { - UART0.Interrupt = interrupt.New(stm32.IRQ_USART3, _UART0.handleInterrupt) + UART1.Interrupt = interrupt.New(stm32.IRQ_USART3, _UART1.handleInterrupt) } // SPI pins diff --git a/src/machine/board_nucleol031k6.go b/src/machine/board_nucleol031k6.go index dc80b50d..695dd8b0 100644 --- a/src/machine/board_nucleol031k6.go +++ b/src/machine/board_nucleol031k6.go @@ -63,15 +63,14 @@ const ( var ( // USART2 is the hardware serial port connected to the onboard ST-LINK // debugger to be exposed as virtual COM port over USB on Nucleo boards. - // Both UART0 and UART1 refer to USART2. - UART0 = &_UART0 - _UART0 = UART{ + UART1 = &_UART1 + _UART1 = UART{ Buffer: NewRingBuffer(), Bus: stm32.USART2, TxAltFuncSelector: 4, RxAltFuncSelector: 4, } - UART1 = UART0 + Serial = UART1 // I2C1 is documented, alias to I2C0 as well I2C1 = &I2C{ @@ -89,5 +88,5 @@ var ( ) func init() { - UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt) + UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt) } diff --git a/src/machine/board_nucleol432kc.go b/src/machine/board_nucleol432kc.go index bb5133d2..8f32c46a 100644 --- a/src/machine/board_nucleol432kc.go +++ b/src/machine/board_nucleol432kc.go @@ -65,15 +65,14 @@ const ( var ( // USART2 is the hardware serial port connected to the onboard ST-LINK // debugger to be exposed as virtual COM port over USB on Nucleo boards. - // Both UART0 and UART1 refer to USART2. - UART0 = &_UART0 - _UART0 = UART{ + UART1 = &_UART1 + _UART1 = UART{ Buffer: NewRingBuffer(), Bus: stm32.USART2, TxAltFuncSelector: 7, RxAltFuncSelector: 3, } - UART1 = UART0 + Serial = UART1 // I2C1 is documented, alias to I2C0 as well I2C1 = &I2C{ @@ -91,5 +90,5 @@ var ( ) func init() { - UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt) + UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt) } diff --git a/src/machine/board_nucleol552ze.go b/src/machine/board_nucleol552ze.go index a20285c4..98e2d5c1 100644 --- a/src/machine/board_nucleol552ze.go +++ b/src/machine/board_nucleol552ze.go @@ -31,15 +31,14 @@ const ( var ( // LPUART1 is the hardware serial port connected to the onboard ST-LINK // debugger to be exposed as virtual COM port over USB on Nucleo boards. - // Both UART0 and UART1 refer to LPUART1. - UART0 = &_UART0 - _UART0 = UART{ + UART1 = &_UART1 + _UART1 = UART{ Buffer: NewRingBuffer(), Bus: stm32.LPUART1, TxAltFuncSelector: UART_ALT_FN, RxAltFuncSelector: UART_ALT_FN, } - UART1 = UART0 + Serial = UART1 ) const ( @@ -57,5 +56,5 @@ var ( ) func init() { - UART0.Interrupt = interrupt.New(stm32.IRQ_LPUART1, _UART0.handleInterrupt) + UART1.Interrupt = interrupt.New(stm32.IRQ_LPUART1, _UART1.handleInterrupt) } diff --git a/src/machine/board_p1am-100.go b/src/machine/board_p1am-100.go index 1f492fe5..46964e4e 100644 --- a/src/machine/board_p1am-100.go +++ b/src/machine/board_p1am-100.go @@ -66,7 +66,7 @@ const ( BASE_ENABLE_PIN Pin = PB09 ) -// UART0 aka USBCDC pins +// USBCDC pins const ( USBCDC_DM_PIN Pin = PA24 USBCDC_DP_PIN Pin = PA25 diff --git a/src/machine/board_particle_argon.go b/src/machine/board_particle_argon.go index 5401c4ad..1130eaf8 100644 --- a/src/machine/board_particle_argon.go +++ b/src/machine/board_particle_argon.go @@ -41,8 +41,7 @@ const ( // UART var ( - Serial = USB - UART0 = NRF_UART0 + Serial = UART0 ) const ( diff --git a/src/machine/board_particle_boron.go b/src/machine/board_particle_boron.go index cb05e725..6c2f70a8 100644 --- a/src/machine/board_particle_boron.go +++ b/src/machine/board_particle_boron.go @@ -41,8 +41,7 @@ const ( // UART var ( - Serial = USB - UART0 = NRF_UART0 + Serial = UART0 ) const ( diff --git a/src/machine/board_particle_xenon.go b/src/machine/board_particle_xenon.go index c1614636..a6e48ae0 100644 --- a/src/machine/board_particle_xenon.go +++ b/src/machine/board_particle_xenon.go @@ -41,8 +41,7 @@ const ( // UART var ( - Serial = USB - UART0 = NRF_UART0 + Serial = UART0 ) const ( diff --git a/src/machine/board_pca10031.go b/src/machine/board_pca10031.go index a4798814..fbddfb23 100644 --- a/src/machine/board_pca10031.go +++ b/src/machine/board_pca10031.go @@ -19,6 +19,8 @@ const ( LED_BLUE Pin = 23 ) +var Serial = UART0 + // UART pins const ( UART_TX_PIN Pin = 9 diff --git a/src/machine/board_pca10040.go b/src/machine/board_pca10040.go index 8d73e655..10e2ab2e 100644 --- a/src/machine/board_pca10040.go +++ b/src/machine/board_pca10040.go @@ -23,6 +23,8 @@ const ( BUTTON4 Pin = 16 ) +var Serial = UART0 + // UART pins for NRF52840-DK const ( UART_TX_PIN Pin = 6 diff --git a/src/machine/board_pca10056.go b/src/machine/board_pca10056.go index 5a9bcd5f..824bd3f0 100644 --- a/src/machine/board_pca10056.go +++ b/src/machine/board_pca10056.go @@ -22,6 +22,8 @@ const ( BUTTON4 Pin = 25 ) +var Serial = UART0 + // UART pins const ( UART_TX_PIN Pin = 6 diff --git a/src/machine/board_pca10056_baremetal.go b/src/machine/board_pca10056_baremetal.go deleted file mode 100644 index 75fcdee0..00000000 --- a/src/machine/board_pca10056_baremetal.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build nrf52840,pca10056 - -package machine - -// UART0 is the NRF UART -var ( - UART0 = NRF_UART0 -) diff --git a/src/machine/board_pca10059.go b/src/machine/board_pca10059.go index fd70cd3b..5079534a 100644 --- a/src/machine/board_pca10059.go +++ b/src/machine/board_pca10059.go @@ -34,9 +34,9 @@ const ( UART_RX_PIN Pin = NoPin ) -// UART0 is the USB device +// Serial is the USB device var ( - UART0 = USB + Serial = USB ) // I2C pins (unused) diff --git a/src/machine/board_pinetime-devkit0.go b/src/machine/board_pinetime-devkit0.go index 3526769c..5222010b 100644 --- a/src/machine/board_pinetime-devkit0.go +++ b/src/machine/board_pinetime-devkit0.go @@ -17,6 +17,8 @@ const ( LED3 = LCD_BACKLIGHT_LOW ) +var Serial = UART0 + // UART pins for PineTime. Note that RX is set to NoPin as RXD is not listed in // the PineTime schematic 1.0: // http://files.pine64.org/doc/PineTime/PineTime%20Port%20Assignment%20rev1.0.pdf diff --git a/src/machine/board_pybadge.go b/src/machine/board_pybadge.go index 35e446b3..687d933b 100644 --- a/src/machine/board_pybadge.go +++ b/src/machine/board_pybadge.go @@ -66,7 +66,9 @@ const ( BUTTON_B_MASK = 128 ) -// UART0 aka USBCDC pins +var Serial = USB + +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/board_pygamer.go b/src/machine/board_pygamer.go index 7e5c08e7..e12eed9e 100644 --- a/src/machine/board_pygamer.go +++ b/src/machine/board_pygamer.go @@ -69,7 +69,9 @@ const ( BUTTON_B_MASK = 128 ) -// UART0 aka USBCDC pins +var Serial = USB + +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/board_pyportal.go b/src/machine/board_pyportal.go index ff3ad1a1..c2ffb386 100644 --- a/src/machine/board_pyportal.go +++ b/src/machine/board_pyportal.go @@ -94,7 +94,9 @@ const ( LED = D13 ) -// UART0 aka USBCDC pins +var Serial = USB + +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/board_qtpy.go b/src/machine/board_qtpy.go index 883a32ba..23c7beca 100644 --- a/src/machine/board_qtpy.go +++ b/src/machine/board_qtpy.go @@ -45,7 +45,7 @@ const ( LED = D13 ) -// UART0 aka USBCDC pins +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/board_reelboard.go b/src/machine/board_reelboard.go index 400ad421..70eb7053 100644 --- a/src/machine/board_reelboard.go +++ b/src/machine/board_reelboard.go @@ -29,6 +29,8 @@ const ( BUTTON Pin = 7 ) +var Serial = UART0 + // UART pins const ( UART_TX_PIN Pin = 6 diff --git a/src/machine/board_reelboard_baremetal.go b/src/machine/board_reelboard_baremetal.go deleted file mode 100644 index 3ae65074..00000000 --- a/src/machine/board_reelboard_baremetal.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build nrf52840,reelboard - -package machine - -// UART0 is the NRF UART -var ( - UART0 = NRF_UART0 -) diff --git a/src/machine/board_stm32f4disco.go b/src/machine/board_stm32f4disco.go index 8c3976ab..7a061607 100644 --- a/src/machine/board_stm32f4disco.go +++ b/src/machine/board_stm32f4disco.go @@ -27,19 +27,19 @@ const ( ) var ( - UART0 = &_UART0 - _UART0 = UART{ + UART1 = &_UART1 + _UART1 = UART{ Buffer: NewRingBuffer(), Bus: stm32.USART2, TxAltFuncSelector: AF7_USART1_2_3, RxAltFuncSelector: AF7_USART1_2_3, } - UART1 = UART0 + Serial = UART1 ) // set up RX IRQ handler. Follow similar pattern for other UARTx instances func init() { - UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt) + UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt) } // SPI pins diff --git a/src/machine/board_teensy40.go b/src/machine/board_teensy40.go index 7f0781f0..54ae4e6b 100644 --- a/src/machine/board_teensy40.go +++ b/src/machine/board_teensy40.go @@ -136,7 +136,7 @@ const ( ) var ( - UART0 = UART1 // alias UART0 to UART1 + Serial = UART1 UART1 = &_UART1 _UART1 = UART{ Bus: nxp.LPUART6, diff --git a/src/machine/board_trinket.go b/src/machine/board_trinket.go index 6305cb70..068fa0d7 100644 --- a/src/machine/board_trinket.go +++ b/src/machine/board_trinket.go @@ -33,7 +33,7 @@ const ( LED = D13 ) -// UART0 aka USBCDC pins +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/board_wioterminal.go b/src/machine/board_wioterminal.go index 7fde5c72..abbe5550 100644 --- a/src/machine/board_wioterminal.go +++ b/src/machine/board_wioterminal.go @@ -325,7 +325,9 @@ const ( OUTPUT_CTR_3V3 = PC15 ) -// UART0 aka USBCDC pins +var Serial = USB + +// USBCDC pins const ( USBCDC_DM_PIN = PIN_USB_DM USBCDC_DP_PIN = PIN_USB_DP diff --git a/src/machine/board_x9pro.go b/src/machine/board_x9pro.go index d615b598..63d7257a 100644 --- a/src/machine/board_x9pro.go +++ b/src/machine/board_x9pro.go @@ -26,3 +26,5 @@ const ( ) const HasLowFrequencyCrystal = true + +var Serial = UART0 diff --git a/src/machine/board_xiao.go b/src/machine/board_xiao.go index b18a44e3..ac5ffbda 100644 --- a/src/machine/board_xiao.go +++ b/src/machine/board_xiao.go @@ -48,7 +48,7 @@ const ( LED3 = LED_TXL ) -// UART0 aka USBCDC pins +// USBCDC pins const ( USBCDC_DM_PIN = PA24 USBCDC_DP_PIN = PA25 diff --git a/src/machine/machine_atmega.go b/src/machine/machine_atmega.go index 6d9a5eda..fe6536e7 100644 --- a/src/machine/machine_atmega.go +++ b/src/machine/machine_atmega.go @@ -121,6 +121,9 @@ func (i2c *I2C) readByte() byte { return byte(avr.TWDR.Get()) } +// Always use UART0 as the serial output. +var Serial = UART0 + // UART var ( // UART0 is the hardware serial port on the AVR. diff --git a/src/machine/machine_atsamd21.go b/src/machine/machine_atsamd21.go index a9a02437..97704584 100644 --- a/src/machine/machine_atsamd21.go +++ b/src/machine/machine_atsamd21.go @@ -505,8 +505,7 @@ type UART struct { } var ( - // UART0 is actually a USB CDC interface. - UART0 = &USBCDC{Buffer: NewRingBuffer()} + USB = &USBCDC{Buffer: NewRingBuffer()} ) const ( @@ -1985,7 +1984,7 @@ func handleUSB(intr interrupt.Interrupt) { // Start of frame if (flags & sam.USB_DEVICE_INTFLAG_SOF) > 0 { - UART0.Flush() + USB.Flush() // if you want to blink LED showing traffic, this would be the place... } @@ -2045,7 +2044,7 @@ func handleUSB(intr interrupt.Interrupt) { setEPINTFLAG(i, sam.USB_DEVICE_EPINTFLAG_TRCPT1) if i == usb_CDC_ENDPOINT_IN { - UART0.waitTxc = false + USB.waitTxc = false } } } @@ -2359,7 +2358,7 @@ func handleEndpoint(ep uint32) { // move to ring buffer for i := 0; i < count; i++ { - UART0.Receive(byte((udd_ep_out_cache_buffer[ep][i] & 0xFF))) + USB.Receive(byte((udd_ep_out_cache_buffer[ep][i] & 0xFF))) } // set byte count to zero diff --git a/src/machine/machine_atsamd51.go b/src/machine/machine_atsamd51.go index 4b633389..2e7a6700 100644 --- a/src/machine/machine_atsamd51.go +++ b/src/machine/machine_atsamd51.go @@ -951,8 +951,8 @@ type UART struct { } var ( - // UART0 is actually a USB CDC interface. - UART0 = &USBCDC{Buffer: NewRingBuffer()} + // USB is a USB CDC interface. + USB = &USBCDC{Buffer: NewRingBuffer()} ) const ( @@ -2193,7 +2193,7 @@ func handleUSBIRQ(interrupt.Interrupt) { // Start of frame if (flags & sam.USB_DEVICE_INTFLAG_SOF) > 0 { - UART0.Flush() + USB.Flush() // if you want to blink LED showing traffic, this would be the place... } @@ -2253,7 +2253,7 @@ func handleUSBIRQ(interrupt.Interrupt) { setEPINTFLAG(i, sam.USB_DEVICE_ENDPOINT_EPINTFLAG_TRCPT1) if i == usb_CDC_ENDPOINT_IN { - UART0.waitTxc = false + USB.waitTxc = false } } } @@ -2567,7 +2567,7 @@ func handleEndpoint(ep uint32) { // move to ring buffer for i := 0; i < count; i++ { - UART0.Receive(byte((udd_ep_out_cache_buffer[ep][i] & 0xFF))) + USB.Receive(byte((udd_ep_out_cache_buffer[ep][i] & 0xFF))) } // set byte count to zero diff --git a/src/machine/machine_generic.go b/src/machine/machine_generic.go index 697af241..98dca2df 100644 --- a/src/machine/machine_generic.go +++ b/src/machine/machine_generic.go @@ -8,6 +8,7 @@ var ( SPI0 = SPI{0} I2C0 = &I2C{0} UART0 = &UART{0} + USB = &UART{100} ) const ( diff --git a/src/machine/machine_nrf.go b/src/machine/machine_nrf.go index ee883ccc..7af22000 100644 --- a/src/machine/machine_nrf.go +++ b/src/machine/machine_nrf.go @@ -138,8 +138,8 @@ type UART struct { // UART var ( // UART0 is the hardware UART on the NRF SoC. - _NRF_UART0 = UART{Buffer: NewRingBuffer()} - NRF_UART0 = &_NRF_UART0 + _UART0 = UART{Buffer: NewRingBuffer()} + UART0 = &_UART0 ) // Configure the UART. @@ -165,7 +165,7 @@ func (uart *UART) Configure(config UARTConfig) { nrf.UART0.INTENSET.Set(nrf.UART_INTENSET_RXDRDY_Msk) // Enable RX IRQ. - intr := interrupt.New(nrf.IRQ_UART0, _NRF_UART0.handleInterrupt) + intr := interrupt.New(nrf.IRQ_UART0, _UART0.handleInterrupt) intr.SetPriority(0xc0) // low priority intr.Enable() } diff --git a/src/machine/machine_nrf51.go b/src/machine/machine_nrf51.go index 4615a549..d60dc5f1 100644 --- a/src/machine/machine_nrf51.go +++ b/src/machine/machine_nrf51.go @@ -6,10 +6,6 @@ import ( "device/nrf" ) -var ( - UART0 = NRF_UART0 -) - func CPUFrequency() uint32 { return 16000000 } diff --git a/src/machine/machine_nrf52.go b/src/machine/machine_nrf52.go index 44120028..45e48159 100644 --- a/src/machine/machine_nrf52.go +++ b/src/machine/machine_nrf52.go @@ -42,10 +42,6 @@ const ( P0_31 Pin = 31 ) -var ( - UART0 = NRF_UART0 -) - // Get peripheral and pin number for this GPIO pin. func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) { return nrf.P0, uint32(p) diff --git a/src/machine/machine_nrf52833.go b/src/machine/machine_nrf52833.go index 1920b4e6..73f86f15 100644 --- a/src/machine/machine_nrf52833.go +++ b/src/machine/machine_nrf52833.go @@ -58,10 +58,6 @@ const ( P1_15 Pin = 47 ) -var ( - UART0 = NRF_UART0 -) - // Get peripheral and pin number for this GPIO pin. func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) { if p >= 32 { diff --git a/src/runtime/runtime_atmega.go b/src/runtime/runtime_atmega.go index 6d02e071..3c3d57bc 100644 --- a/src/runtime/runtime_atmega.go +++ b/src/runtime/runtime_atmega.go @@ -8,11 +8,11 @@ import ( ) func initUART() { - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) } func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } // Sleep for a given period. The period is defined by the WDT peripheral, and is diff --git a/src/runtime/runtime_atsamd21.go b/src/runtime/runtime_atsamd21.go index 117f5a6d..5ae58121 100644 --- a/src/runtime/runtime_atsamd21.go +++ b/src/runtime/runtime_atsamd21.go @@ -30,11 +30,11 @@ func init() { initADCClock() // connect to USB CDC interface - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) } func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } func initClocks() { diff --git a/src/runtime/runtime_atsamd51.go b/src/runtime/runtime_atsamd51.go index f59c82f2..54034445 100644 --- a/src/runtime/runtime_atsamd51.go +++ b/src/runtime/runtime_atsamd51.go @@ -30,11 +30,11 @@ func init() { initADCClock() // connect to USB CDC interface - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) } func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } func initClocks() { diff --git a/src/runtime/runtime_esp32.go b/src/runtime/runtime_esp32.go index ca7d7c14..2fdeab90 100644 --- a/src/runtime/runtime_esp32.go +++ b/src/runtime/runtime_esp32.go @@ -14,7 +14,7 @@ type timeUnit int64 var currentTime timeUnit func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } func postinit() {} @@ -53,7 +53,7 @@ func main() { preinit() // Initialize UART. - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) // Configure timer 0 in timer group 0, for timekeeping. // EN: Enable the timer. diff --git a/src/runtime/runtime_esp8266.go b/src/runtime/runtime_esp8266.go index 28af3c55..290d51c7 100644 --- a/src/runtime/runtime_esp8266.go +++ b/src/runtime/runtime_esp8266.go @@ -14,7 +14,7 @@ type timeUnit int64 var currentTime timeUnit = 0 func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } // Write to the internal control bus (using I2C?). @@ -37,7 +37,7 @@ func main() { rom_i2c_writeReg(103, 4, 2, 145) // Initialize UART. - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) // Initialize timer. Bits: // ENABLE: timer enable diff --git a/src/runtime/runtime_fe310.go b/src/runtime/runtime_fe310.go index d2e0d91e..fbc97199 100644 --- a/src/runtime/runtime_fe310.go +++ b/src/runtime/runtime_fe310.go @@ -93,11 +93,11 @@ func initPeripherals() { sifive.RTC.RTCCFG.Set(sifive.RTC_RTCCFG_ENALWAYS) // Configure the UART. - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) } func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } var timerWakeup volatile.Register8 diff --git a/src/runtime/runtime_k210.go b/src/runtime/runtime_k210.go index 93236181..8648f11c 100644 --- a/src/runtime/runtime_k210.go +++ b/src/runtime/runtime_k210.go @@ -105,11 +105,11 @@ func initPeripherals() { // Enable FPIOA peripheral. kendryte.SYSCTL.CLK_EN_PERI.SetBits(kendryte.SYSCTL_CLK_EN_PERI_FPIOA_CLK_EN) - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) } func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } var timerWakeup volatile.Register8 diff --git a/src/runtime/runtime_nrf.go b/src/runtime/runtime_nrf.go index 2e7765b6..60d20bdf 100644 --- a/src/runtime/runtime_nrf.go +++ b/src/runtime/runtime_nrf.go @@ -29,7 +29,7 @@ func main() { } func init() { - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) initLFCLK() initRTC() } @@ -64,7 +64,7 @@ func initRTC() { } func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } func sleepTicks(d timeUnit) { diff --git a/src/runtime/runtime_stm32f103.go b/src/runtime/runtime_stm32f103.go index 50d2b968..9af5cea1 100644 --- a/src/runtime/runtime_stm32f103.go +++ b/src/runtime/runtime_stm32f103.go @@ -33,7 +33,7 @@ func init() { Device: stm32.TIM3, }) - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) initTickTimer(&timerInfo{ EnableRegister: &stm32.RCC.APB1ENR, @@ -43,7 +43,7 @@ func init() { } func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } // initCLK sets clock to 72MHz using HSE 8MHz crystal w/ PLL X 9 (8MHz x 9 = 72MHz). diff --git a/src/runtime/runtime_stm32f405.go b/src/runtime/runtime_stm32f405.go index 799e4eac..7944fe12 100644 --- a/src/runtime/runtime_stm32f405.go +++ b/src/runtime/runtime_stm32f405.go @@ -181,10 +181,10 @@ func initCLK() { func initCOM() { if machine.NUM_UART_INTERFACES > 0 { - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) } } func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } diff --git a/src/runtime/runtime_stm32f407.go b/src/runtime/runtime_stm32f407.go index a1af7bbf..17a79eb7 100644 --- a/src/runtime/runtime_stm32f407.go +++ b/src/runtime/runtime_stm32f407.go @@ -51,7 +51,7 @@ func init() { Device: stm32.TIM3, }) - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) initTickTimer(&timerInfo{ EnableRegister: &stm32.RCC.APB1ENR, @@ -61,7 +61,7 @@ func init() { } func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } func initCLK() { diff --git a/src/runtime/runtime_stm32f7x2.go b/src/runtime/runtime_stm32f7x2.go index 034986b3..9e76694f 100644 --- a/src/runtime/runtime_stm32f7x2.go +++ b/src/runtime/runtime_stm32f7x2.go @@ -50,7 +50,7 @@ func init() { Device: stm32.TIM3, }) - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) initTickTimer(&timerInfo{ EnableRegister: &stm32.RCC.APB1ENR, @@ -60,7 +60,7 @@ func init() { } func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } func initCLK() { diff --git a/src/runtime/runtime_stm32l0.go b/src/runtime/runtime_stm32l0.go index be61749e..ef1be16d 100644 --- a/src/runtime/runtime_stm32l0.go +++ b/src/runtime/runtime_stm32l0.go @@ -14,7 +14,7 @@ const ( type arrtype = uint16 func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } func initCLK() { diff --git a/src/runtime/runtime_stm32l0x1.go b/src/runtime/runtime_stm32l0x1.go index 1d48388e..264efaf0 100644 --- a/src/runtime/runtime_stm32l0x1.go +++ b/src/runtime/runtime_stm32l0x1.go @@ -34,7 +34,7 @@ func init() { Device: stm32.TIM22, }) - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) initTickTimer(&timerInfo{ EnableRegister: &stm32.RCC.APB2ENR, diff --git a/src/runtime/runtime_stm32l0x2.go b/src/runtime/runtime_stm32l0x2.go index 6eccf0eb..2412d7e5 100644 --- a/src/runtime/runtime_stm32l0x2.go +++ b/src/runtime/runtime_stm32l0x2.go @@ -34,7 +34,7 @@ func init() { Device: stm32.TIM3, }) - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) initTickTimer(&timerInfo{ EnableRegister: &stm32.RCC.APB1ENR, diff --git a/src/runtime/runtime_stm32l4x2.go b/src/runtime/runtime_stm32l4x2.go index 9aad880c..7bdf39bf 100644 --- a/src/runtime/runtime_stm32l4x2.go +++ b/src/runtime/runtime_stm32l4x2.go @@ -75,7 +75,7 @@ func init() { Device: stm32.TIM15, }) - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) initTickTimer(&timerInfo{ EnableRegister: &stm32.RCC.APB2ENR, @@ -85,7 +85,7 @@ func init() { } func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } func initCLK() { diff --git a/src/runtime/runtime_stm32l5x2.go b/src/runtime/runtime_stm32l5x2.go index 1ecc662b..e4445080 100644 --- a/src/runtime/runtime_stm32l5x2.go +++ b/src/runtime/runtime_stm32l5x2.go @@ -51,7 +51,7 @@ func init() { Device: stm32.TIM15, }) - machine.UART0.Configure(machine.UARTConfig{}) + machine.Serial.Configure(machine.UARTConfig{}) initTickTimer(&timerInfo{ EnableRegister: &stm32.RCC.APB2ENR, @@ -61,7 +61,7 @@ func init() { } func putchar(c byte) { - machine.UART0.WriteByte(c) + machine.Serial.WriteByte(c) } func initCLK() {