diff --git a/TESTS/mbed_drivers/reset_reason/main.cpp b/TESTS/mbed_drivers/reset_reason/main.cpp index f12a5a50fc..f03588ba21 100644 --- a/TESTS/mbed_drivers/reset_reason/main.cpp +++ b/TESTS/mbed_drivers/reset_reason/main.cpp @@ -49,7 +49,20 @@ #define MSG_KEY_RESET_REASON "reason" #define MSG_KEY_DEVICE_RESET "reset" -#define SERIAL_FLUSH_TIME_MS 20 +/* To prevent a loss of Greentea data, the serial buffers have to be flushed + * before the UART peripheral shutdown. The UART shutdown happens when the + * device is entering the deepsleep mode or performing a reset. + * + * With the current API, it is not possible to check if the hardware buffers + * are empty. However, it is possible to determine the time required for the + * buffers to flush. + * + * Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W) + * and a default UART config (9600, 8N1), flushing the Tx FIFO wold take: + * (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms. + * To be on the safe side, set the wait time to 150 ms. + */ +#define SERIAL_FLUSH_TIME_MS 150 typedef enum { CMD_STATUS_CONTINUE, diff --git a/TESTS/mbed_drivers/watchdog/main.cpp b/TESTS/mbed_drivers/watchdog/main.cpp index 9e73d346a0..79503b3a4b 100644 --- a/TESTS/mbed_drivers/watchdog/main.cpp +++ b/TESTS/mbed_drivers/watchdog/main.cpp @@ -51,12 +51,12 @@ * are empty. However, it is possible to determine the time required for the * buffers to flush. * - * Take NUMAKER_PFM_NUC472 as an example: - * The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600, - * flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms. - * To be on the safe side, set the wait time to 20 ms. + * Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W) + * and a default UART config (9600, 8N1), flushing the Tx FIFO wold take: + * (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms. + * To be on the safe side, set the wait time to 150 ms. */ -#define SERIAL_FLUSH_TIME_MS 20 +#define SERIAL_FLUSH_TIME_MS 150 int CASE_INDEX_START; int CASE_INDEX_CURRENT; diff --git a/TESTS/mbed_drivers/watchdog_reset/main.cpp b/TESTS/mbed_drivers/watchdog_reset/main.cpp index 5ce319adfb..5f32b3b544 100644 --- a/TESTS/mbed_drivers/watchdog_reset/main.cpp +++ b/TESTS/mbed_drivers/watchdog_reset/main.cpp @@ -61,12 +61,12 @@ * are empty. However, it is possible to determine the time required for the * buffers to flush. * - * Take NUMAKER_PFM_NUC472 as an example: - * The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600, - * flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms. - * To be on the safe side, set the wait time to 20 ms. + * Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W) + * and a default UART config (9600, 8N1), flushing the Tx FIFO wold take: + * (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms. + * To be on the safe side, set the wait time to 150 ms. */ -#define SERIAL_FLUSH_TIME_MS 20 +#define SERIAL_FLUSH_TIME_MS 150 #define TIMEOUT_US (1000 * (TIMEOUT_MS)) #define KICK_ADVANCE_US (1000 * (KICK_ADVANCE_MS)) @@ -112,10 +112,11 @@ void test_simple_reset() // Phase 1. -- run the test code. // Init the watchdog and wait for a device reset. - if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { + if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) { TEST_ASSERT_MESSAGE(0, "Dev-host communication error."); return; } + wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. Watchdog &watchdog = Watchdog::get_instance(); TEST_ASSERT_FALSE(watchdog.is_running()); TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS)); @@ -141,10 +142,11 @@ void test_sleep_reset() } // Phase 1. -- run the test code. - if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { + if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) { TEST_ASSERT_MESSAGE(0, "Dev-host communication error."); return; } + wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. Watchdog &watchdog = Watchdog::get_instance(); TEST_ASSERT_FALSE(watchdog.is_running()); TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS)); @@ -232,10 +234,11 @@ void test_restart_reset() // The watchdog should trigger before twice the timeout value. wait_us(TIMEOUT_US / 2 + TIMEOUT_US); - if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { + if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) { TEST_ASSERT_MESSAGE(0, "Dev-host communication error."); return; } + wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. TEST_ASSERT_TRUE(watchdog.start(TIMEOUT_MS)); TEST_ASSERT_TRUE(watchdog.is_running()); // Watchdog should fire before twice the timeout value. @@ -268,10 +271,11 @@ void test_kick_reset() wait_us(TIMEOUT_US - KICK_ADVANCE_US); watchdog.kick(); } - if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { + if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) { TEST_ASSERT_MESSAGE(0, "Dev-host communication error."); return; } + wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. // Watchdog should fire before twice the timeout value. wait_us(2 * TIMEOUT_US); // Device reset expected. diff --git a/TESTS/mbed_hal/lp_ticker/main.cpp b/TESTS/mbed_hal/lp_ticker/main.cpp index 5438fe2343..ffe6456797 100644 --- a/TESTS/mbed_hal/lp_ticker/main.cpp +++ b/TESTS/mbed_hal/lp_ticker/main.cpp @@ -47,21 +47,20 @@ ticker_irq_handler_type prev_handler; #define LP_TICKER_OV_LIMIT 4000 -/* Flush serial buffer before deep sleep +/* To prevent a loss of Greentea data, the serial buffers have to be flushed + * before the UART peripheral shutdown. The UART shutdown happens when the + * device is entering the deepsleep mode or performing a reset. * - * Since deepsleep() may shut down the UART peripheral, we wait for some time - * to allow for hardware serial buffers to completely flush. + * With the current API, it is not possible to check if the hardware buffers + * are empty. However, it is possible to determine the time required for the + * buffers to flush. * - * Take NUMAKER_PFM_NUC472 as an example: - * Its UART peripheral has 16-byte Tx FIFO. With baud rate set to 9600, flush - * Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 (ms). So set wait time to - * 20ms here for safe. - * - * This should be replaced with a better function that checks if the - * hardware buffers are empty. However, such an API does not exist now, - * so we'll use the busy_wait_ms() function for now. + * Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W) + * and a default UART config (9600, 8N1), flushing the Tx FIFO wold take: + * (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms. + * To be on the safe side, set the wait time to 150 ms. */ -#define SERIAL_FLUSH_TIME_MS 20 +#define SERIAL_FLUSH_TIME_MS 150 void busy_wait_ms(int ms) { diff --git a/TESTS/mbed_hal/reset_reason/main.cpp b/TESTS/mbed_hal/reset_reason/main.cpp index b97b907409..fedeb49441 100644 --- a/TESTS/mbed_hal/reset_reason/main.cpp +++ b/TESTS/mbed_hal/reset_reason/main.cpp @@ -49,19 +49,20 @@ #define MSG_KEY_RESET_REASON "reason" #define MSG_KEY_DEVICE_RESET "reset" -/* To prevent loss of Greentea data, flush serial buffers before the UART peripheral shutdown. The UART shutdown happens when the +/* To prevent a loss of Greentea data, the serial buffers have to be flushed + * before the UART peripheral shutdown. The UART shutdown happens when the * device is entering the deepsleep mode or performing a reset. * * With the current API, it is not possible to check if the hardware buffers - * are empty. However, you can determine the amount of time required for the + * are empty. However, it is possible to determine the time required for the * buffers to flush. * - * For example, NUMAKER_PFM_NUC472: - * The UART peripheral has 16-byte Tx FIFO. With a baud rate of 9600, - * flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms. - * To be on the safe side, set the wait time to 20 ms. + * Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W) + * and a default UART config (9600, 8N1), flushing the Tx FIFO wold take: + * (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms. + * To be on the safe side, set the wait time to 150 ms. */ -#define SERIAL_FLUSH_TIME_MS 20 +#define SERIAL_FLUSH_TIME_MS 150 typedef enum { CMD_STATUS_CONTINUE, diff --git a/TESTS/mbed_hal/sleep/sleep_test_utils.h b/TESTS/mbed_hal/sleep/sleep_test_utils.h index 59724014af..8ed08fc7dd 100644 --- a/TESTS/mbed_hal/sleep/sleep_test_utils.h +++ b/TESTS/mbed_hal/sleep/sleep_test_utils.h @@ -29,21 +29,20 @@ #include "hal/us_ticker_api.h" #include "hal/lp_ticker_api.h" -/* Flush serial buffer before deep sleep +/* To prevent a loss of Greentea data, the serial buffers have to be flushed + * before the UART peripheral shutdown. The UART shutdown happens when the + * device is entering the deepsleep mode or performing a reset. * - * Since deepsleep() may shut down the UART peripheral, we wait for some time - * to allow for hardware serial buffers to completely flush. + * With the current API, it is not possible to check if the hardware buffers + * are empty. However, it is possible to determine the time required for the + * buffers to flush. * - * Take NUMAKER_PFM_NUC472 as an example: - * Its UART peripheral has 16-byte Tx FIFO. With baud rate set to 9600, flush - * Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 (ms). So set wait time to - * 20ms here for safe. - * - * This should be replaced with a better function that checks if the - * hardware buffers are empty. However, such an API does not exist now, - * so we'll use the busy_wait_ms() function for now. + * Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W) + * and a default UART config (9600, 8N1), flushing the Tx FIFO wold take: + * (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms. + * To be on the safe side, set the wait time to 150 ms. */ -#define SERIAL_FLUSH_TIME_MS 20 +#define SERIAL_FLUSH_TIME_MS 150 #define US_PER_S 1000000 diff --git a/TESTS/mbed_hal/watchdog/main.cpp b/TESTS/mbed_hal/watchdog/main.cpp index e77d38edd3..bec743658d 100644 --- a/TESTS/mbed_hal/watchdog/main.cpp +++ b/TESTS/mbed_hal/watchdog/main.cpp @@ -52,12 +52,12 @@ * are empty. However, it is possible to determine the time required for the * buffers to flush. * - * Take NUMAKER_PFM_NUC472 as an example: - * The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600, - * flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms. - * To be on the safe side, set the wait time to 20 ms. + * Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W) + * and a default UART config (9600, 8N1), flushing the Tx FIFO wold take: + * (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms. + * To be on the safe side, set the wait time to 150 ms. */ -#define SERIAL_FLUSH_TIME_MS 20 +#define SERIAL_FLUSH_TIME_MS 150 int CASE_INDEX_START; int CASE_INDEX_CURRENT; diff --git a/TESTS/mbed_hal/watchdog_reset/main.cpp b/TESTS/mbed_hal/watchdog_reset/main.cpp index a909474e49..6f3fa9704d 100644 --- a/TESTS/mbed_hal/watchdog_reset/main.cpp +++ b/TESTS/mbed_hal/watchdog_reset/main.cpp @@ -61,12 +61,12 @@ * are empty. However, it is possible to determine the time required for the * buffers to flush. * - * Take NUMAKER_PFM_NUC472 as an example: - * The UART peripheral has 16-byte Tx FIFO. With a baud rate set to 9600, - * flushing the Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 ms. - * To be on the safe side, set the wait time to 20 ms. + * Assuming the biggest Tx FIFO of 128 bytes (as for CY8CPROTO_062_4343W) + * and a default UART config (9600, 8N1), flushing the Tx FIFO wold take: + * (1 start_bit + 8 data_bits + 1 stop_bit) * 128 * 1000 / 9600 = 133.3 ms. + * To be on the safe side, set the wait time to 150 ms. */ -#define SERIAL_FLUSH_TIME_MS 20 +#define SERIAL_FLUSH_TIME_MS 150 #define TIMEOUT_US (1000 * (TIMEOUT_MS)) #define KICK_ADVANCE_US (1000 * (KICK_ADVANCE_MS)) @@ -111,10 +111,11 @@ void test_simple_reset() // Phase 1. -- run the test code. // Init the watchdog and wait for a device reset. watchdog_config_t config = { TIMEOUT_MS }; - if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { + if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) { TEST_ASSERT_MESSAGE(0, "Dev-host communication error."); return; } + wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config)); // Watchdog should fire before twice the timeout value. wait_us(2 * TIMEOUT_US); // Device reset expected. @@ -138,10 +139,11 @@ void test_sleep_reset() // Phase 1. -- run the test code. watchdog_config_t config = { TIMEOUT_MS }; - if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { + if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) { TEST_ASSERT_MESSAGE(0, "Dev-host communication error."); return; } + wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config)); sleep_manager_lock_deep_sleep(); if (sleep_manager_can_deep_sleep()) { @@ -176,6 +178,7 @@ void test_deepsleep_reset() return; } wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. + wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config)); if (!sleep_manager_can_deep_sleep()) { TEST_ASSERT_MESSAGE(0, "Deepsleep should be allowed."); @@ -221,10 +224,11 @@ void test_restart_reset() // The watchdog should trigger before twice the timeout value. wait_us(TIMEOUT_US / 2 + TIMEOUT_US); - if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { + if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) { TEST_ASSERT_MESSAGE(0, "Dev-host communication error."); return; } + wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. TEST_ASSERT_EQUAL(WATCHDOG_STATUS_OK, hal_watchdog_init(&config)); // Watchdog should fire before twice the timeout value. wait_us(2 * TIMEOUT_US); // Device reset expected. @@ -254,10 +258,11 @@ void test_kick_reset() wait_us(TIMEOUT_US - KICK_ADVANCE_US); hal_watchdog_kick(); } - if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS) == false) { + if (send_reset_notification(¤t_case, 2 * TIMEOUT_MS + SERIAL_FLUSH_TIME_MS) == false) { TEST_ASSERT_MESSAGE(0, "Dev-host communication error."); return; } + wait_us(SERIAL_FLUSH_TIME_US); // Wait for the serial buffers to flush. // Watchdog should fire before twice the timeout value. wait_us(2 * TIMEOUT_US); // Device reset expected.