From dc981ce50973f7acb40aae7488b050eae88f8736 Mon Sep 17 00:00:00 2001 From: Kenneth Bell Date: Sun, 7 Mar 2021 10:55:50 -0800 Subject: [PATCH] stm32: separate altfunc selection for UART Tx/Rx This is needed for stm32l432 nucleo with different altfun for tx and rx --- src/machine/board_feather-stm32f405.go | 21 ++++++++++++--------- src/machine/board_nucleof722ze.go | 7 ++++--- src/machine/board_nucleol552ze.go | 7 ++++--- src/machine/board_stm32f4disco.go | 7 ++++--- src/machine/machine_stm32_uart.go | 9 +++++---- src/machine/machine_stm32f405.go | 4 ++-- src/machine/machine_stm32f407.go | 4 ++-- src/machine/machine_stm32f7x2.go | 4 ++-- src/machine/machine_stm32l5x2.go | 4 ++-- 9 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/machine/board_feather-stm32f405.go b/src/machine/board_feather-stm32f405.go index 16b0ac8e..438c16c0 100644 --- a/src/machine/board_feather-stm32f405.go +++ b/src/machine/board_feather-stm32f405.go @@ -120,19 +120,22 @@ const ( var ( UART1 = UART{ - Buffer: NewRingBuffer(), - Bus: stm32.USART3, - AltFuncSelector: AF7_USART1_2_3, + Buffer: NewRingBuffer(), + Bus: stm32.USART3, + TxAltFuncSelector: AF7_USART1_2_3, + RxAltFuncSelector: AF7_USART1_2_3, } UART2 = UART{ - Buffer: NewRingBuffer(), - Bus: stm32.USART6, - AltFuncSelector: AF8_USART4_5_6, + Buffer: NewRingBuffer(), + Bus: stm32.USART6, + TxAltFuncSelector: AF8_USART4_5_6, + RxAltFuncSelector: AF8_USART4_5_6, } UART3 = UART{ - Buffer: NewRingBuffer(), - Bus: stm32.USART1, - AltFuncSelector: AF7_USART1_2_3, + Buffer: NewRingBuffer(), + Bus: stm32.USART1, + TxAltFuncSelector: AF7_USART1_2_3, + RxAltFuncSelector: AF7_USART1_2_3, } UART0 = UART1 ) diff --git a/src/machine/board_nucleof722ze.go b/src/machine/board_nucleof722ze.go index 2bce529e..eac0348c 100644 --- a/src/machine/board_nucleof722ze.go +++ b/src/machine/board_nucleof722ze.go @@ -33,9 +33,10 @@ var ( // debugger to be exposed as virtual COM port over USB on Nucleo boards. // Both UART0 and UART1 refer to USART2. UART0 = UART{ - Buffer: NewRingBuffer(), - Bus: stm32.USART3, - AltFuncSelector: UART_ALT_FN, + Buffer: NewRingBuffer(), + Bus: stm32.USART3, + TxAltFuncSelector: UART_ALT_FN, + RxAltFuncSelector: UART_ALT_FN, } UART1 = &UART0 ) diff --git a/src/machine/board_nucleol552ze.go b/src/machine/board_nucleol552ze.go index fe06182b..b97be272 100644 --- a/src/machine/board_nucleol552ze.go +++ b/src/machine/board_nucleol552ze.go @@ -33,9 +33,10 @@ var ( // debugger to be exposed as virtual COM port over USB on Nucleo boards. // Both UART0 and UART1 refer to LPUART1. UART0 = UART{ - Buffer: NewRingBuffer(), - Bus: stm32.LPUART1, - AltFuncSelector: UART_ALT_FN, + Buffer: NewRingBuffer(), + Bus: stm32.LPUART1, + TxAltFuncSelector: UART_ALT_FN, + RxAltFuncSelector: UART_ALT_FN, } UART1 = &UART0 ) diff --git a/src/machine/board_stm32f4disco.go b/src/machine/board_stm32f4disco.go index f1be4814..06cd50ad 100644 --- a/src/machine/board_stm32f4disco.go +++ b/src/machine/board_stm32f4disco.go @@ -28,9 +28,10 @@ const ( var ( UART0 = UART{ - Buffer: NewRingBuffer(), - Bus: stm32.USART2, - AltFuncSelector: AF7_USART1_2_3, + Buffer: NewRingBuffer(), + Bus: stm32.USART2, + TxAltFuncSelector: AF7_USART1_2_3, + RxAltFuncSelector: AF7_USART1_2_3, } UART1 = &UART0 ) diff --git a/src/machine/machine_stm32_uart.go b/src/machine/machine_stm32_uart.go index 64b3345a..62f7cb19 100644 --- a/src/machine/machine_stm32_uart.go +++ b/src/machine/machine_stm32_uart.go @@ -13,10 +13,11 @@ import ( // UART representation type UART struct { - Buffer *RingBuffer - Bus *stm32.USART_Type - Interrupt interrupt.Interrupt - AltFuncSelector uint8 + Buffer *RingBuffer + Bus *stm32.USART_Type + Interrupt interrupt.Interrupt + TxAltFuncSelector uint8 + RxAltFuncSelector uint8 // Registers specific to the chip rxReg *volatile.Register32 diff --git a/src/machine/machine_stm32f405.go b/src/machine/machine_stm32f405.go index eb54c2af..ce802ddc 100644 --- a/src/machine/machine_stm32f405.go +++ b/src/machine/machine_stm32f405.go @@ -37,8 +37,8 @@ const ( 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) + config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector) + config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector) } func (uart *UART) getBaudRateDivisor(baudRate uint32) uint32 { diff --git a/src/machine/machine_stm32f407.go b/src/machine/machine_stm32f407.go index c33094f1..341ce992 100644 --- a/src/machine/machine_stm32f407.go +++ b/src/machine/machine_stm32f407.go @@ -37,8 +37,8 @@ const ( // Configure the UART. 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) + config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector) + config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector) } // UART baudrate calc based on the bus and clockspeed diff --git a/src/machine/machine_stm32f7x2.go b/src/machine/machine_stm32f7x2.go index 2724c6e4..8038fa7a 100644 --- a/src/machine/machine_stm32f7x2.go +++ b/src/machine/machine_stm32f7x2.go @@ -17,8 +17,8 @@ func CPUFrequency() uint32 { // Configure the UART. 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) + config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector) + config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector) } // UART baudrate calc based on the bus and clockspeed diff --git a/src/machine/machine_stm32l5x2.go b/src/machine/machine_stm32l5x2.go index 898be952..7d31396f 100644 --- a/src/machine/machine_stm32l5x2.go +++ b/src/machine/machine_stm32l5x2.go @@ -22,8 +22,8 @@ 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) + config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector) + config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector) } // UART baudrate calc based on the bus and clockspeed