Skip to content

Commit 9838a23

Browse files
committed
make board_uart_read()/write() return -1 when unimplemented for consistency across all families
1 parent 3c6c874 commit 9838a23

File tree

25 files changed

+100
-90
lines changed

25 files changed

+100
-90
lines changed

.claude/commands/hil.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,21 @@ Run Hardware-in-the-Loop (HIL) tests on physical boards.
77

88
## Instructions
99

10-
1. Determine the HIL config file:
11-
```bash
12-
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 )
13-
```
14-
Default is `local.json` for local development.
15-
16-
2. Parse $ARGUMENTS:
10+
1. Parse $ARGUMENTS:
1711
- If $ARGUMENTS contains `-b BOARD_NAME`, run for that specific board only.
1812
- If $ARGUMENTS is empty or has no `-b`, run for all boards in the config.
1913
- Pass through any other flags (e.g. `-v` for verbose, `-r N` for retry count) directly to the command.
2014

21-
3. Determine whether to run **locally** or **remotely via SSH**:
15+
2. Determine whether to run **locally** or **remotely via SSH**:
2216
- **Local**: boards are attached to this machine (default when `local.json` is used)
2317
- **Remote (`ssh ci.lan`)**: boards are attached to the CI machine (when `tinyusb.json` is used)
2418

25-
4. **Local execution** (boards attached to this machine):
19+
3. **Local execution** (boards attached to this machine):
2620
```bash
2721
python test/hil/hil_test.py -b BOARD_NAME -B examples $HIL_CONFIG $EXTRA_ARGS
2822
```
2923

30-
5. **Remote execution** (boards attached to `ci.lan`):
24+
4. **Remote execution** (boards attached to `ci.lan`):
3125
Only copy the minimal files needed (firmware binaries + test script + config), then run remotely.
3226

3327
```bash
@@ -56,9 +50,9 @@ Run Hardware-in-the-Loop (HIL) tests on physical boards.
5650
- Flasher tools: `JLinkExe`, `openocd`, etc. as needed by the board
5751
- USB access to the boards (udev rules configured)
5852

59-
6. Use a timeout of at least 20 minutes (600000ms). HIL tests take 2-5 minutes. NEVER cancel early.
53+
5. Use a timeout of at least 20 minutes (600000ms). HIL tests take 2-5 minutes. NEVER cancel early.
6054

61-
7. After the test completes:
55+
6. After the test completes:
6256
- Show the test output to the user.
6357
- Summarize pass/fail results per board.
6458
- If there are failures, suggest re-running with `-v` flag for verbose output to help debug.

hw/bsp/board.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,22 @@ int sys_read (int fhdl, char *buf, size_t count) {
9797
#else
9898

9999
// Default logging with on-board UART
100-
// Retry to ensure printf/log output is not lost when board_uart_write is non-blocking
100+
// board_uart_write() is non-blocking, retry until all bytes sent.
101+
// Returns negative if UART is not available (stub), break immediately.
101102
int sys_write (int fhdl, const char *buf, size_t count) {
102103
(void) fhdl;
103-
int written = 0;
104-
while ((size_t)written < count) {
105-
int wr = board_uart_write(buf + written, (int)(count - (size_t)written));
106-
if (wr > 0) {
107-
written += wr;
104+
size_t written = 0;
105+
while (written < count) {
106+
int wr = board_uart_write(buf + written, (int)(count - written));
107+
if (wr < 0) {
108+
break; // UART not available
108109
}
110+
if (wr == 0) {
111+
continue; // TX busy, keep trying
112+
}
113+
written += (size_t) wr;
109114
}
110-
return written;
115+
return (int) written;
111116
}
112117

113118
int sys_read (int fhdl, char *buf, size_t count) {

hw/bsp/da1469x/family.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ uint32_t board_button_read(void) {
123123
int board_uart_read(uint8_t* buf, int len) {
124124
(void) buf;
125125
(void) len;
126-
return 0;
126+
return -1;
127127
}
128128

129129
int board_uart_write(void const* buf, int len) {
130130
(void) buf;
131131
(void) len;
132132

133-
return 0;
133+
return -1;
134134
}
135135

136136
#if CFG_TUSB_OS == OPT_OS_NONE

hw/bsp/efm32/family.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,13 @@ uint32_t board_button_read(void)
673673
int board_uart_read(uint8_t* buf, int len)
674674
{
675675
(void) buf; (void) len;
676-
return 0;
676+
return -1;
677677
}
678678

679679
int board_uart_write(void const * buf, int len)
680680
{
681681
(void) buf; (void) len;
682-
return 0;
682+
return -1;
683683
}
684684

685685
#if CFG_TUSB_OS == OPT_OS_NONE

hw/bsp/lpc11/family.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ uint32_t board_button_read(void) {
114114
int board_uart_read(uint8_t* buf, int len) {
115115
(void) buf;
116116
(void) len;
117-
return 0;
117+
return -1;
118118
}
119119

120120
int board_uart_write(void const* buf, int len) {
121121
(void) buf;
122122
(void) len;
123-
return 0;
123+
return -1;
124124
}
125125

126126
#if CFG_TUSB_OS == OPT_OS_NONE

hw/bsp/lpc13/family.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ uint32_t board_button_read(void) {
101101
int board_uart_read(uint8_t* buf, int len) {
102102
(void) buf;
103103
(void) len;
104-
return 0;
104+
return -1;
105105
}
106106

107107
int board_uart_write(void const* buf, int len) {
108108
(void) buf;
109109
(void) len;
110-
return 0;
110+
return -1;
111111
}

hw/bsp/lpc17/family.c

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,13 @@ void board_init(void) {
6464
Chip_GPIO_SetPinDIROutput(LPC_GPIO, LED_PORT, LED_PIN);
6565
Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_PORT, BUTTON_PIN);
6666

67-
#if 0
6867
//------------- UART -------------//
69-
PINSEL_CFG_Type PinCfg =
70-
{
71-
.Portnum = 0,
72-
.Pinnum = 0, // TXD is P0.0
73-
.Funcnum = 2,
74-
.OpenDrain = 0,
75-
.Pinmode = 0
76-
};
77-
PINSEL_ConfigPin(&PinCfg);
78-
79-
PinCfg.Portnum = 0;
80-
PinCfg.Pinnum = 1; // RXD is P0.1
81-
PINSEL_ConfigPin(&PinCfg);
82-
83-
UART_CFG_Type UARTConfigStruct;
84-
UART_ConfigStructInit(&UARTConfigStruct);
85-
UARTConfigStruct.Baud_rate = CFG_BOARD_UART_BAUDRATE;
86-
87-
UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
88-
UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
89-
#endif
68+
// Pin muxing for UART3 (TXD3=P0.0, RXD3=P0.1) is configured in board.h pinmuxing[]
69+
Chip_UART_Init(BOARD_UART_PORT);
70+
Chip_UART_SetBaud(BOARD_UART_PORT, CFG_BOARD_UART_BAUDRATE);
71+
Chip_UART_ConfigData(BOARD_UART_PORT, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS));
72+
Chip_UART_SetupFIFOS(BOARD_UART_PORT, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0));
73+
Chip_UART_TXEnable(BOARD_UART_PORT);
9074

9175
//------------- USB -------------//
9276
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) {
125109
}
126110

127111
int board_uart_read(uint8_t* buf, int len) {
128-
// return UART_ReceiveByte(BOARD_UART_PORT);
129-
(void) buf;
130-
(void) len;
131-
return 0;
112+
int count = 0;
113+
while (count < len) {
114+
if (BOARD_UART_PORT->LSR & UART_LSR_RDR) {
115+
buf[count] = (uint8_t) BOARD_UART_PORT->RBR;
116+
count++;
117+
} else {
118+
break;
119+
}
120+
}
121+
return count;
132122
}
133123

134124
int board_uart_write(void const* buf, int len) {
135-
// UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
136-
(void) buf;
137-
(void) len;
138-
return 0;
125+
const uint8_t *p = (const uint8_t *) buf;
126+
int count = 0;
127+
while (count < len) {
128+
if (BOARD_UART_PORT->LSR & UART_LSR_THRE) {
129+
BOARD_UART_PORT->THR = p[count];
130+
count++;
131+
} else {
132+
break;
133+
}
134+
}
135+
return count;
139136
}
140137

141138
#if CFG_TUSB_OS == OPT_OS_NONE

hw/bsp/lpc40/family.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ int board_uart_read(uint8_t *buf, int len) {
139139
//return UART_ReceiveByte(BOARD_UART_PORT);
140140
(void) buf;
141141
(void) len;
142-
return 0;
142+
return -1;
143143
}
144144

145145
int board_uart_write(void const *buf, int len) {
146146
//UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
147147
(void) buf;
148148
(void) len;
149-
return 0;
149+
return -1;
150150
}
151151

152152
#if CFG_TUSB_OS == OPT_OS_NONE

hw/bsp/lpc51/family.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ uint32_t board_button_read(void) {
106106
int board_uart_read(uint8_t* buf, int len) {
107107
(void) buf;
108108
(void) len;
109-
return 0;
109+
return -1;
110110
}
111111

112112
int board_uart_write(void const* buf, int len) {
113113
(void) buf;
114114
(void) len;
115-
return 0;
115+
return -1;
116116
}
117117

118118
#if CFG_TUSB_OS == OPT_OS_NONE

hw/bsp/lpc54/family.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ uint32_t board_button_read(void) {
224224
int board_uart_read(uint8_t* buf, int len) {
225225
(void) buf;
226226
(void) len;
227-
return 0;
227+
return -1;
228228
}
229229

230230
int board_uart_write(void const* buf, int len) {
@@ -243,7 +243,7 @@ int board_uart_write(void const* buf, int len) {
243243
#else
244244
(void) buf;
245245
(void) len;
246-
return 0;
246+
return -1;
247247
#endif
248248
}
249249

0 commit comments

Comments
 (0)