Skip to content

Commit fa7eb7d

Browse files
author
Filip Jagodzinski
committed
Test: Sleep: Increase the UART flush wait
1 parent 7f1ed02 commit fa7eb7d

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

TESTS/mbed_hal/sleep/sleep_test_utils.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,20 @@
2929
#include "hal/us_ticker_api.h"
3030
#include "hal/lp_ticker_api.h"
3131

32-
/* Flush serial buffer before deep sleep
32+
/* To prevent a loss of Greentea data, the serial buffers have to be flushed
33+
* before the UART peripheral shutdown. The UART shutdown happens when the
34+
* device is entering the deepsleep mode or performing a reset.
3335
*
34-
* Since deepsleep() may shut down the UART peripheral, we wait for some time
35-
* to allow for hardware serial buffers to completely flush.
36+
* With the current API, it is not possible to check if the hardware buffers
37+
* are empty. However, it is possible to determine the time required for the
38+
* buffers to flush.
3639
*
37-
* Take NUMAKER_PFM_NUC472 as an example:
38-
* Its UART peripheral has 16-byte Tx FIFO. With baud rate set to 9600, flush
39-
* Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 (ms). So set wait time to
40-
* 20ms here for safe.
41-
*
42-
* This should be replaced with a better function that checks if the
43-
* hardware buffers are empty. However, such an API does not exist now,
44-
* so we'll use the busy_wait_ms() function for now.
40+
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
41+
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
42+
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
43+
* To be on the safe side, set the wait time to 150 ms.
4544
*/
46-
#define SERIAL_FLUSH_TIME_MS 20
45+
#define SERIAL_FLUSH_TIME_MS 150
4746

4847
#define US_PER_S 1000000
4948

0 commit comments

Comments
 (0)