all: add a flag to the command line to select the serial implementation

This can be very useful for some purposes:

  * It makes it possible to disable the UART in cases where it is not
    needed or needs to be disabled to conserve power.
  * It makes it possible to disable the serial output to reduce code
    size, which may be important for some chips. Sometimes, a few kB can
    be saved this way.
  * It makes it possible to override the default, for example you might
    want to use an actual UART to debug the USB-CDC implementation.

It also lowers the dependency on having machine.Serial defined, which is
often not defined when targeting a chip. Eventually, we might want to
make it possible to write `-target=nrf52` or `-target=atmega328p` for
example to target the chip itself with no board specific assumptions.

The defaults don't change. I checked this by running `make smoketest`
before and after and comparing the results.
Этот коммит содержится в:
Ayke van Laethem 2021-06-01 13:27:58 +02:00 коммит произвёл Ron Evans
родитель 75298bb84b
коммит 96e863f0f3
114 изменённых файлов: 185 добавлений и 104 удалений

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

@ -436,6 +436,8 @@ endif
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pca10040 -opt=1 examples/blinky1 $(TINYGO) build -size short -o test.hex -target=pca10040 -opt=1 examples/blinky1
@$(MD5SUM) test.hex @$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pca10040 -serial=none examples/echo
@$(MD5SUM) test.hex
$(TINYGO) build -o test.nro -target=nintendoswitch examples/serial $(TINYGO) build -o test.nro -target=nintendoswitch examples/serial
@$(MD5SUM) test.nro @$(MD5SUM) test.nro
$(TINYGO) build -size short -o test.hex -target=pca10040 -opt=0 ./testdata/stdlib.go $(TINYGO) build -size short -o test.hex -target=pca10040 -opt=0 ./testdata/stdlib.go

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

