Skip to content

Commit 1933884

Browse files
committed
Bare metal profile: Enable USB serial greentea test
1 parent 918d679 commit 1933884

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

TESTS/usb_device/serial/main.cpp

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
#error [NOT_SUPPORTED] usb device tests not enabled
2020
#else
2121

22-
#if !defined(MBED_CONF_RTOS_PRESENT)
23-
#error [NOT_SUPPORTED] USB stack and test cases require RTOS to run.
24-
#else
25-
2622
#if !defined(DEVICE_USBDEVICE) || !DEVICE_USBDEVICE
2723
#error [NOT_SUPPORTED] USB Device not supported for this target
2824
#else
@@ -152,8 +148,11 @@ line_coding_t test_codings[] = {
152148
{ 9600, 8, 0, 0 },
153149
{ 57600, 8, 0, 0 },
154150
};
155-
151+
#if defined(MBED_CONF_RTOS_PRESENT)
156152
Mail<line_coding_t, 8> lc_mail;
153+
#else
154+
static CircularBuffer<line_coding_t, 8> lc_data;
155+
#endif
157156

158157
#define EF_SEND (1ul << 0)
159158
EventFlags event_flags;
@@ -388,6 +387,17 @@ void tx_thread_fun(USBCDC *usb_cdc)
388387
}
389388
}
390389

390+
void tx_ticker_fun(USBCDC *usb_cdc, uint8_t start_val)
391+
{
392+
static uint8_t buff_val = start_val;
393+
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+
}
398+
buff_val++;
399+
}
400+
391401
/** Test CDC receive single bytes concurrently
392402
*
393403
* Given the USB CDC device connected to a host
@@ -405,9 +415,15 @@ void test_cdc_rx_single_bytes_concurrent()
405415
ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS);
406416
#endif
407417
usb_cdc.wait_ready();
418+
#if defined(MBED_CONF_RTOS_PRESENT)
408419
Thread tx_thread;
409420
event_flags.set(EF_SEND);
410421
tx_thread.start(mbed::callback(tx_thread_fun, &usb_cdc));
422+
#else
423+
Ticker t;
424+
t.attach_us([&] { tx_ticker_fun(&usb_cdc, 0); }, 3000);
425+
#endif
426+
411427
uint8_t buff = 0x01;
412428
for (int expected = 0xff; expected >= 0; expected--) {
413429
TEST_ASSERT(usb_cdc.receive(&buff, 1, NULL));
@@ -418,7 +434,9 @@ void test_cdc_rx_single_bytes_concurrent()
418434
TEST_ASSERT_EQUAL_UINT8(expected, buff);
419435
}
420436
event_flags.clear(EF_SEND);
437+
#if defined(MBED_CONF_RTOS_PRESENT)
421438
tx_thread.join();
439+
#endif
422440
// Wait for the host to close its port.
423441
while (usb_cdc.ready()) {
424442
ThisThread::sleep_for(1);
@@ -482,9 +500,14 @@ void test_cdc_rx_multiple_bytes_concurrent()
482500
ThisThread::sleep_for(LINUX_HOST_DTR_FIX_DELAY_MS);
483501
#endif
484502
usb_cdc.wait_ready();
503+
#if defined(MBED_CONF_RTOS_PRESENT)
485504
Thread tx_thread;
486505
event_flags.set(EF_SEND);
487506
tx_thread.start(mbed::callback(tx_thread_fun, &usb_cdc));
507+
#else
508+
Ticker t;
509+
t.attach_us([&] { tx_ticker_fun(&usb_cdc, 0); }, 3000);
510+
#endif
488511
uint8_t buff[RX_BUFF_SIZE] = { 0 };
489512
uint8_t expected_buff[RX_BUFF_SIZE] = { 0 };
490513
for (int expected = 0xff; expected >= 0; expected--) {
@@ -501,8 +524,12 @@ void test_cdc_rx_multiple_bytes_concurrent()
501524
TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_buff, buff, RX_BUFF_SIZE);
502525
}
503526
}
527+
#if defined(MBED_CONF_RTOS_PRESENT)
504528
event_flags.clear(EF_SEND);
505529
tx_thread.join();
530+
#else
531+
t.detach();
532+
#endif
506533
// Wait for the host to close its port.
507534
while (usb_cdc.ready()) {
508535
ThisThread::sleep_for(1);
@@ -742,12 +769,22 @@ void test_serial_printf_scanf()
742769

743770
void line_coding_changed_cb(int baud, int bits, int parity, int stop)
744771
{
772+
#if defined(MBED_CONF_RTOS_PRESENT)
745773
line_coding_t *lc = lc_mail.alloc();
746774
lc->baud = baud;
747775
lc->bits = bits;
748776
lc->parity = parity;
749777
lc->stop = stop;
750778
lc_mail.put(lc);
779+
#else
780+
line_coding_t lc = {0};
781+
lc.baud = baud;
782+
lc.bits = bits;
783+
lc.parity = parity;
784+
lc.stop = stop;
785+
lc_data.push(lc);
786+
event_flags.set(EF_SEND);
787+
#endif
751788
}
752789

753790
/** Test Serial / CDC line coding change
@@ -785,6 +822,7 @@ void test_serial_line_coding_change()
785822
// calls to line_coding_changed callback on the device.
786823
while (num_expected_callbacks > 0) {
787824
num_expected_callbacks--;
825+
#if defined(MBED_CONF_RTOS_PRESENT)
788826
osEvent event = lc_mail.get();
789827
TEST_ASSERT_EQUAL_UINT32(osEventMail, event.status);
790828
lc_actual = (line_coding_t *) event.value.p;
@@ -795,12 +833,23 @@ void test_serial_line_coding_change()
795833
// set of params.
796834
lc_mail.free(lc_actual);
797835
}
836+
#else
837+
line_coding_t lc_receive = {0};
838+
event_flags.wait_all(EF_SEND);
839+
lc_data.pop(lc_receive);
840+
if (lc_expected->get_num_diffs(lc_receive) == 0) {
841+
break;
842+
}
843+
lc_actual = &lc_receive;
844+
#endif
798845
}
799846
TEST_ASSERT_EQUAL_INT(lc_expected->baud, lc_actual->baud);
800847
TEST_ASSERT_EQUAL_INT(lc_expected->bits, lc_actual->bits);
801848
TEST_ASSERT_EQUAL_INT(lc_expected->parity, lc_actual->parity);
802849
TEST_ASSERT_EQUAL_INT(lc_expected->stop, lc_actual->stop);
850+
#if defined(MBED_CONF_RTOS_PRESENT)
803851
lc_mail.free(lc_actual);
852+
#endif
804853
lc_prev = lc_expected;
805854
}
806855
// Wait for the host to close its port.
@@ -857,5 +906,4 @@ int main()
857906
}
858907

859908
#endif // !defined(DEVICE_USBDEVICE) || !DEVICE_USBDEVICE
860-
#endif // !defined(MBED_CONF_RTOS_PRESENT)
861909
#endif // !defined(USB_DEVICE_TESTS)

0 commit comments

Comments
 (0)