Skip to content

Commit 1160a86

Browse files
Merge branch 'test/fix_flaky_lp_uart_tests' into 'master'
fix(lp_uart): Fixed flaky LP UART unit tests Closes IDFCI-2722 See merge request espressif/esp-idf!36943
2 parents 0902e70 + 800b5f8 commit 1160a86

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_main_uart.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -10,6 +10,7 @@
1010
#include "ulp_lp_core_utils.h"
1111
#include "ulp_lp_core_uart.h"
1212
#include "ulp_lp_core_print.h"
13+
#include "soc/soc_caps.h"
1314

1415
#define LP_UART_PORT_NUM LP_UART_NUM_0
1516
#define LP_UART_BUFFER_LEN UART_BUF_SIZE
@@ -95,5 +96,10 @@ int main(void)
9596
/* Synchronize with the HP core running the test */
9697
test_cmd = LP_CORE_NO_COMMAND;
9798
test_cmd_reply = LP_CORE_COMMAND_OK;
99+
100+
/* Wake up the HP core */
101+
#if SOC_LIGHT_SLEEP_SUPPORTED
102+
ulp_lp_core_wakeup_main_processor();
103+
#endif /* SOC_LIGHT_SLEEP_SUPPORTED */
98104
}
99105
}

components/ulp/test_apps/lp_core/lp_core_basic_tests/main/test_lp_core_uart.c

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -18,6 +18,10 @@
1818
#include "esp_log.h"
1919

2020
#include "driver/uart.h"
21+
#include "soc/soc_caps.h"
22+
#if SOC_LIGHT_SLEEP_SUPPORTED
23+
#include "esp_sleep.h"
24+
#endif /* SOC_LIGHT_SLEEP_SUPPORTED */
2125

2226
extern const uint8_t lp_core_main_uart_bin_start[] asm("_binary_lp_core_test_app_uart_bin_start");
2327
extern const uint8_t lp_core_main_uart_bin_end[] asm("_binary_lp_core_test_app_uart_bin_end");
@@ -136,6 +140,9 @@ static void setup_test_print_data(void)
136140

137141
static void hp_uart_read(void)
138142
{
143+
/* Wait for LP UART to be initialized first */
144+
unity_wait_for_signal("LP UART init done");
145+
139146
/* Configure HP UART driver */
140147
uart_config_t hp_uart_cfg = {
141148
.baud_rate = lp_uart_cfg.uart_proto_cfg.baud_rate,
@@ -203,6 +210,9 @@ static void test_lp_uart_write(void)
203210
/* Setup LP UART with default configuration */
204211
TEST_ASSERT(ESP_OK == lp_core_uart_init(&lp_uart_cfg));
205212

213+
/* Notify HP UART once LP UART is initialized */
214+
unity_send_signal("LP UART init done");
215+
206216
/* Wait for the HP UART device to be initialized */
207217
unity_wait_for_signal("HP UART init done");
208218

@@ -216,9 +226,22 @@ static void test_lp_uart_write(void)
216226
setup_test_data((uint8_t *)&ulp_tx_data, NULL);
217227
ulp_tx_len = TEST_DATA_LEN + sizeof(start_pattern);
218228

229+
/* Configure ULP wakeup source */
230+
#if SOC_LIGHT_SLEEP_SUPPORTED
231+
esp_sleep_enable_ulp_wakeup();
232+
#endif /* SOC_LIGHT_SLEEP_SUPPORTED */
233+
219234
/* Start the test */
220235
ESP_LOGI(TAG, "Write test start");
221236
ulp_test_cmd = LP_CORE_LP_UART_WRITE_TEST;
237+
238+
#if SOC_LIGHT_SLEEP_SUPPORTED
239+
/* Enter light sleep */
240+
esp_light_sleep_start();
241+
#endif /* SOC_LIGHT_SLEEP_SUPPORTED */
242+
243+
vTaskDelay(10);
244+
TEST_ASSERT_EQUAL(ulp_test_cmd_reply, LP_CORE_COMMAND_OK);
222245
}
223246

224247
static void hp_uart_read_options(void)
@@ -310,13 +333,29 @@ static void test_lp_uart_write_options(void)
310333
setup_test_data((uint8_t *)&ulp_tx_data, NULL);
311334
ulp_tx_len = TEST_DATA_LEN + sizeof(start_pattern);
312335

336+
/* Configure ULP wakeup source */
337+
#if SOC_LIGHT_SLEEP_SUPPORTED
338+
esp_sleep_enable_ulp_wakeup();
339+
#endif /* SOC_LIGHT_SLEEP_SUPPORTED */
340+
313341
/* Start the test */
314342
ESP_LOGI(TAG, "Write test start");
315343
ulp_test_cmd = LP_CORE_LP_UART_WRITE_TEST;
344+
345+
#if SOC_LIGHT_SLEEP_SUPPORTED
346+
/* Enter light sleep */
347+
esp_light_sleep_start();
348+
#endif /* SOC_LIGHT_SLEEP_SUPPORTED */
349+
350+
vTaskDelay(10);
351+
TEST_ASSERT_EQUAL(ulp_test_cmd_reply, LP_CORE_COMMAND_OK);
316352
}
317353

