aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/usart.c
diff options
context:
space:
mode:
Diffstat (limited to 'libmaple/usart.c')
-rw-r--r--libmaple/usart.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/libmaple/usart.c b/libmaple/usart.c
index d08d3cf..ef54ad0 100644
--- a/libmaple/usart.c
+++ b/libmaple/usart.c
@@ -33,18 +33,18 @@
#include "nvic.h"
#include "usart.h"
-#define USART1_BASE 0x40013800
-#define USART2_BASE 0x40004400
-#define USART3_BASE 0x40004800
-#define UART4_BASE 0x40004C00 // High-density devices only (Maple Native)
-#define UART5_BASE 0x40005000 // High-density devices only (Maple Native)
-
-#define USART_UE BIT(13)
-#define USART_M BIT(12)
-#define USART_TE BIT(3)
-#define USART_RE BIT(2)
-#define USART_RXNEIE BIT(5) // read data register not empty interrupt enable
-#define USART_TC BIT(6)
+#define USART1_BASE 0x40013800
+#define USART2_BASE 0x40004400
+#define USART3_BASE 0x40004800
+#define UART4_BASE 0x40004C00 // High-density devices only (Maple Native)
+#define UART5_BASE 0x40005000 // High-density devices only (Maple Native)
+
+#define USART_UE BIT(13)
+#define USART_M BIT(12)
+#define USART_TE BIT(3)
+#define USART_RE BIT(2)
+#define USART_RXNEIE BIT(5) // read data register not empty interrupt enable
+#define USART_TC BIT(6)
/* usart descriptor table */
struct usart_dev usart_dev_table[] = {
@@ -63,6 +63,7 @@ struct usart_dev usart_dev_table[] = {
.rcc_dev_num = RCC_USART3,
.nvic_dev_num = NVIC_USART3
},
+ /*
#if NR_USART >= 5
[UART4] = {
.base = (usart_port*)UART4_BASE,
@@ -75,6 +76,7 @@ struct usart_dev usart_dev_table[] = {
.nvic_dev_num = NVIC_UART5
},
#endif
+ */
};
/* usart interrupt handlers */
@@ -148,12 +150,12 @@ void usart_init(uint8 usart_num, uint32 baud) {
* @brief Turn off all USARTs.
*/
void usart_disable_all() {
- usart_disable(1);
- usart_disable(2);
- usart_disable(3);
+ usart_disable(USART1);
+ usart_disable(USART2);
+ usart_disable(USART3);
#if NR_USART >= 5
- usart_disable(4);
- usart_disable(5);
+ usart_disable(UART4);
+ usart_disable(UART5);
#endif
}
@@ -165,7 +167,7 @@ void usart_disable(uint8 usart_num) {
usart_port *port = usart_dev_table[usart_num].base;
/* TC bit must be high before disabling the usart */
- while ((port->SR & USART_TC) == 0)
+ while((port->CR1 & USART_UE) && !(port->SR & USART_TC))
;
/* Disable UE */