use print library instead of stdio
This commit is contained in:
parent
6531aac77b
commit
aa0a5dd0a9
57
main.c
57
main.c
|
@ -20,11 +20,8 @@
|
||||||
|
|
||||||
/* standard libraries */
|
/* standard libraries */
|
||||||
#include <stdint.h> // standard integer types
|
#include <stdint.h> // standard integer types
|
||||||
#include <stdio.h> // standard I/O facilities
|
|
||||||
#include <stdlib.h> // standard utilities
|
#include <stdlib.h> // standard utilities
|
||||||
#include <unistd.h> // standard streams
|
|
||||||
#include <string.h> // string utilities
|
#include <string.h> // string utilities
|
||||||
#include <math.h> // mathematical utilities
|
|
||||||
|
|
||||||
/* STM32 (including CM3) libraries */
|
/* STM32 (including CM3) libraries */
|
||||||
#include <libopencmsis/core_cm3.h> // Cortex M3 utilities
|
#include <libopencmsis/core_cm3.h> // Cortex M3 utilities
|
||||||
|
@ -40,6 +37,7 @@
|
||||||
|
|
||||||
/* own libraries */
|
/* own libraries */
|
||||||
#include "global.h" // board definitions
|
#include "global.h" // board definitions
|
||||||
|
#include "print.h" // printing utilities
|
||||||
#include "usart.h" // USART utilities
|
#include "usart.h" // USART utilities
|
||||||
#include "usb_cdcacm.h" // USB CDC ACM utilities
|
#include "usb_cdcacm.h" // USB CDC ACM utilities
|
||||||
|
|
||||||
|
@ -51,33 +49,31 @@
|
||||||
volatile bool rtc_internal_tick_flag = false; /**< flag set when internal RTC ticked */
|
volatile bool rtc_internal_tick_flag = false; /**< flag set when internal RTC ticked */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
int _write(int file, char *ptr, int len)
|
|
||||||
{
|
|
||||||
int i; // how much data has been sent
|
|
||||||
static char newline = 0; // what newline has been sent
|
|
||||||
|
|
||||||
if (file == STDOUT_FILENO || file == STDERR_FILENO) {
|
size_t putc(char c)
|
||||||
for (i = 0; i < len; i++) {
|
{
|
||||||
if (ptr[i] == '\r' || ptr[i] == '\n') { // send CR+LF newline for most carriage return and line feed combination
|
size_t length = 0; // number of characters printed
|
||||||
if (newline==0 || (newline==ptr[i])) { // newline has already been detected
|
static char newline = 0; // to remember on which character we sent the newline
|
||||||
usart_putchar_nonblocking('\r'); // send newline over USART
|
if (0==c) {
|
||||||
usart_putchar_nonblocking('\n'); // send newline over USART
|
length = 0; // don't print string termination character
|
||||||
cdcacm_putchar('\r'); // send newline over USB
|
} else if ('\r' == c || '\n' == c) { // send CR+LF newline for most carriage return and line feed combination
|
||||||
cdcacm_putchar('\n'); // send newline over USB
|
if (0==newline || c==newline) { // send newline only if not already send (and only once on \r\n or \n\r)
|
||||||
newline = ptr[i]; // remember the newline
|
usart_putchar_nonblocking('\r'); // send CR over USART
|
||||||
|
cdcacm_putchar('\r'); // send CR over USB
|
||||||
|
usart_putchar_nonblocking('\n'); // send LF over USART
|
||||||
|
cdcacm_putchar('\n'); // send LF over USB
|
||||||
|
length += 2; // remember we printed 2 characters
|
||||||
|
newline = c; // remember on which character we sent the newline
|
||||||
|
} else {
|
||||||
|
length = 0; // the \r or \n of \n\r or \r\n has already been printed
|
||||||
}
|
}
|
||||||
if (ptr[i] == '\n') { // line feed are always considered to end a line (the LF+CR combination is not supported to better support the others)
|
} else {
|
||||||
|
usart_putchar_nonblocking(c); // send byte over USART
|
||||||
|
cdcacm_putchar(c); // send byte over USB
|
||||||
newline = 0; // clear new line
|
newline = 0; // clear new line
|
||||||
|
length++; // remember we printed 1 character
|
||||||
}
|
}
|
||||||
} else { // non-newline character
|
return length; // return number of characters printed
|
||||||
usart_putchar_nonblocking(ptr[i]); // send byte over USART
|
|
||||||
cdcacm_putchar(ptr[i]); // send byte over USB
|
|
||||||
newline = 0; // clear new line
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** user input command */
|
/** user input command */
|
||||||
|
@ -149,16 +145,9 @@ void main(void)
|
||||||
iwdg_start(); // start independent watchdog
|
iwdg_start(); // start independent watchdog
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// setup board
|
board_setup(); // setup board
|
||||||
board_setup();
|
|
||||||
|
|
||||||
// setup USART and USB for user communication
|
|
||||||
usart_setup(); // setup USART (for printing)
|
usart_setup(); // setup USART (for printing)
|
||||||
cdcacm_setup(); // setup USB CDC ACM (for printing)
|
cdcacm_setup(); // setup USB CDC ACM (for printing)
|
||||||
setbuf(stdout, NULL); // set standard out buffer to NULL to immediately print
|
|
||||||
setbuf(stderr, NULL); // set standard error buffer to NULL to immediately print
|
|
||||||
|
|
||||||
// minimal setup ready
|
|
||||||
printf("welcome to the STM32F1 CuVoodoo example code\n"); // print welcome message
|
printf("welcome to the STM32F1 CuVoodoo example code\n"); // print welcome message
|
||||||
|
|
||||||
#if !(DEBUG)
|
#if !(DEBUG)
|
||||||
|
|
Loading…
Reference in New Issue