Skip to content

Commit dd54804

Browse files
authored
Merge pull request #12262 from fkjagodzinski/test_update-uart_flush_delay
Test: Increase the UART flush delay
2 parents c27e644 + e8bbbaf commit dd54804

File tree

8 files changed

+81
-60
lines changed

8 files changed

+81
-60
lines changed

TESTS/mbed_drivers/reset_reason/main.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,20 @@
4949
#define MSG_KEY_RESET_REASON "reason"
5050
#define MSG_KEY_DEVICE_RESET "reset"
5151

52-
#define SERIAL_FLUSH_TIME_MS 20
52+
/* To prevent a loss of Greentea data, the serial buffers have to be flushed
53+
* before the UART peripheral shutdown. The UART shutdown happens when the
54+
* device is entering the deepsleep mode or performing a reset.
55+
*
56+
* With the current API, it is not possible to check if the hardware buffers
57+
* are empty. However, it is possible to determine the time required for the
58+
* buffers to flush.
59+
*
60+
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
61+
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
62+
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
63+
* To be on the safe side, set the wait time to 150 ms.
64+
*/
65+
#define SERIAL_FLUSH_TIME_MS 150
5366

5467
typedef enum {
5568
CMD_STATUS_CONTINUE,

TESTS/mbed_drivers/watchdog/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@
5151
* are empty. However, it is possible to determine the time required for the
5252
* buffers to flush.
5353
*
54-
* Take NUMAKER_PFM_NUC472 as an example:
55-
* The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600,
56-
* flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms.
57-
* To be on the safe side, set the wait time to 20 ms.
54+
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
55+
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
56+
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
57+
* To be on the safe side, set the wait time to 150 ms.
5858
*/
59-
#define SERIAL_FLUSH_TIME_MS 20
59+
#define SERIAL_FLUSH_TIME_MS 150
6060

6161
int CASE_INDEX_START;
6262
int CASE_INDEX_CURRENT;

TESTS/mbed_drivers/watchdog_reset/main.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@
6161
* are empty. However, it is possible to determine the time required for the
6262
* buffers to flush.
6363
*
64-
* Take NUMAKER_PFM_NUC472 as an example:
65-
* The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600,
66-
* flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms.
67-
* To be on the safe side, set the wait time to 20 ms.
64+
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
65+
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
66+
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
67+
* To be on the safe side, set the wait time to 150 ms.
6868
*/
69-
#define SERIAL_FLUSH_TIME_MS 20
69+
#define SERIAL_FLUSH_TIME_MS 150
7070

7171
#define TIMEOUT_US (1000 * (TIMEOUT_MS))
7272
#define KICK_ADVANCE_US (1000 * (KICK_ADVANCE_MS))
@@ -112,10 +112,11 @@ void test_simple_reset()
112112

113113
// Phase 1. -- run the test code.
114114
// Init the watchdog and wait for a device reset.
115-
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
115+
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
116116
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
117117
return;
118118
}
119+
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
119120
Watchdog &watchdog = Watchdog::get_instance();
120121
TEST_ASSERT_FALSE(watchdog.is_running());
121122
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
@@ -141,10 +142,11 @@ void test_sleep_reset()
141142
}
142143

143144
// Phase 1. -- run the test code.
144-
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
145+
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
145146
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
146147
return;
147148
}
149+
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
148150
Watchdog &watchdog = Watchdog::get_instance();
149151
TEST_ASSERT_FALSE(watchdog.is_running());
150152
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
@@ -232,10 +234,11 @@ void test_restart_reset()
232234
// The watchdog should trigger before twice the timeout value.
233235
wait_us(TIMEOUT_US / 2 + TIMEOUT_US);
234236

235-
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
237+
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
236238
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
237239
return;
238240
}
241+
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
239242
TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS));
240243
TEST_ASSERT_TRUE(watchdog.is_running());
241244
// Watchdog should fire before twice the timeout value.
@@ -268,10 +271,11 @@ void test_kick_reset()
268271
wait_us(TIMEOUT_US - KICK_ADVANCE_US);
269272
watchdog.kick();
270273
}
271-
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
274+
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
272275
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
273276
return;
274277
}
278+
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
275279
// Watchdog should fire before twice the timeout value.
276280
wait_us(2 * TIMEOUT_US); // Device reset expected.
277281

TESTS/mbed_hal/lp_ticker/main.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,20 @@ ticker_irq_handler_type prev_handler;
4747

4848
#define LP_TICKER_OV_LIMIT 4000
4949

50-
/* Flush serial buffer before deep sleep
50+
/* To prevent a loss of Greentea data, the serial buffers have to be flushed
51+
* before the UART peripheral shutdown. The UART shutdown happens when the
52+
* device is entering the deepsleep mode or performing a reset.
5153
*
52-
* Since deepsleep() may shut down the UART peripheral, we wait for some time
53-
* to allow for hardware serial buffers to completely flush.
54+
* With the current API, it is not possible to check if the hardware buffers
55+
* are empty. However, it is possible to determine the time required for the
56+
* buffers to flush.
5457
*
55-
* Take NUMAKER_PFM_NUC472 as an example:
56-
* Its UART peripheral has 16-byte Tx FIFO. With baud rate set to 9600, flush
57-
* Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 (ms). So set wait time to
58-
* 20ms here for safe.
59-
*
60-
* This should be replaced with a better function that checks if the
61-
* hardware buffers are empty. However, such an API does not exist now,
62-
* so we'll use the busy_wait_ms() function for now.
58+
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
59+
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
60+
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
61+
* To be on the safe side, set the wait time to 150 ms.
6362
*/
64-
#define SERIAL_FLUSH_TIME_MS 20
63+
#define SERIAL_FLUSH_TIME_MS 150
6564

