diff --git a/examples/device/board_test/src/main.c b/examples/device/board_test/src/main.c index 5e28cbb27..74beda55f 100644 --- a/examples/device/board_test/src/main.c +++ b/examples/device/board_test/src/main.c @@ -56,7 +56,7 @@ int main(void) { uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED; - // Blink every interval ms + // Blink and print every interval ms if ( !(board_millis() - start_ms < interval_ms) ) { board_uart_write(HELLO_STR, strlen(HELLO_STR)); @@ -66,6 +66,13 @@ int main(void) board_led_write(led_state); led_state = 1 - led_state; // toggle } + + // echo + uint8_t ch; + if ( board_uart_read(&ch, 1) ) + { + board_uart_write(&ch, 1); + } } return 0; diff --git a/hw/bsp/board.c b/hw/bsp/board.c index e208624ba..a22b462d9 100644 --- a/hw/bsp/board.c +++ b/hw/bsp/board.c @@ -103,7 +103,8 @@ TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count) TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count) { (void) fhdl; - return SEGGER_RTT_Read(0, buf, count); + int rd = (int) SEGGER_RTT_Read(0, buf, count); + return (rd > 0) ? rd : -1; } #endif @@ -143,7 +144,8 @@ TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count) TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count) { (void) fhdl; - return board_uart_read((uint8_t*) buf, (int) count); + int rd = board_uart_read((uint8_t*) buf, (int) count); + return (rd > 0) ? rd : -1; } #endif diff --git a/hw/bsp/board.h b/hw/bsp/board.h index 339e2e3b5..0826d7786 100644 --- a/hw/bsp/board.h +++ b/hw/bsp/board.h @@ -66,9 +66,11 @@ void board_led_write(bool state); uint32_t board_button_read(void); // Get characters from UART +// Return number of read bytes int board_uart_read(uint8_t* buf, int len); // Send characters to UART +// Return number of sent bytes int board_uart_write(void const * buf, int len); #if CFG_TUSB_OS == OPT_OS_NONE diff --git a/hw/bsp/ea4357/ea4357.c b/hw/bsp/ea4357/ea4357.c index 2c1d08770..f88d3b89e 100644 --- a/hw/bsp/ea4357/ea4357.c +++ b/hw/bsp/ea4357/ea4357.c @@ -272,9 +272,7 @@ uint32_t board_button_read(void) int board_uart_read(uint8_t* buf, int len) { - //return UART_ReceiveByte(BOARD_UART_DEV); - (void) buf; (void) len; - return 0; + return Chip_UART_Read(UART_DEV, buf, len); } int board_uart_write(void const * buf, int len) diff --git a/hw/bsp/lpc18/family.c b/hw/bsp/lpc18/family.c index 0fc788873..72c20e034 100644 --- a/hw/bsp/lpc18/family.c +++ b/hw/bsp/lpc18/family.c @@ -141,9 +141,7 @@ uint32_t board_button_read(void) int board_uart_read(uint8_t* buf, int len) { - //return UART_ReceiveByte(BOARD_UART_PORT); - (void) buf; (void) len; - return 0; + return Chip_UART_Read(UART_DEV, buf, len); } int board_uart_write(void const * buf, int len) diff --git a/hw/bsp/rp2040/board.h b/hw/bsp/rp2040/board.h index 56b8fec84..f25f80e09 100644 --- a/hw/bsp/rp2040/board.h +++ b/hw/bsp/rp2040/board.h @@ -52,7 +52,7 @@ #endif // VBUS enable pin and its active state -// #define PIO_USB_VBUSEN_PIN 22 +#define PIO_USB_VBUSEN_PIN 22 #ifndef PIO_USB_VBUSEN_STATE #define PIO_USB_VBUSEN_STATE 1