|
px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
|
How to direct the AVR Libc stdout stream to send characters using a UART.
File(s):
The UART is configured to 115200 BAUD, 8 Data Bits, No Parity and 1 Stop Bit. The following strings are sent upon start up:
printf - String in data memory (SRAM) printf_P - String in program memory (FLASH) PRINTF_P - String in program memory (FLASH)
Remember that the XMODEM-CRC bootloader will send a 'C' character upon reset and this will be shown in addition to the printf strings.
A custom handler "uart_putchar(...)" is linked to the stdout stream to send a character and inject a "\r" (Carriage Return) before every "\n" (Line Feed).
This example draws attention to the handling of the Harvard architecture by the GCC compiler and the AVR Libc library. The 8-bit AVRs have a small amount of SRAM (data memory) and therefore it is desirable to store constant strings in FLASH (program memory) and access it from there and not use a copy in SRAM.
The recommended solution is to use the macros in <avr/pgmspace.h> and string handling functions with the suffix "_P", e.g. "printf_P(...)" instead of "printf(...)". This handling has been encapsulated with the following variable argument macro:
All of this functionality has been encapsulated in the following modules:
See:
More info: