summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Borneo <antonio.borneo@st.com>2016-07-07 12:32:36 +0200
committerAntonio Borneo <antonio.borneo@st.com>2017-05-30 22:51:31 +0200
commit94eb7cea428e83f84cf4b42fb0a49d15af9e5bd3 (patch)
tree81a6bc5c19ed2fa0596e7fdd02033fcffa101428
parenta01ea4e28585b4548efa14eadb48c88db5f84ff1 (diff)
downloadcontexthub-94eb7cea428e83f84cf4b42fb0a49d15af9e5bd3.tar.gz
nanohub: firmware: flush usart
Entering in sleep-mode freezes several clock in the device; if usart is still transmitting, this will cause sending incorrect data. Wait for usart to complete transmission. Change-Id: Ide972e55b1e850d3310e935912697e9aa17a638c Signed-off-by: Antonio Borneo <antonio.borneo@st.com>
-rw-r--r--firmware/os/inc/usart.h1
-rw-r--r--firmware/os/platform/stm32/platform.c3
-rw-r--r--firmware/os/platform/stm32/usart.c11
3 files changed, 15 insertions, 0 deletions
diff --git a/firmware/os/inc/usart.h b/firmware/os/inc/usart.h
index ab7a477d..1ef18e50 100644
--- a/firmware/os/inc/usart.h
+++ b/firmware/os/inc/usart.h
@@ -63,6 +63,7 @@ void usartOpen(struct usart* __restrict usart, UsartPort port, /* port number is
UsatStopBitsCfg stop_bits, UsartParityCfg parity,
UsartFlowControlCfg flow_control);
void usartClose(const struct usart* __restrict usart);
+void usartFlush(const struct usart* __restrict usart);
void usartPutchar(const struct usart* __restrict usart, char c);
#ifdef __cplusplus
diff --git a/firmware/os/platform/stm32/platform.c b/firmware/os/platform/stm32/platform.c
index 5c8082c4..befafe9f 100644
--- a/firmware/os/platform/stm32/platform.c
+++ b/firmware/os/platform/stm32/platform.c
@@ -184,6 +184,9 @@ void platEarlyLogFlush(void)
void platLogFlush(void *userData)
{
+#ifdef DEBUG_UART_UNITNO
+ usartFlush(&mDbgUart);
+#endif
#if defined(DEBUG_LOG_EVT)
if (userData && mLateBoot)
osEnqueueEvtOrFree(EVENT_TYPE_BIT_DISCARDABLE | EVT_DEBUG_LOG, userData, heapFree);
diff --git a/firmware/os/platform/stm32/usart.c b/firmware/os/platform/stm32/usart.c
index 302cb852..26f644f9 100644
--- a/firmware/os/platform/stm32/usart.c
+++ b/firmware/os/platform/stm32/usart.c
@@ -144,6 +144,17 @@ void usartClose(const struct usart* __restrict usart)
gpioRelease(usart->tx);
}
+/*
+ * don't use this immediately after usart initialization
+ * the test is valid only after the first char has been sent out
+ */
+void usartFlush(const struct usart* __restrict usart)
+{
+ struct StmUsart *block = (struct StmUsart*)mUsartPorts[usart->unit];
+
+ while ((block->SR & 0x00c0) != 0x00c0);
+}
+
void usartPutchar(const struct usart* __restrict usart, char c)
{
struct StmUsart *block = (struct StmUsart*)mUsartPorts[usart->unit];