summaryrefslogtreecommitdiff
path: root/ports/stm32/uart.c
diff options
context:
space:
mode:
authorTobias Badertscher <badi@baerospace.ch>2018-12-09 17:07:56 +0100
committerDamien George <damien.p.george@gmail.com>2018-12-29 17:21:37 +1100
commit372e7a4dc6f565ac75b58e960fb480b520b9a07e (patch)
tree1be85bd89e4d12cc94411d89a3e1822293f4276a /ports/stm32/uart.c
parent06236bf28e0240b6a4193dae8f558a3804f5e4b6 (diff)
stm32: Implement UART.irq() method with initial support for RX idle IRQ.
Diffstat (limited to 'ports/stm32/uart.c')
-rw-r--r--ports/stm32/uart.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/ports/stm32/uart.c b/ports/stm32/uart.c
index ff1e86004..74e601f3b 100644
--- a/ports/stm32/uart.c
+++ b/ports/stm32/uart.c
@@ -33,6 +33,7 @@
#include "py/mperrno.h"
#include "py/mphal.h"
#include "lib/utils/interrupt_char.h"
+#include "lib/utils/mpirq.h"
#include "uart.h"
#include "irq.h"
#include "pendsv.h"
@@ -327,6 +328,9 @@ bool uart_init(pyb_uart_obj_t *uart_obj,
uart_obj->char_width = CHAR_WIDTH_8BIT;
}
+ uart_obj->mp_irq_trigger = 0;
+ uart_obj->mp_irq_obj = NULL;
+
return true;
}
@@ -697,4 +701,24 @@ void uart_irq_handler(mp_uint_t uart_id) {
}
}
}
+
+ // Set user IRQ flags
+ self->mp_irq_flags = 0;
+ #if defined(STM32F4)
+ if (self->uartx->SR & USART_SR_IDLE) {
+ (void)self->uartx->SR;
+ (void)self->uartx->DR;
+ self->mp_irq_flags |= UART_FLAG_IDLE;
+ }
+ #else
+ if (self->uartx->ISR & USART_ISR_IDLE) {
+ self->uartx->ICR = USART_ICR_IDLECF;
+ self->mp_irq_flags |= UART_FLAG_IDLE;
+ }
+ #endif
+
+ // Check the flags to see if the user handler should be called
+ if (self->mp_irq_trigger & self->mp_irq_flags) {
+ mp_irq_handler(self->mp_irq_obj);
+ }
}