mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 14:33:41 +00:00
b67351babe
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.
93 lines
1.8 KiB
Go
93 lines
1.8 KiB
Go
// +build nucleol031k6
|
|
|
|
package machine
|
|
|
|
import (
|
|
"device/stm32"
|
|
"runtime/interrupt"
|
|
)
|
|
|
|
const (
|
|
LED = LED_BUILTIN
|
|
LED_BUILTIN = LED_GREEN
|
|
LED_GREEN = PB3
|
|
)
|
|
|
|
const (
|
|
// Arduino Pins
|
|
A0 = PA0 // ADC_IN0
|
|
A1 = PA1 // ADC_IN1
|
|
A2 = PA3 // ADC_IN3
|
|
A3 = PA4 // ADC_IN4
|
|
A4 = PA5 // ADC_IN5 || I2C1_SDA
|
|
A5 = PA6 // ADC_IN6 || I2C1_SCL
|
|
A6 = PA7 // ADC_IN7
|
|
A7 = PA2 // ADC_IN2
|
|
|
|
D0 = PA10 // USART1_TX
|
|
D1 = PA9 // USART1_RX
|
|
D2 = PA12
|
|
D3 = PB0 // TIM2_CH3
|
|
D4 = PB7
|
|
D5 = PB6 // TIM16_CH1N
|
|
D6 = PB1 // TIM14_CH1
|
|
D9 = PA8 // TIM1_CH1
|
|
D10 = PA11 // SPI_CS || TIM1_CH4
|
|
D11 = PB5 // SPI1_MOSI || TIM3_CH2
|
|
D12 = PB4 // SPI1_MISO
|
|
D13 = PB3 // SPI1_SCK
|
|
)
|
|
|
|
const (
|
|
// UART pins
|
|
// PA2 and PA15 are connected to the ST-Link Virtual Com Port (VCP)
|
|
UART_TX_PIN = PA2
|
|
UART_RX_PIN = PA15
|
|
|
|
// SPI
|
|
SPI1_SCK_PIN = PB3
|
|
SPI1_SDI_PIN = PB5
|
|
SPI1_SDO_PIN = PB4
|
|
SPI0_SCK_PIN = SPI1_SCK_PIN
|
|
SPI0_SDI_PIN = SPI1_SDI_PIN
|
|
SPI0_SDO_PIN = SPI1_SDO_PIN
|
|
|
|
// I2C pins
|
|
// PB6 and PB7 are mapped to CN4 pin 7 and CN4 pin 8 respectively with the
|
|
// default solder bridge settings
|
|
I2C0_SCL_PIN = PB7
|
|
I2C0_SDA_PIN = PB6
|
|
I2C0_ALT_FUNC = 1
|
|
)
|
|
|
|
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.
|
|
UART1 = &_UART1
|
|
_UART1 = UART{
|
|
Buffer: NewRingBuffer(),
|
|
Bus: stm32.USART2,
|
|
TxAltFuncSelector: 4,
|
|
RxAltFuncSelector: 4,
|
|
}
|
|
Serial = UART1
|
|
|
|
// I2C1 is documented, alias to I2C0 as well
|
|
I2C1 = &I2C{
|
|
Bus: stm32.I2C1,
|
|
AltFuncSelector: 1,
|
|
}
|
|
I2C0 = I2C1
|
|
|
|
// SPI
|
|
SPI0 = SPI{
|
|
Bus: stm32.SPI1,
|
|
AltFuncSelector: 0,
|
|
}
|
|
SPI1 = &SPI0
|
|
)
|
|
|
|
func init() {
|
|
UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt)
|
|
}
|