summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-07-19 12:05:25 +0700
committerhathach <[email protected]>2013-07-19 12:05:25 +0700
commit23f4d7356f822692471f6341791940678a75d6d2 (patch)
tree534a6287179cd95e9ddda91bd013129207b81e97
parenta522263a9d43679ea9ffa499c1ea0efba4a523ad (diff)
change printf retarget to make \n to \r\n automatically
-rw-r--r--demos/bsp/boards/printf_retarget.c21
-rw-r--r--demos/host/src/main.c12
2 files changed, 26 insertions, 7 deletions
diff --git a/demos/bsp/boards/printf_retarget.c b/demos/bsp/boards/printf_retarget.c
index 56e59d801..49a2150ee 100644
--- a/demos/bsp/boards/printf_retarget.c
+++ b/demos/bsp/boards/printf_retarget.c
@@ -51,7 +51,26 @@ int __sys_write (int iFileHandle, char *pcBuffer, int iLength)
(void) iFileHandle;
#if CFG_PRINTF_TARGET == PRINTF_TARGET_UART
- return board_uart_send((uint8_t*)pcBuffer, iLength);
+ // following code to make \n --> \r\n
+ int length = iLength;
+ char* p_newline_pos = memchr(pcBuffer, '\n', length);
+
+ while(p_newline_pos != NULL)
+ {
+ uint32_t chunk_len = p_newline_pos - pcBuffer;
+
+ board_uart_send((uint8_t*)pcBuffer, chunk_len);
+ board_uart_send(&"\r\n", 2);
+
+ pcBuffer += (chunk_len + 1);
+ length -= (chunk_len + 1);
+ p_newline_pos = memchr(pcBuffer, '\n', length);
+ }
+
+ board_uart_send((uint8_t*)pcBuffer, length);
+
+ return iLength;
+
#elif CFG_PRINTF_TARGET == PRINTF_TARGET_SWO
uint32_t i;
for (i = 0; i<iLength; i++)
diff --git a/demos/host/src/main.c b/demos/host/src/main.c
index 6c15c024b..a58fccdd2 100644
--- a/demos/host/src/main.c
+++ b/demos/host/src/main.c
@@ -174,12 +174,12 @@ OSAL_TASK_FUNCTION( led_blinking_task ) (void* p_task_para)
//--------------------------------------------------------------------+
void print_greeting(void)
{
- printf("\r\n\
---------------------------------------------------------------------\r\n\
-- Host Demo (a tinyusb example)\r\n\
-- if you find any bugs or get any questions, feel free to file an\r\n\
-- issue at https://github.com/hathach/tinyusb\r\n\
---------------------------------------------------------------------\r\n\r\n"
+ printf("\n\
+--------------------------------------------------------------------\n\
+- Host Demo (a tinyusb example)\n\
+- if you find any bugs or get any questions, feel free to file an\n\
+- issue at https://github.com/hathach/tinyusb\n\
+--------------------------------------------------------------------\n\n"
);
}