@ -55,7 +55,7 @@ func (c *Config) GOARCH() string {
// BuildTags returns the complete list of build tags used during this build. // BuildTags returns the complete list of build tags used during this build.
func (c *Config) BuildTags() []string { func (c *Config) BuildTags() []string {
tags := append(c.Target.BuildTags, []string{"tinygo", "gc." + c.GC(), "scheduler." + c.Scheduler()}...) tags := append(c.Target.BuildTags, []string{"tinygo", "gc." + c.GC(), "scheduler." + c.Scheduler(), "serial." + c.Serial()}...)
for i := 1; i <= c.GoMinorVersion; i++ { for i := 1; i <= c.GoMinorVersion; i++ {
tags = append(tags, fmt.Sprintf("go1.%d", i)) tags = append(tags, fmt.Sprintf("go1.%d", i))
} }
@ -113,6 +113,18 @@ func (c *Config) Scheduler() string {
return "coroutines" return "coroutines"
} }
// Serial returns the serial implementation for this build configuration: uart,
// usb (meaning USB-CDC), or none.
func (c *Config) Serial() string {
if c.Options.Serial != "" {
return c.Options.Serial
}
if c.Target.Serial != "" {
return c.Target.Serial
}
return "none"
}
// OptLevels returns the optimization level (0-2), size level (0-2), and inliner // OptLevels returns the optimization level (0-2), size level (0-2), and inliner
// threshold as used in the LLVM optimization pipeline. // threshold as used in the LLVM optimization pipeline.
func (c *Config) OptLevels() (optLevel, sizeLevel int, inlinerThreshold uint) { func (c *Config) OptLevels() (optLevel, sizeLevel int, inlinerThreshold uint) {

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

@ -9,6 +9,7 @@ import (
var ( var (
validGCOptions = []string{"none", "leaking", "extalloc", "conservative"} validGCOptions = []string{"none", "leaking", "extalloc", "conservative"}
validSchedulerOptions = []string{"none", "tasks", "coroutines"} validSchedulerOptions = []string{"none", "tasks", "coroutines"}
validSerialOptions = []string{"none", "uart", "usb"}
validPrintSizeOptions = []string{"none", "short", "full"} validPrintSizeOptions = []string{"none", "short", "full"}
validPanicStrategyOptions = []string{"print", "trap"} validPanicStrategyOptions = []string{"print", "trap"}
validOptOptions = []string{"none", "0", "1", "2", "s", "z"} validOptOptions = []string{"none", "0", "1", "2", "s", "z"}
@ -22,6 +23,7 @@ type Options struct {
GC string GC string
PanicStrategy string PanicStrategy string
Scheduler string Scheduler string
Serial string
PrintIR bool PrintIR bool
DumpSSA bool DumpSSA bool
VerifyIR bool VerifyIR bool
@ -59,6 +61,15 @@ func (o *Options) Verify() error {
} }
} }
if o.Serial != "" {
valid := isInArray(validSerialOptions, o.Serial)
if !valid {
return fmt.Errorf(`invalid serial option '%s': valid values are %s`,
o.Serial,
strings.Join(validSerialOptions, ", "))
}
}
if o.PrintSizes != "" { if o.PrintSizes != "" {
valid := isInArray(validPrintSizeOptions, o.PrintSizes) valid := isInArray(validPrintSizeOptions, o.PrintSizes)
if !valid { if !valid {

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

@ -31,6 +31,7 @@ type TargetSpec struct {
BuildTags []string `json:"build-tags"` BuildTags []string `json:"build-tags"`
GC string `json:"gc"` GC string `json:"gc"`
Scheduler string `json:"scheduler"` Scheduler string `json:"scheduler"`
Serial string `json:"serial"` // which serial output to use (uart, usb, none)
Linker string `json:"linker"` Linker string `json:"linker"`
RTLib string `json:"rtlib"` // compiler runtime library (libgcc, compiler-rt) RTLib string `json:"rtlib"` // compiler runtime library (libgcc, compiler-rt)
Libc string `json:"libc"` Libc string `json:"libc"`

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

@ -1009,6 +1009,7 @@ func main() {
gc := flag.String("gc", "", "garbage collector to use (none, leaking, extalloc, conservative)") gc := flag.String("gc", "", "garbage collector to use (none, leaking, extalloc, conservative)")
panicStrategy := flag.String("panic", "print", "panic strategy (print, trap)") panicStrategy := flag.String("panic", "print", "panic strategy (print, trap)")
scheduler := flag.String("scheduler", "", "which scheduler to use (none, coroutines, tasks)") scheduler := flag.String("scheduler", "", "which scheduler to use (none, coroutines, tasks)")
serial := flag.String("serial", "", "which serial output to use (none, uart, usb)")
printIR := flag.Bool("printir", false, "print LLVM IR") printIR := flag.Bool("printir", false, "print LLVM IR")
dumpSSA := flag.Bool("dumpssa", false, "dump internal Go SSA") dumpSSA := flag.Bool("dumpssa", false, "dump internal Go SSA")
verifyIR := flag.Bool("verifyir", false, "run extra verification steps on LLVM IR") verifyIR := flag.Bool("verifyir", false, "run extra verification steps on LLVM IR")
@ -1081,6 +1082,7 @@ func main() {
GC: *gc, GC: *gc,
PanicStrategy: *panicStrategy, PanicStrategy: *panicStrategy,
Scheduler: *scheduler, Scheduler: *scheduler,
Serial: *serial,
PrintIR: *printIR, PrintIR: *printIR,
DumpSSA: *dumpSSA, DumpSSA: *dumpSSA,
VerifyIR: *verifyIR, VerifyIR: *verifyIR,

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

@ -47,8 +47,6 @@ const (
LED = D6 LED = D6
) )
var Serial = USB
// USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN Pin = PA24 USBCDC_DM_PIN Pin = PA24

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

@ -35,8 +35,6 @@ 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,5 +74,3 @@ const (
PB30 Pin = 62 PB30 Pin = 62
PB31 Pin = 63 PB31 Pin = 63
) )
var Serial = USB

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

@ -15,8 +15,6 @@ 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

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

@ -17,7 +17,7 @@ const (
BUTTON = PA0 BUTTON = PA0
) )
var Serial = UART1 var DefaultUART = UART1
// UART pins // UART pins
const ( const (

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

@ -57,8 +57,6 @@ const (
UART_RX_PIN = P0_30 // PORTB UART_RX_PIN = P0_30 // PORTB
) )
var Serial = USB
// I2C pins // I2C pins
const ( const (
SDA_PIN = P0_05 // I2C0 external SDA_PIN = P0_05 // I2C0 external

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

@ -104,11 +104,6 @@ const (
UART_TX_PIN = D1 UART_TX_PIN = D1
) )
// Serial is the USB device
var (
Serial = USB
)
// I2C pins // I2C pins
const ( const (
SDA_PIN = D20 // I2C0 external SDA_PIN = D20 // I2C0 external

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

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

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

@ -47,8 +47,6 @@ const (
WS2812 = D8 WS2812 = D8
) )
var Serial = USB
// USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24

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

@ -40,8 +40,6 @@ const (
WS2812 = D8 WS2812 = D8
) )
var Serial = USB
// USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24

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

@ -76,11 +76,6 @@ const (
UART_TX_PIN = D1 UART_TX_PIN = D1
) )
// Serial is the USB device
var (
Serial = USB
)
// I2C pins // I2C pins
const ( const (
SDA_PIN = D22 // I2C0 external SDA_PIN = D22 // I2C0 external

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

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

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

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

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

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

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

@ -37,8 +37,6 @@ const (
LED = D13 LED = D13
) )
var Serial = USB
// USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24

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

@ -70,11 +70,6 @@ const (
UART_TX_PIN = D1 UART_TX_PIN = D1
) )
// Serial is the USB device
var (
Serial = USB
)
// I2C pins // I2C pins
const ( const (
SDA_PIN = D21 // I2C0 external SDA_PIN = D21 // I2C0 external

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

@ -54,7 +54,7 @@ const (
I2C0_SDA_PIN = PA10 I2C0_SDA_PIN = PA10
) )
var Serial = UART0 var DefaultUART = UART0
var ( var (

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

@ -52,7 +52,7 @@ const (
LED_BLUE = D14 LED_BLUE = D14
) )
var Serial = UART0 var DefaultUART = UART0
// Default pins for UARTHS. // Default pins for UARTHS.
const ( const (

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

@ -41,8 +41,6 @@ const (
WS2812 = D40 WS2812 = D40
) )
var Serial = USB
// USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24

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

@ -12,7 +12,7 @@ const (
BUTTONB Pin = P11 BUTTONB Pin = P11
) )
var Serial = UART0 var DefaultUART = UART0
// UART pins // UART pins
const ( const (

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

@ -12,7 +12,7 @@ const (
BUTTONB Pin = 26 BUTTONB Pin = 26
) )
var Serial = UART0 var DefaultUART = UART0
// UART pins // UART pins
const ( const (

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

@ -54,11 +54,6 @@ const (
UART_TX_PIN = P0_08 UART_TX_PIN = P0_08
) )
// Serial is the USB device
var (
Serial = USB
)
// I2C pins // I2C pins
const ( const (
SDA_PIN = P0_17 // I2C0 external SDA_PIN = P0_17 // I2C0 external

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

@ -20,8 +20,6 @@ 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,9 +23,6 @@ const (
UART_RX_PIN Pin = NoPin UART_RX_PIN Pin = NoPin
) )
// Serial is the USB device
var Serial = USB
// I2C pins (unused) // I2C pins (unused)
const ( const (
SDA_PIN = NoPin SDA_PIN = NoPin

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

@ -18,9 +18,6 @@ const (
UART_RX_PIN Pin = 19 UART_RX_PIN Pin = 19
) )
// Serial is the USB device
var Serial = USB
// I2C pins (unused) // I2C pins (unused)
const ( const (
SDA_PIN = NoPin SDA_PIN = NoPin

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

@ -34,7 +34,7 @@ var (
Buffer: NewRingBuffer(), Buffer: NewRingBuffer(),
Bus: stm32.USART2, Bus: stm32.USART2,
} }
Serial = UART2 DefaultUART = UART2
) )
func init() { func init() {

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

@ -38,7 +38,7 @@ var (
TxAltFuncSelector: UART_ALT_FN, TxAltFuncSelector: UART_ALT_FN,
RxAltFuncSelector: UART_ALT_FN, RxAltFuncSelector: UART_ALT_FN,
} }
Serial = UART1 DefaultUART = UART1
) )
func init() { func init() {

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

@ -76,7 +76,7 @@ var (
TxAltFuncSelector: 4, TxAltFuncSelector: 4,
RxAltFuncSelector: 4, RxAltFuncSelector: 4,
} }
Serial = UART1 DefaultUART = UART1
// I2C1 is documented, alias to I2C0 as well // I2C1 is documented, alias to I2C0 as well
I2C1 = &I2C{ I2C1 = &I2C{

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

@ -78,7 +78,7 @@ var (
TxAltFuncSelector: 7, TxAltFuncSelector: 7,
RxAltFuncSelector: 3, RxAltFuncSelector: 3,
} }
Serial = UART1 DefaultUART = UART1
// I2C1 is documented, alias to I2C0 as well // I2C1 is documented, alias to I2C0 as well
I2C1 = &I2C{ I2C1 = &I2C{

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

@ -38,7 +38,7 @@ var (
TxAltFuncSelector: UART_ALT_FN, TxAltFuncSelector: UART_ALT_FN,
RxAltFuncSelector: UART_ALT_FN, RxAltFuncSelector: UART_ALT_FN,
} }
Serial = UART1 DefaultUART = UART1
) )
const ( const (

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

@ -41,7 +41,7 @@ const (
// UART // UART
var ( var (
Serial = UART0 DefaultUART = UART0
) )
const ( const (

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

@ -41,7 +41,7 @@ const (
// UART // UART
var ( var (
Serial = UART0 DefaultUART = UART0
) )
const ( const (

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

@ -41,7 +41,7 @@ const (
// UART // UART
var ( var (
Serial = UART0 DefaultUART = UART0
) )
const ( const (

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

@ -19,7 +19,7 @@ const (
LED_BLUE Pin = 23 LED_BLUE Pin = 23
) )
var Serial = UART0 var DefaultUART = UART0
// UART pins // UART pins
const ( const (

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

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

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

@ -22,7 +22,7 @@ const (
BUTTON4 Pin = 25 BUTTON4 Pin = 25
) )
var Serial = UART0 var DefaultUART = UART0
// UART pins // UART pins
const ( const (

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

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

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

@ -17,7 +17,7 @@ const (
LED3 = LCD_BACKLIGHT_LOW LED3 = LCD_BACKLIGHT_LOW
) )
var Serial = UART0 var DefaultUART = 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:

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

@ -67,8 +67,6 @@ const (
BUTTON_B_MASK = 128 BUTTON_B_MASK = 128
) )
var Serial = USB
// USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24

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

@ -70,8 +70,6 @@ const (
BUTTON_B_MASK = 128 BUTTON_B_MASK = 128
) )
var Serial = USB
// USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24

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

@ -95,8 +95,6 @@ const (
LED = D13 LED = D13
) )
var Serial = USB
// USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PA24 USBCDC_DM_PIN = PA24

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

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

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

@ -38,7 +38,7 @@ var (
TxAltFuncSelector: AF7_USART1_2_3, TxAltFuncSelector: AF7_USART1_2_3,
RxAltFuncSelector: AF7_USART1_2_3, RxAltFuncSelector: AF7_USART1_2_3,
} }
Serial = UART1 DefaultUART = 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

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

@ -87,6 +87,8 @@ var (
TeensyUART5 = UART4 TeensyUART5 = UART4
) )
var DefaultUART = UART0
const ( const (
defaultUART0RX = D00 defaultUART0RX = D00
defaultUART0TX = D01 defaultUART0TX = D01

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

@ -136,9 +136,9 @@ const (
) )
var ( var (
Serial = UART1 DefaultUART = UART1
UART1 = &_UART1 UART1 = &_UART1
_UART1 = UART{ _UART1 = UART{
Bus: nxp.LPUART6, Bus: nxp.LPUART6,
Buffer: NewRingBuffer(), Buffer: NewRingBuffer(),
txBuffer: NewRingBuffer(), txBuffer: NewRingBuffer(),

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

@ -325,8 +325,6 @@ const (
OUTPUT_CTR_3V3 = PC15 OUTPUT_CTR_3V3 = PC15
) )
var Serial = USB
// USBCDC pins // USBCDC pins
const ( const (
USBCDC_DM_PIN = PIN_USB_DM USBCDC_DM_PIN = PIN_USB_DM

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

@ -27,4 +27,4 @@ const (
const HasLowFrequencyCrystal = true const HasLowFrequencyCrystal = true
var Serial = UART0 var DefaultUART = UART0

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

@ -122,7 +122,7 @@ func (i2c *I2C) readByte() byte {
} }
// Always use UART0 as the serial output. // Always use UART0 as the serial output.
var Serial = UART0 var DefaultUART = UART0
// UART // UART
var ( var (

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

@ -251,6 +251,8 @@ func (p Pin) mux() *volatile.Register32 {
} }
} }
var DefaultUART = UART0
var ( var (
UART0 = &_UART0 UART0 = &_UART0
_UART0 = UART{Bus: esp.UART0, Buffer: NewRingBuffer()} _UART0 = UART{Bus: esp.UART0, Buffer: NewRingBuffer()}

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

@ -139,6 +139,8 @@ func (p Pin) PortMaskClear() (*uint32, uint32) {
return &esp.GPIO.GPIO_OUT_W1TC.Reg, 1 << p return &esp.GPIO.GPIO_OUT_W1TC.Reg, 1 << p
} }
var DefaultUART = UART0
// UART0 is a hardware UART that supports both TX and RX. // UART0 is a hardware UART that supports both TX and RX.
var UART0 = &_UART0 var UART0 = &_UART0
var _UART0 = UART{Buffer: NewRingBuffer()} var _UART0 = UART{Buffer: NewRingBuffer()}

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

@ -11,6 +11,12 @@ var (
USB = &UART{100} USB = &UART{100}
) )
// The Serial port always points to the default UART in a simulated environment.
//
// TODO: perhaps this should be a special serial object that outputs via WASI
// stdout calls.
var Serial = UART0
const ( const (
PinInput PinMode = iota PinInput PinMode = iota
PinOutput PinOutput
@ -118,12 +124,6 @@ type UART struct {
Bus uint8 Bus uint8
} }
type UARTConfig struct {
BaudRate uint32
TX Pin
RX Pin
}
// Configure the UART. // Configure the UART.
func (uart *UART) Configure(config UARTConfig) { func (uart *UART) Configure(config UARTConfig) {
uartConfigure(uart.Bus, config.TX, config.RX) uartConfigure(uart.Bus, config.TX, config.RX)

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

@ -108,7 +108,7 @@ var (
} }
) )
var Serial = UART0 var DefaultUART = UART0
func init() { func init() {
UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt) UART0.Interrupt = interrupt.New(rp.IRQ_UART0_IRQ, _UART0.handleInterrupt)

6
src/machine/serial-none.go Обычный файл
Просмотреть файл

@ -0,0 +1,6 @@
// +build baremetal,serial.none
package machine
// Serial is a null device: writes to it are ignored.
var Serial = NullSerial{}

6
src/machine/serial-uart.go Обычный файл
Просмотреть файл

@ -0,0 +1,6 @@
// +build baremetal,serial.uart
package machine
// Serial is implemented via the default (usually the first) UART on the chip.
var Serial = DefaultUART

6
src/machine/serial-usb.go Обычный файл
Просмотреть файл

@ -0,0 +1,6 @@
// +build baremetal,serial.usb
package machine
// Serial is implemented via USB (USB-CDC).
var Serial = USB

46
src/machine/serial.go Обычный файл
Просмотреть файл

@ -0,0 +1,46 @@
package machine
import "errors"
var errNoByte = errors.New("machine: no byte read")
// UARTConfig is a struct with which a UART (or similar object) can be
// configured. The baud rate is usually respected, but TX and RX may be ignored
// depending on the chip and the type of object.
type UARTConfig struct {
BaudRate uint32
TX Pin
RX Pin
}
// NullSerial is a serial version of /dev/null (or null router): it drops
// everything that is written to it.
type NullSerial struct {
}
// Configure does nothing: the null serial has no configuration.
func (ns NullSerial) Configure(config UARTConfig) error {
return nil
}
// WriteByte is a no-op: the null serial doesn't write bytes.
func (ns NullSerial) WriteByte(b byte) error {
return nil
}
// ReadByte always returns an error because there aren't any bytes to read.
func (ns NullSerial) ReadByte() (byte, error) {
return 0, errNoByte
}
// Buffered returns how many bytes are buffered in the UART. It always returns 0
// as there are no bytes to read.
func (ns NullSerial) Buffered() int {
return 0
}
// Write is a no-op: none of the data is being written and it will not return an
// error.
func (ns NullSerial) Write(p []byte) (n int, err error) {
return len(p), nil
}

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

@ -23,12 +23,6 @@ const (
ParityOdd UARTParity = 2 ParityOdd UARTParity = 2
) )
type UARTConfig struct {
BaudRate uint32
TX Pin
RX Pin
}
// To implement the UART interface for a board, you must declare a concrete type as follows: // To implement the UART interface for a board, you must declare a concrete type as follows:
// //
// type UART struct { // type UART struct {

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

@ -1,6 +1,7 @@
{ {
"inherits": ["atsamd21g18a"], "inherits": ["atsamd21g18a"],
"build-tags": ["arduino_mkr1000"], "build-tags": ["arduino_mkr1000"],
"serial": "usb",
"flash-command": "bossac -i -e -w -v -R -U --port={port} --offset=0x2000 {bin}", "flash-command": "bossac -i -e -w -v -R -U --port={port} --offset=0x2000 {bin}",
"flash-1200-bps-reset": "true" "flash-1200-bps-reset": "true"
} }

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

@ -1,6 +1,7 @@
{ {
"inherits": ["atsamd21g18a"], "inherits": ["atsamd21g18a"],
"build-tags": ["arduino_zero"], "build-tags": ["arduino_zero"],
"serial": "usb",
"flash-command": "bossac -i -e -w -v -R -U --port={port} --offset=0x2000 {bin}", "flash-command": "bossac -i -e -w -v -R -U --port={port} --offset=0x2000 {bin}",
"flash-1200-bps-reset": "true" "flash-1200-bps-reset": "true"
} }

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

@ -2,6 +2,7 @@
"inherits": ["avr"], "inherits": ["avr"],
"cpu": "atmega1280", "cpu": "atmega1280",
"build-tags": ["atmega1280", "atmega"], "build-tags": ["atmega1280", "atmega"],
"serial": "uart",
"cflags": [ "cflags": [
"-mmcu=atmega1280" "-mmcu=atmega1280"
], ],

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

@ -2,6 +2,7 @@
"inherits": ["avr"], "inherits": ["avr"],
"cpu": "atmega1284p", "cpu": "atmega1284p",
"build-tags": ["atmega1284p", "atmega"], "build-tags": ["atmega1284p", "atmega"],
"serial": "uart",
"cflags": [ "cflags": [
"-mmcu=atmega1284p" "-mmcu=atmega1284p"
], ],

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

@ -2,6 +2,7 @@
"inherits": ["avr"], "inherits": ["avr"],
"cpu": "atmega2560", "cpu": "atmega2560",
"build-tags": ["atmega2560", "atmega"], "build-tags": ["atmega2560", "atmega"],
"serial": "uart",
"cflags": [ "cflags": [
"-mmcu=atmega2560" "-mmcu=atmega2560"
], ],

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

@ -2,6 +2,7 @@
"inherits": ["avr"], "inherits": ["avr"],
"cpu": "atmega328p", "cpu": "atmega328p",
"build-tags": ["atmega328p", "atmega", "avr5"], "build-tags": ["atmega328p", "atmega", "avr5"],
"serial": "uart",
"cflags": [ "cflags": [
"-mmcu=atmega328p" "-mmcu=atmega328p"
], ],

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

@ -1,6 +1,7 @@
{ {
"inherits": ["cortex-m0plus"], "inherits": ["cortex-m0plus"],
"build-tags": ["atsamd21e18a", "atsamd21e18", "atsamd21", "sam"], "build-tags": ["atsamd21e18a", "atsamd21e18", "atsamd21", "sam"],
"serial": "usb",
"linkerscript": "targets/atsamd21.ld", "linkerscript": "targets/atsamd21.ld",
"extra-files": [ "extra-files": [
"src/device/sam/atsamd21e18a.s" "src/device/sam/atsamd21e18a.s"

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

@ -1,6 +1,7 @@
{ {
"inherits": ["cortex-m0plus"], "inherits": ["cortex-m0plus"],
"build-tags": ["atsamd21g18a", "atsamd21g18", "atsamd21", "sam"], "build-tags": ["atsamd21g18a", "atsamd21g18", "atsamd21", "sam"],
"serial": "usb",
"linkerscript": "targets/atsamd21.ld", "linkerscript": "targets/atsamd21.ld",
"extra-files": [ "extra-files": [
"src/device/sam/atsamd21g18a.s" "src/device/sam/atsamd21g18a.s"

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

@ -1,6 +1,7 @@
{ {
"inherits": ["atsame54p20a"], "inherits": ["atsame54p20a"],
"build-tags": ["atsame54_xpro"], "build-tags": ["atsame54_xpro"],
"serial": "usb",
"flash-method": "openocd", "flash-method": "openocd",
"openocd-interface": "cmsis-dap", "openocd-interface": "cmsis-dap",
"default-stack-size": 4096 "default-stack-size": 4096

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

@ -1,6 +1,7 @@
{ {
"inherits": ["cortex-m3"], "inherits": ["cortex-m3"],
"build-tags": ["bluepill", "stm32f103", "stm32f1", "stm32"], "build-tags": ["bluepill", "stm32f103", "stm32f1", "stm32"],
"serial": "uart",
"linkerscript": "targets/stm32.ld", "linkerscript": "targets/stm32.ld",
"extra-files": [ "extra-files": [
"src/device/stm32/stm32f103.s" "src/device/stm32/stm32f103.s"

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

@ -1,6 +1,7 @@
{ {
"inherits": ["nrf52840"], "inherits": ["nrf52840"],
"build-tags": ["circuitplay_bluefruit","nrf52840_reset_uf2", "softdevice", "s140v6"], "build-tags": ["circuitplay_bluefruit","nrf52840_reset_uf2", "softdevice", "s140v6"],
"serial": "usb",
"flash-1200-bps-reset": "true", "flash-1200-bps-reset": "true",
"flash-method": "msd", "flash-method": "msd",
"serial-port": ["acm:239a:8045", "acm:239a:45"], "serial-port": ["acm:239a:8045", "acm:239a:45"],

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

@ -1,6 +1,7 @@
{ {
"inherits": ["nrf52840"], "inherits": ["nrf52840"],
"build-tags": ["clue_alpha","nrf52840_reset_uf2", "softdevice", "s140v6"], "build-tags": ["clue_alpha","nrf52840_reset_uf2", "softdevice", "s140v6"],
"serial": "usb",
"flash-1200-bps-reset": "true", "flash-1200-bps-reset": "true",
"flash-method": "msd", "flash-method": "msd",
"msd-volume-name": "CLUEBOOT", "msd-volume-name": "CLUEBOOT",

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

@ -3,6 +3,7 @@
"cpu": "esp32", "cpu": "esp32",
"build-tags": ["esp32", "esp"], "build-tags": ["esp32", "esp"],
"scheduler": "tasks", "scheduler": "tasks",
"serial": "uart",
"linker": "xtensa-esp32-elf-ld", "linker": "xtensa-esp32-elf-ld",
"default-stack-size": 2048, "default-stack-size": 2048,
"cflags": [ "cflags": [

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

@ -1,6 +1,7 @@
{ {
"inherits": ["atsame51j19a"], "inherits": ["atsame51j19a"],
"build-tags": ["feather_m4_can"], "build-tags": ["feather_m4_can"],
"serial": "usb",
"flash-1200-bps-reset": "true", "flash-1200-bps-reset": "true",
"flash-method": "msd", "flash-method": "msd",
"msd-volume-name": "FTHRCANBOOT", "msd-volume-name": "FTHRCANBOOT",

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

@ -1,6 +1,7 @@
{ {
"inherits": ["atsamd51j19a"], "inherits": ["atsamd51j19a"],
"build-tags": ["feather_m4"], "build-tags": ["feather_m4"],
"serial": "usb",
"flash-1200-bps-reset": "true", "flash-1200-bps-reset": "true",
"flash-method": "msd", "flash-method": "msd",
"msd-volume-name": "FEATHERBOOT", "msd-volume-name": "FEATHERBOOT",

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

@ -1,6 +1,7 @@
{ {
"inherits": ["nrf52840"], "inherits": ["nrf52840"],
"build-tags": ["feather_nrf52840","nrf52840_reset_uf2", "softdevice", "s140v6"], "build-tags": ["feather_nrf52840","nrf52840_reset_uf2", "softdevice", "s140v6"],
"serial": "usb",
"flash-1200-bps-reset": "true", "flash-1200-bps-reset": "true",
"flash-method": "msd", "flash-method": "msd",
"msd-volume-name": "FTHR840BOOT", "msd-volume-name": "FTHR840BOOT",

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

@ -1,6 +1,7 @@
{ {
"inherits": ["cortex-m4"], "inherits": ["cortex-m4"],
"build-tags": ["feather_stm32f405", "stm32f405", "stm32f4", "stm32"], "build-tags": ["feather_stm32f405", "stm32f405", "stm32f4", "stm32"],
"serial": "uart",
"automatic-stack-size": false, "automatic-stack-size": false,
"linkerscript": "targets/stm32f405.ld", "linkerscript": "targets/stm32f405.ld",
"extra-files": [ "extra-files": [

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

@ -1,6 +1,7 @@
{ {
"inherits": ["atsamd51p20a"], "inherits": ["atsamd51p20a"],
"build-tags": ["grandcentral_m4"], "build-tags": ["grandcentral_m4"],
"serial": "usb",
"flash-1200-bps-reset": "true", "flash-1200-bps-reset": "true",
"flash-method": "msd", "flash-method": "msd",
"msd-volume-name": "GCM4BOOT", "msd-volume-name": "GCM4BOOT",

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

@ -1,6 +1,7 @@
{ {
"inherits": ["fe310"], "inherits": ["fe310"],
"build-tags": ["hifive1b", "qemu"], "build-tags": ["hifive1b", "qemu"],
"serial": "uart",
"linkerscript": "targets/hifive1-qemu.ld", "linkerscript": "targets/hifive1-qemu.ld",
"emulator": ["qemu-system-riscv32", "-machine", "sifive_e", "-nographic", "-kernel"] "emulator": ["qemu-system-riscv32", "-machine", "sifive_e", "-nographic", "-kernel"]
} }

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

@ -1,6 +1,7 @@
{ {
"inherits": ["fe310"], "inherits": ["fe310"],
"build-tags": ["hifive1b"], "build-tags": ["hifive1b"],
"serial": "uart",
"linkerscript": "targets/hifive1b.ld", "linkerscript": "targets/hifive1b.ld",
"flash-method": "msd", "flash-method": "msd",
"msd-volume-name": "HiFive", "msd-volume-name": "HiFive",

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

@ -1,6 +1,7 @@
{ {
"inherits": ["atsamd51g19a"], "inherits": ["atsamd51g19a"],
"build-tags": ["itsybitsy_m4"], "build-tags": ["itsybitsy_m4"],
"serial": "usb",
"flash-1200-bps-reset": "true", "flash-1200-bps-reset": "true",
"flash-method": "msd", "flash-method": "msd",
"serial-port": ["acm:239a:802b", "acm:239a:002b"], "serial-port": ["acm:239a:802b", "acm:239a:002b"],

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

@ -1,6 +1,7 @@
{ {
"inherits": ["nrf52840"], "inherits": ["nrf52840"],
"build-tags": ["itsybitsy_nrf52840","nrf52840_reset_uf2", "softdevice", "s140v6"], "build-tags": ["itsybitsy_nrf52840","nrf52840_reset_uf2", "softdevice", "s140v6"],
"serial": "usb",
"flash-1200-bps-reset": "true", "flash-1200-bps-reset": "true",
"flash-method": "msd", "flash-method": "msd",
"msd-volume-name": "ITSY840BOOT", "msd-volume-name": "ITSY840BOOT",

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

@ -5,6 +5,7 @@
"build-tags": [ "build-tags": [
"lgt92" "lgt92"
], ],
"serial": "uart",
"linkerscript": "targets/stm32l072czt6.ld", "linkerscript": "targets/stm32l072czt6.ld",
"flash-method": "openocd", "flash-method": "openocd",
"openocd-interface": "stlink-v2", "openocd-interface": "stlink-v2",

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

@ -1,6 +1,7 @@
{ {
"inherits": ["k210"], "inherits": ["k210"],
"build-tags": ["maixbit"], "build-tags": ["maixbit"],
"serial": "uart",
"linkerscript": "targets/maixbit.ld", "linkerscript": "targets/maixbit.ld",
"flash-command": "kflash -p {port} --noansi --verbose {bin}" "flash-command": "kflash -p {port} --noansi --verbose {bin}"
} }

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

@ -1,6 +1,7 @@
{ {
"inherits": ["atsamd51j19a"], "inherits": ["atsamd51j19a"],
"build-tags": ["metro_m4_airlift"], "build-tags": ["metro_m4_airlift"],
"serial": "usb",
"flash-1200-bps-reset": "true", "flash-1200-bps-reset": "true",
"flash-method": "msd", "flash-method": "msd",
"msd-volume-name": "METROM4BOOT", "msd-volume-name": "METROM4BOOT",

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

@ -1,6 +1,7 @@
{ {
"inherits": ["nrf52833"], "inherits": ["nrf52833"],
"build-tags": ["microbit_v2"], "build-tags": ["microbit_v2"],
"serial": "uart",
"flash-method": "msd", "flash-method": "msd",
"openocd-interface": "cmsis-dap", "openocd-interface": "cmsis-dap",
"msd-volume-name": "MICROBIT", "msd-volume-name": "MICROBIT",

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

@ -1,6 +1,7 @@
{ {
"inherits": ["nrf51"], "inherits": ["nrf51"],
"build-tags": ["microbit"], "build-tags": ["microbit"],
"serial": "uart",
"flash-method": "msd", "flash-method": "msd",
"openocd-interface": "cmsis-dap", "openocd-interface": "cmsis-dap",
"msd-volume-name": "MICROBIT", "msd-volume-name": "MICROBIT",

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

@ -1,6 +1,7 @@
{ {
"inherits": ["nrf52840"], "inherits": ["nrf52840"],
"build-tags": ["nicenano","nrf52840_reset_uf2", "softdevice", "s140v6"], "build-tags": ["nicenano","nrf52840_reset_uf2", "softdevice", "s140v6"],
"serial": "usb",
"flash-1200-bps-reset": "true", "flash-1200-bps-reset": "true",
"flash-method": "msd", "flash-method": "msd",
"msd-volume-name": "NICENANO", "msd-volume-name": "NICENANO",

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

@ -1,4 +1,5 @@
{ {
"inherits": ["esp8266"], "inherits": ["esp8266"],
"build-tags": ["nodemcu"] "build-tags": ["nodemcu"],
"serial": "uart"
} }

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

@ -1,6 +1,7 @@
{ {
"inherits": ["nrf52840"], "inherits": ["nrf52840"],
"build-tags": ["nrf52840_mdk_usb_dongle", "nrf52840_reset_uf2", "softdevice", "s140v6"], "build-tags": ["nrf52840_mdk_usb_dongle", "nrf52840_reset_uf2", "softdevice", "s140v6"],
"serial": "usb",
"flash-1200-bps-reset": "true", "flash-1200-bps-reset": "true",
"flash-method": "msd", "flash-method": "msd",
"msd-volume-name": "MDK-DONGLE", "msd-volume-name": "MDK-DONGLE",

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

@ -1,6 +1,7 @@
{ {
"inherits": ["nrf52840"], "inherits": ["nrf52840"],
"build-tags": ["nrf52840_mdk"], "build-tags": ["nrf52840_mdk"],
"serial": "usb",
"flash-method": "openocd", "flash-method": "openocd",
"openocd-interface": "cmsis-dap" "openocd-interface": "cmsis-dap"
} }

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

@ -1,6 +1,7 @@
{ {
"inherits": ["cortex-m3"], "inherits": ["cortex-m3"],
"build-tags": ["nucleof103rb", "stm32f103", "stm32f1","stm32"], "build-tags": ["nucleof103rb", "stm32f103", "stm32f1","stm32"],
"serial": "uart",
"linkerscript": "targets/stm32f103rb.ld", "linkerscript": "targets/stm32f103rb.ld",
"extra-files": [ "extra-files": [
"src/device/stm32/stm32f103.s" "src/device/stm32/stm32f103.s"

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

@ -1,6 +1,7 @@
{ {
"inherits": ["cortex-m7"], "inherits": ["cortex-m7"],
"build-tags": ["nucleof722ze", "stm32f7x2", "stm32f7", "stm32"], "build-tags": ["nucleof722ze", "stm32f7x2", "stm32f7", "stm32"],
"serial": "uart",
"linkerscript": "targets/stm32f7x2zetx.ld", "linkerscript": "targets/stm32f7x2zetx.ld",
"extra-files": [ "extra-files": [
"src/device/stm32/stm32f7x2.s" "src/device/stm32/stm32f7x2.s"

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

@ -1,6 +1,7 @@
{ {
"inherits": ["cortex-m0"], "inherits": ["cortex-m0"],
"build-tags": ["nucleol031k6", "stm32l031", "stm32l0x1", "stm32l0", "stm32"], "build-tags": ["nucleol031k6", "stm32l031", "stm32l0x1", "stm32l0", "stm32"],
"serial": "uart",
"linkerscript": "targets/stm32l031k6.ld", "linkerscript": "targets/stm32l031k6.ld",
"extra-files": [ "extra-files": [
"src/device/stm32/stm32l0x1.s" "src/device/stm32/stm32l0x1.s"

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

@ -1,6 +1,7 @@
{ {
"inherits": ["cortex-m4"], "inherits": ["cortex-m4"],
"build-tags": ["nucleol432kc", "stm32l432", "stm32l4x2", "stm32l4", "stm32"], "build-tags": ["nucleol432kc", "stm32l432", "stm32l4x2", "stm32l4", "stm32"],
"serial": "uart",
"linkerscript": "targets/stm32l4x2.ld", "linkerscript": "targets/stm32l4x2.ld",
"extra-files": [ "extra-files": [
"src/device/stm32/stm32l4x2.s" "src/device/stm32/stm32l4x2.s"

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

@ -1,6 +1,7 @@
{ {
"inherits": ["cortex-m33"], "inherits": ["cortex-m33"],
"build-tags": ["nucleol552ze", "stm32l552", "stm32l5x2", "stm32l5", "stm32"], "build-tags": ["nucleol552ze", "stm32l552", "stm32l5x2", "stm32l5", "stm32"],
"serial": "uart",
"linkerscript": "targets/stm32l5x2xe.ld", "linkerscript": "targets/stm32l5x2xe.ld",
"extra-files": [ "extra-files": [
"src/device/stm32/stm32l552.s" "src/device/stm32/stm32l552.s"

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

@ -1,6 +1,7 @@
{ {
"inherits": ["nrf52840"], "inherits": ["nrf52840"],
"build-tags": ["particle_3rd_gen"], "build-tags": ["particle_3rd_gen"],
"serial": "uart",
"flash-method": "openocd", "flash-method": "openocd",
"openocd-interface": "cmsis-dap" "openocd-interface": "cmsis-dap"
} }

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

@ -1,6 +1,7 @@
{ {
"inherits": ["nrf51"], "inherits": ["nrf51"],
"build-tags": ["pca10031"], "build-tags": ["pca10031"],
"serial": "uart",
"flash-command": "nrfjprog -f nrf51 --sectorerase --program {hex} --reset", "flash-command": "nrfjprog -f nrf51 --sectorerase --program {hex} --reset",
"openocd-interface": "cmsis-dap" "openocd-interface": "cmsis-dap"
} }

Показаны не все изменённые файлы, т.к. их слишком много Показать больше