mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 21:13:39 +00:00
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.
This commit is contained in:
committed by
Ron Evans
parent
aa5b8d0df7
commit
b67351babe
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -14,7 +14,7 @@ const (
|
||||
type arrtype = uint16
|
||||
|
||||
func putchar(c byte) {
|
||||
machine.UART0.WriteByte(c)
|
||||
machine.Serial.WriteByte(c)
|
||||
}
|
||||
|
||||
func initCLK() {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user