stm32: Harmonization of UART logic

This commit is contained in:
Kenneth Bell
2020-12-15 23:26:16 -08:00
committed by deadprogram
parent af02c09b56
commit 289e1aa197
8 changed files with 81 additions and 188 deletions
+11 -12
View File
@@ -6,7 +6,6 @@ package machine
import (
"device/stm32"
"runtime/interrupt"
)
func CPUFrequency() uint32 {
@@ -33,18 +32,10 @@ const (
AF15_EVENTOUT = 15
)
//---------- UART related types and code
// UART representation
type UART struct {
Buffer *RingBuffer
Bus *stm32.USART_Type
Interrupt interrupt.Interrupt
AltFuncSelector uint8
}
//---------- UART related code
// Configure the UART.
func (uart UART) configurePins(config UARTConfig) {
func (uart *UART) configurePins(config UARTConfig) {
// enable the alternate functions on the TX and RX pins
config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.AltFuncSelector)
config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.AltFuncSelector)
@@ -52,7 +43,7 @@ func (uart UART) configurePins(config UARTConfig) {
// UART baudrate calc based on the bus and clockspeed
// NOTE: keep this in sync with the runtime/runtime_stm32f407.go clock init code
func (uart UART) getBaudRateDivisor(baudRate uint32) uint32 {
func (uart *UART) getBaudRateDivisor(baudRate uint32) uint32 {
var clock uint32
switch uart.Bus {
case stm32.USART1, stm32.USART6:
@@ -63,6 +54,14 @@ func (uart UART) getBaudRateDivisor(baudRate uint32) uint32 {
return clock / baudRate
}
// Register names vary by ST processor, these are for STM F407
func (uart *UART) setRegisters() {
uart.rxReg = &uart.Bus.DR
uart.txReg = &uart.Bus.DR
uart.statusReg = &uart.Bus.SR
uart.txEmptyFlag = stm32.USART_SR_TXE
}
//---------- SPI related types and code
// SPI on the STM32Fxxx using MODER / alternate function pins