aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/usart.c7
-rw-r--r--src/wiring/comm/HardwareSerial.cpp2
2 files changed, 9 insertions, 0 deletions
diff --git a/src/lib/usart.c b/src/lib/usart.c
index 96e920c..0fd4e05 100644
--- a/src/lib/usart.c
+++ b/src/lib/usart.c
@@ -76,6 +76,11 @@ typedef struct usart_port {
volatile uint32 GTPR; // Guard time and prescaler register
} usart_port;
+void USART1_IRQHandler(void) {
+ /* Read the data */
+ ring_buf1.buf[ring_buf1.tail++] = (uint8_t)(((usart_port*)(USART1_BASE))->DR);
+ ring_buf1.tail %= USART_RECV_BUF_SIZE;
+}
/* Don't overrun your buffer, seriously */
void USART2_IRQHandler(void) {
@@ -118,6 +123,8 @@ void usart_init(uint8 usart_num, uint32 baud) {
port = (usart_port*)USART1_BASE;
ring_buf = &ring_buf1;
clk_speed = USART1_CLK;
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
+ REG_SET(NVIC_ISER1, BIT(5));
break;
case 2:
port = (usart_port*)USART2_BASE;
diff --git a/src/wiring/comm/HardwareSerial.cpp b/src/wiring/comm/HardwareSerial.cpp
index 3d0a0ce..04d8d18 100644
--- a/src/wiring/comm/HardwareSerial.cpp
+++ b/src/wiring/comm/HardwareSerial.cpp
@@ -72,6 +72,8 @@ void HardwareSerial::begin(uint32_t baud) {
case 1:
gpio_set_mode(USART1_TX_PORT, USART1_TX_PIN, GPIO_MODE_AF_OUTPUT_PP);
gpio_set_mode(USART1_RX_PORT, USART1_RX_PIN, GPIO_MODE_INPUT_FLOATING);
+ /* Turn off any pwm */
+ timers_disable_channel(1, 2);
break;
case 2:
gpio_set_mode(USART2_TX_PORT, USART2_TX_PIN, GPIO_MODE_AF_OUTPUT_PP);