6665
void busy_wait_ms(int ms)
6766
{

TESTS/mbed_hal/reset_reason/main.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,20 @@
4949
#define MSG_KEY_RESET_REASON "reason"
5050
#define MSG_KEY_DEVICE_RESET "reset"
5151

52-
/* To prevent loss of Greentea data, flush serial buffers before the UART peripheral shutdown. The UART shutdown happens when the
52+
/* To prevent a loss of Greentea data, the serial buffers have to be flushed
53+
* before the UART peripheral shutdown. The UART shutdown happens when the
5354
* device is entering the deepsleep mode or performing a reset.
5455
*
5556
* With the current API, it is not possible to check if the hardware buffers
56-
* are empty. However, you can determine the amount of time required for the
57+
* are empty. However, it is possible to determine the time required for the
5758
* buffers to flush.
5859
*
59-
* For example, NUMAKER_PFM_NUC472:
60-
* The UART peripheral has 16-byte Tx FIFO. With a baud rate of 9600,
61-
* flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms.
62-
* To be on the safe side, set the wait time to 20 ms.
60+
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
61+
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
62+
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
63+
* To be on the safe side, set the wait time to 150 ms.
6364
*/
64-
#define SERIAL_FLUSH_TIME_MS 20
65+
#define SERIAL_FLUSH_TIME_MS 150
6566

6667
typedef enum {
6768
CMD_STATUS_CONTINUE,

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

TESTS/mbed_hal/watchdog/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
* are empty. However, it is possible to determine the time required for the
5353
* buffers to flush.
5454
*
55-
* Take NUMAKER_PFM_NUC472 as an example:
56-
* The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600,
57-
* flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms.
58-
* To be on the safe side, set the wait time to 20 ms.
55+
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
56+
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
57+
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
58+
* To be on the safe side, set the wait time to 150 ms.
5959
*/
60-
#define SERIAL_FLUSH_TIME_MS 20
60+
#define SERIAL_FLUSH_TIME_MS 150
6161

6262
int CASE_INDEX_START;
6363
int CASE_INDEX_CURRENT;

TESTS/mbed_hal/watchdog_reset/main.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@
6161
* are empty. However, it is possible to determine the time required for the
6262
* buffers to flush.
6363
*
64-
* Take NUMAKER_PFM_NUC472 as an example:
65-
* The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600,
66-
* flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms.
67-
* To be on the safe side, set the wait time to 20 ms.
64+
* Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W)
65+
* and a default UART config (9600, 8N1), flushing the Tx FIFO wold take:
66+
* (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms.
67+
* To be on the safe side, set the wait time to 150 ms.
6868
*/
69-
#define SERIAL_FLUSH_TIME_MS 20
69+
#define SERIAL_FLUSH_TIME_MS 150
7070

7171
#define TIMEOUT_US (1000 * (TIMEOUT_MS))
7272
#define KICK_ADVANCE_US (1000 * (KICK_ADVANCE_MS))
@@ -111,10 +111,11 @@ void test_simple_reset()
111111
// Phase 1. -- run the test code.
112112
// Init the watchdog and wait for a device reset.
113113
watchdog_config_t config = { TIMEOUT_MS };
114-
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
114+
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
115115
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
116116
return;
117117
}
118+
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
118119
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
119120
// Watchdog should fire before twice the timeout value.
120121
wait_us(2 * TIMEOUT_US); // Device reset expected.
@@ -138,10 +139,11 @@ void test_sleep_reset()
138139

139140
// Phase 1. -- run the test code.
140141
watchdog_config_t config = { TIMEOUT_MS };
141-
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
142+
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
142143
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
143144
return;
144145
}
146+
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
145147
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
146148
sleep_manager_lock_deep_sleep();
147149
if (sleep_manager_can_deep_sleep()) {
@@ -176,6 +178,7 @@ void test_deepsleep_reset()
176178
return;
177179
}
178180
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
181+
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
179182
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
180183
if (!sleep_manager_can_deep_sleep()) {
181184
TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed.");
@@ -221,10 +224,11 @@ void test_restart_reset()
221224
// The watchdog should trigger before twice the timeout value.
222225
wait_us(TIMEOUT_US / 2 + TIMEOUT_US);
223226

224-
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
227+
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
225228
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
226229
return;
227230
}
231+
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
228232
TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config));
229233
// Watchdog should fire before twice the timeout value.
230234
wait_us(2 * TIMEOUT_US); // Device reset expected.
@@ -254,10 +258,11 @@ void test_kick_reset()
254258
wait_us(TIMEOUT_US - KICK_ADVANCE_US);
255259
hal_watchdog_kick();
256260
}
257-
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS) == false) {
261+
if (send_reset_notification(&current_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) {
258262
TEST_ASSERT_MESSAGE(0, "Dev-host communication error.");
259263
return;
260264
}
265+
wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush.
261266
// Watchdog should fire before twice the timeout value.
262267
wait_us(2 * TIMEOUT_US); // Device reset expected.
263268

0 commit comments

Comments
 (0)