Skip to content

Commit 481d714

Browse files
committed
stmhal: Overhaul UART class to use read/write, and improve it.
UART object now uses a stream-like interface: read, readall, readline, readinto, readchar, write, writechar. Timeouts are configured when the UART object is initialised, using timeout and timeout_char keyword args. The object includes optional read buffering, using interrupts. You can set the buffer size dynamically using read_buf_len keyword arg. A size of 0 disables buffering.
1 parent 20f59e1 commit 481d714

File tree

8 files changed

+449
-199
lines changed

8 files changed

+449
-199
lines changed

stmhal/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ int main(void) {
320320
pin_init0();
321321
extint_init0();
322322
timer_init0();
323+
uart_init0();
323324

324325
#if MICROPY_HW_ENABLE_RNG
325326
rng_init0();
@@ -543,6 +544,7 @@ int main(void) {
543544

544545
printf("PYB: soft reboot\n");
545546
timer_deinit();
547+
uart_deinit();
546548

547549
first_soft_reset = false;
548550
goto soft_reset;

stmhal/qstrdefsport.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,17 @@ Q(baudrate)
143143
Q(bits)
144144
Q(stop)
145145
Q(parity)
146+
Q(read_buf_len)
147+
Q(buf)
148+
Q(len)
149+
Q(timeout)
150+
Q(timeout_char)
146151
Q(init)
147152
Q(deinit)
148-
Q(all)
149-
Q(send)
150-
Q(recv)
153+
Q(any)
154+
Q(writechar)
155+
Q(readchar)
156+
Q(readinto)
151157

152158
// for CAN class
153159
Q(CAN)

stmhal/stm32f4xx_it.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include "obj.h"
7777
#include "extint.h"
7878
#include "timer.h"
79+
#include "uart.h"
7980
#include "storage.h"
8081

8182
extern void __fatal_error(const char*);
@@ -395,3 +396,24 @@ void TIM8_UP_TIM13_IRQHandler(void) {
395396
void TIM8_TRG_COM_TIM14_IRQHandler(void) {
396397
timer_irq_handler(14);
397398
}
399+
400+
// UART/USART IRQ handlers
401+
void USART1_IRQHandler(void) {
402+
uart_irq_handler(1);
403+
}
404+
405+
void USART2_IRQHandler(void) {
406+
uart_irq_handler(2);
407+
}
408+
409+
void USART3_IRQHandler(void) {
410+
uart_irq_handler(3);
411+
}
412+
413+
void UART4_IRQHandler(void) {
414+
uart_irq_handler(4);
415+
}
416+
417+
void USART6_IRQHandler(void) {
418+
uart_irq_handler(6);
419+
}

0 commit comments

Comments
 (0)