Skip to content

Commit 54931ab

Browse files
committed
Call non-blocking USB send_nb instead of blocking send from ticker callback
1 parent 7940403 commit 54931ab

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

TESTS/usb_device/serial/main.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,14 @@ void tx_thread_fun(USBCDC *usb_cdc)
387387
}
388388
}
389389

390-
void tx_ticker_fun(USBCDC *usb_cdc, uint8_t start_val)
390+
void tx_ticker_fun(USBCDC *usb_cdc, uint8_t start_val, uint8_t size = TX_BUFF_SIZE)
391391
{
392392
static uint8_t buff_val = start_val;
393+
uint32_t actual_tx = 0;
393394
uint8_t buff[TX_BUFF_SIZE] = { 0 };
394-
memset(buff, buff_val, TX_BUFF_SIZE);
395-
while (usb_cdc->send(buff, TX_BUFF_SIZE)) {
396-
break;
397-
}
395+
memset(buff, buff_val, size);
396+
usb_cdc->send_nb(buff, size, &actual_tx);
397+
TEST_ASSERT_EQUAL_UINT8(size, actual_tx);
398398
buff_val++;
399399
}
400400

@@ -421,7 +421,7 @@ void test_cdc_rx_single_bytes_concurrent()
421421
tx_thread.start(mbed::callback(tx_thread_fun, &usb_cdc));
422422
#else
423423
Ticker t;
424-
t.attach([&] { tx_ticker_fun(&usb_cdc, 0); }, 3ms);
424+
t.attach([&] { tx_ticker_fun(&usb_cdc, 0, 1); }, 2ms);
425425
#endif
426426

427427
uint8_t buff = 0x01;
@@ -433,9 +433,12 @@ void test_cdc_rx_single_bytes_concurrent()
433433
TEST_ASSERT(usb_cdc.receive(&buff, 1, NULL));
434434
TEST_ASSERT_EQUAL_UINT8(expected, buff);
435435
}
436-
event_flags.clear(EF_SEND);
436+
437437
#if defined(MBED_CONF_RTOS_PRESENT)
438+
event_flags.clear(EF_SEND);
438439
tx_thread.join();
440+
#else
441+
t.detach();
439442
#endif
440443
// Wait for the host to close its port.
441444
while (usb_cdc.ready()) {

0 commit comments

Comments
 (0)