From b9107397b21d480e590068e447947f0e28f481a1 Mon Sep 17 00:00:00 2001 From: Nico Tonnhofer Date: Thu, 19 Nov 2015 00:21:31 +0100 Subject: [PATCH] STM32F411: serial-stm32.c: allow sending arbitrarily long messages. On ARM we use only the 16 byte hardware buffer for sending and receiving over the serial line, which is often too short for debugging messages. This implementation works fine and still neither blocks nor introduces delays for short messages. Removed while-loop. Looks like we need some more us than the LPC?!? With +7us we do not lose characters anymore. --- serial-stm32.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/serial-stm32.c b/serial-stm32.c index a98bac5..d450bd2 100644 --- a/serial-stm32.c +++ b/serial-stm32.c @@ -11,7 +11,9 @@ */ #if defined TEACUP_C_INCLUDE && defined __ARM_STM32F411__ + #include "arduino.h" +#include "delay.h" #ifdef XONXOFF #error XON/XOFF protocol not yet implemented for ARM. \ @@ -83,7 +85,9 @@ void serial_init() Divisor = int((div - int(div))*16) BRR = Mantisse + Divisor */ + #if !defined BAUD #define BAUD 115200 + #endif #define SERIAL_APBCLK (__SYSTEM_CLOCK/2) @@ -132,7 +136,8 @@ uint8_t serial_txchars(void) { /** Send one character. */ void serial_writechar(uint8_t data) { - while (!serial_txchars()); + if ( !serial_txchars()) // Queue full? + delay_us((1000000 / BAUD * 10) + 7); USART2->DR = (uint32_t)(data & 0x1FF); }