318354
static void hp_uart_write(void)
319355
{
356+
/* Wait for LP UART to be initialized first */
357+
unity_wait_for_signal("LP UART init done");
358+
320359
/* Configure HP UART driver */
321360
uart_config_t hp_uart_cfg = {
322361
.baud_rate = lp_uart_cfg.uart_proto_cfg.baud_rate,
@@ -365,6 +404,9 @@ static void test_lp_uart_read(void)
365404
/* Setup LP UART with updated configuration */
366405
TEST_ASSERT(ESP_OK == lp_core_uart_init(&lp_uart_cfg));
367406

407+
/* Notify HP UART once LP UART is initialized */
408+
unity_send_signal("LP UART init done");
409+
368410
/* Wait for the HP UART device to be initialized */
369411
unity_wait_for_signal("HP UART init done");
370412

@@ -409,6 +451,9 @@ static void test_lp_uart_read(void)
409451

410452
static void hp_uart_write_options(void)
411453
{
454+
/* Wait for LP UART to be initialized first */
455+
unity_wait_for_signal("LP UART init done");
456+
412457
/* Configure HP UART driver */
413458
uart_config_t hp_uart_cfg = {
414459
.baud_rate = lp_uart_cfg1.uart_proto_cfg.baud_rate,
@@ -457,6 +502,9 @@ static void test_lp_uart_read_options(void)
457502
/* Setup LP UART with updated configuration */
458503
TEST_ASSERT(ESP_OK == lp_core_uart_init(&lp_uart_cfg1));
459504

505+
/* Notify HP UART once LP UART is initialized */
506+
unity_send_signal("LP UART init done");
507+
460508
/* Wait for the HP UART device to be initialized */
461509
unity_wait_for_signal("HP UART init done");
462510

@@ -504,6 +552,9 @@ static void test_lp_uart_read_multi_byte(void)
504552
/* Setup LP UART with updated configuration */
505553
TEST_ASSERT(ESP_OK == lp_core_uart_init(&lp_uart_cfg));
506554

555+
/* Notify HP UART once LP UART is initialized */
556+
unity_send_signal("LP UART init done");
557+
507558
/* Wait for the HP UART device to be initialized */
508559
unity_wait_for_signal("HP UART init done");
509560

@@ -550,6 +601,9 @@ static void test_lp_uart_read_multi_byte(void)
550601

551602
static void hp_uart_read_print(void)
552603
{
604+
/* Wait for LP UART to be initialized first */
605+
unity_wait_for_signal("LP UART init done");
606+
553607
/* Configure HP UART driver */
554608
uart_config_t hp_uart_cfg = {
555609
.baud_rate = lp_uart_cfg.uart_proto_cfg.baud_rate,
@@ -629,6 +683,9 @@ static void test_lp_uart_print(void)
629683
/* Setup LP UART with default configuration */
630684
TEST_ASSERT(ESP_OK == lp_core_uart_init(&lp_uart_cfg));
631685

686+
/* Notify HP UART once LP UART is initialized */
687+
unity_send_signal("LP UART init done");
688+
632689
/* Wait for the HP UART device to be initialized */
633690
unity_wait_for_signal("HP UART init done");
634691

@@ -647,9 +704,22 @@ static void test_lp_uart_print(void)
647704
ulp_test_hex = test_hex;
648705
ulp_test_character = test_character;
649706

707+
/* Configure ULP wakeup source */
708+
#if SOC_LIGHT_SLEEP_SUPPORTED
709+
esp_sleep_enable_ulp_wakeup();
710+
#endif /* SOC_LIGHT_SLEEP_SUPPORTED */
711+
650712
/* Start the test */
651713
ESP_LOGI(TAG, "LP Core print test start");
652714
ulp_test_cmd = LP_CORE_LP_UART_PRINT_TEST;
715+
716+
#if SOC_LIGHT_SLEEP_SUPPORTED
717+
/* Enter light sleep */
718+
esp_light_sleep_start();
719+
#endif /* SOC_LIGHT_SLEEP_SUPPORTED */
720+
721+
vTaskDelay(10);
722+
TEST_ASSERT_EQUAL(ulp_test_cmd_reply, LP_CORE_COMMAND_OK);
653723
}
654724

655725
/* Test LP UART write operation with default LP UART initialization configuration */

0 commit comments

Comments
 (0)