From 6ad80f03326525337aabc6878952a7034bade8c3 Mon Sep 17 00:00:00 2001 From: Song Ruo Jing Date: Wed, 22 Nov 2023 17:27:43 +0800 Subject: [PATCH] refactor(uart): make uart driver as component, and fix astyle --- components/app_trace/CMakeLists.txt | 3 +-- components/bt/CMakeLists.txt | 2 +- components/console/CMakeLists.txt | 4 +++- components/driver/CMakeLists.txt | 9 +------- components/driver/Kconfig | 2 -- .../driver/test_apps/.build-test-rules.yml | 12 ---------- .../test_apps/.build-test-rules.yml | 2 ++ components/esp_driver_gptimer/CMakeLists.txt | 2 +- components/esp_driver_uart/CMakeLists.txt | 11 +++++++++ .../Kconfig.uart => esp_driver_uart/Kconfig} | 4 ++-- .../include/driver/uart.h | 7 ++---- .../include/driver/uart_select.h | 0 .../uart => esp_driver_uart}/linker.lf | 0 .../uart => esp_driver_uart/src}/uart.c | 18 +++++++-------- .../test_apps/.build-test-rules.yml | 19 +++++++++++++++ .../test_apps/rs485/CMakeLists.txt | 0 .../test_apps/rs485/README.md | 0 .../test_apps/rs485/main/CMakeLists.txt | 2 +- .../test_apps/rs485/main/test_app_main.c | 17 ++++---------- .../test_apps/rs485/main/test_rs485.c | 23 ++++++++----------- .../test_apps/rs485/pytest_rs485.py | 0 .../test_apps/rs485/sdkconfig.ci.release | 0 .../test_apps/rs485/sdkconfig.defaults | 0 .../test_apps/uart/CMakeLists.txt | 2 +- .../test_apps/uart/README.md | 0 .../test_apps/uart/main/CMakeLists.txt | 2 +- .../test_apps/uart/main/test_app_main.c | 16 ++++--------- .../test_apps/uart/main/test_uart.c | 14 +++++------ .../test_apps/uart/pytest_uart.py | 0 .../test_apps/uart/sdkconfig.ci.iram_safe | 0 .../test_apps/uart/sdkconfig.ci.release | 0 .../test_apps/uart/sdkconfig.defaults | 0 .../main/CMakeLists.txt | 2 +- .../test_apps/rtc_8md256/main/CMakeLists.txt | 2 +- .../test_apps/rtc_clk/main/CMakeLists.txt | 2 +- .../rtc_power_modes/main/CMakeLists.txt | 2 +- .../main/CMakeLists.txt | 3 ++- components/openthread/CMakeLists.txt | 2 +- components/vfs/CMakeLists.txt | 1 + docs/doxygen/Doxyfile | 2 +- .../release-5.x/5.3/peripherals.rst | 1 + .../release-5.x/5.3/peripherals.rst | 1 + examples/bluetooth/.build-test-rules.yml | 12 +++++----- examples/wifi/.build-test-rules.yml | 4 ++-- 44 files changed, 98 insertions(+), 107 deletions(-) create mode 100644 components/esp_driver_uart/CMakeLists.txt rename components/{driver/uart/Kconfig.uart => esp_driver_uart/Kconfig} (87%) rename components/{driver/uart => esp_driver_uart}/include/driver/uart.h (98%) rename components/{driver/uart => esp_driver_uart}/include/driver/uart_select.h (100%) rename components/{driver/uart => esp_driver_uart}/linker.lf (100%) rename components/{driver/uart => esp_driver_uart/src}/uart.c (99%) create mode 100644 components/esp_driver_uart/test_apps/.build-test-rules.yml rename components/{driver => esp_driver_uart}/test_apps/rs485/CMakeLists.txt (100%) rename components/{driver => esp_driver_uart}/test_apps/rs485/README.md (100%) rename components/{driver => esp_driver_uart}/test_apps/rs485/main/CMakeLists.txt (82%) rename components/{driver => esp_driver_uart}/test_apps/rs485/main/test_app_main.c (62%) rename components/{driver => esp_driver_uart}/test_apps/rs485/main/test_rs485.c (96%) rename components/{driver => esp_driver_uart}/test_apps/rs485/pytest_rs485.py (100%) rename components/{driver => esp_driver_uart}/test_apps/rs485/sdkconfig.ci.release (100%) rename components/{driver => esp_driver_uart}/test_apps/rs485/sdkconfig.defaults (100%) rename components/{driver => esp_driver_uart}/test_apps/uart/CMakeLists.txt (88%) rename components/{driver => esp_driver_uart}/test_apps/uart/README.md (100%) rename components/{driver => esp_driver_uart}/test_apps/uart/main/CMakeLists.txt (86%) rename components/{driver => esp_driver_uart}/test_apps/uart/main/test_app_main.c (60%) rename components/{driver => esp_driver_uart}/test_apps/uart/main/test_uart.c (98%) rename components/{driver => esp_driver_uart}/test_apps/uart/pytest_uart.py (100%) rename components/{driver => esp_driver_uart}/test_apps/uart/sdkconfig.ci.iram_safe (100%) rename components/{driver => esp_driver_uart}/test_apps/uart/sdkconfig.ci.release (100%) rename components/{driver => esp_driver_uart}/test_apps/uart/sdkconfig.defaults (100%) diff --git a/components/app_trace/CMakeLists.txt b/components/app_trace/CMakeLists.txt index ff17766bae..c4b31ca7dc 100644 --- a/components/app_trace/CMakeLists.txt +++ b/components/app_trace/CMakeLists.txt @@ -63,8 +63,7 @@ endif() idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" PRIV_INCLUDE_DIRS "${priv_include_dirs}" - PRIV_REQUIRES soc esp_driver_gptimer esp_driver_gpio - driver # TODO: replace with esp_driver_uart (IDF-8384) + PRIV_REQUIRES esp_driver_gptimer esp_driver_gpio esp_driver_uart REQUIRES esp_timer LDFRAGMENTS linker.lf) diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index a1a02cb41a..35236d12d6 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -785,7 +785,7 @@ idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" PRIV_INCLUDE_DIRS "${priv_include_dirs}" REQUIRES esp_timer esp_wifi - PRIV_REQUIRES nvs_flash soc esp_pm esp_phy esp_coex mbedtls driver vfs + PRIV_REQUIRES nvs_flash soc esp_pm esp_phy esp_coex mbedtls esp_driver_uart vfs esp_ringbuf LDFRAGMENTS "${ldfragments}") if(CONFIG_BT_ENABLED) diff --git a/components/console/CMakeLists.txt b/components/console/CMakeLists.txt index 5904ac5ada..f0aaabb340 100644 --- a/components/console/CMakeLists.txt +++ b/components/console/CMakeLists.txt @@ -28,4 +28,6 @@ idf_component_register(SRCS "commands.c" ${argtable_srcs} INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} REQUIRES vfs - PRIV_REQUIRES driver) + PRIV_REQUIRES esp_driver_uart + driver # to be replaced by esp_driver_usj + ) diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 116e5b3c9c..3c7d4c2fc0 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -14,7 +14,6 @@ set(includes "deprecated" "parlio/include" "touch_sensor/include" "twai/include" - "uart/include" "usb_serial_jtag/include") # Always included linker fragments @@ -101,13 +100,6 @@ if(CONFIG_SOC_TWAI_SUPPORTED) list(APPEND ldfragments "twai/linker.lf") endif() -# UART related source files -if(CONFIG_SOC_UART_SUPPORTED) - list(APPEND srcs "uart/uart.c") - - list(APPEND ldfragments "uart/linker.lf") -endif() - # USB Serial JTAG related source files if(CONFIG_SOC_USB_SERIAL_JTAG_SUPPORTED) list(APPEND srcs "usb_serial_jtag/usb_serial_jtag.c" @@ -135,6 +127,7 @@ else() esp_driver_gpio esp_driver_pcnt esp_driver_gptimer esp_driver_spi esp_driver_mcpwm esp_driver_ana_cmpr esp_driver_i2s esp_driver_sdmmc esp_driver_sdspi esp_driver_sdio esp_driver_dac esp_driver_rmt esp_driver_tsens esp_driver_sdm esp_driver_i2c + esp_driver_uart LDFRAGMENTS ${ldfragments} ) endif() diff --git a/components/driver/Kconfig b/components/driver/Kconfig index abb9f51283..01d8babbd8 100644 --- a/components/driver/Kconfig +++ b/components/driver/Kconfig @@ -64,8 +64,6 @@ menu "Driver Configurations" orsource "./twai/Kconfig.twai" - orsource "./uart/Kconfig.uart" - menu "USB Serial/JTAG Configuration" depends on SOC_USB_SERIAL_JTAG_SUPPORTED config USJ_NO_AUTO_LS_ON_CONNECTION diff --git a/components/driver/test_apps/.build-test-rules.yml b/components/driver/test_apps/.build-test-rules.yml index 5cd7de2780..735ddbaa99 100644 --- a/components/driver/test_apps/.build-test-rules.yml +++ b/components/driver/test_apps/.build-test-rules.yml @@ -78,14 +78,6 @@ components/driver/test_apps/parlio: temporary: true reason: lack of runner -components/driver/test_apps/rs485: - disable: - - if: SOC_UART_SUPPORTED != 1 - disable_test: - - if: IDF_TARGET != "esp32" - temporary: true - reason: lack of runners - components/driver/test_apps/touch_sensor_v1: disable: - if: SOC_TOUCH_SENSOR_VERSION != 1 @@ -98,10 +90,6 @@ components/driver/test_apps/twai: disable: - if: SOC_TWAI_SUPPORTED != 1 -components/driver/test_apps/uart: - disable: - - if: SOC_UART_SUPPORTED != 1 - components/driver/test_apps/usb_serial_jtag: disable: - if: SOC_USB_SERIAL_JTAG_SUPPORTED != 1 diff --git a/components/esp_driver_gpio/test_apps/.build-test-rules.yml b/components/esp_driver_gpio/test_apps/.build-test-rules.yml index 13e104d9c9..d9694c7aef 100644 --- a/components/esp_driver_gpio/test_apps/.build-test-rules.yml +++ b/components/esp_driver_gpio/test_apps/.build-test-rules.yml @@ -8,3 +8,5 @@ components/esp_driver_gpio/test_apps/gpio_extensions: enable: - if: SOC_DEDICATED_GPIO_SUPPORTED == 1 - if: SOC_GPIO_SUPPORT_PIN_GLITCH_FILTER == 1 or SOC_GPIO_FLEX_GLITCH_FILTER_NUM > 0 + depends_components: + - esp_driver_gpio diff --git a/components/esp_driver_gptimer/CMakeLists.txt b/components/esp_driver_gptimer/CMakeLists.txt index 4ec99842f0..9b0871a8f7 100644 --- a/components/esp_driver_gptimer/CMakeLists.txt +++ b/components/esp_driver_gptimer/CMakeLists.txt @@ -11,6 +11,6 @@ endif() idf_component_register(SRCS ${srcs} INCLUDE_DIRS ${public_include} - PRIV_REQUIRES "esp_pm" + REQUIRES "esp_pm" LDFRAGMENTS "linker.lf" ) diff --git a/components/esp_driver_uart/CMakeLists.txt b/components/esp_driver_uart/CMakeLists.txt new file mode 100644 index 0000000000..8d3fbddd56 --- /dev/null +++ b/components/esp_driver_uart/CMakeLists.txt @@ -0,0 +1,11 @@ +set(srcs) +set(public_include "include") +if(CONFIG_SOC_UART_SUPPORTED) + list(APPEND srcs "src/uart.c") +endif() + +idf_component_register(SRCS ${srcs} + INCLUDE_DIRS ${public_include} + PRIV_REQUIRES esp_pm esp_driver_gpio esp_ringbuf + LDFRAGMENTS "linker.lf" + ) diff --git a/components/driver/uart/Kconfig.uart b/components/esp_driver_uart/Kconfig similarity index 87% rename from components/driver/uart/Kconfig.uart rename to components/esp_driver_uart/Kconfig index 4272cb290f..275084d519 100644 --- a/components/driver/uart/Kconfig.uart +++ b/components/esp_driver_uart/Kconfig @@ -1,4 +1,4 @@ -menu "UART Configuration" +menu "ESP-Driver:UART Configurations" config UART_ISR_IN_IRAM bool "Place UART ISR function into IRAM" @@ -9,4 +9,4 @@ menu "UART Configuration" If this option is not selected, UART interrupt will be disabled for a long time and may cause data lost when doing spi flash operation. -endmenu # UART Configuration +endmenu diff --git a/components/driver/uart/include/driver/uart.h b/components/esp_driver_uart/include/driver/uart.h similarity index 98% rename from components/driver/uart/include/driver/uart.h rename to components/esp_driver_uart/include/driver/uart.h index 2ff0e56603..e6ee0565ba 100644 --- a/components/driver/uart/include/driver/uart.h +++ b/components/esp_driver_uart/include/driver/uart.h @@ -14,10 +14,7 @@ extern "C" { #include "esp_intr_alloc.h" #include "soc/soc_caps.h" #include "freertos/FreeRTOS.h" -#include "freertos/semphr.h" -#include "freertos/task.h" #include "freertos/queue.h" -#include "freertos/ringbuf.h" #include "hal/uart_types.h" /* @brief When calling `uart_set_pin`, instead of GPIO number, `UART_PIN_NO_CHANGE` @@ -86,7 +83,7 @@ typedef struct { uart_event_type_t type; /*!< UART event type */ size_t size; /*!< UART data size for UART_DATA event*/ bool timeout_flag; /*!< UART data read timeout flag for UART_DATA event (no new data received during configured RX TOUT)*/ - /*!< If the event is caused by FIFO-full interrupt, then there will be no event with the timeout flag before the next byte coming.*/ + /*!< If the event is caused by FIFO-full interrupt, then there will be no event with the timeout flag before the next byte coming.*/ } uart_event_t; typedef intr_handle_t uart_isr_handle_t; @@ -285,7 +282,7 @@ esp_err_t uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow * - ESP_OK Success * - ESP_FAIL Parameter error */ - esp_err_t uart_set_sw_flow_ctrl(uart_port_t uart_num, bool enable, uint8_t rx_thresh_xon, uint8_t rx_thresh_xoff); +esp_err_t uart_set_sw_flow_ctrl(uart_port_t uart_num, bool enable, uint8_t rx_thresh_xon, uint8_t rx_thresh_xoff); /** * @brief Get the UART hardware flow control configuration. diff --git a/components/driver/uart/include/driver/uart_select.h b/components/esp_driver_uart/include/driver/uart_select.h similarity index 100% rename from components/driver/uart/include/driver/uart_select.h rename to components/esp_driver_uart/include/driver/uart_select.h diff --git a/components/driver/uart/linker.lf b/components/esp_driver_uart/linker.lf similarity index 100% rename from components/driver/uart/linker.lf rename to components/esp_driver_uart/linker.lf diff --git a/components/driver/uart/uart.c b/components/esp_driver_uart/src/uart.c similarity index 99% rename from components/driver/uart/uart.c rename to components/esp_driver_uart/src/uart.c index 013c66d421..a9c3ae51d9 100644 --- a/components/driver/uart/uart.c +++ b/components/esp_driver_uart/src/uart.c @@ -20,7 +20,6 @@ #include "esp_private/critical_section.h" #include "hal/uart_hal.h" #include "hal/gpio_hal.h" -#include "hal/clk_tree_ll.h" #include "soc/uart_periph.h" #include "driver/uart.h" #include "driver/gpio.h" @@ -28,7 +27,6 @@ #include "driver/uart_select.h" #include "driver/lp_io.h" #include "esp_private/uart_share_hw_ctrl.h" -#include "esp_private/periph_ctrl.h" #include "esp_clk_tree.h" #include "sdkconfig.h" #include "esp_rom_gpio.h" @@ -620,7 +618,7 @@ static bool uart_try_set_iomux_pin(uart_port_t uart_num, int io_num, uint32_t id } /* Assign the correct funct to the GPIO. */ - assert (upin->iomux_func != -1); + assert(upin->iomux_func != -1); if (uart_num < SOC_UART_HP_NUM) { gpio_iomux_out(io_num, upin->iomux_func, false); @@ -1073,7 +1071,7 @@ static void UART_ISR_ATTR uart_rx_intr_handler_default(void *param) p_uart->rx_buffered_len + pat_idx); } UART_EXIT_CRITICAL_ISR(&(uart_context[uart_num].spinlock)); - sent = xQueueSendFromISR(p_uart->event_queue, (void * )&uart_event, &HPTaskAwoken); + sent = xQueueSendFromISR(p_uart->event_queue, (void *)&uart_event, &HPTaskAwoken); need_yield |= (HPTaskAwoken == pdTRUE); if ((p_uart->event_queue != NULL) && (sent == pdFALSE)) { #ifndef CONFIG_UART_ISR_IN_IRAM //Only log if ISR is not in IRAM @@ -1198,19 +1196,19 @@ static void UART_ISR_ATTR uart_rx_intr_handler_default(void *param) need_yield |= (HPTaskAwoken == pdTRUE); } } - #if SOC_UART_SUPPORT_WAKEUP_INT +#if SOC_UART_SUPPORT_WAKEUP_INT else if (uart_intr_status & UART_INTR_WAKEUP) { uart_hal_clr_intsts_mask(&(uart_context[uart_num].hal), UART_INTR_WAKEUP); uart_event.type = UART_WAKEUP; } - #endif +#endif else { uart_hal_clr_intsts_mask(&(uart_context[uart_num].hal), uart_intr_status); /*simply clear all other intr status*/ uart_event.type = UART_EVENT_MAX; } if (uart_event.type != UART_EVENT_MAX && p_uart->event_queue) { - sent = xQueueSendFromISR(p_uart->event_queue, (void * )&uart_event, &HPTaskAwoken); + sent = xQueueSendFromISR(p_uart->event_queue, (void *)&uart_event, &HPTaskAwoken); need_yield |= (HPTaskAwoken == pdTRUE); if (sent == pdFALSE) { #ifndef CONFIG_UART_ISR_IN_IRAM //Only log if ISR is not in IRAM @@ -1323,7 +1321,7 @@ static int uart_tx_all(uart_port_t uart_num, const char *src, size_t size, bool xRingbufferSend(p_uart_obj[uart_num]->tx_ring_buf, (void *) &evt, sizeof(uart_tx_data_t), portMAX_DELAY); while (size > 0) { size_t send_size = size > max_size / 2 ? max_size / 2 : size; - xRingbufferSend(p_uart_obj[uart_num]->tx_ring_buf, (void *) (src + offset), send_size, portMAX_DELAY); + xRingbufferSend(p_uart_obj[uart_num]->tx_ring_buf, (void *)(src + offset), send_size, portMAX_DELAY); size -= send_size; offset += send_size; uart_enable_tx_intr(uart_num, 1, UART_THRESHOLD_NUM(uart_num, UART_EMPTY_THRESH_DEFAULT)); @@ -1644,8 +1642,8 @@ esp_err_t uart_driver_install(uart_port_t uart_num, int rx_buffer_size, int tx_b uart_hal_clr_intsts_mask(&(uart_context[uart_num].hal), UART_LL_INTR_MASK); ret = esp_intr_alloc(uart_periph_signal[uart_num].irq, intr_alloc_flags, - uart_rx_intr_handler_default, p_uart_obj[uart_num], - &p_uart_obj[uart_num]->intr_handle); + uart_rx_intr_handler_default, p_uart_obj[uart_num], + &p_uart_obj[uart_num]->intr_handle); ESP_GOTO_ON_ERROR(ret, err, UART_TAG, "Could not allocate an interrupt for UART"); ret = uart_intr_config(uart_num, &uart_intr); diff --git a/components/esp_driver_uart/test_apps/.build-test-rules.yml b/components/esp_driver_uart/test_apps/.build-test-rules.yml new file mode 100644 index 0000000000..f930c4ec13 --- /dev/null +++ b/components/esp_driver_uart/test_apps/.build-test-rules.yml @@ -0,0 +1,19 @@ +# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps + +components/esp_driver_uart/test_apps/rs485: + disable: + - if: SOC_UART_SUPPORTED != 1 + disable_test: + - if: IDF_TARGET != "esp32" + temporary: true + reason: lack of runners + depends_components: + - esp_driver_uart + - esp_driver_gpio + +components/esp_driver_uart/test_apps/uart: + disable: + - if: SOC_UART_SUPPORTED != 1 + depends_components: + - esp_driver_uart + - esp_driver_gpio diff --git a/components/driver/test_apps/rs485/CMakeLists.txt b/components/esp_driver_uart/test_apps/rs485/CMakeLists.txt similarity index 100% rename from components/driver/test_apps/rs485/CMakeLists.txt rename to components/esp_driver_uart/test_apps/rs485/CMakeLists.txt diff --git a/components/driver/test_apps/rs485/README.md b/components/esp_driver_uart/test_apps/rs485/README.md similarity index 100% rename from components/driver/test_apps/rs485/README.md rename to components/esp_driver_uart/test_apps/rs485/README.md diff --git a/components/driver/test_apps/rs485/main/CMakeLists.txt b/components/esp_driver_uart/test_apps/rs485/main/CMakeLists.txt similarity index 82% rename from components/driver/test_apps/rs485/main/CMakeLists.txt rename to components/esp_driver_uart/test_apps/rs485/main/CMakeLists.txt index 48d86f05ec..c4e68d5014 100644 --- a/components/driver/test_apps/rs485/main/CMakeLists.txt +++ b/components/esp_driver_uart/test_apps/rs485/main/CMakeLists.txt @@ -2,6 +2,6 @@ # the component can be registered as WHOLE_ARCHIVE idf_component_register( SRCS "test_app_main.c" "test_rs485.c" - REQUIRES driver unity test_utils + REQUIRES esp_driver_uart unity test_utils WHOLE_ARCHIVE ) diff --git a/components/driver/test_apps/rs485/main/test_app_main.c b/components/esp_driver_uart/test_apps/rs485/main/test_app_main.c similarity index 62% rename from components/driver/test_apps/rs485/main/test_app_main.c rename to components/esp_driver_uart/test_apps/rs485/main/test_app_main.c index 8d94794888..0eb34f65b5 100644 --- a/components/driver/test_apps/rs485/main/test_app_main.c +++ b/components/esp_driver_uart/test_apps/rs485/main/test_app_main.c @@ -5,30 +5,21 @@ */ #include "unity.h" +#include "unity_test_runner.h" #include "unity_test_utils.h" #include "esp_heap_caps.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" #define TEST_MEMORY_LEAK_THRESHOLD (200) -static size_t before_free_8bit; -static size_t before_free_32bit; - - void setUp(void) { - before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); - before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); + unity_utils_record_free_mem(); } void tearDown(void) { - size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); - size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); - printf("\n"); - unity_utils_check_leak(before_free_8bit, after_free_8bit, "8BIT", TEST_MEMORY_LEAK_THRESHOLD); - unity_utils_check_leak(before_free_32bit, after_free_32bit, "32BIT", TEST_MEMORY_LEAK_THRESHOLD); + esp_reent_cleanup(); //clean up some of the newlib's lazy allocations + unity_utils_evaluate_leaks_direct(TEST_MEMORY_LEAK_THRESHOLD); } void app_main(void) diff --git a/components/driver/test_apps/rs485/main/test_rs485.c b/components/esp_driver_uart/test_apps/rs485/main/test_rs485.c similarity index 96% rename from components/driver/test_apps/rs485/main/test_rs485.c rename to components/esp_driver_uart/test_apps/rs485/main/test_rs485.c index 774adc641f..dac0945a48 100644 --- a/components/driver/test_apps/rs485/main/test_rs485.c +++ b/components/esp_driver_uart/test_apps/rs485/main/test_rs485.c @@ -111,20 +111,18 @@ static const uint8_t crc_low[] = { 0x40 }; - // Calculate buffer checksum using tables // The checksum CRC16 algorithm is specific // for Modbus standard and uses polynomial value = 0xA001 -static uint16_t get_buffer_crc16( uint8_t * frame_ptr, uint16_t length ) +static uint16_t get_buffer_crc16(uint8_t * frame_ptr, uint16_t length) { - TEST_ASSERT( frame_ptr != NULL); + TEST_ASSERT(frame_ptr != NULL); uint8_t crc_hi_byte = 0xFF; uint8_t crc_low_byte = 0xFF; int index; - while ( length-- ) - { + while (length--) { index = crc_low_byte ^ *(frame_ptr++); crc_low_byte = crc_hi_byte ^ crc_hi[index]; crc_hi_byte = crc_low[index]; @@ -135,7 +133,7 @@ static uint16_t get_buffer_crc16( uint8_t * frame_ptr, uint16_t length ) // Fill the buffer with random numbers and apply CRC16 at the end static uint16_t buffer_fill_random(uint8_t *buffer, size_t length) { - TEST_ASSERT( buffer != NULL); + TEST_ASSERT(buffer != NULL); // Packet is too short if (length < 4) { return 0; @@ -177,8 +175,8 @@ static void rs485_init(void) static esp_err_t print_packet_data(const char *str, uint8_t *buffer, uint16_t buffer_size) { - TEST_ASSERT( buffer != NULL); - TEST_ASSERT( str != NULL); + TEST_ASSERT(buffer != NULL); + TEST_ASSERT(str != NULL); // Calculate the checksum of the buffer uint16_t crc16_calc = get_buffer_crc16(buffer, (buffer_size - 2)); @@ -187,7 +185,7 @@ static esp_err_t print_packet_data(const char *str, uint8_t *buffer, uint16_t bu // Print an array of data printf("%s%s RS485 packet = [ ", str, state_str); for (int i = 0; i < buffer_size; i++) { - printf("0x%.2X ", (uint8_t)buffer[i]); + printf("0x%.2X ", (uint8_t)buffer[i]); } printf(" ]\r\n"); printf("crc_in = 0x%.4X\r\n", (uint16_t)crc16_in); @@ -205,7 +203,7 @@ static void rs485_slave(void) unity_send_signal("Slave_ready"); unity_wait_for_signal("Master_started"); ESP_LOGI(TAG, "Start recieve loop."); - for(int pack_count = 0; pack_count < PACKETS_NUMBER; pack_count++) { + for (int pack_count = 0; pack_count < PACKETS_NUMBER; pack_count++) { //Read slave_data from UART int len = uart_read_bytes(UART_NUM1, slave_data, BUF_SIZE, PACKET_READ_TICS); //Write slave_data back to UART @@ -247,7 +245,7 @@ static void rs485_master(void) unity_wait_for_signal("Slave_ready"); unity_send_signal("Master_started"); ESP_LOGI(TAG, "Start recieve loop."); - for(int i = 0; i < PACKETS_NUMBER; i++) { + for (int i = 0; i < PACKETS_NUMBER; i++) { // Form random buffer with CRC16 buffer_fill_random(master_buffer, BUF_SIZE); // Print created packet for debugging @@ -268,8 +266,7 @@ static void rs485_master(void) err_count++; printf("Errors: %d\r\n", err_count); } - } - else { + } else { printf("Incorrect answer from slave, length = %d.\r\n", len); err_count++; } diff --git a/components/driver/test_apps/rs485/pytest_rs485.py b/components/esp_driver_uart/test_apps/rs485/pytest_rs485.py similarity index 100% rename from components/driver/test_apps/rs485/pytest_rs485.py rename to components/esp_driver_uart/test_apps/rs485/pytest_rs485.py diff --git a/components/driver/test_apps/rs485/sdkconfig.ci.release b/components/esp_driver_uart/test_apps/rs485/sdkconfig.ci.release similarity index 100% rename from components/driver/test_apps/rs485/sdkconfig.ci.release rename to components/esp_driver_uart/test_apps/rs485/sdkconfig.ci.release diff --git a/components/driver/test_apps/rs485/sdkconfig.defaults b/components/esp_driver_uart/test_apps/rs485/sdkconfig.defaults similarity index 100% rename from components/driver/test_apps/rs485/sdkconfig.defaults rename to components/esp_driver_uart/test_apps/rs485/sdkconfig.defaults diff --git a/components/driver/test_apps/uart/CMakeLists.txt b/components/esp_driver_uart/test_apps/uart/CMakeLists.txt similarity index 88% rename from components/driver/test_apps/uart/CMakeLists.txt rename to components/esp_driver_uart/test_apps/uart/CMakeLists.txt index 2e1f783b1d..a79832e8c8 100644 --- a/components/driver/test_apps/uart/CMakeLists.txt +++ b/components/esp_driver_uart/test_apps/uart/CMakeLists.txt @@ -12,7 +12,7 @@ project(uart_test) if(CONFIG_COMPILER_DUMP_RTL_FILES) add_custom_target(check_test_app_sections ALL COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py - --rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/driver/,${CMAKE_BINARY_DIR}/esp-idf/hal/ + --rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/esp_driver_uart/,${CMAKE_BINARY_DIR}/esp-idf/hal/ --elf-file ${CMAKE_BINARY_DIR}/uart_test.elf find-refs --from-sections=.iram0.text diff --git a/components/driver/test_apps/uart/README.md b/components/esp_driver_uart/test_apps/uart/README.md similarity index 100% rename from components/driver/test_apps/uart/README.md rename to components/esp_driver_uart/test_apps/uart/README.md diff --git a/components/driver/test_apps/uart/main/CMakeLists.txt b/components/esp_driver_uart/test_apps/uart/main/CMakeLists.txt similarity index 86% rename from components/driver/test_apps/uart/main/CMakeLists.txt rename to components/esp_driver_uart/test_apps/uart/main/CMakeLists.txt index e4d03ea3f7..3f7856d5f5 100644 --- a/components/driver/test_apps/uart/main/CMakeLists.txt +++ b/components/esp_driver_uart/test_apps/uart/main/CMakeLists.txt @@ -2,6 +2,6 @@ # the component can be registered as WHOLE_ARCHIVE idf_component_register( SRCS "test_app_main.c" "test_uart.c" - REQUIRES driver unity + REQUIRES esp_driver_uart unity WHOLE_ARCHIVE ) diff --git a/components/driver/test_apps/uart/main/test_app_main.c b/components/esp_driver_uart/test_apps/uart/main/test_app_main.c similarity index 60% rename from components/driver/test_apps/uart/main/test_app_main.c rename to components/esp_driver_uart/test_apps/uart/main/test_app_main.c index c1070bd94d..f349470829 100644 --- a/components/driver/test_apps/uart/main/test_app_main.c +++ b/components/esp_driver_uart/test_apps/uart/main/test_app_main.c @@ -5,29 +5,21 @@ */ #include "unity.h" +#include "unity_test_runner.h" #include "unity_test_utils.h" #include "esp_heap_caps.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" #define TEST_MEMORY_LEAK_THRESHOLD (200) -static size_t before_free_8bit; -static size_t before_free_32bit; - void setUp(void) { - before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); - before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); + unity_utils_record_free_mem(); } void tearDown(void) { - size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); - size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); - printf("\n"); - unity_utils_check_leak(before_free_8bit, after_free_8bit, "8BIT", TEST_MEMORY_LEAK_THRESHOLD); - unity_utils_check_leak(before_free_32bit, after_free_32bit, "32BIT", TEST_MEMORY_LEAK_THRESHOLD); + esp_reent_cleanup(); //clean up some of the newlib's lazy allocations + unity_utils_evaluate_leaks_direct(TEST_MEMORY_LEAK_THRESHOLD); } void app_main(void) diff --git a/components/driver/test_apps/uart/main/test_uart.c b/components/esp_driver_uart/test_apps/uart/main/test_uart.c similarity index 98% rename from components/driver/test_apps/uart/main/test_uart.c rename to components/esp_driver_uart/test_apps/uart/main/test_uart.c index 688040e649..790f6a8e6f 100644 --- a/components/driver/test_apps/uart/main/test_uart.c +++ b/components/esp_driver_uart/test_apps/uart/main/test_uart.c @@ -98,7 +98,7 @@ static void test_task3(void *pvParameters) TEST_CASE("test uart_wait_tx_done is not blocked when ticks_to_wait=0", "[uart]") { xTaskCreate(test_task3, "tsk3", 4096, NULL, 5, NULL); - while(!case_end); + while (!case_end); vTaskDelay(2); // wait for test_task3 to exit } @@ -231,13 +231,13 @@ static void uart_write_task(void *param) { int uart_num = (int)param; uint8_t *tx_buf = (uint8_t *)malloc(1024); - if(tx_buf == NULL) { + if (tx_buf == NULL) { TEST_FAIL_MESSAGE("tx buffer malloc fail"); } - for(int i = 1; i < 1023; i++) { + for (int i = 1; i < 1023; i++) { tx_buf[i] = (i & 0xff); } - for(int i = 0; i < 1024; i++) { + for (int i = 0; i < 1024; i++) { //d[0] and d[1023] are header tx_buf[0] = (i & 0xff); tx_buf[1023] = ((~i) & 0xff); @@ -261,7 +261,7 @@ TEST_CASE("uart read write test", "[uart]") { const int uart_num = UART_NUM1; uint8_t *rd_data = (uint8_t *)malloc(1024); - if(rd_data == NULL) { + if (rd_data == NULL) { TEST_FAIL_MESSAGE("rx buffer malloc fail"); } uart_config_t uart_config = { @@ -330,7 +330,7 @@ TEST_CASE("uart tx with ringbuffer test", "[uart]") const int uart_num = UART_NUM1; uint8_t *rd_data = (uint8_t *)malloc(1024); uint8_t *wr_data = (uint8_t *)malloc(1024); - if(rd_data == NULL || wr_data == NULL) { + if (rd_data == NULL || wr_data == NULL) { TEST_FAIL_MESSAGE("buffer malloc fail"); } uart_config_t uart_config = { @@ -344,7 +344,7 @@ TEST_CASE("uart tx with ringbuffer test", "[uart]") }; uart_wait_tx_idle_polling(uart_num); TEST_ESP_OK(uart_param_config(uart_num, &uart_config)); - TEST_ESP_OK(uart_driver_install(uart_num, 1024 * 2, 1024 *2, 20, NULL, 0)); + TEST_ESP_OK(uart_driver_install(uart_num, 1024 * 2, 1024 * 2, 20, NULL, 0)); TEST_ESP_OK(uart_set_loop_back(uart_num, true)); TEST_ESP_OK(uart_set_pin(uart_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART1_CTS_PIN)); //Connect the RTS out_signal to the CTS pin (which is mapped to CTS in_signal) diff --git a/components/driver/test_apps/uart/pytest_uart.py b/components/esp_driver_uart/test_apps/uart/pytest_uart.py similarity index 100% rename from components/driver/test_apps/uart/pytest_uart.py rename to components/esp_driver_uart/test_apps/uart/pytest_uart.py diff --git a/components/driver/test_apps/uart/sdkconfig.ci.iram_safe b/components/esp_driver_uart/test_apps/uart/sdkconfig.ci.iram_safe similarity index 100% rename from components/driver/test_apps/uart/sdkconfig.ci.iram_safe rename to components/esp_driver_uart/test_apps/uart/sdkconfig.ci.iram_safe diff --git a/components/driver/test_apps/uart/sdkconfig.ci.release b/components/esp_driver_uart/test_apps/uart/sdkconfig.ci.release similarity index 100% rename from components/driver/test_apps/uart/sdkconfig.ci.release rename to components/esp_driver_uart/test_apps/uart/sdkconfig.ci.release diff --git a/components/driver/test_apps/uart/sdkconfig.defaults b/components/esp_driver_uart/test_apps/uart/sdkconfig.defaults similarity index 100% rename from components/driver/test_apps/uart/sdkconfig.defaults rename to components/esp_driver_uart/test_apps/uart/sdkconfig.defaults diff --git a/components/esp_hw_support/test_apps/esp_hw_support_unity_tests/main/CMakeLists.txt b/components/esp_hw_support/test_apps/esp_hw_support_unity_tests/main/CMakeLists.txt index dcac67fadb..40a5a7555b 100644 --- a/components/esp_hw_support/test_apps/esp_hw_support_unity_tests/main/CMakeLists.txt +++ b/components/esp_hw_support/test_apps/esp_hw_support_unity_tests/main/CMakeLists.txt @@ -19,5 +19,5 @@ endif() # In order for the cases defined by `TEST_CASE` to be linked into the final elf, # the component can be registered as WHOLE_ARCHIVE idf_component_register(SRCS ${srcs} - REQUIRES unity driver test_utils efuse + REQUIRES unity esp_driver_gpio esp_driver_gptimer esp_driver_uart test_utils efuse WHOLE_ARCHIVE) diff --git a/components/esp_hw_support/test_apps/rtc_8md256/main/CMakeLists.txt b/components/esp_hw_support/test_apps/rtc_8md256/main/CMakeLists.txt index 3e8fc6861e..c99a60f5ac 100644 --- a/components/esp_hw_support/test_apps/rtc_8md256/main/CMakeLists.txt +++ b/components/esp_hw_support/test_apps/rtc_8md256/main/CMakeLists.txt @@ -4,5 +4,5 @@ set(srcs "test_app_main.c" # In order for the cases defined by `TEST_CASE` to be linked into the final elf, # the component can be registered as WHOLE_ARCHIVE idf_component_register(SRCS ${srcs} - PRIV_REQUIRES unity driver + PRIV_REQUIRES unity esp_driver_uart WHOLE_ARCHIVE) diff --git a/components/esp_hw_support/test_apps/rtc_clk/main/CMakeLists.txt b/components/esp_hw_support/test_apps/rtc_clk/main/CMakeLists.txt index 37e22584de..a9565cef39 100644 --- a/components/esp_hw_support/test_apps/rtc_clk/main/CMakeLists.txt +++ b/components/esp_hw_support/test_apps/rtc_clk/main/CMakeLists.txt @@ -4,5 +4,5 @@ set(srcs "test_app_main.c" # In order for the cases defined by `TEST_CASE` to be linked into the final elf, # the component can be registered as WHOLE_ARCHIVE idf_component_register(SRCS ${srcs} - REQUIRES unity driver test_utils + REQUIRES unity esp_driver_gpio test_utils WHOLE_ARCHIVE) diff --git a/components/esp_hw_support/test_apps/rtc_power_modes/main/CMakeLists.txt b/components/esp_hw_support/test_apps/rtc_power_modes/main/CMakeLists.txt index 802123e798..ae51e0fd58 100644 --- a/components/esp_hw_support/test_apps/rtc_power_modes/main/CMakeLists.txt +++ b/components/esp_hw_support/test_apps/rtc_power_modes/main/CMakeLists.txt @@ -4,5 +4,5 @@ set(srcs "test_app_main.c" # In order for the cases defined by `TEST_CASE` to be linked into the final elf, # the component can be registered as WHOLE_ARCHIVE idf_component_register(SRCS ${srcs} - PRIV_REQUIRES unity driver + PRIV_REQUIRES unity esp_driver_uart driver WHOLE_ARCHIVE) diff --git a/components/esp_system/test_apps/esp_system_unity_tests/main/CMakeLists.txt b/components/esp_system/test_apps/esp_system_unity_tests/main/CMakeLists.txt index 3e822ddec1..7ce2d84614 100644 --- a/components/esp_system/test_apps/esp_system_unity_tests/main/CMakeLists.txt +++ b/components/esp_system/test_apps/esp_system_unity_tests/main/CMakeLists.txt @@ -1,6 +1,7 @@ set(requires "unity" "test_utils" - "driver" + "esp_driver_uart" + "esp_driver_gpio" "esp_timer" "nvs_flash" "esp_psram") diff --git a/components/openthread/CMakeLists.txt b/components/openthread/CMakeLists.txt index b878ce0e6d..8dfd62708f 100644 --- a/components/openthread/CMakeLists.txt +++ b/components/openthread/CMakeLists.txt @@ -196,7 +196,7 @@ idf_component_register(SRC_DIRS "${src_dirs}" EXCLUDE_SRCS "${exclude_srcs}" INCLUDE_DIRS "${public_include_dirs}" PRIV_INCLUDE_DIRS "${private_include_dirs}" - REQUIRES esp_netif lwip driver + REQUIRES esp_netif lwip esp_driver_uart driver LDFRAGMENTS linker.lf PRIV_REQUIRES console esp_event esp_partition esp_timer ieee802154 mbedtls nvs_flash) diff --git a/components/vfs/CMakeLists.txt b/components/vfs/CMakeLists.txt index d056cd8b0d..f46a303948 100644 --- a/components/vfs/CMakeLists.txt +++ b/components/vfs/CMakeLists.txt @@ -11,6 +11,7 @@ list(APPEND sources "vfs.c" "vfs_console.c") list(APPEND pr driver + esp_driver_uart esp_timer) idf_component_register(SRCS ${sources} diff --git a/docs/doxygen/Doxyfile b/docs/doxygen/Doxyfile index 2d1665f9ec..035d5fa498 100644 --- a/docs/doxygen/Doxyfile +++ b/docs/doxygen/Doxyfile @@ -78,7 +78,6 @@ INPUT = \ $(PROJECT_PATH)/components/driver/parlio/include/driver/parlio_types.h \ $(PROJECT_PATH)/components/driver/touch_sensor/include/driver/touch_sensor_common.h \ $(PROJECT_PATH)/components/driver/twai/include/driver/twai.h \ - $(PROJECT_PATH)/components/driver/uart/include/driver/uart.h \ $(PROJECT_PATH)/components/driver/test_apps/components/esp_serial_slave_link/include/esp_serial_slave_link/essl_sdio.h \ $(PROJECT_PATH)/components/driver/test_apps/components/esp_serial_slave_link/include/esp_serial_slave_link/essl_spi.h \ $(PROJECT_PATH)/components/driver/test_apps/components/esp_serial_slave_link/include/esp_serial_slave_link/essl.h \ @@ -143,6 +142,7 @@ INPUT = \ $(PROJECT_PATH)/components/esp_driver_spi/include/driver/spi_slave_hd.h \ $(PROJECT_PATH)/components/esp_driver_spi/include/driver/spi_slave.h \ $(PROJECT_PATH)/components/esp_driver_tsens/include/driver/temperature_sensor.h \ + $(PROJECT_PATH)/components/esp_driver_uart/include/driver/uart.h \ $(PROJECT_PATH)/components/esp_eth/include/esp_eth_com.h \ $(PROJECT_PATH)/components/esp_eth/include/esp_eth_driver.h \ $(PROJECT_PATH)/components/esp_eth/include/esp_eth_mac.h \ diff --git a/docs/en/migration-guides/release-5.x/5.3/peripherals.rst b/docs/en/migration-guides/release-5.x/5.3/peripherals.rst index ff7b10ec00..e4d72fcec8 100644 --- a/docs/en/migration-guides/release-5.x/5.3/peripherals.rst +++ b/docs/en/migration-guides/release-5.x/5.3/peripherals.rst @@ -20,6 +20,7 @@ In order to control the dependence of other components on drivers at a smaller g - `esp_driver_tsens` - Driver for Temperature Sensor - `esp_driver_sdm` - Driver for Sigma-Delta Modulator - `esp_driver_i2c` - Driver for I2C +- `esp_driver_uart` - Driver for UART For compatibility, the original `driver`` component is still treated as an all-in-one component by registering these `esp_driver_xyz`` components as its public dependencies. In other words, you do not need to modify the CMake file of an existing project, but you now have a way to specify the specific peripheral driver that your project depends on. diff --git a/docs/zh_CN/migration-guides/release-5.x/5.3/peripherals.rst b/docs/zh_CN/migration-guides/release-5.x/5.3/peripherals.rst index 59a5447efa..7d2530255d 100644 --- a/docs/zh_CN/migration-guides/release-5.x/5.3/peripherals.rst +++ b/docs/zh_CN/migration-guides/release-5.x/5.3/peripherals.rst @@ -20,6 +20,7 @@ - `esp_driver_tsens` - 温度传感器驱动 - `esp_driver_sdm` - Sigma-Delta 调制器驱动 - `esp_driver_i2c` - I2C 驱动 +- `esp_driver_uart` - UART 驱动 为了兼容性,原来的 `driver` 组件仍然存在,并作为一个 “all-in-one" 的组件,将以上这些 `esp_driver_xyz` 组件注册成自己的公共依赖。换句话说,你无需修改既有项目的 CMake 文件,但是你现在多了一个途径去指定你项目依赖的具体的外设驱动。 diff --git a/examples/bluetooth/.build-test-rules.yml b/examples/bluetooth/.build-test-rules.yml index 72d1facb01..4917e5c5fc 100644 --- a/examples/bluetooth/.build-test-rules.yml +++ b/examples/bluetooth/.build-test-rules.yml @@ -43,9 +43,9 @@ examples/bluetooth/bluedroid/classic_bt: - vfs - esp_driver_gpio - esp_driver_i2s + - esp_driver_uart depends_filepatterns: - components/driver/dac/**/* - - components/driver/uart/**/* examples/bluetooth/bluedroid/coex/a2dp_gatts_coex: <<: *bt_default_depends @@ -134,15 +134,15 @@ examples/bluetooth/hci/controller_hci_uart_esp32: <<: *bt_default_depends enable: - if: IDF_TARGET == "esp32" - depends_filepatterns: - - components/driver/uart/**/* + depends_components: + - esp_driver_uart examples/bluetooth/hci/controller_hci_uart_esp32c3_and_esp32s3: <<: *bt_default_depends enable: - if: IDF_TARGET in ["esp32c3", "esp32s3"] - depends_filepatterns: - - components/driver/uart/**/* + depends_components: + - esp_driver_uart # config BT_NIMBLE_ENABLED does not depends on any soc cap @@ -256,7 +256,7 @@ examples/bluetooth/nimble/throughput_app: - if: SOC_BLE_SUPPORTED != 1 depends_components: - esp_driver_gpio + - esp_driver_uart depends_filepatterns: - examples/bluetooth/nimble/common/**/* - examples/bluetooth/nimble/throughput_app/blecent_throughput/components/**/* - - components/driver/uart/**/* diff --git a/examples/wifi/.build-test-rules.yml b/examples/wifi/.build-test-rules.yml index d7aab698ee..1a6e8bc6d6 100644 --- a/examples/wifi/.build-test-rules.yml +++ b/examples/wifi/.build-test-rules.yml @@ -65,8 +65,8 @@ examples/wifi/power_save: <<: *wifi_depends_default disable: - if: SOC_WIFI_SUPPORTED != 1 - depends_filepatterns: - - components/driver/uart/**/* + depends_components: + - esp_driver_uart examples/wifi/wifi_aware: disable: