machine: define Serial as the default output

Previously, the machine.UART0 object had two meanings:

  - it was the first UART on the chip
  - it was the default output for println

These two meanings conflict, and resulted in workarounds like:

  - Defining UART0 to refer to the USB-CDC interface (atsamd21,
    atsamd51, nrf52840), even though that clearly isn't an UART.
  - Defining NRF_UART0 to avoid a conflict with UART0 (which was
    redefined as a USB-CDC interface).
  - Defining aliases like UART0 = UART1, which refer to the same
    hardware peripheral (stm32).

This commit changes this to use a new machine.Serial object for the
default serial port. It might refer to the first or second UART
depending on the board, or even to the USB-CDC interface. Also, UART0
now really refers to the first UART on the chip, no longer to a USB-CDC
interface.

The changes in the runtime package are all just search+replace. The
changes in the machine package are a mixture of search+replace and
manual modifications.

This commit does not affect binary size, in fact it doesn't affect the
resulting binary at all.
Этот коммит содержится в:
Ayke van Laethem 2021-05-13 14:07:22 +02:00 коммит произвёл Ron Evans
родитель aa5b8d0df7
коммит b67351babe
82 изменённых файлов: 171 добавлений и 156 удалений

Просмотреть файл

@ -349,6 +349,8 @@ smoketest:
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=feather-m4-can examples/caninterrupt $(TINYGO) build -size short -o test.hex -target=feather-m4-can examples/caninterrupt
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=arduino-nano33 examples/blinky1
@$(MD5SUM) test.hex
# test pwm # test pwm
$(TINYGO) build -size short -o test.hex -target=itsybitsy-m0 examples/pwm $(TINYGO) build -size short -o test.hex -target=itsybitsy-m0 examples/pwm
@$(MD5SUM) test.hex @$(MD5SUM) test.hex

Просмотреть файл

