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,25 +6,16 @@ package machine
import (
"device/stm32"
"runtime/interrupt"
)
func CPUFrequency() uint32 {
return 216000000
}
//---------- 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)
@@ -32,7 +23,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_stm32f7x2.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:
@@ -42,3 +33,11 @@ func (uart UART) getBaudRateDivisor(baudRate uint32) uint32 {
}
return clock / baudRate
}
// Register names vary by ST processor, these are for STM F7x2
func (uart *UART) setRegisters() {
uart.rxReg = &uart.Bus.RDR
uart.txReg = &uart.Bus.TDR
uart.statusReg = &uart.Bus.ISR
uart.txEmptyFlag = stm32.USART_ISR_TXE
}