summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2017-10-02 08:14:22 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-10-18 08:30:16 -0700
commit7501654d201199fe12d351a6ae0ffecdb3ca7933 (patch)
treea576999ee1f66489e74d09650be648246c5468cd /chip
parent8434ed8f1020d47d11bf38193700d4e7b6eb1694 (diff)
downloadchrome-ec-7501654d201199fe12d351a6ae0ffecdb3ca7933.tar.gz
chip/stm32/usart: Add flags to usart_config
Allows setting TXINV/RXINV bits. BRANCH=none BUG=b:65697962 TEST=make BOARD=wand -j Change-Id: Ib1bb290cd9758c53b98c8fc1ca1a9369c8cff39e Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/694561 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r--chip/stm32/usart.c13
-rw-r--r--chip/stm32/usart.h36
2 files changed, 33 insertions, 16 deletions
diff --git a/chip/stm32/usart.c b/chip/stm32/usart.c
index d47d13e149..75859fa979 100644
--- a/chip/stm32/usart.c
+++ b/chip/stm32/usart.c
@@ -17,6 +17,7 @@
void usart_init(struct usart_config const *config)
{
intptr_t base = config->hw->base;
+ uint32_t cr2;
/*
* Enable clock to USART, this must be done first, before attempting
@@ -40,8 +41,18 @@ void usart_init(struct usart_config const *config)
* 8N1, 16 samples per bit. error interrupts, and special modes
* disabled.
*/
+
+ cr2 = 0x0000;
+#if defined(CHIP_FAMILY_STM32F0) || defined(CHIP_FAMILY_STM32F3) || \
+ defined(CHIP_FAMILY_STM32L4)
+ if (config->flags & USART_CONFIG_FLAG_RX_INV)
+ cr2 |= (1 << 16);
+ if (config->flags & USART_CONFIG_FLAG_TX_INV)
+ cr2 |= (1 << 17);
+#endif
+
STM32_USART_CR1(base) = 0x0000;
- STM32_USART_CR2(base) = 0x0000;
+ STM32_USART_CR2(base) = cr2;
STM32_USART_CR3(base) = 0x0000;
/*
diff --git a/chip/stm32/usart.h b/chip/stm32/usart.h
index cbfd8eca21..e158382b58 100644
--- a/chip/stm32/usart.h
+++ b/chip/stm32/usart.h
@@ -133,6 +133,11 @@ struct usart_config {
*/
int baud;
+ /* Other flags. */
+#define USART_CONFIG_FLAG_RX_INV (1 << 0)
+#define USART_CONFIG_FLAG_TX_INV (1 << 1)
+ unsigned int flags;
+
struct consumer consumer;
struct producer producer;
};
@@ -154,21 +159,22 @@ struct usart_config {
* BUILD_ASSERT(RX_QUEUE.unit_bytes == 1);
* BUILD_ASSERT(TX_QUEUE.unit_bytes == 1);
*/
-#define USART_CONFIG(HW, RX, TX, BAUD, RX_QUEUE, TX_QUEUE) \
- ((struct usart_config const) { \
- .hw = &HW, \
- .rx = &RX, \
- .tx = &TX, \
- .state = &((struct usart_state){}), \
- .baud = BAUD, \
- .consumer = { \
- .queue = &TX_QUEUE, \
- .ops = &TX.consumer_ops, \
- }, \
- .producer = { \
- .queue = &RX_QUEUE, \
- .ops = &RX.producer_ops, \
- }, \
+#define USART_CONFIG(HW, RX, TX, BAUD, FLAGS, RX_QUEUE, TX_QUEUE) \
+ ((struct usart_config const) { \
+ .hw = &HW, \
+ .rx = &RX, \
+ .tx = &TX, \
+ .state = &((struct usart_state){}), \
+ .baud = BAUD, \
+ .flags = FLAGS, \
+ .consumer = { \
+ .queue = &TX_QUEUE, \
+ .ops = &TX.consumer_ops, \
+ }, \
+ .producer = { \
+ .queue = &RX_QUEUE, \
+ .ops = &RX.producer_ops, \
+ }, \
})
/*