@ -9,7 +9,7 @@ import (
// change these to test a different UART or pins if available // change these to test a different UART or pins if available
var ( var (
uart = machine.UART0 uart = machine.Serial
tx = machine.UART_TX_PIN tx = machine.UART_TX_PIN
rx = machine.UART_RX_PIN rx = machine.UART_RX_PIN
) )

Просмотреть файл

@ -47,7 +47,9 @@ const (
LED = D6 LED = D6
) )
// UART0 aka USBCDC pins var Serial = USB
// USBCDC pins
const ( const (
USBCDC_DM_PIN Pin = PA24 USBCDC_DM_PIN Pin = PA24
USBCDC_DP_PIN Pin = PA25 USBCDC_DP_PIN Pin = PA25

Просмотреть файл

@ -46,7 +46,7 @@ const (
LED = D13 LED = D13
) )
// UART0 aka USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN Pin = PA24 USBCDC_DM_PIN Pin = PA24
USBCDC_DP_PIN Pin = PA25 USBCDC_DP_PIN Pin = PA25

Просмотреть файл

@ -35,6 +35,8 @@ const (
LED3 Pin = PB03 // RX LED LED3 Pin = PB03 // RX LED
) )
var Serial = USB
// ADC pins // ADC pins
const ( const (
AREF Pin = PA03 AREF Pin = PA03

Просмотреть файл

@ -74,3 +74,5 @@ const (
PB30 Pin = 62 PB30 Pin = 62
PB31 Pin = 63 PB31 Pin = 63
) )
var Serial = USB

Просмотреть файл

@ -15,6 +15,8 @@ const (
BUTTON = PB31 BUTTON = PB31
) )
var Serial = USB
const ( const (
// https://ww1.microchip.com/downloads/en/DeviceDoc/70005321A.pdf // https://ww1.microchip.com/downloads/en/DeviceDoc/70005321A.pdf
@ -152,7 +154,7 @@ const (
PIN_USB_ID = PC19 PIN_USB_ID = PC19
) )
// UART0 aka USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -50,6 +50,8 @@ const (
LED = PC13 LED = PC13
) )
var Serial = UART1
// UART pins // UART pins
const ( const (
UART_TX_PIN = PA9 UART_TX_PIN = PA9
@ -60,22 +62,21 @@ const (
var ( var (
// USART1 is the first hardware serial port on the STM32. // USART1 is the first hardware serial port on the STM32.
// Both UART0 and UART1 refer to USART1. UART1 = &_UART1
UART0 = &_UART0 _UART1 = UART{
_UART0 = UART{
Buffer: NewRingBuffer(), Buffer: NewRingBuffer(),
Bus: stm32.USART1, Bus: stm32.USART1,
} }
UART1 = &_UART1 UART2 = &_UART2
_UART1 = UART{ _UART2 = UART{
Buffer: NewRingBuffer(), Buffer: NewRingBuffer(),
Bus: stm32.USART2, Bus: stm32.USART2,
} }
) )
func init() { func init() {
UART0.Interrupt = interrupt.New(stm32.IRQ_USART1, _UART0.handleInterrupt) UART1.Interrupt = interrupt.New(stm32.IRQ_USART1, _UART1.handleInterrupt)
UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt) UART2.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART2.handleInterrupt)
} }
// SPI pins // SPI pins

Просмотреть файл

@ -56,10 +56,7 @@ const (
UART_RX_PIN = P0_30 // PORTB UART_RX_PIN = P0_30 // PORTB
) )
// UART0 is the USB device var Serial = USB
var (
UART0 = USB
)
// I2C pins // I2C pins
const ( const (

Просмотреть файл

@ -103,9 +103,9 @@ const (
UART_TX_PIN = D1 UART_TX_PIN = D1
) )
// UART0 is the USB device // Serial is the USB device
var ( var (
UART0 = USB Serial = USB
) )
// I2C pins // I2C pins

Просмотреть файл

@ -68,6 +68,8 @@ const (
ADC3 Pin = IO39 ADC3 Pin = IO39
) )
var Serial = UART0
// UART0 pins // UART0 pins
const ( const (
UART_TX_PIN = IO1 UART_TX_PIN = IO1

Просмотреть файл

@ -42,7 +42,7 @@ const (
LED = D13 LED = D13
) )
// UART0 aka USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -46,7 +46,9 @@ const (
NEOPIXELS = D8 NEOPIXELS = D8
) )
// UART0 aka USBCDC pins var Serial = USB
// USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -39,7 +39,9 @@ const (
LED = D13 LED = D13
) )
// UART0 aka USBCDC pins var Serial = USB
// USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -75,9 +75,9 @@ const (
UART_TX_PIN = D1 UART_TX_PIN = D1
) )
// UART0 is the USB device // Serial is the USB device
var ( var (
UART0 = USB Serial = USB
) )
// I2C pins // I2C pins

Просмотреть файл

@ -140,7 +140,7 @@ var (
TxAltFuncSelector: AF7_USART1_2_3, TxAltFuncSelector: AF7_USART1_2_3,
RxAltFuncSelector: AF7_USART1_2_3, RxAltFuncSelector: AF7_USART1_2_3,
} }
UART0 = UART1 Serial = UART1
) )
func initUART() { func initUART() {

Просмотреть файл

@ -141,6 +141,8 @@ const (
NEOPIXEL = NEOPIXEL_PIN NEOPIXEL = NEOPIXEL_PIN
) )
var Serial = USB
// UART pins // UART pins
const ( const (
UART1_RX_PIN = D0 // (PB25) UART1_RX_PIN = D0 // (PB25)

Просмотреть файл

@ -35,6 +35,8 @@ const (
LED_BLUE = P21 LED_BLUE = P21
) )
var Serial = UART0
const ( const (
// TODO: figure out the pin numbers for these. // TODO: figure out the pin numbers for these.
UART_TX_PIN = D1 UART_TX_PIN = D1

Просмотреть файл

@ -42,7 +42,7 @@ const (
LED = D13 LED = D13
) )
// UART0 aka USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -37,7 +37,9 @@ const (
LED = D13 LED = D13
) )
// UART0 aka USBCDC pins var Serial = USB
// USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -70,9 +70,9 @@ const (
UART_TX_PIN = D1 UART_TX_PIN = D1
) )
// UART0 is the USB device // Serial is the USB device
var ( var (
UART0 = USB Serial = USB
) )
// I2C pins // I2C pins

Просмотреть файл

@ -54,6 +54,8 @@ const (
I2C0_SDA_PIN = PA10 I2C0_SDA_PIN = PA10
) )
var Serial = UART0
var ( var (
// Console UART (LPUSART1) // Console UART (LPUSART1)

Просмотреть файл

@ -52,6 +52,8 @@ const (
LED_BLUE = D14 LED_BLUE = D14
) )
var Serial = UART0
// Default pins for UARTHS. // Default pins for UARTHS.
const ( const (
UART_TX_PIN = D5 UART_TX_PIN = D5

Просмотреть файл

@ -40,7 +40,9 @@ const (
LED = D13 LED = D13
) )
// UART0 aka USBCDC pins var Serial = USB
// USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -12,6 +12,8 @@ const (
BUTTONB Pin = P11 BUTTONB Pin = P11
) )
var Serial = UART0
// UART pins // UART pins
const ( const (
UART_TX_PIN Pin = P34 UART_TX_PIN Pin = P34

Просмотреть файл

@ -12,6 +12,8 @@ const (
BUTTONB Pin = 26 BUTTONB Pin = 26
) )
var Serial = UART0
// UART pins // UART pins
const ( const (
UART_TX_PIN Pin = 24 UART_TX_PIN Pin = 24

Просмотреть файл

@ -54,9 +54,9 @@ const (
UART_TX_PIN = P0_08 UART_TX_PIN = P0_08
) )
// UART0 is the USB device // Serial is the USB device
var ( var (
UART0 = USB Serial = USB
) )
// I2C pins // I2C pins

Просмотреть файл

@ -20,6 +20,8 @@ const (
// Onboard blue LED (on the AI-Thinker module). // Onboard blue LED (on the AI-Thinker module).
const LED = D4 const LED = D4
var Serial = UART0
// SPI pins // SPI pins
const ( const (
SPI0_SCK_PIN = D5 SPI0_SCK_PIN = D5

Просмотреть файл

@ -23,10 +23,8 @@ const (
UART_RX_PIN Pin = NoPin UART_RX_PIN Pin = NoPin
) )
// UART0 is the USB device // Serial is the USB device
var ( var Serial = USB
UART0 = USB
)
// I2C pins (unused) // I2C pins (unused)
const ( const (

Просмотреть файл

@ -18,10 +18,8 @@ const (
UART_RX_PIN Pin = 19 UART_RX_PIN Pin = 19
) )
// UART0 is the USB device // Serial is the USB device
var ( var Serial = USB
UART0 = USB
)
// I2C pins (unused) // I2C pins (unused)
const ( const (

Просмотреть файл

@ -99,17 +99,16 @@ const (
var ( var (
// USART2 is the hardware serial port connected to the onboard ST-LINK // 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. // debugger to be exposed as virtual COM port over USB on Nucleo boards.
// Both UART0 and UART1 refer to USART2. UART2 = &_UART2
UART0 = &_UART0 _UART2 = UART{
_UART0 = UART{
Buffer: NewRingBuffer(), Buffer: NewRingBuffer(),
Bus: stm32.USART2, Bus: stm32.USART2,
} }
UART2 = UART0 Serial = UART2
) )
func init() { func init() {
UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt) UART2.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART2.handleInterrupt)
} }
// SPI pins // SPI pins

Просмотреть файл

@ -31,19 +31,18 @@ const (
var ( var (
// USART3 is the hardware serial port connected to the onboard ST-LINK // 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. // debugger to be exposed as virtual COM port over USB on Nucleo boards.
// Both UART0 and UART1 refer to USART2. UART1 = &_UART1
UART0 = &_UART0 _UART1 = UART{
_UART0 = UART{
Buffer: NewRingBuffer(), Buffer: NewRingBuffer(),
Bus: stm32.USART3, Bus: stm32.USART3,
TxAltFuncSelector: UART_ALT_FN, TxAltFuncSelector: UART_ALT_FN,
RxAltFuncSelector: UART_ALT_FN, RxAltFuncSelector: UART_ALT_FN,
} }
UART1 = UART0 Serial = UART1
) )
func init() { func init() {
UART0.Interrupt = interrupt.New(stm32.IRQ_USART3, _UART0.handleInterrupt) UART1.Interrupt = interrupt.New(stm32.IRQ_USART3, _UART1.handleInterrupt)
} }
// SPI pins // SPI pins

Просмотреть файл

@ -63,15 +63,14 @@ const (
var ( var (
// USART2 is the hardware serial port connected to the onboard ST-LINK // 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. // debugger to be exposed as virtual COM port over USB on Nucleo boards.
// Both UART0 and UART1 refer to USART2. UART1 = &_UART1
UART0 = &_UART0 _UART1 = UART{
_UART0 = UART{
Buffer: NewRingBuffer(), Buffer: NewRingBuffer(),
Bus: stm32.USART2, Bus: stm32.USART2,
TxAltFuncSelector: 4, TxAltFuncSelector: 4,
RxAltFuncSelector: 4, RxAltFuncSelector: 4,
} }
UART1 = UART0 Serial = UART1
// I2C1 is documented, alias to I2C0 as well // I2C1 is documented, alias to I2C0 as well
I2C1 = &I2C{ I2C1 = &I2C{
@ -89,5 +88,5 @@ var (
) )
func init() { func init() {
UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt) UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt)
} }

Просмотреть файл

@ -65,15 +65,14 @@ const (
var ( var (
// USART2 is the hardware serial port connected to the onboard ST-LINK // 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. // debugger to be exposed as virtual COM port over USB on Nucleo boards.
// Both UART0 and UART1 refer to USART2. UART1 = &_UART1
UART0 = &_UART0 _UART1 = UART{
_UART0 = UART{
Buffer: NewRingBuffer(), Buffer: NewRingBuffer(),
Bus: stm32.USART2, Bus: stm32.USART2,
TxAltFuncSelector: 7, TxAltFuncSelector: 7,
RxAltFuncSelector: 3, RxAltFuncSelector: 3,
} }
UART1 = UART0 Serial = UART1
// I2C1 is documented, alias to I2C0 as well // I2C1 is documented, alias to I2C0 as well
I2C1 = &I2C{ I2C1 = &I2C{
@ -91,5 +90,5 @@ var (
) )
func init() { func init() {
UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt) UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt)
} }

Просмотреть файл

@ -31,15 +31,14 @@ const (
var ( var (
// LPUART1 is the hardware serial port connected to the onboard ST-LINK // 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. // debugger to be exposed as virtual COM port over USB on Nucleo boards.
// Both UART0 and UART1 refer to LPUART1. UART1 = &_UART1
UART0 = &_UART0 _UART1 = UART{
_UART0 = UART{
Buffer: NewRingBuffer(), Buffer: NewRingBuffer(),
Bus: stm32.LPUART1, Bus: stm32.LPUART1,
TxAltFuncSelector: UART_ALT_FN, TxAltFuncSelector: UART_ALT_FN,
RxAltFuncSelector: UART_ALT_FN, RxAltFuncSelector: UART_ALT_FN,
} }
UART1 = UART0 Serial = UART1
) )
const ( const (
@ -57,5 +56,5 @@ var (
) )
func init() { func init() {
UART0.Interrupt = interrupt.New(stm32.IRQ_LPUART1, _UART0.handleInterrupt) UART1.Interrupt = interrupt.New(stm32.IRQ_LPUART1, _UART1.handleInterrupt)
} }

Просмотреть файл

@ -66,7 +66,7 @@ const (
BASE_ENABLE_PIN Pin = PB09 BASE_ENABLE_PIN Pin = PB09
) )
// UART0 aka USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN Pin = PA24 USBCDC_DM_PIN Pin = PA24
USBCDC_DP_PIN Pin = PA25 USBCDC_DP_PIN Pin = PA25

Просмотреть файл

@ -41,8 +41,7 @@ const (
// UART // UART
var ( var (
Serial = USB Serial = UART0
UART0 = NRF_UART0
) )
const ( const (

Просмотреть файл

@ -41,8 +41,7 @@ const (
// UART // UART
var ( var (
Serial = USB Serial = UART0
UART0 = NRF_UART0
) )
const ( const (

Просмотреть файл

@ -41,8 +41,7 @@ const (
// UART // UART
var ( var (
Serial = USB Serial = UART0
UART0 = NRF_UART0
) )
const ( const (

Просмотреть файл

@ -19,6 +19,8 @@ const (
LED_BLUE Pin = 23 LED_BLUE Pin = 23
) )
var Serial = UART0
// UART pins // UART pins
const ( const (
UART_TX_PIN Pin = 9 UART_TX_PIN Pin = 9

Просмотреть файл

@ -23,6 +23,8 @@ const (
BUTTON4 Pin = 16 BUTTON4 Pin = 16
) )
var Serial = UART0
// UART pins for NRF52840-DK // UART pins for NRF52840-DK
const ( const (
UART_TX_PIN Pin = 6 UART_TX_PIN Pin = 6

Просмотреть файл

@ -22,6 +22,8 @@ const (
BUTTON4 Pin = 25 BUTTON4 Pin = 25
) )
var Serial = UART0
// UART pins // UART pins
const ( const (
UART_TX_PIN Pin = 6 UART_TX_PIN Pin = 6

Просмотреть файл

@ -1,8 +0,0 @@
// +build nrf52840,pca10056
package machine
// UART0 is the NRF UART
var (
UART0 = NRF_UART0
)

Просмотреть файл

@ -34,9 +34,9 @@ const (
UART_RX_PIN Pin = NoPin UART_RX_PIN Pin = NoPin
) )
// UART0 is the USB device // Serial is the USB device
var ( var (
UART0 = USB Serial = USB
) )
// I2C pins (unused) // I2C pins (unused)

Просмотреть файл

@ -17,6 +17,8 @@ const (
LED3 = LCD_BACKLIGHT_LOW LED3 = LCD_BACKLIGHT_LOW
) )
var Serial = UART0
// UART pins for PineTime. Note that RX is set to NoPin as RXD is not listed in // UART pins for PineTime. Note that RX is set to NoPin as RXD is not listed in
// the PineTime schematic 1.0: // the PineTime schematic 1.0:
// http://files.pine64.org/doc/PineTime/PineTime%20Port%20Assignment%20rev1.0.pdf // http://files.pine64.org/doc/PineTime/PineTime%20Port%20Assignment%20rev1.0.pdf

Просмотреть файл

@ -66,7 +66,9 @@ const (
BUTTON_B_MASK = 128 BUTTON_B_MASK = 128
) )
// UART0 aka USBCDC pins var Serial = USB
// USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -69,7 +69,9 @@ const (
BUTTON_B_MASK = 128 BUTTON_B_MASK = 128
) )
// UART0 aka USBCDC pins var Serial = USB
// USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -94,7 +94,9 @@ const (
LED = D13 LED = D13
) )
// UART0 aka USBCDC pins var Serial = USB
// USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -45,7 +45,7 @@ const (
LED = D13 LED = D13
) )
// UART0 aka USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -29,6 +29,8 @@ const (
BUTTON Pin = 7 BUTTON Pin = 7
) )
var Serial = UART0
// UART pins // UART pins
const ( const (
UART_TX_PIN Pin = 6 UART_TX_PIN Pin = 6

Просмотреть файл

@ -1,8 +0,0 @@
// +build nrf52840,reelboard
package machine
// UART0 is the NRF UART
var (
UART0 = NRF_UART0
)

Просмотреть файл

@ -27,19 +27,19 @@ const (
) )
var ( var (
UART0 = &_UART0 UART1 = &_UART1
_UART0 = UART{ _UART1 = UART{
Buffer: NewRingBuffer(), Buffer: NewRingBuffer(),
Bus: stm32.USART2, Bus: stm32.USART2,
TxAltFuncSelector: AF7_USART1_2_3, TxAltFuncSelector: AF7_USART1_2_3,
RxAltFuncSelector: 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 // set up RX IRQ handler. Follow similar pattern for other UARTx instances
func init() { func init() {
UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt) UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt)
} }
// SPI pins // SPI pins

Просмотреть файл

@ -136,7 +136,7 @@ const (
) )
var ( var (
UART0 = UART1 // alias UART0 to UART1 Serial = UART1
UART1 = &_UART1 UART1 = &_UART1
_UART1 = UART{ _UART1 = UART{
Bus: nxp.LPUART6, Bus: nxp.LPUART6,

Просмотреть файл

@ -33,7 +33,7 @@ const (
LED = D13 LED = D13
) )
// UART0 aka USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -325,7 +325,9 @@ const (
OUTPUT_CTR_3V3 = PC15 OUTPUT_CTR_3V3 = PC15
) )
// UART0 aka USBCDC pins var Serial = USB
// USBCDC pins
const ( const (
USBCDC_DM_PIN = PIN_USB_DM USBCDC_DM_PIN = PIN_USB_DM
USBCDC_DP_PIN = PIN_USB_DP USBCDC_DP_PIN = PIN_USB_DP

Просмотреть файл

@ -26,3 +26,5 @@ const (
) )
const HasLowFrequencyCrystal = true const HasLowFrequencyCrystal = true
var Serial = UART0

Просмотреть файл

@ -48,7 +48,7 @@ const (
LED3 = LED_TXL LED3 = LED_TXL
) )
// UART0 aka USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24
USBCDC_DP_PIN = PA25 USBCDC_DP_PIN = PA25

Просмотреть файл

@ -121,6 +121,9 @@ func (i2c *I2C) readByte() byte {
return byte(avr.TWDR.Get()) return byte(avr.TWDR.Get())
} }
// Always use UART0 as the serial output.
var Serial = UART0
// UART // UART
var ( var (
// UART0 is the hardware serial port on the AVR. // UART0 is the hardware serial port on the AVR.

Просмотреть файл

@ -505,8 +505,7 @@ type UART struct {
} }
var ( var (
// UART0 is actually a USB CDC interface. USB = &USBCDC{Buffer: NewRingBuffer()}
UART0 = &USBCDC{Buffer: NewRingBuffer()}
) )
const ( const (
@ -1985,7 +1984,7 @@ func handleUSB(intr interrupt.Interrupt) {
// Start of frame // Start of frame
if (flags & sam.USB_DEVICE_INTFLAG_SOF) > 0 { 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... // 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) setEPINTFLAG(i, sam.USB_DEVICE_EPINTFLAG_TRCPT1)
if i == usb_CDC_ENDPOINT_IN { if i == usb_CDC_ENDPOINT_IN {
UART0.waitTxc = false USB.waitTxc = false
} }
} }
} }
@ -2359,7 +2358,7 @@ func handleEndpoint(ep uint32) {
// move to ring buffer // move to ring buffer
for i := 0; i < count; i++ { 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 // set byte count to zero

Просмотреть файл

@ -951,8 +951,8 @@ type UART struct {
} }
var ( var (
// UART0 is actually a USB CDC interface. // USB is a USB CDC interface.
UART0 = &USBCDC{Buffer: NewRingBuffer()} USB = &USBCDC{Buffer: NewRingBuffer()}
) )
const ( const (
@ -2193,7 +2193,7 @@ func handleUSBIRQ(interrupt.Interrupt) {
// Start of frame // Start of frame
if (flags & sam.USB_DEVICE_INTFLAG_SOF) > 0 { 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... // 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) setEPINTFLAG(i, sam.USB_DEVICE_ENDPOINT_EPINTFLAG_TRCPT1)
if i == usb_CDC_ENDPOINT_IN { if i == usb_CDC_ENDPOINT_IN {
UART0.waitTxc = false USB.waitTxc = false
} }
} }
} }
@ -2567,7 +2567,7 @@ func handleEndpoint(ep uint32) {
// move to ring buffer // move to ring buffer
for i := 0; i < count; i++ { 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 // set byte count to zero

Просмотреть файл

@ -8,6 +8,7 @@ var (
SPI0 = SPI{0} SPI0 = SPI{0}
I2C0 = &I2C{0} I2C0 = &I2C{0}
UART0 = &UART{0} UART0 = &UART{0}
USB = &UART{100}
) )
const ( const (

Просмотреть файл

@ -138,8 +138,8 @@ type UART struct {
// UART // UART
var ( var (
// UART0 is the hardware UART on the NRF SoC. // UART0 is the hardware UART on the NRF SoC.
_NRF_UART0 = UART{Buffer: NewRingBuffer()} _UART0 = UART{Buffer: NewRingBuffer()}
NRF_UART0 = &_NRF_UART0 UART0 = &_UART0
) )
// Configure the UART. // Configure the UART.
@ -165,7 +165,7 @@ func (uart *UART) Configure(config UARTConfig) {
nrf.UART0.INTENSET.Set(nrf.UART_INTENSET_RXDRDY_Msk) nrf.UART0.INTENSET.Set(nrf.UART_INTENSET_RXDRDY_Msk)
// Enable RX IRQ. // 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.SetPriority(0xc0) // low priority
intr.Enable() intr.Enable()
} }

Просмотреть файл

@ -6,10 +6,6 @@ import (
"device/nrf" "device/nrf"
) )
var (
UART0 = NRF_UART0
)
func CPUFrequency() uint32 { func CPUFrequency() uint32 {
return 16000000 return 16000000
} }

Просмотреть файл

@ -42,10 +42,6 @@ const (
P0_31 Pin = 31 P0_31 Pin = 31
) )
var (
UART0 = NRF_UART0
)
// Get peripheral and pin number for this GPIO pin. // Get peripheral and pin number for this GPIO pin.
func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) { func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) {
return nrf.P0, uint32(p) return nrf.P0, uint32(p)

Просмотреть файл

@ -58,10 +58,6 @@ const (
P1_15 Pin = 47 P1_15 Pin = 47
) )
var (
UART0 = NRF_UART0
)
// Get peripheral and pin number for this GPIO pin. // Get peripheral and pin number for this GPIO pin.
func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) { func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) {
if p >= 32 { if p >= 32 {

Просмотреть файл

@ -8,11 +8,11 @@ import (
) )
func initUART() { func initUART() {
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
} }
func putchar(c byte) { 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 // Sleep for a given period. The period is defined by the WDT peripheral, and is

Просмотреть файл

@ -30,11 +30,11 @@ func init() {
initADCClock() initADCClock()
// connect to USB CDC interface // connect to USB CDC interface
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
} }
func putchar(c byte) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }
func initClocks() { func initClocks() {

Просмотреть файл

@ -30,11 +30,11 @@ func init() {
initADCClock() initADCClock()
// connect to USB CDC interface // connect to USB CDC interface
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
} }
func putchar(c byte) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }
func initClocks() { func initClocks() {

Просмотреть файл

@ -14,7 +14,7 @@ type timeUnit int64
var currentTime timeUnit var currentTime timeUnit
func putchar(c byte) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }
func postinit() {} func postinit() {}
@ -53,7 +53,7 @@ func main() {
preinit() preinit()
// Initialize UART. // Initialize UART.
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
// Configure timer 0 in timer group 0, for timekeeping. // Configure timer 0 in timer group 0, for timekeeping.
// EN: Enable the timer. // EN: Enable the timer.

Просмотреть файл

@ -14,7 +14,7 @@ type timeUnit int64
var currentTime timeUnit = 0 var currentTime timeUnit = 0
func putchar(c byte) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }
// Write to the internal control bus (using I2C?). // Write to the internal control bus (using I2C?).
@ -37,7 +37,7 @@ func main() {
rom_i2c_writeReg(103, 4, 2, 145) rom_i2c_writeReg(103, 4, 2, 145)
// Initialize UART. // Initialize UART.
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
// Initialize timer. Bits: // Initialize timer. Bits:
// ENABLE: timer enable // ENABLE: timer enable

Просмотреть файл

@ -93,11 +93,11 @@ func initPeripherals() {
sifive.RTC.RTCCFG.Set(sifive.RTC_RTCCFG_ENALWAYS) sifive.RTC.RTCCFG.Set(sifive.RTC_RTCCFG_ENALWAYS)
// Configure the UART. // Configure the UART.
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
} }
func putchar(c byte) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }
var timerWakeup volatile.Register8 var timerWakeup volatile.Register8

Просмотреть файл

@ -105,11 +105,11 @@ func initPeripherals() {
// Enable FPIOA peripheral. // Enable FPIOA peripheral.
kendryte.SYSCTL.CLK_EN_PERI.SetBits(kendryte.SYSCTL_CLK_EN_PERI_FPIOA_CLK_EN) 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) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }
var timerWakeup volatile.Register8 var timerWakeup volatile.Register8

Просмотреть файл

@ -29,7 +29,7 @@ func main() {
} }
func init() { func init() {
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
initLFCLK() initLFCLK()
initRTC() initRTC()
} }
@ -64,7 +64,7 @@ func initRTC() {
} }
func putchar(c byte) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }
func sleepTicks(d timeUnit) { func sleepTicks(d timeUnit) {

Просмотреть файл

@ -33,7 +33,7 @@ func init() {
Device: stm32.TIM3, Device: stm32.TIM3,
}) })
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
initTickTimer(&timerInfo{ initTickTimer(&timerInfo{
EnableRegister: &stm32.RCC.APB1ENR, EnableRegister: &stm32.RCC.APB1ENR,
@ -43,7 +43,7 @@ func init() {
} }
func putchar(c byte) { 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). // initCLK sets clock to 72MHz using HSE 8MHz crystal w/ PLL X 9 (8MHz x 9 = 72MHz).

Просмотреть файл

@ -181,10 +181,10 @@ func initCLK() {
func initCOM() { func initCOM() {
if machine.NUM_UART_INTERFACES > 0 { if machine.NUM_UART_INTERFACES > 0 {
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
} }
} }
func putchar(c byte) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }

Просмотреть файл

@ -51,7 +51,7 @@ func init() {
Device: stm32.TIM3, Device: stm32.TIM3,
}) })
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
initTickTimer(&timerInfo{ initTickTimer(&timerInfo{
EnableRegister: &stm32.RCC.APB1ENR, EnableRegister: &stm32.RCC.APB1ENR,
@ -61,7 +61,7 @@ func init() {
} }
func putchar(c byte) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }
func initCLK() { func initCLK() {

Просмотреть файл

@ -50,7 +50,7 @@ func init() {
Device: stm32.TIM3, Device: stm32.TIM3,
}) })
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
initTickTimer(&timerInfo{ initTickTimer(&timerInfo{
EnableRegister: &stm32.RCC.APB1ENR, EnableRegister: &stm32.RCC.APB1ENR,
@ -60,7 +60,7 @@ func init() {
} }
func putchar(c byte) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }
func initCLK() { func initCLK() {

Просмотреть файл

@ -14,7 +14,7 @@ const (
type arrtype = uint16 type arrtype = uint16
func putchar(c byte) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }
func initCLK() { func initCLK() {

Просмотреть файл

@ -34,7 +34,7 @@ func init() {
Device: stm32.TIM22, Device: stm32.TIM22,
}) })
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
initTickTimer(&timerInfo{ initTickTimer(&timerInfo{
EnableRegister: &stm32.RCC.APB2ENR, EnableRegister: &stm32.RCC.APB2ENR,

Просмотреть файл

@ -34,7 +34,7 @@ func init() {
Device: stm32.TIM3, Device: stm32.TIM3,
}) })
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
initTickTimer(&timerInfo{ initTickTimer(&timerInfo{
EnableRegister: &stm32.RCC.APB1ENR, EnableRegister: &stm32.RCC.APB1ENR,

Просмотреть файл

@ -75,7 +75,7 @@ func init() {
Device: stm32.TIM15, Device: stm32.TIM15,
}) })
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
initTickTimer(&timerInfo{ initTickTimer(&timerInfo{
EnableRegister: &stm32.RCC.APB2ENR, EnableRegister: &stm32.RCC.APB2ENR,
@ -85,7 +85,7 @@ func init() {
} }
func putchar(c byte) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }
func initCLK() { func initCLK() {

Просмотреть файл

@ -51,7 +51,7 @@ func init() {
Device: stm32.TIM15, Device: stm32.TIM15,
}) })
machine.UART0.Configure(machine.UARTConfig{}) machine.Serial.Configure(machine.UARTConfig{})
initTickTimer(&timerInfo{ initTickTimer(&timerInfo{
EnableRegister: &stm32.RCC.APB2ENR, EnableRegister: &stm32.RCC.APB2ENR,
@ -61,7 +61,7 @@ func init() {
} }
func putchar(c byte) { func putchar(c byte) {
machine.UART0.WriteByte(c) machine.Serial.WriteByte(c)
} }
func initCLK() { func initCLK() {