From 8fc2e61e2053c4d62b8ad591bfd81e0a72c0b251 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Thu, 24 Jul 2014 22:06:42 +0200 Subject: [PATCH 1/5] stm32f0: be UART0 aware --- boards/stm32f0discovery/include/board.h | 2 + cpu/stm32f0/syscalls.c | 51 ++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/boards/stm32f0discovery/include/board.h b/boards/stm32f0discovery/include/board.h index 13b8451979..556fe1f7ff 100644 --- a/boards/stm32f0discovery/include/board.h +++ b/boards/stm32f0discovery/include/board.h @@ -38,6 +38,8 @@ * @name Assign the UART interface to be used for stdio */ #define STDIO UART_0 +#define STDIO_BAUDRATE (115200U) +#define STDIO_BUFSIZE (64U) /** * @name LED pin definitions diff --git a/cpu/stm32f0/syscalls.c b/cpu/stm32f0/syscalls.c index f8dcdc78e9..b11ab73da9 100644 --- a/cpu/stm32f0/syscalls.c +++ b/cpu/stm32f0/syscalls.c @@ -34,6 +34,9 @@ #include "board.h" #include "periph/uart.h" +#ifdef MODULE_UART0 +#include "board_uart0.h" +#endif /** * manage the heap @@ -41,12 +44,44 @@ extern uint32_t _end; /* address of last used memory cell */ caddr_t heap_top = (caddr_t)&_end + 4; +#ifndef MODULE_UART0 +/** + * @brief use mutex for waiting on incoming UART chars + */ +static mutex_t uart_rx_mutex; +static char rx_buf_mem[STDIO_BUFSIZE]; +static ringbuffer_t rx_buf; +#endif + +/** + * @brief Receive a new character from the UART and put it into the receive buffer + */ +void rx_cb(void *arg, char data) +{ +#ifndef MODULE_UART0 + (void)arg; + + ringbuffer_add_one(&rx_buf, data); + mutex_unlock(&uart_rx_mutex); +#else + if (uart0_handler_pid) { + uart0_handle_incoming(data); + + uart0_notify_thread(); + } +#endif +} + /** * @brief Initialize NewLib, called by __libc_init_array() from the startup script */ void _init(void) { - uart_init_blocking(STDIO, 115200); +#ifndef MODULE_UART0 + mutex_init(&uart_rx_mutex); + ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_BUFSIZE); +#endif + uart_init(STDIO, STDIO_BAUDRATE, rx_cb, 0, 0); } /** @@ -152,11 +187,15 @@ int _open_r(struct _reent *r, const char *name, int mode) */ int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count) { - char c; - char *buff = (char*)buffer; - uart_read_blocking(STDIO, &c); - buff[0] = c; - return 1; +#ifndef MODULE_UART0 + while (rx_buf.avail == 0) { + mutex_lock(&uart_rx_mutex); + } + return ringbuffer_get(&rx_buf, (char*)buffer, rx_buf.avail); +#else + r->_errno = ENODEV; + return -1; +#endif } /** From aefa818338cb4aa90462dcd7995076b134e68ac9 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Thu, 24 Jul 2014 22:07:04 +0200 Subject: [PATCH 2/5] stm32f4: be UART0 aware --- boards/stm32f4discovery/include/board.h | 1 + cpu/stm32f4/periph/uart.c | 1 - cpu/stm32f4/syscalls.c | 59 ++++++++++++++++++++----- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/boards/stm32f4discovery/include/board.h b/boards/stm32f4discovery/include/board.h index e40813bc2e..294a815564 100644 --- a/boards/stm32f4discovery/include/board.h +++ b/boards/stm32f4discovery/include/board.h @@ -40,6 +40,7 @@ */ #define STDIO UART_0 #define STDIO_BAUDRATE (115200U) +#define STDIO_BUFSIZE (64U) /** @} */ /** diff --git a/cpu/stm32f4/periph/uart.c b/cpu/stm32f4/periph/uart.c index 93bddb01f7..891ffd3032 100644 --- a/cpu/stm32f4/periph/uart.c +++ b/cpu/stm32f4/periph/uart.c @@ -27,7 +27,6 @@ /* guard file in case no UART device was specified */ #if UART_NUMOF - /** * @brief Each UART device has to store two callbacks. */ diff --git a/cpu/stm32f4/syscalls.c b/cpu/stm32f4/syscalls.c index fa915f7b60..524bab4436 100644 --- a/cpu/stm32f4/syscalls.c +++ b/cpu/stm32f4/syscalls.c @@ -34,18 +34,54 @@ #include "irq.h" #include "periph/uart.h" +#ifdef MODULE_UART0 +#include "board_uart0.h" +#endif + /** * manage the heap */ extern uint32_t _end; /* address of last used memory cell */ caddr_t heap_top = (caddr_t)&_end + 4; +#ifndef MODULE_UART0 +/** + * @brief use mutex for waiting on incoming UART chars + */ +static mutex_t uart_rx_mutex; +static char rx_buf_mem[STDIO_BUFSIZE]; +static ringbuffer_t rx_buf; +#endif + +/** + * @brief Receive a new character from the UART and put it into the receive buffer + */ +void rx_cb(void *arg, char data) +{ +#ifndef MODULE_UART0 + (void)arg; + + ringbuffer_add_one(&rx_buf, data); + mutex_unlock(&uart_rx_mutex); +#else + if (uart0_handler_pid) { + uart0_handle_incoming(data); + + uart0_notify_thread(); + } +#endif +} + /** * @brief Initialize NewLib, called by __libc_init_array() from the startup script */ void _init(void) { - uart_init_blocking(STDIO, STDIO_BAUDRATE); +#ifndef MODULE_UART0 + mutex_init(&uart_rx_mutex); + ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_BUFSIZE); +#endif + uart_init(STDIO, STDIO_BAUDRATE, rx_cb, 0, 0); } /** @@ -151,11 +187,12 @@ int _open_r(struct _reent *r, const char *name, int mode) */ int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count) { - char c; - char *buff = (char*)buffer; - uart_read_blocking(STDIO, &c); - buff[0] = c; - return 1; +#ifndef MODULE_UART0 + while (rx_buf.avail == 0) { + mutex_lock(&uart_rx_mutex); + } + return ringbuffer_get(&rx_buf, (char*)buffer, rx_buf.avail); +#endif } /** @@ -175,11 +212,13 @@ int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count) */ int _write_r(struct _reent *r, int fd, const void *data, unsigned int count) { - char *c = (char*)data; - for (int i = 0; i < count; i++) { - uart_write_blocking(STDIO, c[i]); + int i = 0; + + while (i < count) { + uart_write_blocking(STDIO, ((char*)data)[i++]); } - return count; + + return i; } /** From fc3864756fbf17872deeb7da75bd307105bec2fd Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Thu, 11 Sep 2014 16:05:39 +0200 Subject: [PATCH 3/5] stm32f3: be UART0 aware --- cpu/stm32f3/syscalls.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cpu/stm32f3/syscalls.c b/cpu/stm32f3/syscalls.c index e2747d46da..3f5ee6c85d 100644 --- a/cpu/stm32f3/syscalls.c +++ b/cpu/stm32f3/syscalls.c @@ -37,28 +37,42 @@ #include "irq.h" #include "periph/uart.h" +#ifdef MODULE_UART0 +#include "board_uart0.h" +#endif + /** * @brief manage the heap */ extern uint32_t _end; /* address of last used memory cell */ caddr_t heap_top = (caddr_t)&_end + 4; +#ifndef MODULE_UART0 /** * @brief use mutex for waiting on incoming UART chars */ static mutex_t uart_rx_mutex; static char rx_buf_mem[STDIO_BUFSIZE]; static ringbuffer_t rx_buf; +#endif /** * @brief Receive a new character from the UART and put it into the receive buffer */ void rx_cb(void *arg, char data) { +#ifndef MODULE_UART0 (void)arg; ringbuffer_add_one(&rx_buf, data); mutex_unlock(&uart_rx_mutex); +#else + if (uart0_handler_pid) { + uart0_handle_incoming(data); + + uart0_notify_thread(); + } +#endif } /** @@ -66,10 +80,11 @@ void rx_cb(void *arg, char data) */ void _init(void) { +#ifndef MODULE_UART0 mutex_init(&uart_rx_mutex); ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_BUFSIZE); - uart_init(STDIO, STDIO_BAUDRATE, rx_cb, 0, 0); -} +#endif + uart_init(STDIO, STDIO_BAUDRATE, rx_cb, 0, 0);} /** * @brief Free resources on NewLib de-initialization, not used for RIOT @@ -174,10 +189,15 @@ int _open_r(struct _reent *r, const char *name, int mode) */ int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count) { +#ifndef MODULE_UART0 while (rx_buf.avail == 0) { mutex_lock(&uart_rx_mutex); } return ringbuffer_get(&rx_buf, (char*)buffer, rx_buf.avail); +#else + r->_errno = ENODEV; + return -1; +#endif } /** From c83e4cb361b453ea6d2df611b79237053e31eff8 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Thu, 11 Sep 2014 16:16:44 +0200 Subject: [PATCH 4/5] stm32f1: unify UART0 use --- boards/iot-lab_M3/include/board.h | 3 +- boards/msbiot/include/board.h | 1 + cpu/stm32f0/Makefile.include | 3 ++ cpu/stm32f0/syscalls.c | 2 ++ cpu/stm32f1/Makefile.include | 3 ++ cpu/stm32f1/periph/uart.c | 22 ++---------- cpu/stm32f1/syscalls.c | 56 ++++++++++++++++++++++++++----- cpu/stm32f4/Makefile.include | 3 ++ cpu/stm32f4/syscalls.c | 2 ++ 9 files changed, 66 insertions(+), 29 deletions(-) diff --git a/boards/iot-lab_M3/include/board.h b/boards/iot-lab_M3/include/board.h index d913d7c4af..4665e2bf16 100644 --- a/boards/iot-lab_M3/include/board.h +++ b/boards/iot-lab_M3/include/board.h @@ -38,7 +38,8 @@ * @{ */ #define STDIO UART_0 -#define STDIO_BAUDRATE (115200) +#define STDIO_BAUDRATE (115200U) +#define STDIO_BUFSIZE (64U) /** @} */ /** diff --git a/boards/msbiot/include/board.h b/boards/msbiot/include/board.h index 18931c63b6..733052f2d9 100644 --- a/boards/msbiot/include/board.h +++ b/boards/msbiot/include/board.h @@ -40,6 +40,7 @@ */ #define STDIO UART_0 #define STDIO_BAUDRATE (115200U) +#define STDIO_BUFSIZE (64U) /** @} */ /** diff --git a/cpu/stm32f0/Makefile.include b/cpu/stm32f0/Makefile.include index c2bd10a423..27d71f5cf2 100644 --- a/cpu/stm32f0/Makefile.include +++ b/cpu/stm32f0/Makefile.include @@ -7,6 +7,9 @@ export USEMODULE += cortex-m0_common # define path to cortex-m common module, which is needed for this CPU export CORTEX_COMMON = $(RIOTCPU)/cortex-m0_common/ +# this CPU implementation makes use of the ringbuffer, so include the lib module +export USEMODULE += lib + # define the linker script to use for this CPU. The CPU_MODEL variable is defined in the # board's Makefile.include. This enables multiple STMF0 controllers with different memory to # use the same code-base. diff --git a/cpu/stm32f0/syscalls.c b/cpu/stm32f0/syscalls.c index b11ab73da9..fbddea6576 100644 --- a/cpu/stm32f0/syscalls.c +++ b/cpu/stm32f0/syscalls.c @@ -30,6 +30,8 @@ #include "thread.h" #include "kernel.h" +#include "mutex.h" +#include "ringbuffer.h" #include "irq.h" #include "board.h" #include "periph/uart.h" diff --git a/cpu/stm32f1/Makefile.include b/cpu/stm32f1/Makefile.include index 87dd950e2b..7370ae77ac 100644 --- a/cpu/stm32f1/Makefile.include +++ b/cpu/stm32f1/Makefile.include @@ -4,6 +4,9 @@ export CFLAGS += -DCOREIF_NG=1 # tell the build system that the CPU depends on the Cortex-M common files export USEMODULE += cortex-m3_common +# this CPU implementation makes use of the ringbuffer, so include the lib module +export USEMODULE += lib + # define path to cortex-m common module, which is needed for this CPU export CORTEXM_COMMON = $(RIOTCPU)/cortex-m3_common/ diff --git a/cpu/stm32f1/periph/uart.c b/cpu/stm32f1/periph/uart.c index 5b4c397b29..bfd8477411 100644 --- a/cpu/stm32f1/periph/uart.c +++ b/cpu/stm32f1/periph/uart.c @@ -29,11 +29,6 @@ #include "sched.h" #include "thread.h" -#ifdef MODULE_UART0 -#include "board_uart0.h" -#endif - - /** * @brief Each UART device has to store two callbacks. */ @@ -296,28 +291,17 @@ static inline void irq_handler(uint8_t uartnum, USART_TypeDef *dev) { if (dev->SR & USART_SR_RXNE) { char data = (char)dev->DR; -#ifdef MODULE_UART0 - if (uart0_handler_pid) { - uart0_handle_incoming(data); - - uart0_notify_thread(); - } -#else config[uartnum].rx_cb(config[uartnum].arg, data); -#endif } else if (dev->SR & USART_SR_ORE) { /* ORE is cleared by reading SR and DR sequentially */ dev->DR; } else if (dev->SR & USART_SR_TXE) { -#ifdef MODULE_UART0 - dev->SR &= ~(USART_SR_TXE); -#else - config[uartnum].tx_cb(config[uartnum].arg); -#endif + if (config[uartnum].tx_cb(config[uartnum].arg) == 0) { + dev->CR1 &= ~(USART_CR1_TXEIE); + } } - if (sched_context_switch_request) { thread_yield(); } diff --git a/cpu/stm32f1/syscalls.c b/cpu/stm32f1/syscalls.c index c7962b99e2..0a3a47d396 100644 --- a/cpu/stm32f1/syscalls.c +++ b/cpu/stm32f1/syscalls.c @@ -28,28 +28,62 @@ #include #include +#include "board.h" #include "thread.h" #include "kernel.h" +#include "mutex.h" +#include "ringbuffer.h" #include "irq.h" #include "periph/uart.h" +#ifdef MODULE_UART0 +#include "board_uart0.h" +#endif + /** * manage the heap */ extern uint32_t _end; /* address of last used memory cell */ caddr_t heap_top = (caddr_t)&_end + 4; +#ifndef MODULE_UART0 +/** + * @brief use mutex for waiting on incoming UART chars + */ +static mutex_t uart_rx_mutex; +static char rx_buf_mem[STDIO_BUFSIZE]; +static ringbuffer_t rx_buf; +#endif + +/** + * @brief Receive a new character from the UART and put it into the receive buffer + */ +void rx_cb(void *arg, char data) +{ +#ifndef MODULE_UART0 + (void)arg; + + ringbuffer_add_one(&rx_buf, data); + mutex_unlock(&uart_rx_mutex); +#else + if (uart0_handler_pid) { + uart0_handle_incoming(data); + + uart0_notify_thread(); + } +#endif +} /** * @brief Initialize NewLib, called by __libc_init_array() from the startup script */ void _init(void) { -#ifdef MODULE_UART0 - uart_init(UART_0, 115200, NULL, NULL, NULL); -#else - uart_init_blocking(UART_0, 115200); +#ifndef MODULE_UART0 + mutex_init(&uart_rx_mutex); + ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_BUFSIZE); #endif + uart_init(STDIO, STDIO_BAUDRATE, rx_cb, 0, 0); } /** @@ -155,11 +189,15 @@ int _open_r(struct _reent *r, const char *name, int mode) */ int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count) { - char c; - char *buff = (char*)buffer; - uart_read_blocking(UART_0, &c); - buff[0] = c; - return 1; +#ifndef MODULE_UART0 + while (rx_buf.avail == 0) { + mutex_lock(&uart_rx_mutex); + } + return ringbuffer_get(&rx_buf, (char*)buffer, rx_buf.avail); +#else + r->_errno = ENODEV; + return -1; +#endif } /** diff --git a/cpu/stm32f4/Makefile.include b/cpu/stm32f4/Makefile.include index 511a37959b..bb97cdfef0 100644 --- a/cpu/stm32f4/Makefile.include +++ b/cpu/stm32f4/Makefile.include @@ -4,6 +4,9 @@ export CFLAGS += -DCOREIF_NG=1 # export the peripheral drivers to be linked into the final binary export USEMODULE += periph +# this CPU implementation makes use of the ringbuffer, so include the lib module +export USEMODULE += lib + # tell the build system that the CPU depends on the Cortex-M common files export USEMODULE += cortex-m4_common diff --git a/cpu/stm32f4/syscalls.c b/cpu/stm32f4/syscalls.c index 524bab4436..25fb668c96 100644 --- a/cpu/stm32f4/syscalls.c +++ b/cpu/stm32f4/syscalls.c @@ -31,6 +31,8 @@ #include "board.h" #include "thread.h" #include "kernel.h" +#include "mutex.h" +#include "ringbuffer.h" #include "irq.h" #include "periph/uart.h" From d0b0af6d8103b4b66eae98940f59ceca4b27ba40 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Thu, 25 Sep 2014 17:39:55 +0200 Subject: [PATCH 5/5] stm32f*: rename STDIO buffer and enable getchar with UART0 --- boards/iot-lab_M3/include/board.h | 2 +- boards/msbiot/include/board.h | 2 +- boards/stm32f0discovery/include/board.h | 2 +- boards/stm32f3discovery/include/board.h | 2 +- boards/stm32f4discovery/include/board.h | 2 +- cpu/stm32f0/syscalls.c | 9 +++++---- cpu/stm32f1/syscalls.c | 9 +++++---- cpu/stm32f3/syscalls.c | 9 +++++---- cpu/stm32f4/syscalls.c | 8 ++++++-- 9 files changed, 26 insertions(+), 19 deletions(-) diff --git a/boards/iot-lab_M3/include/board.h b/boards/iot-lab_M3/include/board.h index 4665e2bf16..8e35ded673 100644 --- a/boards/iot-lab_M3/include/board.h +++ b/boards/iot-lab_M3/include/board.h @@ -39,7 +39,7 @@ */ #define STDIO UART_0 #define STDIO_BAUDRATE (115200U) -#define STDIO_BUFSIZE (64U) +#define STDIO_RX_BUFSIZE (64U) /** @} */ /** diff --git a/boards/msbiot/include/board.h b/boards/msbiot/include/board.h index 733052f2d9..0b6034a9f9 100644 --- a/boards/msbiot/include/board.h +++ b/boards/msbiot/include/board.h @@ -40,7 +40,7 @@ */ #define STDIO UART_0 #define STDIO_BAUDRATE (115200U) -#define STDIO_BUFSIZE (64U) +#define STDIO_RX_BUFSIZE (64U) /** @} */ /** diff --git a/boards/stm32f0discovery/include/board.h b/boards/stm32f0discovery/include/board.h index 556fe1f7ff..355776edf4 100644 --- a/boards/stm32f0discovery/include/board.h +++ b/boards/stm32f0discovery/include/board.h @@ -39,7 +39,7 @@ */ #define STDIO UART_0 #define STDIO_BAUDRATE (115200U) -#define STDIO_BUFSIZE (64U) +#define STDIO_RX_BUFSIZE (64U) /** * @name LED pin definitions diff --git a/boards/stm32f3discovery/include/board.h b/boards/stm32f3discovery/include/board.h index 7918d0f393..0f071217be 100644 --- a/boards/stm32f3discovery/include/board.h +++ b/boards/stm32f3discovery/include/board.h @@ -39,7 +39,7 @@ */ #define STDIO UART_0 #define STDIO_BAUDRATE (115200U) -#define STDIO_BUFSIZE (64U) +#define STDIO_RX_BUFSIZE (64U) /** @} */ /** diff --git a/boards/stm32f4discovery/include/board.h b/boards/stm32f4discovery/include/board.h index 294a815564..0b0195b0a4 100644 --- a/boards/stm32f4discovery/include/board.h +++ b/boards/stm32f4discovery/include/board.h @@ -40,7 +40,7 @@ */ #define STDIO UART_0 #define STDIO_BAUDRATE (115200U) -#define STDIO_BUFSIZE (64U) +#define STDIO_RX_BUFSIZE (64U) /** @} */ /** diff --git a/cpu/stm32f0/syscalls.c b/cpu/stm32f0/syscalls.c index fbddea6576..1f0787e8eb 100644 --- a/cpu/stm32f0/syscalls.c +++ b/cpu/stm32f0/syscalls.c @@ -51,7 +51,7 @@ caddr_t heap_top = (caddr_t)&_end + 4; * @brief use mutex for waiting on incoming UART chars */ static mutex_t uart_rx_mutex; -static char rx_buf_mem[STDIO_BUFSIZE]; +static char rx_buf_mem[STDIO_RX_BUFSIZE]; static ringbuffer_t rx_buf; #endif @@ -81,7 +81,7 @@ void _init(void) { #ifndef MODULE_UART0 mutex_init(&uart_rx_mutex); - ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_BUFSIZE); + ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_RX_BUFSIZE); #endif uart_init(STDIO, STDIO_BAUDRATE, rx_cb, 0, 0); } @@ -195,8 +195,9 @@ int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count) } return ringbuffer_get(&rx_buf, (char*)buffer, rx_buf.avail); #else - r->_errno = ENODEV; - return -1; + char *res = (char*)buffer; + res[0] = (char)uart0_readc(); + return 1; #endif } diff --git a/cpu/stm32f1/syscalls.c b/cpu/stm32f1/syscalls.c index 0a3a47d396..247caa4bb5 100644 --- a/cpu/stm32f1/syscalls.c +++ b/cpu/stm32f1/syscalls.c @@ -51,7 +51,7 @@ caddr_t heap_top = (caddr_t)&_end + 4; * @brief use mutex for waiting on incoming UART chars */ static mutex_t uart_rx_mutex; -static char rx_buf_mem[STDIO_BUFSIZE]; +static char rx_buf_mem[STDIO_RX_BUFSIZE]; static ringbuffer_t rx_buf; #endif @@ -81,7 +81,7 @@ void _init(void) { #ifndef MODULE_UART0 mutex_init(&uart_rx_mutex); - ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_BUFSIZE); + ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_RX_BUFSIZE); #endif uart_init(STDIO, STDIO_BAUDRATE, rx_cb, 0, 0); } @@ -195,8 +195,9 @@ int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count) } return ringbuffer_get(&rx_buf, (char*)buffer, rx_buf.avail); #else - r->_errno = ENODEV; - return -1; + char *res = (char*)buffer; + res[0] = (char)uart0_readc(); + return 1; #endif } diff --git a/cpu/stm32f3/syscalls.c b/cpu/stm32f3/syscalls.c index 3f5ee6c85d..4f89a0e7e3 100644 --- a/cpu/stm32f3/syscalls.c +++ b/cpu/stm32f3/syscalls.c @@ -52,7 +52,7 @@ caddr_t heap_top = (caddr_t)&_end + 4; * @brief use mutex for waiting on incoming UART chars */ static mutex_t uart_rx_mutex; -static char rx_buf_mem[STDIO_BUFSIZE]; +static char rx_buf_mem[STDIO_RX_BUFSIZE]; static ringbuffer_t rx_buf; #endif @@ -82,7 +82,7 @@ void _init(void) { #ifndef MODULE_UART0 mutex_init(&uart_rx_mutex); - ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_BUFSIZE); + ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_RX_BUFSIZE); #endif uart_init(STDIO, STDIO_BAUDRATE, rx_cb, 0, 0);} @@ -195,8 +195,9 @@ int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count) } return ringbuffer_get(&rx_buf, (char*)buffer, rx_buf.avail); #else - r->_errno = ENODEV; - return -1; + char *res = (char*)buffer; + res[0] = (char)uart0_readc(); + return 1; #endif } diff --git a/cpu/stm32f4/syscalls.c b/cpu/stm32f4/syscalls.c index 25fb668c96..2d4508ca3f 100644 --- a/cpu/stm32f4/syscalls.c +++ b/cpu/stm32f4/syscalls.c @@ -51,7 +51,7 @@ caddr_t heap_top = (caddr_t)&_end + 4; * @brief use mutex for waiting on incoming UART chars */ static mutex_t uart_rx_mutex; -static char rx_buf_mem[STDIO_BUFSIZE]; +static char rx_buf_mem[STDIO_RX_BUFSIZE]; static ringbuffer_t rx_buf; #endif @@ -81,7 +81,7 @@ void _init(void) { #ifndef MODULE_UART0 mutex_init(&uart_rx_mutex); - ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_BUFSIZE); + ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_RX_BUFSIZE); #endif uart_init(STDIO, STDIO_BAUDRATE, rx_cb, 0, 0); } @@ -194,6 +194,10 @@ int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count) mutex_lock(&uart_rx_mutex); } return ringbuffer_get(&rx_buf, (char*)buffer, rx_buf.avail); +#else + char *res = (char*)buffer; + res[0] = (char)uart0_readc(); + return 1; #endif }