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.
This commit is contained in:
Nico Tonnhofer 2015-11-19 00:21:31 +01:00
parent 2a96564228
commit b9107397b2
1 changed files with 6 additions and 1 deletions

View File

@ -11,7 +11,9 @@
*/ */
#if defined TEACUP_C_INCLUDE && defined __ARM_STM32F411__ #if defined TEACUP_C_INCLUDE && defined __ARM_STM32F411__
#include "arduino.h" #include "arduino.h"
#include "delay.h"
#ifdef XONXOFF #ifdef XONXOFF
#error XON/XOFF protocol not yet implemented for ARM. \ #error XON/XOFF protocol not yet implemented for ARM. \
@ -83,7 +85,9 @@ void serial_init()
Divisor = int((div - int(div))*16) Divisor = int((div - int(div))*16)
BRR = Mantisse + Divisor BRR = Mantisse + Divisor
*/ */
#if !defined BAUD
#define BAUD 115200 #define BAUD 115200
#endif
#define SERIAL_APBCLK (__SYSTEM_CLOCK/2) #define SERIAL_APBCLK (__SYSTEM_CLOCK/2)
@ -132,7 +136,8 @@ uint8_t serial_txchars(void) {
/** Send one character. /** Send one character.
*/ */
void serial_writechar(uint8_t data) { 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); USART2->DR = (uint32_t)(data & 0x1FF);
} }