From d0b0af6d8103b4b66eae98940f59ceca4b27ba40 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger <thomas.eichinger1@gmail.com> Date: Thu, 25 Sep 2014 17:39:55 +0200 Subject: [PATCH] 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 } -- GitLab