From ca06df793a78da0a8cdf1c6c65e1f73121faddfa Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 12 Apr 2019 20:20:16 +0900 Subject: [PATCH] Add example-usart, which works well with ST Nucleo L432. --- example-usart/sample.c | 26 +++++++++++++++++++++++--- example-usart/stack-def.h | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/example-usart/sample.c b/example-usart/sample.c index 8e517ff..8186f11 100644 --- a/example-usart/sample.c +++ b/example-usart/sample.c @@ -103,6 +103,10 @@ ss_notify (uint8_t dev_no, uint16_t state_bits) int main (int argc, const char *argv[]) { + chopstx_poll_cond_t poll_desc; + uint32_t timeout; + struct chx_poll_head *ph[1]; + (void)argc; (void)argv; @@ -125,11 +129,27 @@ main (int argc, const char *argv[]) usart_init (PRIO_USART, STACK_ADDR_USART, STACK_SIZE_USART, ss_notify); usart_config (2, B115200 | CS8 | STOP1B); + usart_read_prepare_poll (2, &poll_desc); + ph[0] = (struct chx_poll_head *)&poll_desc; + + timeout = 200*1000*6; while (1) { - u ^= 1; - wait_for (200*1000*6); - usart_write (2, "Hello\r\n", 7); + chopstx_poll (&timeout, 1, ph); + if (timeout == 0) + { + usart_write (2, "Hello\r\n", 7); + u ^= 1; + timeout = 200*1000*6; + } + else + { + char buf[256]; + int r; + r = usart_read (2, buf, 256); + if (r) + usart_write (2, buf, r); + } } return 0; diff --git a/example-usart/stack-def.h b/example-usart/stack-def.h index fb9ace6..75119c4 100644 --- a/example-usart/stack-def.h +++ b/example-usart/stack-def.h @@ -1,5 +1,5 @@ #define MAIN_SIZE 0x0080 /* Idle+Exception handlers */ -#define SIZE_0 0x0200 /* Main program */ +#define SIZE_0 0x0300 /* Main program */ #define SIZE_1 0x0100 /* first thread program */ #define SIZE_2 0x0100 /* second thread program */ #define SIZE_3 0x0200 /* third thread program */