summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2026-04-04 21:32:39 +0700
committerhathach <[email protected]>2026-04-04 21:32:39 +0700
commit9838a231ad9bff623a3ec819d05aad4a4087193b (patch)
tree1c01f46f96780feb96c2a8a036a38a8eabb64666
parent3c6c87479be6a9fdd04240b8bb1267ef80b1a0e8 (diff)
make board_uart_read()/write() return -1 when unimplemented for consistency across all families
-rw-r--r--.claude/commands/hil.md18
-rw-r--r--hw/bsp/board.c19
-rw-r--r--hw/bsp/da1469x/family.c4
-rw-r--r--hw/bsp/efm32/family.c4
-rw-r--r--hw/bsp/lpc11/family.c4
-rw-r--r--hw/bsp/lpc13/family.c4
-rw-r--r--hw/bsp/lpc17/family.c57
-rw-r--r--hw/bsp/lpc40/family.c4
-rw-r--r--hw/bsp/lpc51/family.c4
-rw-r--r--hw/bsp/lpc54/family.c4
-rw-r--r--hw/bsp/lpc55/family.c4
-rw-r--r--hw/bsp/mcx/family.c4
-rw-r--r--hw/bsp/nrf/family.c2
-rw-r--r--hw/bsp/nuc100_120/family.c4
-rw-r--r--hw/bsp/nuc121_125/family.c4
-rw-r--r--hw/bsp/nuc126/family.c4
-rw-r--r--hw/bsp/nuc505/family.c4
-rw-r--r--hw/bsp/pic32mz/family.c2
-rw-r--r--hw/bsp/ra/family.c4
-rw-r--r--hw/bsp/rw61x/family.c4
-rw-r--r--hw/bsp/samd11/family.c4
-rw-r--r--hw/bsp/samd2x_l2x/family.c6
-rw-r--r--hw/bsp/samd5x_e5x/family.c4
-rw-r--r--hw/bsp/same7x/family.c2
-rw-r--r--test/hil/tinyusb.json16
25 files changed, 100 insertions, 90 deletions
diff --git a/.claude/commands/hil.md b/.claude/commands/hil.md
index 266321bb9..07e1a865b 100644
--- a/.claude/commands/hil.md
+++ b/.claude/commands/hil.md
@@ -7,27 +7,21 @@ Run Hardware-in-the-Loop (HIL) tests on physical boards.
## Instructions
-1. Determine the HIL config file:
- ```bash
- HIL_CONFIG=$( (systemctl list-units --type=service --state=running 2>/dev/null; systemctl --user list-units --type=service --state=running 2>/dev/null) | grep -q 'actions\.runner' && echo tinyusb.json || echo local.json )
- ```
- Default is `local.json` for local development.
-
-2. Parse $ARGUMENTS:
+1. Parse $ARGUMENTS:
- If $ARGUMENTS contains `-b BOARD_NAME`, run for that specific board only.
- If $ARGUMENTS is empty or has no `-b`, run for all boards in the config.
- Pass through any other flags (e.g. `-v` for verbose, `-r N` for retry count) directly to the command.
-3. Determine whether to run **locally** or **remotely via SSH**:
+2. Determine whether to run **locally** or **remotely via SSH**:
- **Local**: boards are attached to this machine (default when `local.json` is used)
- **Remote (`ssh ci.lan`)**: boards are attached to the CI machine (when `tinyusb.json` is used)
-4. **Local execution** (boards attached to this machine):
+3. **Local execution** (boards attached to this machine):
```bash
python test/hil/hil_test.py -b BOARD_NAME -B examples $HIL_CONFIG $EXTRA_ARGS
```
-5. **Remote execution** (boards attached to `ci.lan`):
+4. **Remote execution** (boards attached to `ci.lan`):
Only copy the minimal files needed (firmware binaries + test script + config), then run remotely.
```bash
@@ -56,9 +50,9 @@ Run Hardware-in-the-Loop (HIL) tests on physical boards.
- Flasher tools: `JLinkExe`, `openocd`, etc. as needed by the board
- USB access to the boards (udev rules configured)
-6. Use a timeout of at least 20 minutes (600000ms). HIL tests take 2-5 minutes. NEVER cancel early.
+5. Use a timeout of at least 20 minutes (600000ms). HIL tests take 2-5 minutes. NEVER cancel early.
-7. After the test completes:
+6. After the test completes:
- Show the test output to the user.
- Summarize pass/fail results per board.
- If there are failures, suggest re-running with `-v` flag for verbose output to help debug.
diff --git a/hw/bsp/board.c b/hw/bsp/board.c
index 1c159189c..ae58bb5fc 100644
--- a/hw/bsp/board.c
+++ b/hw/bsp/board.c
@@ -97,17 +97,22 @@ int sys_read (int fhdl, char *buf, size_t count) {
#else
// Default logging with on-board UART
-// Retry to ensure printf/log output is not lost when board_uart_write is non-blocking
+// board_uart_write() is non-blocking, retry until all bytes sent.
+// Returns negative if UART is not available (stub), break immediately.
int sys_write (int fhdl, const char *buf, size_t count) {
(void) fhdl;
- int written = 0;
- while ((size_t)written < count) {
- int wr = board_uart_write(buf + written, (int)(count - (size_t)written));
- if (wr > 0) {
- written += wr;
+ size_t written = 0;
+ while (written < count) {
+ int wr = board_uart_write(buf + written, (int)(count - written));
+ if (wr < 0) {
+ break; // UART not available
}
+ if (wr == 0) {
+ continue; // TX busy, keep trying
+ }
+ written += (size_t) wr;
}
- return written;
+ return (int) written;
}
int sys_read (int fhdl, char *buf, size_t count) {
diff --git a/hw/bsp/da1469x/family.c b/hw/bsp/da1469x/family.c
index a4f7f2e8d..5f7e2d42f 100644
--- a/hw/bsp/da1469x/family.c
+++ b/hw/bsp/da1469x/family.c
@@ -123,14 +123,14 @@ uint32_t board_button_read(void) {
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
#if CFG_TUSB_OS == OPT_OS_NONE
diff --git a/hw/bsp/efm32/family.c b/hw/bsp/efm32/family.c
index d318e20d6..7a5ea6a74 100644
--- a/hw/bsp/efm32/family.c
+++ b/hw/bsp/efm32/family.c
@@ -673,13 +673,13 @@ uint32_t board_button_read(void)
int board_uart_read(uint8_t* buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const * buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
#if CFG_TUSB_OS == OPT_OS_NONE
diff --git a/hw/bsp/lpc11/family.c b/hw/bsp/lpc11/family.c
index 76c2bd17c..06b74bcd7 100644
--- a/hw/bsp/lpc11/family.c
+++ b/hw/bsp/lpc11/family.c
@@ -114,13 +114,13 @@ uint32_t board_button_read(void) {
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
#if CFG_TUSB_OS == OPT_OS_NONE
diff --git a/hw/bsp/lpc13/family.c b/hw/bsp/lpc13/family.c
index 8513f4df4..e25449689 100644
--- a/hw/bsp/lpc13/family.c
+++ b/hw/bsp/lpc13/family.c
@@ -101,11 +101,11 @@ uint32_t board_button_read(void) {
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
diff --git a/hw/bsp/lpc17/family.c b/hw/bsp/lpc17/family.c
index f398f7e3c..6b94c1163 100644
--- a/hw/bsp/lpc17/family.c
+++ b/hw/bsp/lpc17/family.c
@@ -64,29 +64,13 @@ void board_init(void) {
Chip_GPIO_SetPinDIROutput(LPC_GPIO, LED_PORT, LED_PIN);
Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_PORT, BUTTON_PIN);
-#if 0
//------------- UART -------------//
- PINSEL_CFG_Type PinCfg =
- {
- .Portnum = 0,
- .Pinnum = 0, // TXD is P0.0
- .Funcnum = 2,
- .OpenDrain = 0,
- .Pinmode = 0
- };
- PINSEL_ConfigPin(&PinCfg);
-
- PinCfg.Portnum = 0;
- PinCfg.Pinnum = 1; // RXD is P0.1
- PINSEL_ConfigPin(&PinCfg);
-
- UART_CFG_Type UARTConfigStruct;
- UART_ConfigStructInit(&UARTConfigStruct);
- UARTConfigStruct.Baud_rate = CFG_BOARD_UART_BAUDRATE;
-
- UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
- UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
-#endif
+ // Pin muxing for UART3 (TXD3=P0.0, RXD3=P0.1) is configured in board.h pinmuxing[]
+ Chip_UART_Init(BOARD_UART_PORT);
+ Chip_UART_SetBaud(BOARD_UART_PORT, CFG_BOARD_UART_BAUDRATE);
+ Chip_UART_ConfigData(BOARD_UART_PORT, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS));
+ Chip_UART_SetupFIFOS(BOARD_UART_PORT, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0));
+ Chip_UART_TXEnable(BOARD_UART_PORT);
//------------- USB -------------//
Chip_IOCON_SetPinMuxing(LPC_IOCON, pin_usb_mux, sizeof(pin_usb_mux) / sizeof(PINMUX_GRP_T));
@@ -125,17 +109,30 @@ 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;
+ int count = 0;
+ while (count < len) {
+ if (BOARD_UART_PORT->LSR & UART_LSR_RDR) {
+ buf[count] = (uint8_t) BOARD_UART_PORT->RBR;
+ count++;
+ } else {
+ break;
+ }
+ }
+ return count;
}
int board_uart_write(void const* buf, int len) {
-// UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
- (void) buf;
- (void) len;
- return 0;
+ const uint8_t *p = (const uint8_t *) buf;
+ int count = 0;
+ while (count < len) {
+ if (BOARD_UART_PORT->LSR & UART_LSR_THRE) {
+ BOARD_UART_PORT->THR = p[count];
+ count++;
+ } else {
+ break;
+ }
+ }
+ return count;
}
#if CFG_TUSB_OS == OPT_OS_NONE
diff --git a/hw/bsp/lpc40/family.c b/hw/bsp/lpc40/family.c
index 237cd996b..d8a63576b 100644
--- a/hw/bsp/lpc40/family.c
+++ b/hw/bsp/lpc40/family.c
@@ -139,14 +139,14 @@ int board_uart_read(uint8_t *buf, int len) {
//return UART_ReceiveByte(BOARD_UART_PORT);
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const *buf, int len) {
//UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
(void) buf;
(void) len;
- return 0;
+ return -1;
}
#if CFG_TUSB_OS == OPT_OS_NONE
diff --git a/hw/bsp/lpc51/family.c b/hw/bsp/lpc51/family.c
index 847972350..57c3e26dd 100644
--- a/hw/bsp/lpc51/family.c
+++ b/hw/bsp/lpc51/family.c
@@ -106,13 +106,13 @@ uint32_t board_button_read(void) {
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
#if CFG_TUSB_OS == OPT_OS_NONE
diff --git a/hw/bsp/lpc54/family.c b/hw/bsp/lpc54/family.c
index 129f9f0ec..5a5087e56 100644
--- a/hw/bsp/lpc54/family.c
+++ b/hw/bsp/lpc54/family.c
@@ -224,7 +224,7 @@ uint32_t board_button_read(void) {
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const* buf, int len) {
@@ -243,7 +243,7 @@ int board_uart_write(void const* buf, int len) {
#else
(void) buf;
(void) len;
- return 0;
+ return -1;
#endif
}
diff --git a/hw/bsp/lpc55/family.c b/hw/bsp/lpc55/family.c
index b9d856f86..e021caf35 100644
--- a/hw/bsp/lpc55/family.c
+++ b/hw/bsp/lpc55/family.c
@@ -173,7 +173,7 @@ uint32_t board_button_read(void) {
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const* buf, int len) {
@@ -192,7 +192,7 @@ int board_uart_write(void const* buf, int len) {
#else
(void) buf;
(void) len;
- return 0;
+ return -1;
#endif
}
diff --git a/hw/bsp/mcx/family.c b/hw/bsp/mcx/family.c
index f50a65120..2facfb1e0 100644
--- a/hw/bsp/mcx/family.c
+++ b/hw/bsp/mcx/family.c
@@ -199,7 +199,7 @@ uint32_t board_button_read(void) {
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const* buf, int len) {
@@ -217,7 +217,7 @@ int board_uart_write(void const* buf, int len) {
return count;
#else
(void) buf; (void) len;
- return 0;
+ return -1;
#endif
}
diff --git a/hw/bsp/nrf/family.c b/hw/bsp/nrf/family.c
index 04bfbf320..f1e8b829c 100644
--- a/hw/bsp/nrf/family.c
+++ b/hw/bsp/nrf/family.c
@@ -274,7 +274,7 @@ size_t board_get_unique_id(uint8_t id[], size_t max_len) {
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
// nrfx_err_t err = nrfx_uarte_rx(&_uart_id, buf, (size_t) len);
// return NRFX_SUCCESS == err ? len : 0;
}
diff --git a/hw/bsp/nuc100_120/family.c b/hw/bsp/nuc100_120/family.c
index cfe60121c..4ff24aae7 100644
--- a/hw/bsp/nuc100_120/family.c
+++ b/hw/bsp/nuc100_120/family.c
@@ -120,11 +120,11 @@ uint32_t board_button_read(void)
int board_uart_read(uint8_t* buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const * buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
diff --git a/hw/bsp/nuc121_125/family.c b/hw/bsp/nuc121_125/family.c
index dce5b4d62..9dd3c71fc 100644
--- a/hw/bsp/nuc121_125/family.c
+++ b/hw/bsp/nuc121_125/family.c
@@ -109,11 +109,11 @@ uint32_t board_button_read(void)
int board_uart_read(uint8_t* buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const * buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
diff --git a/hw/bsp/nuc126/family.c b/hw/bsp/nuc126/family.c
index 3343064e5..663bffbe7 100644
--- a/hw/bsp/nuc126/family.c
+++ b/hw/bsp/nuc126/family.c
@@ -134,11 +134,11 @@ uint32_t board_button_read(void)
int board_uart_read(uint8_t* buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const * buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
diff --git a/hw/bsp/nuc505/family.c b/hw/bsp/nuc505/family.c
index f1a77e4a5..41f6017c2 100644
--- a/hw/bsp/nuc505/family.c
+++ b/hw/bsp/nuc505/family.c
@@ -117,11 +117,11 @@ uint32_t board_button_read(void)
int board_uart_read(uint8_t* buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const * buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
diff --git a/hw/bsp/pic32mz/family.c b/hw/bsp/pic32mz/family.c
index 2bfc876e1..5805e653f 100644
--- a/hw/bsp/pic32mz/family.c
+++ b/hw/bsp/pic32mz/family.c
@@ -96,7 +96,7 @@ TU_ATTR_WEAK int board_uart_read(uint8_t * buf, int len)
(void) buf;
(void) len;
- return 0;
+ return -1;
}
TU_ATTR_WEAK int board_uart_write(void const * buf, int len)
diff --git a/hw/bsp/ra/family.c b/hw/bsp/ra/family.c
index f371e694b..c8a4d33d9 100644
--- a/hw/bsp/ra/family.c
+++ b/hw/bsp/ra/family.c
@@ -153,13 +153,13 @@ size_t board_get_unique_id(uint8_t id[], size_t max_len) {
int board_uart_read(uint8_t *buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const *buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
#if CFG_TUSB_OS == OPT_OS_NONE
diff --git a/hw/bsp/rw61x/family.c b/hw/bsp/rw61x/family.c
index 951c266ea..5d7bd4754 100644
--- a/hw/bsp/rw61x/family.c
+++ b/hw/bsp/rw61x/family.c
@@ -108,7 +108,7 @@ uint32_t board_button_read(void) {
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const* buf, int len) {
@@ -126,7 +126,7 @@ int board_uart_write(void const* buf, int len) {
return count;
#else
(void) buf; (void) len;
- return 0;
+ return -1;
#endif
}
diff --git a/hw/bsp/samd11/family.c b/hw/bsp/samd11/family.c
index bccbac8ea..0c987b85a 100644
--- a/hw/bsp/samd11/family.c
+++ b/hw/bsp/samd11/family.c
@@ -137,13 +137,13 @@ uint32_t board_button_read(void)
int board_uart_read(uint8_t* buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const * buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
#if CFG_TUSB_OS == OPT_OS_NONE
diff --git a/hw/bsp/samd2x_l2x/family.c b/hw/bsp/samd2x_l2x/family.c
index 737219b6c..11b6343cd 100644
--- a/hw/bsp/samd2x_l2x/family.c
+++ b/hw/bsp/samd2x_l2x/family.c
@@ -322,7 +322,7 @@ static inline void uart_send_str(const char* text)
int board_uart_read(uint8_t* buf, int len)
{
(void) buf; (void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const * buf, int len)
@@ -343,13 +343,13 @@ static void uart_init(void) {
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
#endif
diff --git a/hw/bsp/samd5x_e5x/family.c b/hw/bsp/samd5x_e5x/family.c
index c008b9719..71ef2d6ce 100644
--- a/hw/bsp/samd5x_e5x/family.c
+++ b/hw/bsp/samd5x_e5x/family.c
@@ -194,13 +194,13 @@ size_t board_get_unique_id(uint8_t id[], size_t max_len) {
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const* buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
#if CFG_TUSB_OS == OPT_OS_NONE
diff --git a/hw/bsp/same7x/family.c b/hw/bsp/same7x/family.c
index 61c1792d1..d02e6c5f1 100644
--- a/hw/bsp/same7x/family.c
+++ b/hw/bsp/same7x/family.c
@@ -133,7 +133,7 @@ uint32_t board_button_read(void) {
int board_uart_read(uint8_t *buf, int len) {
(void) buf;
(void) len;
- return 0;
+ return -1;
}
int board_uart_write(void const *buf, int len) {
diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json
index b9c768d14..3c03b3721 100644
--- a/test/hil/tinyusb.json
+++ b/test/hil/tinyusb.json
@@ -177,7 +177,21 @@
"uid": "560AE75E1C7152C9",
"tests": {
"device": false, "host": true, "dual": false,
- "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002694", "is_cdc": true}]
+ "dev_attached": [
+ {
+ "vid_pid": "1a86_55d4",
+ "serial": "52D2002694",
+ "is_cdc": true
+ },
+ {
+ "vid_pid": "0951_1603",
+ "serial": "820000000000000045B46338",
+ "is_msc": true,
+ "block_size": 512,
+ "block_count": 3987456,
+ "msc_inquiry": "Kingston DataTraveler 2.0 1.0"
+ }
+ ]
},
"flasher": {
"name": "openocd",