aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/libmaple.h4
-rw-r--r--libmaple/systick.c6
-rw-r--r--libmaple/systick.h1
-rw-r--r--libmaple/usart.c38
4 files changed, 29 insertions, 20 deletions
diff --git a/libmaple/libmaple.h b/libmaple/libmaple.h
index 437566f..3a4042a 100644
--- a/libmaple/libmaple.h
+++ b/libmaple/libmaple.h
@@ -74,7 +74,7 @@
// Debug port settings (from ASSERT)
#define ERROR_LED_PORT GPIOA_BASE
#define ERROR_LED_PIN 5
- #define ERROR_USART_NUM 2
+ #define ERROR_USART_NUM USART2
#define ERROR_USART_BAUD 9600
#define ERROR_TX_PIN 2
#define ERROR_TX_PORT GPIOA_BASE
@@ -113,7 +113,7 @@
#define ERROR_LED_PORT GPIOC_BASE
#define ERROR_LED_PIN 15
- #define ERROR_USART_NUM 1
+ #define ERROR_USART_NUM USART1
#define ERROR_USART_BAUD 9600
#define ERROR_TX_PIN 10
#define ERROR_TX_PORT GPIOA_BASE
diff --git a/libmaple/systick.c b/libmaple/systick.c
index 8b0d92a..456ac2f 100644
--- a/libmaple/systick.c
+++ b/libmaple/systick.c
@@ -52,6 +52,12 @@ void systick_init(uint32 reload_val) {
SYSTICK_TICKINT);
}
+void systick_disable() {
+ /* clock the system timer with the core clock, but don't turn it on
+ or enable interrupt. */
+ __write(SYSTICK_CSR, SYSTICK_SRC_HCLK);
+}
+
void SysTickHandler(void) {
systick_timer_millis++;
}
diff --git a/libmaple/systick.h b/libmaple/systick.h
index 57b724a..86284f8 100644
--- a/libmaple/systick.h
+++ b/libmaple/systick.h
@@ -43,6 +43,7 @@ extern "C"{
#endif
void systick_init(uint32 reload_val);
+void systick_disable();
static inline uint32 systick_get_count(void) {
return __read(SYSTICK_CNT);
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 */