Skip to content

Printing to the Terminal

Richard Arthurs edited this page Apr 15, 2018 · 5 revisions

There are several functions we've implemented to print to the terminal via the UART, and they're applicable in different situations.

serialSendQ()

SerialSendQ sends text to the UART via the transmit queue. This is a safe, reliable way to send things out when your feature will be operating under RTOS control. To use, #include "sfu_uart.h" serialSendQ("hello!")

If you create a buffer and snprintf formatted data into it, you can also pass the buffer right to serialSendQ. Since queues send by copy, your data will go right in and be sent out correctly.

Formatting data

By default, serialSendQ sends out ascii characters, so sending '65' would send an A. To format data printf style, create a buffer, snprintf() your data into it to use the format specifiers, and serialSendQ the buffer out. Snprintf() will not overflow the buffer. This is a safe method to print more complex data out from tasks. To use, #include "printf.h"

char genBuf[20] = { '\0' };
uint32_t my_int;
my_int = 234;
snprintf(genBuf, 20, "Hello %i", my_int);
serialSendQ(genBuf);

printf()

Printf is appropriate for use before we get into the RTOS. Within the RTOS, its use is not recommended as it has issues being thread safe (despite saying it's thread safe). Additionally, it uses a lot of memory.

serialSendln()

This is suitable for use outside of RTOS control, such as for printing startup messages.