From 575c03f31c5c92144e8ee034d2b99679db09785f Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Mon, 20 Nov 2017 17:36:55 +0800 Subject: [PATCH] chip/stm32: Add support for half-duplex UART BRANCH=none BUG=b:65697962 TEST=make BOARD=wand -j Change-Id: I2af4acb5cce6da6ce2f01d6d60cf5e806c9a4ed2 Signed-off-by: Nicolas Boichat Reviewed-on: https://chromium-review.googlesource.com/821891 Reviewed-by: Vincent Palatin --- chip/stm32/usart.c | 7 +++++-- chip/stm32/usart.h | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/chip/stm32/usart.c b/chip/stm32/usart.c index 75859fa979..893303deaf 100644 --- a/chip/stm32/usart.c +++ b/chip/stm32/usart.c @@ -17,7 +17,7 @@ void usart_init(struct usart_config const *config) { intptr_t base = config->hw->base; - uint32_t cr2; + uint32_t cr2, cr3; /* * Enable clock to USART, this must be done first, before attempting @@ -43,6 +43,7 @@ void usart_init(struct usart_config const *config) */ cr2 = 0x0000; + cr3 = 0x0000; #if defined(CHIP_FAMILY_STM32F0) || defined(CHIP_FAMILY_STM32F3) || \ defined(CHIP_FAMILY_STM32L4) if (config->flags & USART_CONFIG_FLAG_RX_INV) @@ -50,10 +51,12 @@ void usart_init(struct usart_config const *config) if (config->flags & USART_CONFIG_FLAG_TX_INV) cr2 |= (1 << 17); #endif + if (config->flags & USART_CONFIG_FLAG_HDSEL) + cr3 |= (1 << 3); STM32_USART_CR1(base) = 0x0000; STM32_USART_CR2(base) = cr2; - STM32_USART_CR3(base) = 0x0000; + STM32_USART_CR3(base) = cr3; /* * Enable the RX, TX, and variant specific HW. diff --git a/chip/stm32/usart.h b/chip/stm32/usart.h index e158382b58..d218f64fd5 100644 --- a/chip/stm32/usart.h +++ b/chip/stm32/usart.h @@ -133,9 +133,10 @@ struct usart_config { */ int baud; - /* Other flags. */ + /* Other flags (rx/tx inversion, half-duplex). */ #define USART_CONFIG_FLAG_RX_INV (1 << 0) #define USART_CONFIG_FLAG_TX_INV (1 << 1) +#define USART_CONFIG_FLAG_HDSEL (1 << 2) unsigned int flags; struct consumer consumer;