23
23
24
24
#include " USBTester.h"
25
25
26
+ // If disconnect() + connect() occur too fast the reset event will be dropped.
27
+ // At a minimum there should be a 200us delay between disconnect and connect.
28
+ // To be on the safe side I would recommend a 1ms delay, so the host controller
29
+ // has an entire USB frame to detect the disconnect.
30
+ #define MIN_DISCONNECT_TIME_US 1000
31
+
26
32
#if !defined(DEVICE_USBDEVICE) || !DEVICE_USBDEVICE
27
33
#error [NOT_SUPPORTED] USB Device not supported for this target
28
34
#endif
@@ -166,11 +172,7 @@ void device_soft_reconnection_test()
166
172
167
173
for (int i = 0 ; i < reconnect_try_count; i++) {
168
174
serial.disconnect ();
169
- // If disconnect() + connect() occur too fast the reset event will be dropped.
170
- // At a minimum there should be a 200us delay between disconnect and connect.
171
- // To be on the safe side I would recommend a 1ms delay, so the host controller
172
- // has an entire USB frame to detect the disconnect.
173
- wait_ms (1 );
175
+ wait_us (MIN_DISCONNECT_TIME_US);
174
176
serial.connect ();
175
177
greentea_send_kv (" device_soft_reconnection_test" , serial.get_serial_desc_string ());
176
178
// Wait for host before terminating
@@ -179,13 +181,13 @@ void device_soft_reconnection_test()
179
181
}
180
182
181
183
serial.disconnect ();
182
- wait_ms ( 1 );
184
+ wait_us (MIN_DISCONNECT_TIME_US );
183
185
serial.connect ();
184
186
serial.disconnect ();
185
- wait_ms ( 1 );
187
+ wait_us (MIN_DISCONNECT_TIME_US );
186
188
serial.connect ();
187
189
serial.disconnect ();
188
- wait_ms ( 1 );
190
+ wait_us (MIN_DISCONNECT_TIME_US );
189
191
serial.connect ();
190
192
greentea_send_kv (" device_soft_reconnection_test" , serial.get_serial_desc_string ());
191
193
// Wait for host before terminating
@@ -228,50 +230,44 @@ void repeated_construction_destruction_test()
228
230
{
229
231
USBTester serial (vendor_id, product_id, product_release, true );
230
232
TEST_ASSERT_EQUAL (true , serial.configured ());
231
- wait_ms (1 );
232
233
}
233
234
234
- wait_ms ( 1 );
235
+ wait_us (MIN_DISCONNECT_TIME_US );
235
236
{
236
237
USBTester serial (vendor_id, product_id, product_release, true );
237
238
TEST_ASSERT_EQUAL (true , serial.configured ());
238
- wait_ms (1 );
239
239
}
240
240
241
- wait_ms ( 1 );
241
+ wait_us (MIN_DISCONNECT_TIME_US );
242
242
{
243
243
USBTester serial (vendor_id, product_id, product_release, true );
244
244
TEST_ASSERT_EQUAL (true , serial.configured ());
245
- wait_ms (1 );
246
245
}
247
246
248
- wait_ms ( 1 );
247
+ wait_us (MIN_DISCONNECT_TIME_US );
249
248
{
250
249
USBTester serial (vendor_id, product_id, product_release, true );
251
250
TEST_ASSERT_EQUAL (true , serial.configured ());
252
- wait_ms (1 );
253
251
greentea_send_kv (" repeated_construction_destruction_test" , serial.get_serial_desc_string ());
254
252
// Wait for host before terminating
255
253
greentea_parse_kv (_key, _value, sizeof (_key), sizeof (_value));
256
254
TEST_ASSERT_EQUAL_STRING (" pass" , _key);
257
255
}
258
256
259
- wait_ms ( 1 );
257
+ wait_us (MIN_DISCONNECT_TIME_US );
260
258
{
261
259
USBTester serial (vendor_id, product_id, product_release, true );
262
260
TEST_ASSERT_EQUAL (true , serial.configured ());
263
- wait_ms (1 );
264
261
greentea_send_kv (" repeated_construction_destruction_test" , serial.get_serial_desc_string ());
265
262
// Wait for host before terminating
266
263
greentea_parse_kv (_key, _value, sizeof (_key), sizeof (_value));
267
264
TEST_ASSERT_EQUAL_STRING (" pass" , _key);
268
265
}
269
266
270
- wait_ms ( 1 );
267
+ wait_us (MIN_DISCONNECT_TIME_US );
271
268
{
272
269
USBTester serial (vendor_id, product_id, product_release, true );
273
270
TEST_ASSERT_EQUAL (true , serial.configured ());
274
- wait_ms (1 );
275
271
greentea_send_kv (" repeated_construction_destruction_test" , serial.get_serial_desc_string ());
276
272
// Wait for host before terminating
277
273
greentea_parse_kv (_key, _value, sizeof (_key), sizeof (_value));
0 commit comments