diff --git a/managed_components/espressif__button/.component_hash b/components/espressif__button/.component_hash similarity index 100% rename from managed_components/espressif__button/.component_hash rename to components/espressif__button/.component_hash diff --git a/managed_components/espressif__button/CHANGELOG.md b/components/espressif__button/CHANGELOG.md similarity index 100% rename from managed_components/espressif__button/CHANGELOG.md rename to components/espressif__button/CHANGELOG.md diff --git a/managed_components/espressif__button/CMakeLists.txt b/components/espressif__button/CMakeLists.txt similarity index 100% rename from managed_components/espressif__button/CMakeLists.txt rename to components/espressif__button/CMakeLists.txt diff --git a/managed_components/espressif__button/Kconfig b/components/espressif__button/Kconfig similarity index 100% rename from managed_components/espressif__button/Kconfig rename to components/espressif__button/Kconfig diff --git a/managed_components/espressif__button/README.md b/components/espressif__button/README.md similarity index 100% rename from managed_components/espressif__button/README.md rename to components/espressif__button/README.md diff --git a/managed_components/espressif__button/button_adc.c b/components/espressif__button/button_adc.c similarity index 100% rename from managed_components/espressif__button/button_adc.c rename to components/espressif__button/button_adc.c diff --git a/managed_components/espressif__button/button_gpio.c b/components/espressif__button/button_gpio.c similarity index 100% rename from managed_components/espressif__button/button_gpio.c rename to components/espressif__button/button_gpio.c diff --git a/managed_components/espressif__button/button_matrix.c b/components/espressif__button/button_matrix.c similarity index 100% rename from managed_components/espressif__button/button_matrix.c rename to components/espressif__button/button_matrix.c diff --git a/components/espressif__button/examples/button_power_save/CMakeLists.txt b/components/espressif__button/examples/button_power_save/CMakeLists.txt new file mode 100644 index 0000000..78c65a1 --- /dev/null +++ b/components/espressif__button/examples/button_power_save/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(button_power_save) diff --git a/components/espressif__button/examples/button_power_save/README.md b/components/espressif__button/examples/button_power_save/README.md new file mode 100644 index 0000000..4e05d2e --- /dev/null +++ b/components/espressif__button/examples/button_power_save/README.md @@ -0,0 +1,43 @@ +## Button Power Save Example + +This example demonstrates how to utilize the `button` component in conjunction with the light sleep low-power mode. + +* `button` [Component Introduction](https://docs.espressif.com/projects/esp-iot-solution/en/latest/input_device/button.html) + +## Hardware + +* Any GPIO on any development board can be used in this example. + +## Build and Flash + +Build the project and flash it to the board, then run the monitor tool to view the serial output: + +* Run `. ./export.sh` to set IDF environment +* Run `idf.py set-target esp32xx` to set target chip +* Run `idf.py -p PORT flash monitor` to build, flash and monitor the project + +(To exit the serial monitor, type `Ctrl-]`.) + +See the Getting Started Guide for all the steps to configure and use the ESP-IDF to build projects. + +## Example Output + +``` +I (1139) pm: Frequency switching config: CPU_MAX: 160, APB_MAX: 80, APB_MIN: 80, Light sleep: ENABLED +I (1149) sleep: Code start at 42000020, total 119.03 KiB, data start at 3c000000, total 49152.00 KiB +I (1159) button: IoT Button Version: 3.2.0 +I (1163) gpio: GPIO[0]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 +I (2922) button_power_save: Button event BUTTON_PRESS_DOWN +I (3017) button_power_save: Button event BUTTON_PRESS_UP +I (3017) button_power_save: Wake up from light sleep, reason 4 +I (3200) button_power_save: Button event BUTTON_SINGLE_CLICK +I (3200) button_power_save: Wake up from light sleep, reason 4 +I (3202) button_power_save: Button event BUTTON_PRESS_REPEAT_DONE +I (3208) button_power_save: Wake up from light sleep, reason 4 +I (3627) button_power_save: Button event BUTTON_PRESS_DOWN +I (3702) button_power_save: Button event BUTTON_PRESS_UP +I (3702) button_power_save: Wake up from light sleep, reason 4 +I (3887) button_power_save: Button event BUTTON_SINGLE_CLICK +I (3887) button_power_save: Wake up from light sleep, reason 4 +I (3889) button_power_save: Button event BUTTON_PRESS_REPEAT_DONE +``` \ No newline at end of file diff --git a/components/espressif__button/examples/button_power_save/main/CMakeLists.txt b/components/espressif__button/examples/button_power_save/main/CMakeLists.txt new file mode 100644 index 0000000..cf2c455 --- /dev/null +++ b/components/espressif__button/examples/button_power_save/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "main.c" + INCLUDE_DIRS ".") diff --git a/components/espressif__button/examples/button_power_save/main/Kconfig.projbuild b/components/espressif__button/examples/button_power_save/main/Kconfig.projbuild new file mode 100644 index 0000000..a8bc22c --- /dev/null +++ b/components/espressif__button/examples/button_power_save/main/Kconfig.projbuild @@ -0,0 +1,87 @@ +menu "Example Configuration" + + choice ENTER_LIGHT_SLEEP_MODE + prompt "Enter light sleep mode" + default ENTER_LIGHT_SLEEP_AUTO + depends on PM_ENABLE + help + Enable light sleep mode to save power. + + config ENTER_LIGHT_SLEEP_AUTO + bool "Auto enter Light Sleep" + config ENTER_LIGHT_SLEEP_MODE_MANUALLY + bool "Manually enter Light Sleep" + endchoice + + choice EXAMPLE_MAX_CPU_FREQ + prompt "Maximum CPU frequency" + default EXAMPLE_MAX_CPU_FREQ_80 if !IDF_TARGET_ESP32H2 + default EXAMPLE_MAX_CPU_FREQ_96 if IDF_TARGET_ESP32H2 + depends on PM_ENABLE + help + Maximum CPU frequency to use for dynamic frequency scaling. + + config EXAMPLE_MAX_CPU_FREQ_80 + bool "80 MHz" + config EXAMPLE_MAX_CPU_FREQ_96 + bool "96 MHz" + depends on IDF_TARGET_ESP32H2 + config EXAMPLE_MAX_CPU_FREQ_120 + bool "120 MHz" + depends on IDF_TARGET_ESP32C2 + config EXAMPLE_MAX_CPU_FREQ_160 + bool "160 MHz" + depends on !IDF_TARGET_ESP32C2 + config EXAMPLE_MAX_CPU_FREQ_240 + bool "240 MHz" + depends on IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + endchoice + + config EXAMPLE_MAX_CPU_FREQ_MHZ + int + default 80 if EXAMPLE_MAX_CPU_FREQ_80 + default 96 if EXAMPLE_MAX_CPU_FREQ_96 + default 120 if EXAMPLE_MAX_CPU_FREQ_120 + default 160 if EXAMPLE_MAX_CPU_FREQ_160 + default 240 if EXAMPLE_MAX_CPU_FREQ_240 + + choice EXAMPLE_MIN_CPU_FREQ + prompt "Minimum CPU frequency" + default EXAMPLE_MIN_CPU_FREQ_10M if !IDF_TARGET_ESP32H2 + default EXAMPLE_MIN_CPU_FREQ_32M if IDF_TARGET_ESP32H2 + depends on PM_ENABLE + help + Minimum CPU frequency to use for dynamic frequency scaling. + Should be set to XTAL frequency or XTAL frequency divided by integer. + + config EXAMPLE_MIN_CPU_FREQ_40M + bool "40 MHz (use with 40MHz XTAL)" + depends on XTAL_FREQ_40 || XTAL_FREQ_AUTO || ESP32_XTAL_FREQ_40 || ESP32_XTAL_FREQ_AUTO || !IDF_TARGET_ESP32 + config EXAMPLE_MIN_CPU_FREQ_20M + bool "20 MHz (use with 40MHz XTAL)" + depends on XTAL_FREQ_40 || XTAL_FREQ_AUTO || ESP32_XTAL_FREQ_40 || ESP32_XTAL_FREQ_AUTO || !IDF_TARGET_ESP32 + config EXAMPLE_MIN_CPU_FREQ_10M + bool "10 MHz (use with 40MHz XTAL)" + depends on XTAL_FREQ_40 || XTAL_FREQ_AUTO || ESP32_XTAL_FREQ_40 || ESP32_XTAL_FREQ_AUTO || !IDF_TARGET_ESP32 + config EXAMPLE_MIN_CPU_FREQ_26M + bool "26 MHz (use with 26MHz XTAL)" + depends on XTAL_FREQ_26 || XTAL_FREQ_AUTO || ESP32_XTAL_FREQ_26 || ESP32_XTAL_FREQ_AUTO + config EXAMPLE_MIN_CPU_FREQ_13M + bool "13 MHz (use with 26MHz XTAL)" + depends on XTAL_FREQ_26 || XTAL_FREQ_AUTO || ESP32_XTAL_FREQ_26 || ESP32_XTAL_FREQ_AUTO + config EXAMPLE_MIN_CPU_FREQ_32M + bool "32 MHz (use with 32MHz XTAL)" + depends on IDF_TARGET_ESP32H2 + depends on XTAL_FREQ_32 || XTAL_FREQ_AUTO + endchoice + + config EXAMPLE_MIN_CPU_FREQ_MHZ + int + default 40 if EXAMPLE_MIN_CPU_FREQ_40M + default 20 if EXAMPLE_MIN_CPU_FREQ_20M + default 10 if EXAMPLE_MIN_CPU_FREQ_10M + default 26 if EXAMPLE_MIN_CPU_FREQ_26M + default 13 if EXAMPLE_MIN_CPU_FREQ_13M + default 32 if EXAMPLE_MIN_CPU_FREQ_32M + +endmenu diff --git a/components/espressif__button/examples/button_power_save/main/idf_component.yml b/components/espressif__button/examples/button_power_save/main/idf_component.yml new file mode 100644 index 0000000..f237544 --- /dev/null +++ b/components/espressif__button/examples/button_power_save/main/idf_component.yml @@ -0,0 +1,6 @@ +version: "0.0.1" +dependencies: + idf: ">=4.4" + button: + version: "*" + override_path: "../../../../components/button" diff --git a/components/espressif__button/examples/button_power_save/main/main.c b/components/espressif__button/examples/button_power_save/main/main.c new file mode 100644 index 0000000..0a6b249 --- /dev/null +++ b/components/espressif__button/examples/button_power_save/main/main.c @@ -0,0 +1,139 @@ +/* + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_log.h" +#include "esp_pm.h" +#include "iot_button.h" +#include "esp_sleep.h" +#include "esp_idf_version.h" + +/* Most development boards have "boot" button attached to GPIO0. + * You can also change this to another pin. + */ +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C6 +#define BOOT_BUTTON_NUM 9 +#else +#define BOOT_BUTTON_NUM 0 +#endif +#define BUTTON_ACTIVE_LEVEL 0 + +static const char *TAG = "button_power_save"; + +const char *button_event_table[] = { + "BUTTON_PRESS_DOWN", + "BUTTON_PRESS_UP", + "BUTTON_PRESS_REPEAT", + "BUTTON_PRESS_REPEAT_DONE", + "BUTTON_SINGLE_CLICK", + "BUTTON_DOUBLE_CLICK", + "BUTTON_MULTIPLE_CLICK", + "BUTTON_LONG_PRESS_START", + "BUTTON_LONG_PRESS_HOLD", + "BUTTON_LONG_PRESS_UP", + "BUTTON_PRESS_END", +}; + +static void button_event_cb(void *arg, void *data) +{ + ESP_LOGI(TAG, "Button event %s", button_event_table[(button_event_t)data]); + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); + if (cause != ESP_SLEEP_WAKEUP_UNDEFINED) { + ESP_LOGI(TAG, "Wake up from light sleep, reason %d", cause); + } +} + +#if CONFIG_ENTER_LIGHT_SLEEP_MODE_MANUALLY +void button_enter_power_save(void *usr_data) +{ + ESP_LOGI(TAG, "Can enter power save now"); + esp_light_sleep_start(); +} +#endif + +void button_init(uint32_t button_num) +{ + button_config_t btn_cfg = { + .type = BUTTON_TYPE_GPIO, + .gpio_button_config = { + .gpio_num = button_num, + .active_level = BUTTON_ACTIVE_LEVEL, +#if CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE + .enable_power_save = true, +#endif + }, + }; + button_handle_t btn = iot_button_create(&btn_cfg); + assert(btn); + esp_err_t err = iot_button_register_cb(btn, BUTTON_PRESS_DOWN, button_event_cb, (void *)BUTTON_PRESS_DOWN); + err |= iot_button_register_cb(btn, BUTTON_PRESS_UP, button_event_cb, (void *)BUTTON_PRESS_UP); + err |= iot_button_register_cb(btn, BUTTON_PRESS_REPEAT, button_event_cb, (void *)BUTTON_PRESS_REPEAT); + err |= iot_button_register_cb(btn, BUTTON_PRESS_REPEAT_DONE, button_event_cb, (void *)BUTTON_PRESS_REPEAT_DONE); + err |= iot_button_register_cb(btn, BUTTON_SINGLE_CLICK, button_event_cb, (void *)BUTTON_SINGLE_CLICK); + err |= iot_button_register_cb(btn, BUTTON_DOUBLE_CLICK, button_event_cb, (void *)BUTTON_DOUBLE_CLICK); + err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_START, button_event_cb, (void *)BUTTON_LONG_PRESS_START); + err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_HOLD, button_event_cb, (void *)BUTTON_LONG_PRESS_HOLD); + err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_UP, button_event_cb, (void *)BUTTON_LONG_PRESS_UP); + err |= iot_button_register_cb(btn, BUTTON_PRESS_END, button_event_cb, (void *)BUTTON_PRESS_END); + +#if CONFIG_ENTER_LIGHT_SLEEP_MODE_MANUALLY + /*!< For enter Power Save */ + button_power_save_config_t config = { + .enter_power_save_cb = button_enter_power_save, + }; + err |= iot_button_register_power_save_cb(&config); +#endif + + ESP_ERROR_CHECK(err); +} + +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0) +void power_save_init(void) +{ + esp_pm_config_t pm_config = { + .max_freq_mhz = CONFIG_EXAMPLE_MAX_CPU_FREQ_MHZ, + .min_freq_mhz = CONFIG_EXAMPLE_MIN_CPU_FREQ_MHZ, +#if CONFIG_FREERTOS_USE_TICKLESS_IDLE + .light_sleep_enable = true +#endif + }; + ESP_ERROR_CHECK(esp_pm_configure(&pm_config)); +} +#else +void power_save_init(void) +{ +#if CONFIG_IDF_TARGET_ESP32 + esp_pm_config_esp32_t pm_config = { +#elif CONFIG_IDF_TARGET_ESP32S2 + esp_pm_config_esp32s2_t pm_config = { +#elif CONFIG_IDF_TARGET_ESP32C3 + esp_pm_config_esp32c3_t pm_config = { +#elif CONFIG_IDF_TARGET_ESP32S3 + esp_pm_config_esp32s3_t pm_config = { +#elif CONFIG_IDF_TARGET_ESP32C2 + esp_pm_config_esp32c2_t pm_config = { +#endif + .max_freq_mhz = CONFIG_EXAMPLE_MAX_CPU_FREQ_MHZ, + .min_freq_mhz = CONFIG_EXAMPLE_MIN_CPU_FREQ_MHZ, +#if CONFIG_FREERTOS_USE_TICKLESS_IDLE + .light_sleep_enable = true +#endif + }; + ESP_ERROR_CHECK(esp_pm_configure(&pm_config)); +} +#endif + +void app_main(void) +{ + button_init(BOOT_BUTTON_NUM); +#if CONFIG_ENTER_LIGHT_SLEEP_AUTO + power_save_init(); +#else + esp_light_sleep_start(); +#endif +} diff --git a/managed_components/espressif__button/idf_component.yml b/components/espressif__button/idf_component.yml similarity index 100% rename from managed_components/espressif__button/idf_component.yml rename to components/espressif__button/idf_component.yml diff --git a/managed_components/espressif__button/include/button_adc.h b/components/espressif__button/include/button_adc.h similarity index 100% rename from managed_components/espressif__button/include/button_adc.h rename to components/espressif__button/include/button_adc.h diff --git a/managed_components/espressif__button/include/button_gpio.h b/components/espressif__button/include/button_gpio.h similarity index 100% rename from managed_components/espressif__button/include/button_gpio.h rename to components/espressif__button/include/button_gpio.h diff --git a/managed_components/espressif__button/include/button_matrix.h b/components/espressif__button/include/button_matrix.h similarity index 100% rename from managed_components/espressif__button/include/button_matrix.h rename to components/espressif__button/include/button_matrix.h diff --git a/managed_components/espressif__button/include/iot_button.h b/components/espressif__button/include/iot_button.h similarity index 100% rename from managed_components/espressif__button/include/iot_button.h rename to components/espressif__button/include/iot_button.h diff --git a/managed_components/espressif__button/iot_button.c b/components/espressif__button/iot_button.c similarity index 100% rename from managed_components/espressif__button/iot_button.c rename to components/espressif__button/iot_button.c diff --git a/managed_components/espressif__button/license.txt b/components/espressif__button/license.txt similarity index 100% rename from managed_components/espressif__button/license.txt rename to components/espressif__button/license.txt diff --git a/components/espressif__button/test_apps/CMakeLists.txt b/components/espressif__button/test_apps/CMakeLists.txt new file mode 100644 index 0000000..180743a --- /dev/null +++ b/components/espressif__button/test_apps/CMakeLists.txt @@ -0,0 +1,9 @@ + +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components" + "../../button") +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(button_test) diff --git a/components/espressif__button/test_apps/main/CMakeLists.txt b/components/espressif__button/test_apps/main/CMakeLists.txt new file mode 100644 index 0000000..0fc53ca --- /dev/null +++ b/components/espressif__button/test_apps/main/CMakeLists.txt @@ -0,0 +1,9 @@ +if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") + list(APPEND PRIVREQ esp_adc) +else() + list(APPEND PRIVREQ esp_adc_cal) +endif() + +idf_component_register(SRC_DIRS "." + PRIV_INCLUDE_DIRS "." + PRIV_REQUIRES unity test_utils button ${PRIVREQ}) diff --git a/components/espressif__button/test_apps/main/button_test.c b/components/espressif__button/test_apps/main/button_test.c new file mode 100644 index 0000000..47a1461 --- /dev/null +++ b/components/espressif__button/test_apps/main/button_test.c @@ -0,0 +1,767 @@ +/* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "stdio.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/timers.h" +#include "freertos/semphr.h" +#include "freertos/event_groups.h" +#include "esp_idf_version.h" +#include "esp_log.h" +#include "unity.h" +#include "iot_button.h" +#include "sdkconfig.h" + +static const char *TAG = "BUTTON TEST"; + +#define TEST_MEMORY_LEAK_THRESHOLD (-400) +#define BUTTON_IO_NUM 0 +#define BUTTON_ACTIVE_LEVEL 0 +#define BUTTON_NUM 16 + +static size_t before_free_8bit; +static size_t before_free_32bit; +static button_handle_t g_btns[BUTTON_NUM] = {0}; + +static int get_btn_index(button_handle_t btn) +{ + for (size_t i = 0; i < BUTTON_NUM; i++) { + if (btn == g_btns[i]) { + return i; + } + } + return -1; +} + +static void button_press_down_cb(void *arg, void *data) +{ + TEST_ASSERT_EQUAL_HEX(BUTTON_PRESS_DOWN, iot_button_get_event(arg)); + ESP_LOGI(TAG, "BTN%d: BUTTON_PRESS_DOWN", get_btn_index((button_handle_t)arg)); +} + +static void button_press_up_cb(void *arg, void *data) +{ + TEST_ASSERT_EQUAL_HEX(BUTTON_PRESS_UP, iot_button_get_event(arg)); + ESP_LOGI(TAG, "BTN%d: BUTTON_PRESS_UP[%d]", get_btn_index((button_handle_t)arg), iot_button_get_ticks_time((button_handle_t)arg)); +} + +static void button_press_repeat_cb(void *arg, void *data) +{ + ESP_LOGI(TAG, "BTN%d: BUTTON_PRESS_REPEAT[%d]", get_btn_index((button_handle_t)arg), iot_button_get_repeat((button_handle_t)arg)); +} + +static void button_single_click_cb(void *arg, void *data) +{ + TEST_ASSERT_EQUAL_HEX(BUTTON_SINGLE_CLICK, iot_button_get_event(arg)); + ESP_LOGI(TAG, "BTN%d: BUTTON_SINGLE_CLICK", get_btn_index((button_handle_t)arg)); +} + +static void button_double_click_cb(void *arg, void *data) +{ + TEST_ASSERT_EQUAL_HEX(BUTTON_DOUBLE_CLICK, iot_button_get_event(arg)); + ESP_LOGI(TAG, "BTN%d: BUTTON_DOUBLE_CLICK", get_btn_index((button_handle_t)arg)); +} + +static void button_long_press_start_cb(void *arg, void *data) +{ + TEST_ASSERT_EQUAL_HEX(BUTTON_LONG_PRESS_START, iot_button_get_event(arg)); + ESP_LOGI(TAG, "BTN%d: BUTTON_LONG_PRESS_START", get_btn_index((button_handle_t)arg)); +} + +static void button_long_press_hold_cb(void *arg, void *data) +{ + TEST_ASSERT_EQUAL_HEX(BUTTON_LONG_PRESS_HOLD, iot_button_get_event(arg)); + ESP_LOGI(TAG, "BTN%d: BUTTON_LONG_PRESS_HOLD[%d],count is [%d]", get_btn_index((button_handle_t)arg), iot_button_get_ticks_time((button_handle_t)arg), iot_button_get_long_press_hold_cnt((button_handle_t)arg)); +} + +static void button_press_repeat_done_cb(void *arg, void *data) +{ + TEST_ASSERT_EQUAL_HEX(BUTTON_PRESS_REPEAT_DONE, iot_button_get_event(arg)); + ESP_LOGI(TAG, "BTN%d: BUTTON_PRESS_REPEAT_DONE[%d]", get_btn_index((button_handle_t)arg), iot_button_get_repeat((button_handle_t)arg)); +} + +static esp_err_t custom_button_gpio_init(void *param) +{ + button_gpio_config_t *cfg = (button_gpio_config_t *)param; + + return button_gpio_init(cfg); +} + +static uint8_t custom_button_gpio_get_key_value(void *param) +{ + button_gpio_config_t *cfg = (button_gpio_config_t *)param; + + return button_gpio_get_key_level((void *)cfg->gpio_num); +} + +static esp_err_t custom_button_gpio_deinit(void *param) +{ + button_gpio_config_t *cfg = (button_gpio_config_t *)param; + + return button_gpio_deinit(cfg->gpio_num); +} + +TEST_CASE("custom button test", "[button][iot]") +{ + button_gpio_config_t *gpio_cfg = calloc(1, sizeof(button_gpio_config_t)); + gpio_cfg->active_level = 0; + gpio_cfg->gpio_num = 0; + + button_config_t cfg = { + .type = BUTTON_TYPE_CUSTOM, + .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS, + .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS, + .custom_button_config = { + .button_custom_init = custom_button_gpio_init, + .button_custom_deinit = custom_button_gpio_deinit, + .button_custom_get_key_value = custom_button_gpio_get_key_value, + .active_level = 0, + .priv = gpio_cfg, + }, + }; + + g_btns[0] = iot_button_create(&cfg); + TEST_ASSERT_NOT_NULL(g_btns[0]); + iot_button_register_cb(g_btns[0], BUTTON_PRESS_DOWN, button_press_down_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_PRESS_UP, button_press_up_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT, button_press_repeat_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_SINGLE_CLICK, button_single_click_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_DOUBLE_CLICK, button_double_click_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_START, button_long_press_start_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT_DONE, button_press_repeat_done_cb, NULL); + + while (1) { + vTaskDelay(pdMS_TO_TICKS(1000)); + } + + iot_button_delete(g_btns[0]); +} + +TEST_CASE("gpio button test", "[button][iot]") +{ + button_config_t cfg = { + .type = BUTTON_TYPE_GPIO, + .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS, + .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS, + .gpio_button_config = { + .gpio_num = 0, + .active_level = 0, + }, + }; + g_btns[0] = iot_button_create(&cfg); + TEST_ASSERT_NOT_NULL(g_btns[0]); + iot_button_register_cb(g_btns[0], BUTTON_PRESS_DOWN, button_press_down_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_PRESS_UP, button_press_up_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT, button_press_repeat_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_SINGLE_CLICK, button_single_click_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_DOUBLE_CLICK, button_double_click_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_START, button_long_press_start_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT_DONE, button_press_repeat_done_cb, NULL); + + uint8_t level = 0; + level = iot_button_get_key_level(g_btns[0]); + ESP_LOGI(TAG, "button level is %d", level); + + while (1) { + vTaskDelay(pdMS_TO_TICKS(1000)); + } + + iot_button_delete(g_btns[0]); +} + +TEST_CASE("gpio button get event test", "[button][iot]") +{ + const char *EVENT_STR[] = {"BUTTON_PRESS_DOWN", + "BUTTON_PRESS_UP", + "BUTTON_PRESS_REPEAT", + "BUTTON_PRESS_REPEAT_DONE", + "BUTTON_SINGLE_CLICK", + "BUTTON_DOUBLE_CLICK", + "BUTTON_MULTIPLE_CLICK", + "BUTTON_LONG_PRESS_START", + "BUTTON_LONG_PRESS_HOLD", + "BUTTON_LONG_PRESS_UP", + "BUTTON_PRESS_END", + }; + + button_config_t cfg = { + .type = BUTTON_TYPE_GPIO, + .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS, + .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS, + .gpio_button_config = { + .gpio_num = 0, + .active_level = 0, + }, + }; + g_btns[0] = iot_button_create(&cfg); + TEST_ASSERT_NOT_NULL(g_btns[0]); + + uint8_t level = 0; + level = iot_button_get_key_level(g_btns[0]); + ESP_LOGI(TAG, "button level is %d", level); + + while (1) { + button_event_t event = iot_button_get_event(g_btns[0]); + if (event != BUTTON_NONE_PRESS) { + printf("event is %s\n", EVENT_STR[event]); + } + vTaskDelay(pdMS_TO_TICKS(1)); + } + + iot_button_delete(g_btns[0]); +} + +TEST_CASE("gpio button test power save", "[button][iot][power save]") +{ + button_config_t cfg = { + .type = BUTTON_TYPE_GPIO, + .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS, + .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS, + .gpio_button_config = { + .gpio_num = 0, + .active_level = 0, + }, + }; + g_btns[0] = iot_button_create(&cfg); + TEST_ASSERT_NOT_NULL(g_btns[0]); + iot_button_register_cb(g_btns[0], BUTTON_PRESS_DOWN, button_press_down_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_PRESS_UP, button_press_up_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT, button_press_repeat_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_SINGLE_CLICK, button_single_click_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_DOUBLE_CLICK, button_double_click_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_START, button_long_press_start_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb, NULL); + iot_button_register_cb(g_btns[0], BUTTON_PRESS_REPEAT_DONE, button_press_repeat_done_cb, NULL); + + TEST_ASSERT_EQUAL(ESP_OK, iot_button_stop()); + vTaskDelay(pdMS_TO_TICKS(1000)); + TEST_ASSERT_EQUAL(ESP_OK, iot_button_resume()); + + while (1) { + vTaskDelay(pdMS_TO_TICKS(1000)); + } + + iot_button_delete(g_btns[0]); +} + +TEST_CASE("matrix keyboard button test", "[button][matrix key]") +{ + int32_t row_gpio[4] = {4, 5, 6, 7}; + int32_t col_gpio[4] = {3, 8, 16, 15}; + button_config_t cfg = { + .type = BUTTON_TYPE_MATRIX, + .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS, + .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS, + .matrix_button_config = { + .row_gpio_num = 0, + .col_gpio_num = 0, + } + }; + + for (int i = 0; i < 4; i++) { + cfg.matrix_button_config.row_gpio_num = row_gpio[i]; + for (int j = 0; j < 4; j++) { + cfg.matrix_button_config.col_gpio_num = col_gpio[j]; + g_btns[i * 4 + j] = iot_button_create(&cfg); + TEST_ASSERT_NOT_NULL(g_btns[i * 4 + j]); + iot_button_register_cb(g_btns[i * 4 + j], BUTTON_PRESS_DOWN, button_press_down_cb, NULL); + iot_button_register_cb(g_btns[i * 4 + j], BUTTON_PRESS_UP, button_press_up_cb, NULL); + iot_button_register_cb(g_btns[i * 4 + j], BUTTON_PRESS_REPEAT, button_press_repeat_cb, NULL); + iot_button_register_cb(g_btns[i * 4 + j], BUTTON_SINGLE_CLICK, button_single_click_cb, NULL); + iot_button_register_cb(g_btns[i * 4 + j], BUTTON_DOUBLE_CLICK, button_double_click_cb, NULL); + iot_button_register_cb(g_btns[i * 4 + j], BUTTON_LONG_PRESS_START, button_long_press_start_cb, NULL); + iot_button_register_cb(g_btns[i * 4 + j], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb, NULL); + iot_button_register_cb(g_btns[i * 4 + j], BUTTON_PRESS_REPEAT_DONE, button_press_repeat_done_cb, NULL); + } + } + + while (1) { + vTaskDelay(pdMS_TO_TICKS(1000)); + } + + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + iot_button_delete(g_btns[i * 4 + j]); + } + } +} + +#if CONFIG_SOC_ADC_SUPPORTED +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) +TEST_CASE("adc button test", "[button][iot]") +{ + /** ESP32-S3-Korvo board */ + const uint16_t vol[6] = {380, 820, 1180, 1570, 1980, 2410}; + button_config_t cfg = {0}; + cfg.type = BUTTON_TYPE_ADC; + cfg.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS; + cfg.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS; + for (size_t i = 0; i < 6; i++) { + cfg.adc_button_config.adc_channel = 7, + cfg.adc_button_config.button_index = i; + if (i == 0) { + cfg.adc_button_config.min = (0 + vol[i]) / 2; + } else { + cfg.adc_button_config.min = (vol[i - 1] + vol[i]) / 2; + } + + if (i == 5) { + cfg.adc_button_config.max = (vol[i] + 3000) / 2; + } else { + cfg.adc_button_config.max = (vol[i] + vol[i + 1]) / 2; + } + + g_btns[i] = iot_button_create(&cfg); + TEST_ASSERT_NOT_NULL(g_btns[i]); + iot_button_register_cb(g_btns[i], BUTTON_PRESS_DOWN, button_press_down_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_PRESS_UP, button_press_up_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_PRESS_REPEAT, button_press_repeat_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_SINGLE_CLICK, button_single_click_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_DOUBLE_CLICK, button_double_click_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_LONG_PRESS_START, button_long_press_start_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_PRESS_REPEAT_DONE, button_press_repeat_done_cb, NULL); + } + + while (1) { + vTaskDelay(pdMS_TO_TICKS(1000)); + } + for (size_t i = 0; i < 6; i++) { + iot_button_delete(g_btns[i]); + } +} +#else + +#include "esp_adc/adc_cali.h" + +static esp_err_t adc_calibration_init(adc_unit_t unit, adc_atten_t atten, adc_cali_handle_t *out_handle) +{ + +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) +#define ADC_BUTTON_WIDTH SOC_ADC_RTC_MAX_BITWIDTH +#else +#define ADC_BUTTON_WIDTH ADC_WIDTH_MAX - 1 +#endif + + adc_cali_handle_t handle = NULL; + esp_err_t ret = ESP_FAIL; + bool calibrated = false; + +#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED + if (!calibrated) { + ESP_LOGI(TAG, "calibration scheme version is %s", "Curve Fitting"); + adc_cali_curve_fitting_config_t cali_config = { + .unit_id = unit, + .atten = atten, + .bitwidth = ADC_BUTTON_WIDTH, + }; + ret = adc_cali_create_scheme_curve_fitting(&cali_config, &handle); + if (ret == ESP_OK) { + calibrated = true; + } + } +#endif + +#if ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED + if (!calibrated) { + ESP_LOGI(TAG, "calibration scheme version is %s", "Line Fitting"); + adc_cali_line_fitting_config_t cali_config = { + .unit_id = unit, + .atten = atten, + .bitwidth = ADC_BUTTON_WIDTH, + }; + ret = adc_cali_create_scheme_line_fitting(&cali_config, &handle); + if (ret == ESP_OK) { + calibrated = true; + } + } +#endif + + *out_handle = handle; + if (ret == ESP_OK) { + ESP_LOGI(TAG, "Calibration Success"); + } else if (ret == ESP_ERR_NOT_SUPPORTED || !calibrated) { + ESP_LOGW(TAG, "eFuse not burnt, skip software calibration"); + } else { + ESP_LOGE(TAG, "Invalid arg or no memory"); + } + + return calibrated ? ESP_OK : ESP_FAIL; +} + +TEST_CASE("adc button idf5 drive test", "[button][iot]") +{ + adc_oneshot_unit_handle_t adc1_handle; + adc_cali_handle_t adc1_cali_handle; + adc_oneshot_unit_init_cfg_t init_config = { + .unit_id = ADC_UNIT_1, + }; + esp_err_t ret = adc_oneshot_new_unit(&init_config, &adc1_handle); + TEST_ASSERT_TRUE(ret == ESP_OK); + /*!< use atten 11db or 12db */ + adc_calibration_init(ADC_UNIT_1, 3, &adc1_cali_handle); + + /** ESP32-S3-Korvo board */ + const uint16_t vol[6] = {380, 820, 1180, 1570, 1980, 2410}; + button_config_t cfg = {0}; + cfg.type = BUTTON_TYPE_ADC; + cfg.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS; + cfg.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS; + for (size_t i = 0; i < 6; i++) { + cfg.adc_button_config.adc_handle = &adc1_handle; + cfg.adc_button_config.adc_channel = 7, + cfg.adc_button_config.button_index = i; + if (i == 0) { + cfg.adc_button_config.min = (0 + vol[i]) / 2; + } else { + cfg.adc_button_config.min = (vol[i - 1] + vol[i]) / 2; + } + + if (i == 5) { + cfg.adc_button_config.max = (vol[i] + 3000) / 2; + } else { + cfg.adc_button_config.max = (vol[i] + vol[i + 1]) / 2; + } + + g_btns[i] = iot_button_create(&cfg); + TEST_ASSERT_NOT_NULL(g_btns[i]); + iot_button_register_cb(g_btns[i], BUTTON_PRESS_DOWN, button_press_down_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_PRESS_UP, button_press_up_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_PRESS_REPEAT, button_press_repeat_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_SINGLE_CLICK, button_single_click_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_DOUBLE_CLICK, button_double_click_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_LONG_PRESS_START, button_long_press_start_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_LONG_PRESS_HOLD, button_long_press_hold_cb, NULL); + iot_button_register_cb(g_btns[i], BUTTON_PRESS_REPEAT_DONE, button_press_repeat_done_cb, NULL); + } + + while (1) { + vTaskDelay(pdMS_TO_TICKS(1000)); + } + for (size_t i = 0; i < 6; i++) { + iot_button_delete(g_btns[i]); + } +} +#endif +#endif // CONFIG_SOC_ADC_SUPPORTED + +#define GPIO_OUTPUT_IO_45 45 +static EventGroupHandle_t g_check = NULL; +static SemaphoreHandle_t g_auto_check_pass = NULL; +static const char* button_event_str[BUTTON_EVENT_MAX] = { + "BUTTON_PRESS_DOWN", + "BUTTON_PRESS_UP", + "BUTTON_PRESS_REPEAT", + "BUTTON_PRESS_REPEAT_DONE", + "BUTTON_SINGLE_CLICK", + "BUTTON_DOUBLE_CLICK", + "BUTTON_MULTIPLE_CLICK", + "BUTTON_LONG_PRESS_START", + "BUTTON_LONG_PRESS_HOLD", + "BUTTON_LONG_PRESS_UP", + "BUTTON_PRESS_END", +}; + +static button_event_t state = BUTTON_PRESS_DOWN; + +static void button_auto_press_test_task(void *arg) +{ + // test BUTTON_PRESS_DOWN + xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY); + gpio_set_level(GPIO_OUTPUT_IO_45, 0); + vTaskDelay(pdMS_TO_TICKS(100)); + + // // test BUTTON_PRESS_UP + xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY); + gpio_set_level(GPIO_OUTPUT_IO_45, 1); + vTaskDelay(pdMS_TO_TICKS(200)); + + // test BUTTON_PRESS_REPEAT + xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY); + gpio_set_level(GPIO_OUTPUT_IO_45, 0); + vTaskDelay(pdMS_TO_TICKS(100)); + gpio_set_level(GPIO_OUTPUT_IO_45, 1); + vTaskDelay(pdMS_TO_TICKS(100)); + gpio_set_level(GPIO_OUTPUT_IO_45, 0); + vTaskDelay(pdMS_TO_TICKS(100)); + + // test BUTTON_PRESS_REPEAT_DONE + xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY); + gpio_set_level(GPIO_OUTPUT_IO_45, 1); + vTaskDelay(pdMS_TO_TICKS(200)); + + // test BUTTON_SINGLE_CLICK + xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY); + gpio_set_level(GPIO_OUTPUT_IO_45, 0); + vTaskDelay(pdMS_TO_TICKS(100)); + gpio_set_level(GPIO_OUTPUT_IO_45, 1); + vTaskDelay(pdMS_TO_TICKS(200)); + + // test BUTTON_DOUBLE_CLICK + xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY); + gpio_set_level(GPIO_OUTPUT_IO_45, 0); + vTaskDelay(pdMS_TO_TICKS(100)); + gpio_set_level(GPIO_OUTPUT_IO_45, 1); + vTaskDelay(pdMS_TO_TICKS(100)); + gpio_set_level(GPIO_OUTPUT_IO_45, 0); + vTaskDelay(pdMS_TO_TICKS(100)); + gpio_set_level(GPIO_OUTPUT_IO_45, 1); + vTaskDelay(pdMS_TO_TICKS(200)); + + // test BUTTON_MULTIPLE_CLICK + xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY); + for (int i = 0; i < 4; i++) { + gpio_set_level(GPIO_OUTPUT_IO_45, 0); + vTaskDelay(pdMS_TO_TICKS(100)); + gpio_set_level(GPIO_OUTPUT_IO_45, 1); + vTaskDelay(pdMS_TO_TICKS(100)); + } + vTaskDelay(pdMS_TO_TICKS(100)); + + // test BUTTON_LONG_PRESS_START + xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY); + gpio_set_level(GPIO_OUTPUT_IO_45, 0); + vTaskDelay(pdMS_TO_TICKS(1600)); + + // test BUTTON_LONG_PRESS_HOLD and BUTTON_LONG_PRESS_UP + xEventGroupWaitBits(g_check, BIT(0) | BIT(1), pdTRUE, pdTRUE, portMAX_DELAY); + gpio_set_level(GPIO_OUTPUT_IO_45, 1); + + ESP_LOGI(TAG, "Auto Press Success!"); + vTaskDelete(NULL); +} +static void button_auto_check_cb_1(void *arg, void *data) +{ + if (iot_button_get_event(g_btns[0]) == state) { + xEventGroupSetBits(g_check, BIT(1)); + } +} +static void button_auto_check_cb(void *arg, void *data) +{ + if (iot_button_get_event(g_btns[0]) == state) { + ESP_LOGI(TAG, "Auto check: button event %s pass", button_event_str[state]); + xEventGroupSetBits(g_check, BIT(0)); + if (++state >= BUTTON_EVENT_MAX) { + xSemaphoreGive(g_auto_check_pass); + return; + } + } +} + +TEST_CASE("gpio button auto-test", "[button][iot][auto]") +{ + state = BUTTON_PRESS_DOWN; + g_check = xEventGroupCreate(); + g_auto_check_pass = xSemaphoreCreateBinary(); + xEventGroupSetBits(g_check, BIT(0) | BIT(1)); + button_config_t cfg = { + .type = BUTTON_TYPE_GPIO, + .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS, + .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS, + .gpio_button_config = { + .gpio_num = 0, + .active_level = 0, + }, + }; + g_btns[0] = iot_button_create(&cfg); + TEST_ASSERT_NOT_NULL(g_btns[0]); + + /* register iot_button callback for all the button_event */ + for (uint8_t i = 0; i < BUTTON_EVENT_MAX; i++) { + if (i == BUTTON_MULTIPLE_CLICK) { + button_event_config_t btn_cfg; + btn_cfg.event = i; + btn_cfg.event_data.multiple_clicks.clicks = 4; + iot_button_register_event_cb(g_btns[0], btn_cfg, button_auto_check_cb_1, NULL); + iot_button_register_event_cb(g_btns[0], btn_cfg, button_auto_check_cb, NULL); + } else { + iot_button_register_cb(g_btns[0], i, button_auto_check_cb_1, NULL); + iot_button_register_cb(g_btns[0], i, button_auto_check_cb, NULL); + } + } + + TEST_ASSERT_EQUAL(ESP_OK, iot_button_set_param(g_btns[0], BUTTON_LONG_PRESS_TIME_MS, (void *)1500)); + + gpio_config_t io_conf = { + .intr_type = GPIO_INTR_DISABLE, + .mode = GPIO_MODE_OUTPUT, + .pin_bit_mask = (1ULL << GPIO_OUTPUT_IO_45), + .pull_down_en = 0, + .pull_up_en = 0, + }; + gpio_config(&io_conf); + gpio_set_level(GPIO_OUTPUT_IO_45, 1); + + xTaskCreate(button_auto_press_test_task, "button_auto_press_test_task", 1024 * 4, NULL, 10, NULL); + + TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreTake(g_auto_check_pass, pdMS_TO_TICKS(6000))); + + for (uint8_t i = 0; i < BUTTON_EVENT_MAX; i++) { + button_event_config_t btn_cfg; + btn_cfg.event = i; + if (i == BUTTON_MULTIPLE_CLICK) { + btn_cfg.event_data.multiple_clicks.clicks = 4; + } else if (i == BUTTON_LONG_PRESS_UP || i == BUTTON_LONG_PRESS_START) { + btn_cfg.event_data.long_press.press_time = 1500; + } + iot_button_unregister_event(g_btns[0], btn_cfg, button_auto_check_cb); + iot_button_unregister_event(g_btns[0], btn_cfg, button_auto_check_cb_1); + } + + TEST_ASSERT_EQUAL(ESP_OK, iot_button_delete(g_btns[0])); + vEventGroupDelete(g_check); + vSemaphoreDelete(g_auto_check_pass); + vTaskDelay(pdMS_TO_TICKS(100)); +} + +#define TOLERANCE CONFIG_BUTTON_LONG_PRESS_TOLERANCE_MS + +uint16_t long_press_time[5] = {2000, 2500, 3000, 3500, 4000}; +static SemaphoreHandle_t long_press_check = NULL; +static SemaphoreHandle_t long_press_auto_check_pass = NULL; +unsigned int status = 0; + +static void button_auto_long_press_test_task(void *arg) +{ + // Test for BUTTON_LONG_PRESS_START + for (int i = 0; i < 5; i++) { + xSemaphoreTake(long_press_check, portMAX_DELAY); + gpio_set_level(GPIO_OUTPUT_IO_45, 0); + status = (BUTTON_LONG_PRESS_START << 16) | long_press_time[i]; + if (i > 0) { + vTaskDelay(pdMS_TO_TICKS(long_press_time[i] - long_press_time[i - 1])); + } else { + vTaskDelay(pdMS_TO_TICKS(long_press_time[i])); + } + } + vTaskDelay(pdMS_TO_TICKS(100)); + gpio_set_level(GPIO_OUTPUT_IO_45, 1); + xSemaphoreGive(long_press_auto_check_pass); + vTaskDelay(pdMS_TO_TICKS(100)); + // Test for BUTTON_LONG_PRESS_UP + for (int i = 0; i < 5; i++) { + xSemaphoreTake(long_press_check, portMAX_DELAY); + status = (BUTTON_LONG_PRESS_UP << 16) | long_press_time[i]; + gpio_set_level(GPIO_OUTPUT_IO_45, 0); + vTaskDelay(pdMS_TO_TICKS(long_press_time[i] + 10)); + gpio_set_level(GPIO_OUTPUT_IO_45, 1); + } + + ESP_LOGI(TAG, "Auto Long Press Success!"); + vTaskDelete(NULL); +} + +static void button_long_press_auto_check_cb(void *arg, void *data) +{ + uint32_t value = (uint32_t)data; + uint16_t event = (0xffff0000 & value) >> 16; + uint16_t time = 0xffff & value; + uint16_t ticks_time = iot_button_get_ticks_time(g_btns[0]); + if (status == value && abs(ticks_time - time) <= TOLERANCE) { + ESP_LOGI(TAG, "Auto check: button event: %s and time: %d pass", button_event_str[event], time); + + if (event == BUTTON_LONG_PRESS_UP && time == long_press_time[4]) { + xSemaphoreGive(long_press_auto_check_pass); + } + + xSemaphoreGive(long_press_check); + } +} + +TEST_CASE("gpio button long_press auto-test", "[button][long_press][auto]") +{ + ESP_LOGI(TAG, "Starting the test"); + long_press_check = xSemaphoreCreateBinary(); + long_press_auto_check_pass = xSemaphoreCreateBinary(); + xSemaphoreGive(long_press_check); + button_config_t cfg = { + .type = BUTTON_TYPE_GPIO, + .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS, + .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS, + .gpio_button_config = { + .gpio_num = 0, + .active_level = 0, + }, + }; + g_btns[0] = iot_button_create(&cfg); + TEST_ASSERT_NOT_NULL(g_btns[0]); + + button_event_config_t btn_cfg; + btn_cfg.event = BUTTON_LONG_PRESS_START; + for (int i = 0; i < 5; i++) { + btn_cfg.event_data.long_press.press_time = long_press_time[i]; + uint32_t data = (btn_cfg.event << 16) | long_press_time[i]; + iot_button_register_event_cb(g_btns[0], btn_cfg, button_long_press_auto_check_cb, (void*)data); + } + + gpio_config_t io_conf = { + .intr_type = GPIO_INTR_DISABLE, + .mode = GPIO_MODE_OUTPUT, + .pin_bit_mask = (1ULL << GPIO_OUTPUT_IO_45), + .pull_down_en = 0, + .pull_up_en = 0, + }; + gpio_config(&io_conf); + gpio_set_level(GPIO_OUTPUT_IO_45, 1); + xTaskCreate(button_auto_long_press_test_task, "button_auto_long_press_test_task", 1024 * 4, NULL, 10, NULL); + + xSemaphoreTake(long_press_auto_check_pass, portMAX_DELAY); + iot_button_unregister_cb(g_btns[0], BUTTON_LONG_PRESS_START); + btn_cfg.event = BUTTON_LONG_PRESS_UP; + for (int i = 0; i < 5; i++) { + btn_cfg.event_data.long_press.press_time = long_press_time[i]; + uint32_t data = (btn_cfg.event << 16) | long_press_time[i]; + iot_button_register_event_cb(g_btns[0], btn_cfg, button_long_press_auto_check_cb, (void*)data); + } + TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreTake(long_press_auto_check_pass, pdMS_TO_TICKS(17000))); + TEST_ASSERT_EQUAL(ESP_OK, iot_button_delete(g_btns[0])); + vSemaphoreDelete(long_press_check); + vSemaphoreDelete(long_press_auto_check_pass); + vTaskDelay(pdMS_TO_TICKS(100)); +} + +static void check_leak(size_t before_free, size_t after_free, const char *type) +{ + ssize_t delta = after_free - before_free; + printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta); + TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak"); +} + +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); +} + +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); + check_leak(before_free_8bit, after_free_8bit, "8BIT"); + check_leak(before_free_32bit, after_free_32bit, "32BIT"); +} + +void app_main(void) +{ + /* + * ____ _ _ _______ _ + *| _ \ | | | | |__ __| | | + *| |_) | _ _ | |_ | |_ ___ _ __ | | ___ ___ | |_ + *| _ < | | | || __|| __|/ _ \ | '_ \ | | / _ \/ __|| __| + *| |_) || |_| || |_ | |_| (_) || | | | | || __/\__ \| |_ + *|____/ \__,_| \__| \__|\___/ |_| |_| |_| \___||___/ \__| + */ + printf(" ____ _ _ _______ _ \n"); + printf(" | _ \\ | | | | |__ __| | | \n"); + printf(" | |_) | _ _ | |_ | |_ ___ _ __ | | ___ ___ | |_ \n"); + printf(" | _ < | | | || __|| __|/ _ \\ | '_ \\ | | / _ \\/ __|| __|\n"); + printf(" | |_) || |_| || |_ | |_| (_) || | | | | || __/\\__ \\| |_ \n"); + printf(" |____/ \\__,_| \\__| \\__|\\___/ |_| |_| |_| \\___||___/ \\__|\n"); + unity_run_menu(); +} diff --git a/components/espressif__button/test_apps/pytest_button.py b/components/espressif__button/test_apps/pytest_button.py new file mode 100644 index 0000000..1aa4dce --- /dev/null +++ b/components/espressif__button/test_apps/pytest_button.py @@ -0,0 +1,29 @@ +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 + +''' +Steps to run these cases: +- Build + - . ${IDF_PATH}/export.sh + - pip install idf_build_apps + - python tools/build_apps.py components/button/test_apps -t esp32s3 +- Test + - pip install -r tools/requirements/requirement.pytest.txt + - pytest components/button/test_apps --target esp32s3 +''' + +import pytest +from pytest_embedded import Dut + +@pytest.mark.target('esp32s3') +@pytest.mark.env('button') +@pytest.mark.parametrize( + 'config', + [ + 'defaults', + ], +) +def test_button(dut: Dut)-> None: + dut.expect_exact('Press ENTER to see the list of tests.') + dut.write('[auto]') + dut.expect_unity_test_output(timeout = 300) diff --git a/components/espressif__cmake_utilities/.component_hash b/components/espressif__cmake_utilities/.component_hash new file mode 100644 index 0000000..b110e53 --- /dev/null +++ b/components/espressif__cmake_utilities/.component_hash @@ -0,0 +1 @@ +351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f \ No newline at end of file diff --git a/components/espressif__cmake_utilities/CHANGELOG.md b/components/espressif__cmake_utilities/CHANGELOG.md new file mode 100644 index 0000000..26fd7eb --- /dev/null +++ b/components/espressif__cmake_utilities/CHANGELOG.md @@ -0,0 +1,89 @@ +## v0.5.3 - 2023-09-15 + +* fix `add_dependencies called with incorrect number of arguments` in `relinker.cmake` +* `include(cmake_utilities)` is not suggested now, to avoid cmake_utilities dependency issue + +## v0.5.2 - 2023-09-15 + +* Support work on older ESP-IDF, eg: 4.3.x + +## v0.5.1 - 2023-08-22 + +* Add string 1-byte align support + +## v0.5.0 - 2023-08-02 + +* Add GCC LTO support + +## v0.4.8 - 2023-05-24 + +* Add unit test app + +### Bugfix: + +* fix customer target redefinition issue + +## v0.4.7 - 2023-04-21 + +* gen_compressed_ota: support the addition of a v2 compressed OTA header to compressed firmware. + +## v0.4.6 - 2023-04-20 + +* relinker: add IDF v4.3.x support + +## v0.4.5 - 2023-04-17 + +* gen_compressed_ota: remove slash use in gen_custom_ota.py so that the script can be used in the Windows cmd terminal. + +## v0.4.4 - 2023-04-07 + +* relinker: suppressing the creation of `__pycache__` +* relinker: support same name objects in one library + +## v0.4.3 - 2023-03-24 + +* relinker: support decoding to get IRAM excluded libraries + +## v0.4.2 - 2023-03-20 + +### Bugfix: + +* gen_compressed_ota: Fix the number of bytes reserved in the v3 compressed image header +* gen_compressed_ota: Fix definition of MD5 length in compressed image header for different versions. + +## v0.4.1 - 2023-03-15 + +* relinker: add option to use customized configuration files +* relinker: add option to print error information instead of throwing exception when missing function +* relinker: move functions of SPI flash from IRAM to flash only when enable CONFIG_SPI_FLASH_ROM_IMPL +* relinker: move some functions of esp_timer from IRAM to flash only when disable CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD + +## v0.4.0 - 2023-03-13 + +### Feature: + +* Add command `idf.py gen_single_bin` to generate merged bin file +* Add command `idf.py flash_single_bin` to flash generated merged bin +* Add config `Color in diagnostics` to control the GCC color output + +## v0.3.0 - 2023-03-10 + +* Add gen_compressed_ota functionality, please refer to [gen_compressed_ota.md](https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities/docs/gen_compressed_ota.md) + +## v0.2.1 - 2023-03-09 + +### Bugfix: + +* package manager: Fix the compile issue when the name of the component has `-`, just like esp-xxx + +## v0.2.0 - 2023-02-23 + +* Add relinker functionality, please refer to [relinker.md](https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities/docs/relinker.md) + +## v0.1.0 - 2023-01-12 + +### Feature: + +* Add function cu_pkg_get_version +* Add macro cu_pkg_define_version +* Add cmake script to CMAKE_MODULE_PATH diff --git a/components/espressif__cmake_utilities/CMakeLists.txt b/components/espressif__cmake_utilities/CMakeLists.txt new file mode 100644 index 0000000..a96dced --- /dev/null +++ b/components/espressif__cmake_utilities/CMakeLists.txt @@ -0,0 +1 @@ +idf_component_register() diff --git a/components/espressif__cmake_utilities/Kconfig b/components/espressif__cmake_utilities/Kconfig new file mode 100644 index 0000000..96747fd --- /dev/null +++ b/components/espressif__cmake_utilities/Kconfig @@ -0,0 +1,65 @@ +menu "CMake Utilities" + + config CU_RELINKER_ENABLE + bool "Enable relinker" + default n + help + "Enable relinker to linker some IRAM functions to Flash" + + if CU_RELINKER_ENABLE + config CU_RELINKER_ENABLE_PRINT_ERROR_INFO_WHEN_MISSING_FUNCTION + bool "Print error information when missing function" + default y + help + "Enable this option to print error information instead of + throwing exception when missing function" + + config CU_RELINKER_ENABLE_CUSTOMIZED_CONFIGURATION_FILES + bool "Enable customized relinker configuration files" + default n + help + "Enable this option to use customized relinker configuration + files instead of default ones" + + if CU_RELINKER_ENABLE_CUSTOMIZED_CONFIGURATION_FILES + config CU_RELINKER_CUSTOMIZED_CONFIGURATION_FILES_PATH + string "Customized relinker configuration files path" + default "" + help + "Customized relinker configuration files path. This path is + evaluated relative to the project root directory." + endif + endif + + choice CU_DIAGNOSTICS_COLOR + prompt "Color in diagnostics" + default CU_DIAGNOSTICS_COLOR_ALWAYS + help + Use color in diagnostics. "never", "always", or "auto". If "always", GCC will output + with color defined in GCC_COLORS environment variable. If "never", only output plain + text. If "auto", only output with color when the standard error is a terminal and when + not executing in an emacs shell. + + config CU_DIAGNOSTICS_COLOR_NEVER + bool "never" + config CU_DIAGNOSTICS_COLOR_ALWAYS + bool "always" + config CU_DIAGNOSTICS_COLOR_AUTO + bool "auto" + endchoice + + config CU_GCC_LTO_ENABLE + bool "Enable GCC link time optimization(LTO)" + default n + help + "Enable this option, users can enable GCC link time optimization(LTO) + feature for target components or dependencies. + + config CU_GCC_STRING_1BYTE_ALIGN + bool "GCC string 1-byte align" + default n + help + "Enable this option, user can make string in designated components align + by 1-byte instead 1-word(4-byte), this can reduce unnecessary filled data + so that to reduce firmware size." +endmenu diff --git a/components/espressif__cmake_utilities/README.md b/components/espressif__cmake_utilities/README.md new file mode 100644 index 0000000..834ab73 --- /dev/null +++ b/components/espressif__cmake_utilities/README.md @@ -0,0 +1,31 @@ +# Cmake utilities + +[![Component Registry](https://components.espressif.com/components/espressif/cmake_utilities/badge.svg)](https://components.espressif.com/components/espressif/cmake_utilities) + +This component is aiming to provide some useful CMake utilities outside of ESP-IDF. + +## Use + +1. Add dependency of this component in your component or project's idf_component.yml. + + ```yml + dependencies: + espressif/cmake_utilities: "0.*" + ``` + +2. Include the CMake file you need in your component's CMakeLists.txt after `idf_component_register`, or in your project's CMakeLists.txt + + ```cmake + // Note: should remove .cmake postfix when using include(), otherwise the requested file will not found + // Note: should place this line after `idf_component_register` function + // only include the one you needed. + include(package_manager) + ``` + +3. Then you can use the corresponding CMake function which is provided by the CMake file. + +## Supported features + +1. [relinker](https://github.com/espressif/esp-iot-solution/blob/master/tools/cmake_utilities/docs/relinker.md) +2. [gen_compressed_ota](https://github.com/espressif/esp-iot-solution/blob/master/tools/cmake_utilities/docs/gen_compressed_ota.md) +3. [GCC Optimization](https://github.com/espressif/esp-iot-solution/blob/master/tools/cmake_utilities/docs/gcc.md) diff --git a/components/espressif__cmake_utilities/cmake_utilities.cmake b/components/espressif__cmake_utilities/cmake_utilities.cmake new file mode 100644 index 0000000..92ba9bd --- /dev/null +++ b/components/espressif__cmake_utilities/cmake_utilities.cmake @@ -0,0 +1,7 @@ +# Include all cmake modules + +include(gcc) +include(gen_compressed_ota) +include(gen_single_bin) +include(package_manager) +include(relinker) diff --git a/components/espressif__cmake_utilities/docs/gcc.md b/components/espressif__cmake_utilities/docs/gcc.md new file mode 100644 index 0000000..a7817fe --- /dev/null +++ b/components/espressif__cmake_utilities/docs/gcc.md @@ -0,0 +1,108 @@ +# Link Time Optimization(LTO) + +Link time optimization(LTO) improves the optimization effect of GCC, such as reducing binary size, increasing performance, and so on. For more details please refer to related [GCC documents](https://gcc.gnu.org/onlinedocs/gccint/LTO.html). + +## Use + +To use this feature, you need to include the required CMake file in your project's CMakeLists.txt after `project(XXXX)`. + +```cmake +include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +project(XXXX) + +include(gcc) +``` + +The LTO feature is disabled by default. To use it, you should enable the option `CU_GCC_LTO_ENABLE` in menuconfig. Then specify target components or dependencies to be optimized by LTO after `include(gcc)` as follows: + +```cmake +include(gcc) + +cu_gcc_lto_set(COMPONENTS component_a component_b + DEPENDS dependence_a dependence_b) + +cu_gcc_string_1byte_align(COMPONENTS component_c component_d + DEPENDS dependence_c dependence_d) +``` + +Based on your requirement, set compiling optimization level in the option `COMPILER_OPTIMIZATION`. + +* Note + + ``` + 1. Reducing firmware size may decrease performance + 2. Increasing performance may increase firmware size + 3. Enable LTO cause compiling time cost increases a lot + 4. Enable LTO may increase task stack cost + 5. Enable string 1-byte align may decrease string process speed + ``` + +## Limitation + +At the linking stage, the LTO generates new function indexes instead of the file path as follows: + +- LTO + + ```txt + .text 0x00000000420016f4 0x6 /tmp/ccdjwYMH.ltrans51.ltrans.o + 0x00000000420016f4 app_main + ``` + +- Without LTO + + ```txt + .text.app_main 0x00000000420016f4 0x6 esp-idf/main/libmain.a(app_main.c.obj) + 0x00000000420016f4 app_main + ``` + +So tools used to relink functions between flash and IRAM can't affect these optimized components and dependencies again. It is recommended that users had better optimize application components and dependencies than kernel and hardware driver ones. + +## Example + +The example applies LTO in `light` of `esp-matter` because its application code is much larger. Add LTO configuration into project script `CMakeLists.txt` as follows: + +```cmake + +project(light) + +include(gcc) + +# Add +set(app_lto_components main chip esp_matter) +# Add +set(idf_lto_components lwip wpa_supplicant nvs_flash) +# Add +set(lto_depends mbedcrypto) + +# Add +cu_gcc_lto_set(COMPONENTS ${app_lto_components} ${idf_lto_components} + DEPENDS ${lto_depends}) +``` + +Configure `ESP32-C2` as the target platform, enable `CU_GCC_LTO_ENABLE` and `CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE`, set `COMPILER_OPTIMIZATION` to be `-Os`. +Increase the `main` task stack size to `5120` by option `ESP_MAIN_TASK_STACK_SIZE`. +Compile the project, and then you can see the firmware size decrease a lot: + +Option | Firmware size | Stask cost +|:-:|:-:|:-:| + -Os | 1,113,376 | 2508 + -Os + LTO | 1,020,640 | 4204 + +Then add `cu_gcc_string_1byte_align` after `cu_gcc_lto_set`: + +```cmake +# Add +cu_gcc_lto_set(COMPONENTS ${app_lto_components} ${idf_lto_components} + DEPENDS ${lto_depends}) + +cu_gcc_string_1byte_align(COMPONENTS ${app_lto_components} ${idf_lto_components} + DEPENDS ${lto_depends}) +``` + +Build the project and the firmware size is: + +Option | Firmware size | +|:-:|:-:| + -Os + LTO | 1,020,640 | + -Os + LTO + string 1-byte align | 1,018,340 | diff --git a/components/espressif__cmake_utilities/docs/gen_compressed_ota.md b/components/espressif__cmake_utilities/docs/gen_compressed_ota.md new file mode 100644 index 0000000..e3054b3 --- /dev/null +++ b/components/espressif__cmake_utilities/docs/gen_compressed_ota.md @@ -0,0 +1,41 @@ +# Gen Compressed OTA + +When using the compressed OTA, we need to generate the compressed app firmware. This document mainly describes how to generate the compressed app firmware. + +For more information about compressed OTA, refer to [bootloader_support_plus](https://github.com/espressif/esp-iot-solution/tree/master/components/bootloader_support_plus). + +## Use +In order to use this feature, you need to include the needed CMake file in your project's CMakeLists.txt after `project(XXXX)`. + +```cmake +project(XXXX) + +include(gen_compressed_ota) +``` + +Generate the compressed app firmware in an ESP-IDF "project" directory by running: + +```plaintext +idf.py gen_compressed_ota +``` + +This command will compile your project first, then it will generate the compressed app firmware. For example, run the command under the project `simple_ota_examples` folder. If there are no errors, the `custom_ota_binaries` folder will be created and contains the following files: + +```plaintext +simple_ota.bin.xz +simple_ota.bin.xz.packed +``` + +The file named `simple_ota.bin.xz.packed` is the actual compressed app binary file to be transferred. + +In addition, if [secure boot](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/security/secure-boot-v2.html) is enabled, the command will generate the signed compressed app binary file: + +```plaintext +simple_ota.bin.xz.packed.signed +``` + +you can also use the script [gen_custom_ota.py](https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities/scripts/gen_custom_ota.py) to compress the specified app: + +```plaintext +python3 gen_custom_ota.py -i simple_ota.bin +``` diff --git a/components/espressif__cmake_utilities/docs/relinker.md b/components/espressif__cmake_utilities/docs/relinker.md new file mode 100644 index 0000000..2b7be18 --- /dev/null +++ b/components/espressif__cmake_utilities/docs/relinker.md @@ -0,0 +1,66 @@ +# Relinker + +In ESP-IDF, some functions are put in SRAM when link stage, the reason is that some functions are critical, we need to put them in SRAM to speed up the program, or the functions will be executed when the cache is disabled. But actually, some functions can be put into Flash, here, we provide a script to let the user set the functions which are located in SRAM by default to put them into Flash, in order to save more SRAM which can be used as heap region later. This happens in the linker stage, so we call it as relinker. + +## Use + +In order to use this feature, you need to include the needed CMake file in your project's CMakeLists.txt after `project(XXXX)`. + +```cmake +project(XXXX) + +include(relinker) +``` + +The relinker feature is disabled by default, in order to use it, you need to enable the option `CU_RELINKER_ENABLE` in menuconfig. + +Here are the default configuration files in the folder `cmake_utilities/scripts/relinker/examples/esp32c2`, it's just used as a reference. If you would like to use your own configuration files, please enable option `CU_RELINKER_ENABLE_CUSTOMIZED_CONFIGURATION_FILES` and set the path of your configuration files as following, this path is evaluated relative to the project root directory: + +``` +[*] Enable customized relinker configuration files +(path of your configuration files) Customized relinker configuration files path +``` + +> Note: Currently only esp32c2 is supported. + +## Configuration Files + +You can refer to the files in the directory of `cmake_utilities/scripts/relinker/examples/esp32c2`: + +- library.csv +- object.csv +- function.csv + +For example, if you want to link function `__getreent` from SRAM to Flash, firstly you should add it to `function.csv` file as following: + +``` +libfreertos.a,tasks.c.obj,__getreent, +``` + +This means function `__getreent` is in object file `tasks.c.obj`, and object file `tasks.c.obj` is in library `libfreertos.a`. + +If function `__getreent` depends on the option `FREERTOS_PLACE_FUNCTIONS_INTO_FLASH` in menuconfig, then it should be: + +``` +libfreertos.a,tasks.c.obj,__getreent,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +``` + +This means when only `FREERTOS_PLACE_FUNCTIONS_INTO_FLASH` is enabled in menuconfig, function `__getreent` will be linked from SRAM to Flash. + +Next step you should add the path of the object file to `object.csv`: + +``` +libfreertos.a,tasks.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/tasks.c.obj +``` + +This means the object file `tasks.c.obj` is in library `libfreertos.a` and its location is `esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/tasks.c.obj` relative to directory of `build`. + +Next step you should add path of library to `library.csv`: + +``` +libfreertos.a,./esp-idf/freertos/libfreertos.a +``` + +This means library `libfreertos.a`'s location is `./esp-idf/freertos/libfreertos.a` relative to `build`. + +If above related data has exists in corresponding files, please don't add this repeatedly. \ No newline at end of file diff --git a/components/espressif__cmake_utilities/gcc.cmake b/components/espressif__cmake_utilities/gcc.cmake new file mode 100644 index 0000000..5fdd13e --- /dev/null +++ b/components/espressif__cmake_utilities/gcc.cmake @@ -0,0 +1,84 @@ +if(CONFIG_CU_GCC_LTO_ENABLE) + # Enable cmake interprocedural optimization(IPO) support to check if GCC supports link time optimization(LTO) + cmake_policy(SET CMP0069 NEW) + include(CheckIPOSupported) + + # Compare to "ar" and "ranlib", "gcc-ar" and "gcc-ranlib" integrate GCC LTO plugin + set(CMAKE_AR ${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar) + set(CMAKE_RANLIB ${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib) + + macro(cu_gcc_lto_set) + check_ipo_supported(RESULT result) + if(result) + message(STATUS "GCC link time optimization(LTO) is enable") + + set(multi_value COMPONENTS DEPENDS) + cmake_parse_arguments(LTO "" "" "${multi_value}" ${ARGN}) + + # Use full format LTO object file + set(GCC_LTO_OBJECT_TYPE "-ffat-lto-objects") + # Set compression level 9(min:0, max:9) + set(GCC_LTO_COMPRESSION_LEVEL "-flto-compression-level=9") + # Set partition level max to removed used symbol + set(GCC_LTO_PARTITION_LEVEL "-flto-partition=max") + + # Set mode "auto" to increase compiling speed + set(GCC_LTO_COMPILE_OPTIONS "-flto=auto" + ${GCC_LTO_OBJECT_TYPE} + ${GCC_LTO_COMPRESSION_LEVEL}) + + # Enable GCC LTO and plugin when linking stage + set(GCC_LTO_LINK_OPTIONS "-flto" + "-fuse-linker-plugin" + ${GCC_LTO_OBJECT_TYPE} + ${GCC_LTO_PARTITION_LEVEL}) + + message(STATUS "GCC LTO for components: ${LTO_COMPONENTS}") + foreach(c ${LTO_COMPONENTS}) + idf_component_get_property(t ${c} COMPONENT_LIB) + target_compile_options(${t} PRIVATE ${GCC_LTO_COMPILE_OPTIONS}) + endforeach() + + message(STATUS "GCC LTO for dependencies: ${LTO_DEPENDS}") + foreach(d ${LTO_DEPENDS}) + target_compile_options(${d} PRIVATE ${GCC_LTO_COMPILE_OPTIONS}) + endforeach() + + if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "4.4") + target_link_libraries(${project_elf} PRIVATE ${GCC_LTO_LINK_OPTIONS}) + else() + target_link_libraries(${project_elf} ${GCC_LTO_LINK_OPTIONS}) + endif() + else() + message(FATAL_ERROR "GCC link time optimization(LTO) is not supported") + endif() + endmacro() +else() + macro(cu_gcc_lto_set) + message(STATUS "GCC link time optimization(LTO) is not enable") + endmacro() +endif() + +if(CONFIG_CU_GCC_STRING_1BYTE_ALIGN) + macro(cu_gcc_string_1byte_align) + message(STATUS "GCC string 1-byte align is enable") + + set(multi_value COMPONENTS DEPENDS) + cmake_parse_arguments(STR_ALIGN "" "" "${multi_value}" ${ARGN}) + + message(STATUS "GCC string 1-byte align for components: ${STR_ALIGN_COMPONENTS}") + foreach(c ${STR_ALIGN_COMPONENTS}) + idf_component_get_property(t ${c} COMPONENT_LIB) + target_compile_options(${t} PRIVATE "-malign-data=natural") + endforeach() + + message(STATUS "GCC string 1-byte align for dependencies: ${STR_ALIGN_DEPENDS}") + foreach(d ${STR_ALIGN_DEPENDS}) + target_compile_options(${d} PRIVATE "-malign-data=natural") + endforeach() + endmacro() +else() + macro(cu_gcc_string_1byte_align) + message(STATUS "GCC string 1-byte align is not enable") + endmacro() +endif() diff --git a/components/espressif__cmake_utilities/gen_compressed_ota.cmake b/components/espressif__cmake_utilities/gen_compressed_ota.cmake new file mode 100644 index 0000000..2bd41e5 --- /dev/null +++ b/components/espressif__cmake_utilities/gen_compressed_ota.cmake @@ -0,0 +1,18 @@ +if (NOT TARGET gen_compressed_ota) + add_custom_target(gen_compressed_ota) + + if (CONFIG_SECURE_SIGNED_ON_UPDATE_NO_SECURE_BOOT OR CONFIG_SECURE_BOOT_V2_ENABLED) + set(COMPRESSED_OTA_BIN_SIGN_PARA --sign_key ${PROJECT_DIR}/${CONFIG_SECURE_BOOT_SIGNING_KEY}) + else() + set(COMPRESSED_OTA_BIN_SIGN_PARA ) + endif() + + set(GEN_COMPRESSED_BIN_CMD ${CMAKE_CURRENT_LIST_DIR}/scripts/gen_custom_ota.py ${COMPRESSED_OTA_BIN_SIGN_PARA} --add_app_header) + + add_custom_command(TARGET gen_compressed_ota + POST_BUILD + COMMAND ${PYTHON} ${GEN_COMPRESSED_BIN_CMD} + COMMENT "The gen compresssed bin cmd is: ${GEN_COMPRESSED_BIN_CMD}" + ) + add_dependencies(gen_compressed_ota gen_project_binary) +endif() \ No newline at end of file diff --git a/components/espressif__cmake_utilities/gen_single_bin.cmake b/components/espressif__cmake_utilities/gen_single_bin.cmake new file mode 100644 index 0000000..c13c665 --- /dev/null +++ b/components/espressif__cmake_utilities/gen_single_bin.cmake @@ -0,0 +1,27 @@ +# Extend command to idf.py + +# Generate single bin with name ${CMAKE_PROJECT_NAME}_merged.bin +if (NOT TARGET gen_single_bin) + add_custom_target( + gen_single_bin + COMMAND ${CMAKE_COMMAND} -E echo "Merge bin files to ${CMAKE_PROJECT_NAME}_merged.bin" + COMMAND ${ESPTOOLPY} --chip ${IDF_TARGET} merge_bin -o ${CMAKE_PROJECT_NAME}_merged.bin @flash_args + COMMAND ${CMAKE_COMMAND} -E echo "Merge bin done" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPENDS gen_project_binary bootloader + VERBATIM USES_TERMINAL + ) +endif() + +# Flash bin ${CMAKE_PROJECT_NAME}_merged.bin to target chip +if (NOT TARGET flash_single_bin) + add_custom_target( + flash_single_bin + COMMAND ${CMAKE_COMMAND} -E echo "Flash merged bin ${CMAKE_PROJECT_NAME}_merged.bin to address 0x0" + COMMAND ${ESPTOOLPY} --chip ${IDF_TARGET} write_flash 0x0 ${CMAKE_PROJECT_NAME}_merged.bin + COMMAND ${CMAKE_COMMAND} -E echo "Flash merged bin done" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPENDS gen_single_bin + VERBATIM USES_TERMINAL + ) +endif() diff --git a/components/espressif__cmake_utilities/idf_component.yml b/components/espressif__cmake_utilities/idf_component.yml new file mode 100644 index 0000000..e683f53 --- /dev/null +++ b/components/espressif__cmake_utilities/idf_component.yml @@ -0,0 +1,7 @@ +dependencies: + idf: + version: '>=4.1' +description: A collection of useful cmake utilities +issues: https://github.com/espressif/esp-iot-solution/issues +url: https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities +version: 0.5.3 diff --git a/components/espressif__cmake_utilities/license.txt b/components/espressif__cmake_utilities/license.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/components/espressif__cmake_utilities/license.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/components/espressif__cmake_utilities/package_manager.cmake b/components/espressif__cmake_utilities/package_manager.cmake new file mode 100644 index 0000000..caef11b --- /dev/null +++ b/components/espressif__cmake_utilities/package_manager.cmake @@ -0,0 +1,45 @@ +# cu_pkg_get_version +# +# @brief Get the package's version information, the package is installed by component manager. +# +# @param[in] pkg_path the package's path, normally it's ${CMAKE_CURRENT_LIST_DIR}. +# +# @param[out] ver_major the major version of the package +# @param[out] ver_minor the minor version of the package +# @param[out] ver_patch the patch version of the package +function(cu_pkg_get_version pkg_path ver_major ver_minor ver_patch) + set(yml_file "${pkg_path}/idf_component.yml") + if(EXISTS ${yml_file}) + file(READ ${yml_file} ver) + string(REGEX MATCH "(^|\n)version: \"?([0-9]+).([0-9]+).([0-9]+)\"?" _ ${ver}) + set(${ver_major} ${CMAKE_MATCH_2} PARENT_SCOPE) + set(${ver_minor} ${CMAKE_MATCH_3} PARENT_SCOPE) + set(${ver_patch} ${CMAKE_MATCH_4} PARENT_SCOPE) + else() + message(WARNING " ${yml_file} not exist") + endif() +endfunction() + +# cu_pkg_define_version +# +# @brief Add the package's version definitions using format ${NAME}_VER_MAJOR ${NAME}_VER_MINOR ${NAME}_VER_PATCH, +# the ${NAME} will be inferred from package path, and namespace like `espressif__` will be removed if the package download from esp-registry +# eg. espressif__usb_stream and usb_stream will generate same version definitions USB_STREAM_VER_MAJOR ... +# +# @param[in] pkg_path the package's path, normally it's ${CMAKE_CURRENT_LIST_DIR}. +# +macro(cu_pkg_define_version pkg_path) + cu_pkg_get_version(${pkg_path} ver_major ver_minor ver_patch) + get_filename_component(pkg_name ${pkg_path} NAME) + string(FIND ${pkg_name} "__" pkg_name_pos) + if(pkg_name_pos GREATER -1) + math(EXPR pkg_name_pos "${pkg_name_pos} + 2") + string(SUBSTRING ${pkg_name} ${pkg_name_pos} -1 pkg_name) + endif() + string(TOUPPER ${pkg_name} pkg_name) + string(REPLACE "-" "_" pkg_name ${pkg_name}) + message(STATUS "${pkg_name}: ${ver_major}.${ver_minor}.${ver_patch}") + list(LENGTH pkg_name_list len) + target_compile_options(${COMPONENT_LIB} PUBLIC + -D${pkg_name}_VER_MAJOR=${ver_major} -D${pkg_name}_VER_MINOR=${ver_minor} -D${pkg_name}_VER_PATCH=${ver_patch}) +endmacro() diff --git a/components/espressif__cmake_utilities/project_include.cmake b/components/espressif__cmake_utilities/project_include.cmake new file mode 100644 index 0000000..a5de922 --- /dev/null +++ b/components/espressif__cmake_utilities/project_include.cmake @@ -0,0 +1,9 @@ +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH}) + +if(CONFIG_CU_DIAGNOSTICS_COLOR_ALWAYS) + add_compile_options(-fdiagnostics-color=always) +elseif(CONFIG_CU_DIAGNOSTICS_COLOR_AUTO) + add_compile_options(-fdiagnostics-color=auto) +elseif(CONFIG_CU_DIAGNOSTICS_COLOR_NEVER) + add_compile_options(-fdiagnostics-color=never) +endif() diff --git a/components/espressif__cmake_utilities/relinker.cmake b/components/espressif__cmake_utilities/relinker.cmake new file mode 100644 index 0000000..10b9aaf --- /dev/null +++ b/components/espressif__cmake_utilities/relinker.cmake @@ -0,0 +1,73 @@ +# @brief Link designated functions from SRAM to Flash to save SRAM +if(CONFIG_CU_RELINKER_ENABLE) + # project_elf variable is only in project.cmake + if(NOT TARGET customer_sections AND DEFINED project_elf) + message(STATUS "Relinker is enabled.") + if(CONFIG_IDF_TARGET_ESP32C2) + set(target "esp32c2") + else() + message(FATAL_ERROR "Other targets are not supported.") + endif() + + if(CONFIG_CU_RELINKER_ENABLE_CUSTOMIZED_CONFIGURATION_FILES) + idf_build_get_property(project_dir PROJECT_DIR) + get_filename_component(cfg_file_path "${CONFIG_CU_RELINKER_CUSTOMIZED_CONFIGURATION_FILES_PATH}" + ABSOLUTE BASE_DIR "${project_dir}") + + if(NOT EXISTS "${cfg_file_path}") + message(FATAL_ERROR "Relinker Configuration files path ${cfg_file_path} is not found.") + endif() + else() + set(cfg_file_path ${PROJECT_DIR}/relinker/${target}) + if(NOT EXISTS ${cfg_file_path}) + set(cfg_file_path ${CMAKE_CURRENT_LIST_DIR}/scripts/relinker/examples/${target}) + endif() + endif() + + message(STATUS "Relinker configuration files: ${cfg_file_path}") + + set(library_file "${cfg_file_path}/library.csv") + set(object_file "${cfg_file_path}/object.csv") + set(function_file "${cfg_file_path}/function.csv") + set(relinker_script "${CMAKE_CURRENT_LIST_DIR}/scripts/relinker/relinker.py") + + set(cmake_objdump "${CMAKE_OBJDUMP}") + set(link_path "${CMAKE_BINARY_DIR}/esp-idf/esp_system/ld") + set(link_src_file "${link_path}/sections.ld") + set(link_dst_file "${link_path}/customer_sections.ld") + + set(relinker_opts --input ${link_src_file} + --output ${link_dst_file} + --library ${library_file} + --object ${object_file} + --function ${function_file} + --sdkconfig ${sdkconfig} + --objdump ${cmake_objdump}) + + if(CONFIG_CU_RELINKER_ENABLE_PRINT_ERROR_INFO_WHEN_MISSING_FUNCTION) + list(APPEND relinker_opts --missing_function_info True) + endif() + + idf_build_get_property(link_depends __LINK_DEPENDS) + + add_custom_command(OUTPUT ${link_dst_file} + COMMAND ${python} -B ${relinker_script} + ${relinker_opts} + COMMAND ${CMAKE_COMMAND} -E copy + ${link_dst_file} + ${link_src_file} + COMMAND ${CMAKE_COMMAND} -E echo + /*relinker*/ >> + ${link_dst_file} + DEPENDS "${link_depends}" + "${library_file}" + "${object_file}" + "${function_file}" + VERBATIM) + + add_custom_target(customer_sections DEPENDS ${link_dst_file}) + add_dependencies(${project_elf} customer_sections) + endif() +else() + message(STATUS "Relinker isn't enabled.") +endif() diff --git a/components/espressif__cmake_utilities/scripts/gen_custom_ota.py b/components/espressif__cmake_utilities/scripts/gen_custom_ota.py new file mode 100755 index 0000000..00cffc6 --- /dev/null +++ b/components/espressif__cmake_utilities/scripts/gen_custom_ota.py @@ -0,0 +1,243 @@ +#!/usr/bin/env python +# +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# +# SPDX-License-Identifier: Apache-2.0 + +import sys +import struct +import argparse +import binascii +import hashlib +import os +import subprocess +import shutil +import json +import lzma + +# src_file = 'hello-world.bin' +# compressed_file = 'hello-world.bin.xz' +# packed_compressed_file = 'hello-world.bin.xz.packed' +# siged_packed_compressed_file = 'hello-world.bin.xz.packed.signed' + +binary_compress_type = {'none': 0, 'xz':1} +header_version = {'v1': 1, 'v2': 2, 'v3': 3} + +SCRIPT_VERSION = '1.0.0' +ORIGIN_APP_IMAGE_HEADER_LEN = 288 # sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t). See esp_app_format.h +# At present, we calculate the checksum of the first 4KB data of the old app. +OLD_APP_CHECK_DATA_SIZE = 4096 + +# v1 compressed data header: +# Note: Encryption_type field is deprecated, the field is reserved for compatibility. +# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|--------------|------------| +# | | Magic | header | Compress | delta | Encryption | Reserved | Firmware | The length of | The MD5 of | The CRC32 for| compressed | +# | | number | version | type | type | type | | version | compressed data| compressed data| the header | data | +# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|--------------|------------| +# | Size | 4 bytes | 1 byte | 4 bits | 4 bits | 1 bytes | 1 bytes | 32 bytes | 4 bytes | 32 bytes | 4 bytes | | +# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|--------------|------------| +# | Data | String | | | | | | String | little-endian | byte string | little-endian| | +# | type | ended | | | | | | ended | integer | | integer | | +# | |with ‘\0’| | | | | | with ‘\0’| | | | Binary data| +# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|--------------|------------| +# | Data | “ESP” | 1 | 0/1 | 0/1 | | | | | | | | +# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|--------------|------------| + +# v2 compressed data header +# Note: Encryption_type field is deprecated, the field is reserved for compatibility. +# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|---------------|---------------|--------------|------------| +# | | Magic | header | Compress | delta | Encryption | Reserved | Firmware | The length of | The MD5 of | base app check| The CRC32 for | The CRC32 for| compressed | +# | | number | version | type | type | type | | version | compressed data| compressed data| data len | base app data | the header | data | +# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|---------------|---------------|--------------|------------| +# | Size | 4 bytes | 1 byte | 4 bits | 4 bits | 1 bytes | 1 bytes | 32 bytes | 4 bytes | 32 bytes | 4 bytes | 4 bytes | 4 bytes | | +# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|---------------|---------------|--------------|------------| +# | Data | String | | | | | | String | little-endian | byte string | little-endian | little-endian | little-endian| | +# | type | ended | | | | | | ended | integer | | integer | integer | integer | | +# | |with ‘\0’| | | | | | with ‘\0’| | | | | | Binary data| +# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|---------------|---------------|--------------|------------| +# | Data | “ESP” | 1 | 0/1 | 0/1 | | | | | | | | | | +# |------|---------|---------|----------|------------|------------|-----------|----------|----------------|----------------|---------------|---------------|--------------|------------| + +# v3 compressed data header: +# |------|---------|---------|----------|------------|-----------|----------------|----------------|--------------|------------| +# | | Magic | header | Compress | Reserved | Reserved | The length of | The MD5 of | The CRC32 for| compressed | +# | | number | version | type | | | compressed data| compressed data| the header | data | +# |------|---------|---------|----------|------------|-----------|----------------|----------------|--------------|------------| +# | Size | 4 bytes | 1 byte | 4 bits | 4 bits | 8 bytes | 4 bytes | 16 bytes | 4 bytes | | +# |------|---------|---------|----------|------------|-----------|----------------|----------------|--------------|------------| +# | Data | String | integer | | | | little-endian | byte string | little-endian| | +# | type | ended | | | | | integer | | integer | | +# | |with ‘\0’| | | | | | | | Binary data| +# |------|---------|---------|----------|------------|-----------|----------------|----------------|--------------|------------| +# | Data | “ESP” | 3 | 0/1 | | | | | | | +# |------|---------|---------|----------|------------|-----------|----------------|----------------|--------------|------------| + +def xz_compress(store_directory, in_file): + compressed_file = ''.join([in_file,'.xz']) + if(os.path.exists(compressed_file)): + os.remove(compressed_file) + + xz_compressor_filter = [ + {"id": lzma.FILTER_LZMA2, "preset": 6, "dict_size": 64*1024}, + ] + with open(in_file, 'rb') as src_f: + data = src_f.read() + with lzma.open(compressed_file, "wb", format=lzma.FORMAT_XZ, check=lzma.CHECK_CRC32, filters=xz_compressor_filter) as f: + f.write(data) + f.close() + + if not os.path.exists(os.path.join(store_directory, os.path.split(compressed_file)[1])): + shutil.copy(compressed_file, store_directory) + print('copy xz file done') + +def secure_boot_sign(sign_key, in_file, out_file): + ret = subprocess.call('espsecure.py sign_data --version 2 --keyfile {} --output {} {}'.format(sign_key, out_file, in_file), shell = True) + if ret: + raise Exception('sign failed') + +def get_app_name(): + with open('flasher_args.json') as f: + try: + flasher_args = json.load(f) + return flasher_args['app']['file'] + except Exception as e: + print(e) + + return '' + +def get_script_version(): + return SCRIPT_VERSION + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('-hv', '--header_ver', nargs='?', choices = ['v1', 'v2', 'v3'], + default='v3', help='the version of the packed file header [default:v3]') + parser.add_argument('-c', '--compress_type', nargs= '?', choices = ['none', 'xz'], + default='xz', help='compressed type [default:xz]') + parser.add_argument('-i', '--in_file', nargs = '?', + default='', help='the new app firmware') + parser.add_argument('--sign_key', nargs = '?', + default='', help='the sign key used for secure boot') + parser.add_argument('-fv', '--fw_ver', nargs='?', + default='', help='the version of the compressed data(this field is deprecated in v3)') + parser.add_argument('--add_app_header', action="store_true", help='add app header to use native esp_ota_* & esp_https_ota_* APIs') + parser.add_argument('-v', '--version', action='version', version=get_script_version(), help='the version of the script') + + args = parser.parse_args() + + compress_type = args.compress_type + firmware_ver = args.fw_ver + src_file = args.in_file + sign_key = args.sign_key + header_ver = args.header_ver + add_app_header = args.add_app_header + + if src_file == '': + origin_app_name = get_app_name() + if(origin_app_name == ''): + print('get origin app name fail') + return + + if os.path.exists(origin_app_name): + src_file = origin_app_name + else: + print('origin app.bin not found') + return + + print('src file is: {}'.format(src_file)) + + # rebuild the cpmpressed_app directroy + cpmoressed_app_directory = 'custom_ota_binaries' + if os.path.exists(cpmoressed_app_directory): + shutil.rmtree(cpmoressed_app_directory) + + os.mkdir(cpmoressed_app_directory) + print('The compressed file will store in {}'.format(cpmoressed_app_directory)) + + #step1: compress + if compress_type == 'xz': + xz_compress(cpmoressed_app_directory, os.path.abspath(src_file)) + + origin_app_name = os.path.split(src_file)[1] + + compressed_file_name = ''.join([origin_app_name, '.xz']) + compressed_file = os.path.join(cpmoressed_app_directory, compressed_file_name) + else: + compressed_file = ''.join(src_file) + + print('compressed file is: {}'.format(compressed_file)) + + #step2: packet the compressed image header + with open(src_file, 'rb') as s_f: + src_image_header = bytearray(s_f.read(ORIGIN_APP_IMAGE_HEADER_LEN)) + src_image_header[1] = 0x00 + + packed_file = ''.join([compressed_file,'.packed']) + with open(compressed_file, 'rb') as src_f: + data = src_f.read() + f_len = src_f.tell() + # magic number + bin_data = struct.pack('4s', b'ESP') + # header version + bin_data += struct.pack('B', header_version[header_ver]) + # Compress type + bin_data += struct.pack('B', binary_compress_type[compress_type]) + print('compressed type: {}'.format(binary_compress_type[compress_type])) + # in header v1/v2, there is a field "Encryption type", this field has been deprecated in v3 + if (header_version[header_ver] < 3): + bin_data += struct.pack('B', 0) + # Reserved + bin_data += struct.pack('?', 0) + # Firmware version + bin_data += struct.pack('32s', firmware_ver.encode()) + else: + # Reserved + bin_data += struct.pack('10s', b'0') + # The length of the compressed data + bin_data += struct.pack(' OPT_MIN_LEN and l[0] != '#': + mo = re.match( r'(.*)=(.*)', l, re.M|re.I) + if mo: + config[mo.group(1)]=mo.group(2).replace('"', '') + self.config = config + + def index(self, i): + return self.config[i] + + def check(self, options): + options = options.replace(' ', '') + if '&&' in options: + for i in options.split('&&'): + if i[0] == '!': + i = i[1:] + if i in self.config: + return False + else: + if i not in self.config: + return False + else: + i = options + if i[0] == '!': + i = i[1:] + if i in self.config: + return False + else: + if i not in self.config: + return False + return True + +class object_c: + def read_dump_info(self, pathes): + new_env = os.environ.copy() + new_env['LC_ALL'] = 'C' + dumps = list() + print('pathes:', pathes) + for path in pathes: + try: + dump = StringIO(subprocess.check_output([espidf_objdump, '-t', path], env=new_env).decode()) + dumps.append(dump.readlines()) + except subprocess.CalledProcessError as e: + raise RuntimeError('cmd:%s result:%s'%(e.cmd, e.returncode)) + return dumps + + def get_func_section(self, dumps, func): + for dump in dumps: + for l in dump: + if ' %s'%(func) in l and '*UND*' not in l: + m = re.match(r'(\S*)\s*([glw])\s*([F|O])\s*(\S*)\s*(\S*)\s*(\S*)\s*', l, re.M|re.I) + if m and m[6] == func: + return m[4].replace('.text.', '') + if espidf_missing_function_info: + print('%s failed to find section'%(func)) + return None + else: + raise RuntimeError('%s failed to find section'%(func)) + + def __init__(self, name, pathes, libray): + self.name = name + self.libray = libray + self.funcs = dict() + self.pathes = pathes + self.dumps = self.read_dump_info(pathes) + + def append(self, func): + section = self.get_func_section(self.dumps, func) + if section != None: + self.funcs[func] = section + + def functions(self): + nlist = list() + for i in self.funcs: + nlist.append(i) + return nlist + + def sections(self): + nlist = list() + for i in self.funcs: + nlist.append(self.funcs[i]) + return nlist + +class library_c: + def __init__(self, name, path): + self.name = name + self.path = path + self.objs = dict() + + def append(self, obj, path, func): + if obj not in self.objs: + self.objs[obj] = object_c(obj, path, self.name) + self.objs[obj].append(func) + +class libraries_c: + def __init__(self): + self.libs = dict() + + def append(self, lib, lib_path, obj, obj_path, func): + if lib not in self.libs: + self.libs[lib] = library_c(lib, lib_path) + self.libs[lib].append(obj, obj_path, func) + + def dump(self): + for libname in self.libs: + lib = self.libs[libname] + for objname in lib.objs: + obj = lib.objs[objname] + print('%s, %s, %s, %s'%(libname, objname, obj.path, obj.funcs)) + +class paths_c: + def __init__(self): + self.paths = dict() + + def append(self, lib, obj, path): + if '$IDF_PATH' in path: + path = path.replace('$IDF_PATH', os.environ['IDF_PATH']) + + if lib not in self.paths: + self.paths[lib] = dict() + if obj not in self.paths[lib]: + self.paths[lib][obj] = list() + self.paths[lib][obj].append(path) + + def index(self, lib, obj): + if lib not in self.paths: + return None + if '*' in self.paths[lib]: + obj = '*' + return self.paths[lib][obj] + +def generator(library_file, object_file, function_file, sdkconfig_file, missing_function_info, objdump='riscv32-esp-elf-objdump'): + global espidf_objdump, espidf_missing_function_info + espidf_objdump = objdump + espidf_missing_function_info = missing_function_info + + sdkconfig = sdkconfig_c(sdkconfig_file) + + lib_paths = paths_c() + for p in csv.DictReader(open(library_file, 'r')): + lib_paths.append(p['library'], '*', p['path']) + + obj_paths = paths_c() + for p in csv.DictReader(open(object_file, 'r')): + obj_paths.append(p['library'], p['object'], p['path']) + + libraries = libraries_c() + for d in csv.DictReader(open(function_file, 'r')): + if d['option'] and sdkconfig.check(d['option']) == False: + print('skip %s(%s)'%(d['function'], d['option'])) + continue + lib_path = lib_paths.index(d['library'], '*') + obj_path = obj_paths.index(d['library'], d['object']) + if not obj_path: + obj_path = lib_path + libraries.append(d['library'], lib_path[0], d['object'], obj_path, d['function']) + return libraries + +def main(): + argparser = argparse.ArgumentParser(description='Libraries management') + + argparser.add_argument( + '--library', '-l', + help='Library description file', + type=str) + + argparser.add_argument( + '--object', '-b', + help='Object description file', + type=str) + + argparser.add_argument( + '--function', '-f', + help='Function description file', + type=str) + + argparser.add_argument( + '--sdkconfig', '-s', + help='sdkconfig file', + type=str) + + args = argparser.parse_args() + + libraries = generator(args.library, args.object, args.function, args.sdkconfig) + # libraries.dump() + +if __name__ == '__main__': + main() diff --git a/components/espressif__cmake_utilities/scripts/relinker/examples/esp32c2/function.csv b/components/espressif__cmake_utilities/scripts/relinker/examples/esp32c2/function.csv new file mode 100644 index 0000000..73c089a --- /dev/null +++ b/components/espressif__cmake_utilities/scripts/relinker/examples/esp32c2/function.csv @@ -0,0 +1,365 @@ +library,object,function,option +libble_app.a,ble_hw.c.o,r_ble_hw_resolv_list_get_cur_entry, +libble_app.a,ble_ll_adv.c.o,r_ble_ll_adv_set_sched, +libble_app.a,ble_ll_adv.c.o,r_ble_ll_adv_sync_pdu_make, +libble_app.a,ble_ll_adv.c.o,r_ble_ll_adv_sync_calculate, +libble_app.a,ble_ll_conn.c.o,r_ble_ll_conn_is_dev_connected, +libble_app.a,ble_ll_ctrl.c.o,r_ble_ll_ctrl_tx_done, +libble_app.a,ble_lll_adv.c.o,r_ble_lll_adv_aux_scannable_pdu_payload_len, +libble_app.a,ble_lll_adv.c.o,r_ble_lll_adv_halt, +libble_app.a,ble_lll_adv.c.o,r_ble_lll_adv_periodic_schedule_next, +libble_app.a,ble_lll_conn.c.o,r_ble_lll_conn_cth_flow_free_credit, +libble_app.a,ble_lll_conn.c.o,r_ble_lll_conn_update_encryption, +libble_app.a,ble_lll_conn.c.o,r_ble_lll_conn_set_slave_flow_control, +libble_app.a,ble_lll_conn.c.o,r_ble_lll_init_rx_pkt_isr, +libble_app.a,ble_lll_conn.c.o,r_ble_lll_conn_get_rx_mbuf, +libble_app.a,ble_lll_rfmgmt.c.o,r_ble_lll_rfmgmt_enable, +libble_app.a,ble_lll_rfmgmt.c.o,r_ble_lll_rfmgmt_timer_reschedule, +libble_app.a,ble_lll_rfmgmt.c.o,r_ble_lll_rfmgmt_timer_exp, +libble_app.a,ble_lll_scan.c.o,r_ble_lll_scan_targeta_is_matched, +libble_app.a,ble_lll_scan.c.o,r_ble_lll_scan_rx_isr_on_legacy, +libble_app.a,ble_lll_scan.c.o,r_ble_lll_scan_rx_isr_on_aux, +libble_app.a,ble_lll_scan.c.o,r_ble_lll_scan_process_rsp_in_isr, +libble_app.a,ble_lll_scan.c.o,r_ble_lll_scan_rx_pkt_isr, +libble_app.a,ble_lll_sched.c.o,r_ble_lll_sched_execute_check, +libble_app.a,ble_lll_sync.c.o,r_ble_lll_sync_event_start_cb, +libble_app.a,ble_phy.c.o,r_ble_phy_set_rxhdr, +libble_app.a,ble_phy.c.o,r_ble_phy_update_conn_sequence, +libble_app.a,ble_phy.c.o,r_ble_phy_set_sequence_mode, +libble_app.a,ble_phy.c.o,r_ble_phy_txpower_round, +libble_app.a,os_mempool.c.obj,r_os_memblock_put, +libbootloader_support.a,bootloader_flash.c.obj,bootloader_read_flash_id, +libbootloader_support.a,flash_encrypt.c.obj,esp_flash_encryption_enabled, +libbt.a,bt_osi_mem.c.obj,bt_osi_mem_calloc,CONFIG_BT_ENABLED +libbt.a,bt_osi_mem.c.obj,bt_osi_mem_malloc,CONFIG_BT_ENABLED +libbt.a,bt_osi_mem.c.obj,bt_osi_mem_malloc_internal,CONFIG_BT_ENABLED +libbt.a,bt_osi_mem.c.obj,bt_osi_mem_free,CONFIG_BT_ENABLED +libbt.a,bt.c.obj,esp_reset_rpa_moudle,CONFIG_BT_ENABLED +libbt.a,bt.c.obj,osi_assert_wrapper,CONFIG_BT_ENABLED +libbt.a,bt.c.obj,osi_random_wrapper,CONFIG_BT_ENABLED +libbt.a,nimble_port.c.obj,nimble_port_run,CONFIG_BT_NIMBLE_ENABLED +libbt.a,nimble_port.c.obj,nimble_port_get_dflt_eventq,CONFIG_BT_NIMBLE_ENABLED +libbt.a,npl_os_freertos.c.obj,os_callout_timer_cb,CONFIG_BT_ENABLED && !CONFIG_BT_NIMBLE_USE_ESP_TIMER +libbt.a,npl_os_freertos.c.obj,npl_freertos_event_run,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_stop,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_time_get,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_reset,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_is_active,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_get_ticks,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_remaining_ticks,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_time_delay,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_is_empty,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_mutex_pend,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_mutex_release,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_sem_init,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_sem_pend,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_sem_release,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_init,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_deinit,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_event_is_queued,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_event_get_arg,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_time_ms_to_ticks32,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_time_ticks_to_ms32,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_hw_is_in_critical,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_get_time_forever,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_os_started,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_get_current_task_id,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_event_reset,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_mem_reset,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_event_init,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_sem_get_count,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_remove,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_hw_exit_critical,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_mutex_init,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_hw_enter_critical,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_put,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_get,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_sem_deinit,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_mutex_deinit,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_deinit,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_init,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_event_deinit,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_time_ticks_to_ms,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_time_ms_to_ticks,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_callout_set_arg,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_event_set_arg,CONFIG_BT_ENABLED +libbt.a,npl_os_freertos.c.obj,npl_freertos_eventq_put,CONFIG_BT_ENABLED +libdriver.a,gpio.c.obj,gpio_intr_service, +libesp_app_format.a,esp_app_desc.c.obj,esp_app_get_elf_sha256, +libesp_hw_support.a,cpu.c.obj,esp_cpu_wait_for_intr, +libesp_hw_support.a,cpu.c.obj,esp_cpu_reset, +libesp_hw_support.a,esp_clk.c.obj,esp_clk_cpu_freq, +libesp_hw_support.a,esp_clk.c.obj,esp_clk_apb_freq, +libesp_hw_support.a,esp_clk.c.obj,esp_clk_xtal_freq, +libesp_hw_support.a,esp_memory_utils.c.obj,esp_ptr_byte_accessible, +libesp_hw_support.a,hw_random.c.obj,esp_random, +libesp_hw_support.a,intr_alloc.c.obj,shared_intr_isr, +libesp_hw_support.a,intr_alloc.c.obj,esp_intr_noniram_disable, +libesp_hw_support.a,intr_alloc.c.obj,esp_intr_noniram_enable, +libesp_hw_support.a,intr_alloc.c.obj,esp_intr_enable, +libesp_hw_support.a,intr_alloc.c.obj,esp_intr_disable, +libesp_hw_support.a,periph_ctrl.c.obj,wifi_bt_common_module_enable, +libesp_hw_support.a,periph_ctrl.c.obj,wifi_bt_common_module_disable, +libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_ctrl_read_reg, +libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_ctrl_read_reg_mask, +libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_ctrl_write_reg, +libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_ctrl_write_reg_mask, +libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_enter_critical, +libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_exit_critical, +libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_analog_cali_reg_read, +libesp_hw_support.a,regi2c_ctrl.c.obj,regi2c_analog_cali_reg_write, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_32k_enable_external, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_fast_src_set, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_slow_freq_get_hz, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_slow_src_get, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_slow_src_set, +libesp_hw_support.a,rtc_clk.c.obj,rtc_dig_clk8m_disable, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_set_config_fast, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_8m_enable, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_8md256_enabled, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_bbpll_configure, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_bbpll_enable, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_get_config, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_mhz_to_config, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_set_config, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_to_8m, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_to_pll_mhz, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_set_xtal, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_xtal_freq_get, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_cpu_freq_to_xtal, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_bbpll_disable, +libesp_hw_support.a,rtc_clk.c.obj,rtc_clk_apb_freq_update, +libesp_hw_support.a,rtc_clk.c.obj,clk_ll_rtc_slow_get_src,FALSE +libesp_hw_support.a,rtc_init.c.obj,rtc_vddsdio_set_config, +libesp_hw_support.a,rtc_module.c.obj,rtc_isr, +libesp_hw_support.a,rtc_module.c.obj,rtc_isr_noniram_disable, +libesp_hw_support.a,rtc_module.c.obj,rtc_isr_noniram_enable, +libesp_hw_support.a,rtc_sleep.c.obj,rtc_sleep_pu, +libesp_hw_support.a,rtc_sleep.c.obj,rtc_sleep_finish, +libesp_hw_support.a,rtc_sleep.c.obj,rtc_sleep_get_default_config, +libesp_hw_support.a,rtc_sleep.c.obj,rtc_sleep_init, +libesp_hw_support.a,rtc_sleep.c.obj,rtc_sleep_low_init, +libesp_hw_support.a,rtc_sleep.c.obj,rtc_sleep_start, +libesp_hw_support.a,rtc_time.c.obj,rtc_clk_cal, +libesp_hw_support.a,rtc_time.c.obj,rtc_clk_cal_internal, +libesp_hw_support.a,rtc_time.c.obj,rtc_time_get, +libesp_hw_support.a,rtc_time.c.obj,rtc_time_us_to_slowclk, +libesp_hw_support.a,rtc_time.c.obj,rtc_time_slowclk_to_us, +libesp_hw_support.a,sleep_modes.c.obj,periph_ll_periph_enabled, +libesp_hw_support.a,sleep_modes.c.obj,flush_uarts, +libesp_hw_support.a,sleep_modes.c.obj,suspend_uarts, +libesp_hw_support.a,sleep_modes.c.obj,resume_uarts, +libesp_hw_support.a,sleep_modes.c.obj,esp_sleep_start, +libesp_hw_support.a,sleep_modes.c.obj,esp_deep_sleep_start, +libesp_hw_support.a,sleep_modes.c.obj,esp_light_sleep_inner, +libesp_phy.a,phy_init.c.obj,esp_phy_common_clock_enable, +libesp_phy.a,phy_init.c.obj,esp_phy_common_clock_disable, +libesp_phy.a,phy_init.c.obj,esp_wifi_bt_power_domain_on, +libesp_phy.a,phy_override.c.obj,phy_i2c_enter_critical, +libesp_phy.a,phy_override.c.obj,phy_i2c_exit_critical, +libesp_pm.a,pm_locks.c.obj,esp_pm_lock_acquire, +libesp_pm.a,pm_locks.c.obj,esp_pm_lock_release, +libesp_pm.a,pm_impl.c.obj,get_lowest_allowed_mode, +libesp_pm.a,pm_impl.c.obj,esp_pm_impl_switch_mode, +libesp_pm.a,pm_impl.c.obj,on_freq_update, +libesp_pm.a,pm_impl.c.obj,vApplicationSleep,CONFIG_FREERTOS_USE_TICKLESS_IDLE +libesp_pm.a,pm_impl.c.obj,do_switch, +libesp_ringbuf.a,ringbuf.c.obj,prvCheckItemAvail, +libesp_ringbuf.a,ringbuf.c.obj,prvGetFreeSize, +libesp_ringbuf.a,ringbuf.c.obj,prvReceiveGenericFromISR, +libesp_ringbuf.a,ringbuf.c.obj,xRingbufferGetMaxItemSize, +libesp_rom.a,esp_rom_systimer.c.obj,systimer_hal_init, +libesp_rom.a,esp_rom_systimer.c.obj,systimer_hal_set_alarm_period, +libesp_rom.a,esp_rom_systimer.c.obj,systimer_hal_set_alarm_target, +libesp_rom.a,esp_rom_systimer.c.obj,systimer_hal_set_tick_rate_ops, +libesp_rom.a,esp_rom_uart.c.obj,esp_rom_uart_set_clock_baudrate, +libesp_system.a,brownout.c.obj,rtc_brownout_isr_handler, +libesp_system.a,cache_err_int.c.obj,esp_cache_err_get_cpuid, +libesp_system.a,cpu_start.c.obj,call_start_cpu0, +libesp_system.a,crosscore_int.c.obj,esp_crosscore_int_send, +libesp_system.a,crosscore_int.c.obj,esp_crosscore_int_send_yield, +libesp_system.a,esp_system.c.obj,esp_restart, +libesp_system.a,esp_system.c.obj,esp_system_abort, +libesp_system.a,reset_reason.c.obj,esp_reset_reason_set_hint, +libesp_system.a,reset_reason.c.obj,esp_reset_reason_get_hint, +libesp_system.a,ubsan.c.obj,__ubsan_include, +libesp_timer.a,esp_timer.c.obj,esp_timer_get_next_alarm_for_wake_up, +libesp_timer.a,esp_timer.c.obj,timer_list_unlock,!CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD +libesp_timer.a,esp_timer.c.obj,timer_list_lock,!CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD +libesp_timer.a,esp_timer.c.obj,timer_armed, +libesp_timer.a,esp_timer.c.obj,timer_remove, +libesp_timer.a,esp_timer.c.obj,timer_insert,!CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD +libesp_timer.a,esp_timer.c.obj,esp_timer_start_once, +libesp_timer.a,esp_timer.c.obj,esp_timer_start_periodic, +libesp_timer.a,esp_timer.c.obj,esp_timer_stop, +libesp_timer.a,esp_timer.c.obj,esp_timer_get_expiry_time, +libesp_timer.a,esp_timer_impl_systimer.c.obj,esp_timer_impl_get_time,!CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD +libesp_timer.a,esp_timer_impl_systimer.c.obj,esp_timer_impl_set_alarm_id,!CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD +libesp_timer.a,esp_timer_impl_systimer.c.obj,esp_timer_impl_update_apb_freq, +libesp_timer.a,esp_timer_impl_systimer.c.obj,esp_timer_impl_get_min_period_us, +libesp_timer.a,ets_timer_legacy.c.obj,timer_initialized, +libesp_timer.a,ets_timer_legacy.c.obj,ets_timer_arm_us, +libesp_timer.a,ets_timer_legacy.c.obj,ets_timer_arm, +libesp_timer.a,ets_timer_legacy.c.obj,ets_timer_disarm, +libesp_timer.a,system_time.c.obj,esp_system_get_time, +libesp_wifi.a,esp_adapter.c.obj,semphr_take_from_isr_wrapper, +libesp_wifi.a,esp_adapter.c.obj,wifi_realloc, +libesp_wifi.a,esp_adapter.c.obj,coex_event_duration_get_wrapper, +libesp_wifi.a,esp_adapter.c.obj,coex_schm_interval_set_wrapper, +libesp_wifi.a,esp_adapter.c.obj,esp_empty_wrapper, +libesp_wifi.a,esp_adapter.c.obj,wifi_calloc, +libesp_wifi.a,esp_adapter.c.obj,wifi_zalloc_wrapper, +libesp_wifi.a,esp_adapter.c.obj,env_is_chip_wrapper, +libesp_wifi.a,esp_adapter.c.obj,is_from_isr_wrapper, +libesp_wifi.a,esp_adapter.c.obj,semphr_give_from_isr_wrapper, +libesp_wifi.a,esp_adapter.c.obj,mutex_lock_wrapper, +libesp_wifi.a,esp_adapter.c.obj,mutex_unlock_wrapper, +libesp_wifi.a,esp_adapter.c.obj,task_ms_to_tick_wrapper, +libesp_wifi.a,esp_adapter.c.obj,wifi_apb80m_request_wrapper, +libesp_wifi.a,esp_adapter.c.obj,wifi_apb80m_release_wrapper, +libesp_wifi.a,esp_adapter.c.obj,timer_arm_wrapper, +libesp_wifi.a,esp_adapter.c.obj,wifi_malloc, +libesp_wifi.a,esp_adapter.c.obj,timer_disarm_wrapper, +libesp_wifi.a,esp_adapter.c.obj,timer_arm_us_wrapper, +libesp_wifi.a,esp_adapter.c.obj,wifi_rtc_enable_iso_wrapper, +libesp_wifi.a,esp_adapter.c.obj,wifi_rtc_disable_iso_wrapper, +libesp_wifi.a,esp_adapter.c.obj,malloc_internal_wrapper, +libesp_wifi.a,esp_adapter.c.obj,realloc_internal_wrapper, +libesp_wifi.a,esp_adapter.c.obj,calloc_internal_wrapper, +libesp_wifi.a,esp_adapter.c.obj,zalloc_internal_wrapper, +libesp_wifi.a,esp_adapter.c.obj,coex_status_get_wrapper, +libesp_wifi.a,esp_adapter.c.obj,coex_wifi_release_wrapper, +libfreertos.a,list.c.obj,uxListRemove,FALSE +libfreertos.a,list.c.obj,vListInitialise,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,list.c.obj,vListInitialiseItem,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,list.c.obj,vListInsert,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,list.c.obj,vListInsertEnd,FALSE +libfreertos.a,port.c.obj,vApplicationStackOverflowHook,FALSE +libfreertos.a,port.c.obj,vPortYieldOtherCore,FALSE +libfreertos.a,port.c.obj,vPortYield, +libfreertos.a,port_common.c.obj,xPortcheckValidStackMem, +libfreertos.a,port_common.c.obj,vApplicationGetTimerTaskMemory, +libfreertos.a,port_common.c.obj,esp_startup_start_app_common, +libfreertos.a,port_common.c.obj,xPortCheckValidTCBMem, +libfreertos.a,port_common.c.obj,vApplicationGetIdleTaskMemory, +libfreertos.a,port_systick.c.obj,vPortSetupTimer, +libfreertos.a,port_systick.c.obj,xPortSysTickHandler,FALSE +libfreertos.a,queue.c.obj,prvCopyDataFromQueue, +libfreertos.a,queue.c.obj,prvGetDisinheritPriorityAfterTimeout, +libfreertos.a,queue.c.obj,prvIsQueueEmpty, +libfreertos.a,queue.c.obj,prvNotifyQueueSetContainer, +libfreertos.a,queue.c.obj,xQueueReceive, +libfreertos.a,queue.c.obj,prvUnlockQueue, +libfreertos.a,queue.c.obj,xQueueSemaphoreTake, +libfreertos.a,queue.c.obj,xQueueReceiveFromISR, +libfreertos.a,queue.c.obj,uxQueueMessagesWaitingFromISR, +libfreertos.a,queue.c.obj,xQueueIsQueueEmptyFromISR, +libfreertos.a,queue.c.obj,xQueueGiveFromISR, +libfreertos.a,tasks.c.obj,__getreent,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,pcTaskGetName,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,prvAddCurrentTaskToDelayedList,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,prvDeleteTLS,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,pvTaskIncrementMutexHeldCount,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,taskSelectHighestPriorityTaskSMP,FALSE +libfreertos.a,tasks.c.obj,taskYIELD_OTHER_CORE,FALSE +libfreertos.a,tasks.c.obj,vTaskGetSnapshot,CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH +libfreertos.a,tasks.c.obj,vTaskInternalSetTimeOutState,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,vTaskPlaceOnEventList,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,vTaskPlaceOnEventListRestricted,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,vTaskPlaceOnUnorderedEventList,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,vTaskPriorityDisinheritAfterTimeout,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,vTaskReleaseEventListLock,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,vTaskTakeEventListLock,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,xTaskCheckForTimeOut,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,xTaskGetCurrentTaskHandle,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,xTaskGetSchedulerState,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,xTaskGetTickCount,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,xTaskPriorityDisinherit,FALSE +libfreertos.a,tasks.c.obj,xTaskPriorityInherit,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH +libfreertos.a,tasks.c.obj,prvGetExpectedIdleTime,FALSE +libfreertos.a,tasks.c.obj,vTaskStepTick,FALSE +libhal.a,brownout_hal.c.obj,brownout_hal_intr_clear, +libhal.a,efuse_hal.c.obj,efuse_hal_chip_revision, +libhal.a,efuse_hal.c.obj,efuse_hal_get_major_chip_version, +libhal.a,efuse_hal.c.obj,efuse_hal_get_minor_chip_version, +libheap.a,heap_caps.c.obj,dram_alloc_to_iram_addr, +libheap.a,heap_caps.c.obj,heap_caps_free, +libheap.a,heap_caps.c.obj,heap_caps_realloc_base, +libheap.a,heap_caps.c.obj,heap_caps_realloc, +libheap.a,heap_caps.c.obj,heap_caps_calloc_base, +libheap.a,heap_caps.c.obj,heap_caps_calloc, +libheap.a,heap_caps.c.obj,heap_caps_malloc_base, +libheap.a,heap_caps.c.obj,heap_caps_malloc, +libheap.a,heap_caps.c.obj,heap_caps_malloc_default, +libheap.a,heap_caps.c.obj,heap_caps_realloc_default, +libheap.a,heap_caps.c.obj,find_containing_heap, +libheap.a,multi_heap.c.obj,_multi_heap_lock, +libheap.a,multi_heap.c.obj,multi_heap_in_rom_init, +liblog.a,log_freertos.c.obj,esp_log_timestamp, +liblog.a,log_freertos.c.obj,esp_log_impl_lock, +liblog.a,log_freertos.c.obj,esp_log_impl_unlock, +liblog.a,log_freertos.c.obj,esp_log_impl_lock_timeout, +liblog.a,log_freertos.c.obj,esp_log_early_timestamp, +liblog.a,log.c.obj,esp_log_write, +libmbedcrypto.a,esp_mem.c.obj,esp_mbedtls_mem_calloc,!CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC +libmbedcrypto.a,esp_mem.c.obj,esp_mbedtls_mem_free,!CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC +libnewlib.a,assert.c.obj,__assert_func, +libnewlib.a,assert.c.obj,newlib_include_assert_impl, +libnewlib.a,heap.c.obj,_calloc_r, +libnewlib.a,heap.c.obj,_free_r, +libnewlib.a,heap.c.obj,_malloc_r, +libnewlib.a,heap.c.obj,_realloc_r, +libnewlib.a,heap.c.obj,calloc, +libnewlib.a,heap.c.obj,cfree, +libnewlib.a,heap.c.obj,free, +libnewlib.a,heap.c.obj,malloc, +libnewlib.a,heap.c.obj,newlib_include_heap_impl, +libnewlib.a,heap.c.obj,realloc, +libnewlib.a,locks.c.obj,_lock_try_acquire_recursive, +libnewlib.a,locks.c.obj,lock_release_generic, +libnewlib.a,locks.c.obj,_lock_release, +libnewlib.a,locks.c.obj,_lock_release_recursive, +libnewlib.a,locks.c.obj,__retarget_lock_init, +libnewlib.a,locks.c.obj,__retarget_lock_init_recursive, +libnewlib.a,locks.c.obj,__retarget_lock_close, +libnewlib.a,locks.c.obj,__retarget_lock_close_recursive, +libnewlib.a,locks.c.obj,check_lock_nonzero, +libnewlib.a,locks.c.obj,__retarget_lock_acquire, +libnewlib.a,locks.c.obj,lock_init_generic, +libnewlib.a,locks.c.obj,__retarget_lock_acquire_recursive, +libnewlib.a,locks.c.obj,__retarget_lock_try_acquire, +libnewlib.a,locks.c.obj,__retarget_lock_try_acquire_recursive, +libnewlib.a,locks.c.obj,__retarget_lock_release, +libnewlib.a,locks.c.obj,__retarget_lock_release_recursive, +libnewlib.a,locks.c.obj,_lock_close, +libnewlib.a,locks.c.obj,lock_acquire_generic, +libnewlib.a,locks.c.obj,_lock_acquire, +libnewlib.a,locks.c.obj,_lock_acquire_recursive, +libnewlib.a,locks.c.obj,_lock_try_acquire, +libnewlib.a,reent_init.c.obj,esp_reent_init, +libnewlib.a,time.c.obj,_times_r, +libnewlib.a,time.c.obj,_gettimeofday_r, +libpp.a,pp_debug.o,wifi_gpio_debug, +libpthread.a,pthread.c.obj,pthread_mutex_lock_internal, +libpthread.a,pthread.c.obj,pthread_mutex_lock, +libpthread.a,pthread.c.obj,pthread_mutex_unlock, +libriscv.a,interrupt.c.obj,intr_handler_get, +libriscv.a,interrupt.c.obj,intr_handler_set, +libriscv.a,interrupt.c.obj,intr_matrix_route, +libspi_flash.a,flash_brownout_hook.c.obj,spi_flash_needs_reset_check,FALSE +libspi_flash.a,flash_brownout_hook.c.obj,spi_flash_set_erasing_flag,FALSE +libspi_flash.a,flash_ops.c.obj,spi_flash_guard_set,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,flash_ops.c.obj,spi_flash_malloc_internal,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,flash_ops.c.obj,spi_flash_rom_impl_init,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,flash_ops.c.obj,esp_mspi_pin_init,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,flash_ops.c.obj,spi_flash_init_chip_state,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,spi_flash_os_func_app.c.obj,delay_us,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,spi_flash_os_func_app.c.obj,get_buffer_malloc,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,spi_flash_os_func_app.c.obj,release_buffer_malloc,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,spi_flash_os_func_app.c.obj,main_flash_region_protected,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,spi_flash_os_func_app.c.obj,main_flash_op_status,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,spi_flash_os_func_app.c.obj,spi1_flash_os_check_yield,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,spi_flash_os_func_app.c.obj,spi1_flash_os_yield,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,spi_flash_os_func_noos.c.obj,start,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,spi_flash_os_func_noos.c.obj,end,CONFIG_SPI_FLASH_ROM_IMPL +libspi_flash.a,spi_flash_os_func_noos.c.obj,delay_us,CONFIG_SPI_FLASH_ROM_IMPL diff --git a/components/espressif__cmake_utilities/scripts/relinker/examples/esp32c2/library.csv b/components/espressif__cmake_utilities/scripts/relinker/examples/esp32c2/library.csv new file mode 100644 index 0000000..3fd9e4a --- /dev/null +++ b/components/espressif__cmake_utilities/scripts/relinker/examples/esp32c2/library.csv @@ -0,0 +1,24 @@ +library,path +libble_app.a,$IDF_PATH/components/bt/controller/lib_esp32c2/esp32c2-bt-lib/libble_app.a +libpp.a,$IDF_PATH/components/esp_wifi/lib/esp32c2/libpp.a +libbootloader_support.a,./esp-idf/bootloader_support/libbootloader_support.a +libbt.a,./esp-idf/bt/libbt.a +libdriver.a,./esp-idf/driver/libdriver.a +libesp_app_format.a,./esp-idf/esp_app_format/libesp_app_format.a +libesp_hw_support.a,./esp-idf/esp_hw_support/libesp_hw_support.a +libesp_phy.a,./esp-idf/esp_phy/libesp_phy.a +libesp_pm.a,./esp-idf/esp_pm/libesp_pm.a +libesp_ringbuf.a,./esp-idf/esp_ringbuf/libesp_ringbuf.a +libesp_rom.a,./esp-idf/esp_rom/libesp_rom.a +libesp_system.a,./esp-idf/esp_system/libesp_system.a +libesp_timer.a,./esp-idf/esp_timer/libesp_timer.a +libesp_wifi.a,./esp-idf/esp_wifi/libesp_wifi.a +libfreertos.a,./esp-idf/freertos/libfreertos.a +libhal.a,./esp-idf/hal/libhal.a +libheap.a,./esp-idf/heap/libheap.a +liblog.a,./esp-idf/log/liblog.a +libmbedcrypto.a,./esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a +libnewlib.a,./esp-idf/newlib/libnewlib.a +libpthread.a,./esp-idf/pthread/libpthread.a +libriscv.a,./esp-idf/riscv/libriscv.a +libspi_flash.a,./esp-idf/spi_flash/libspi_flash.a diff --git a/components/espressif__cmake_utilities/scripts/relinker/examples/esp32c2/object.csv b/components/espressif__cmake_utilities/scripts/relinker/examples/esp32c2/object.csv new file mode 100644 index 0000000..a897d84 --- /dev/null +++ b/components/espressif__cmake_utilities/scripts/relinker/examples/esp32c2/object.csv @@ -0,0 +1,66 @@ +library,object,path +libbootloader_support.a,bootloader_flash.c.obj,esp-idf/bootloader_support/CMakeFiles/__idf_bootloader_support.dir/bootloader_flash/src/bootloader_flash.c.obj +libbootloader_support.a,flash_encrypt.c.obj,esp-idf/bootloader_support/CMakeFiles/__idf_bootloader_support.dir/src/flash_encrypt.c.obj +libbt.a,bt_osi_mem.c.obj,esp-idf/bt/CMakeFiles/__idf_bt.dir/porting/mem/bt_osi_mem.c.obj +libbt.a,bt.c.obj,esp-idf/bt/CMakeFiles/__idf_bt.dir/controller/esp32c2/bt.c.obj +libbt.a,npl_os_freertos.c.obj,esp-idf/bt/CMakeFiles/__idf_bt.dir/porting/npl/freertos/src/npl_os_freertos.c.obj +libbt.a,nimble_port.c.obj,esp-idf/bt/CMakeFiles/__idf_bt.dir/host/nimble/nimble/porting/nimble/src/nimble_port.c.obj +libdriver.a,gpio.c.obj,esp-idf/driver/CMakeFiles/__idf_driver.dir/gpio/gpio.c.obj +libesp_app_format.a,esp_app_desc.c.obj,esp-idf/esp_app_format/CMakeFiles/__idf_esp_app_format.dir/esp_app_desc.c.obj +libesp_hw_support.a,cpu.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/cpu.c.obj +libesp_hw_support.a,esp_clk.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/esp_clk.c.obj +libesp_hw_support.a,esp_memory_utils.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/esp_memory_utils.c.obj +libesp_hw_support.a,hw_random.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/hw_random.c.obj +libesp_hw_support.a,intr_alloc.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/intr_alloc.c.obj +libesp_hw_support.a,periph_ctrl.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/periph_ctrl.c.obj +libesp_hw_support.a,regi2c_ctrl.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/regi2c_ctrl.c.obj +libesp_hw_support.a,rtc_clk.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/port/esp32c2/rtc_clk.c.obj +libesp_hw_support.a,rtc_init.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/port/esp32c2/rtc_init.c.obj +libesp_hw_support.a,rtc_module.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/rtc_module.c.obj +libesp_hw_support.a,rtc_sleep.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/port/esp32c2/rtc_sleep.c.obj +libesp_hw_support.a,rtc_time.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/port/esp32c2/rtc_time.c.obj +libesp_hw_support.a,sleep_modes.c.obj,esp-idf/esp_hw_support/CMakeFiles/__idf_esp_hw_support.dir/sleep_modes.c.obj +libesp_phy.a,phy_init.c.obj,esp-idf/esp_phy/CMakeFiles/__idf_esp_phy.dir/src/phy_init.c.obj +libesp_phy.a,phy_override.c.obj,esp-idf/esp_phy/CMakeFiles/__idf_esp_phy.dir/src/phy_override.c.obj +libesp_pm.a,pm_locks.c.obj,esp-idf/esp_pm/CMakeFiles/__idf_esp_pm.dir/pm_locks.c.obj +libesp_pm.a,pm_impl.c.obj,esp-idf/esp_pm/CMakeFiles/__idf_esp_pm.dir/pm_impl.c.obj +libesp_ringbuf.a,ringbuf.c.obj,esp-idf/esp_ringbuf/CMakeFiles/__idf_esp_ringbuf.dir/ringbuf.c.obj +libesp_rom.a,esp_rom_systimer.c.obj,esp-idf/esp_rom/CMakeFiles/__idf_esp_rom.dir/patches/esp_rom_systimer.c.obj +libesp_rom.a,esp_rom_uart.c.obj,esp-idf/esp_rom/CMakeFiles/__idf_esp_rom.dir/patches/esp_rom_uart.c.obj +libesp_system.a,brownout.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/port/brownout.c.obj +libesp_system.a,cache_err_int.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/port/soc/esp32c2/cache_err_int.c.obj +libesp_system.a,cpu_start.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/port/cpu_start.c.obj +libesp_system.a,crosscore_int.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/crosscore_int.c.obj +libesp_system.a,esp_system.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/esp_system.c.obj +libesp_system.a,reset_reason.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/port/soc/esp32c2/reset_reason.c.obj +libesp_system.a,ubsan.c.obj,esp-idf/esp_system/CMakeFiles/__idf_esp_system.dir/ubsan.c.obj +libesp_timer.a,esp_timer.c.obj,esp-idf/esp_timer/CMakeFiles/__idf_esp_timer.dir/src/esp_timer.c.obj +libesp_timer.a,esp_timer_impl_systimer.c.obj,esp-idf/esp_timer/CMakeFiles/__idf_esp_timer.dir/src/esp_timer_impl_systimer.c.obj +libesp_timer.a,ets_timer_legacy.c.obj,esp-idf/esp_timer/CMakeFiles/__idf_esp_timer.dir/src/ets_timer_legacy.c.obj +libesp_timer.a,system_time.c.obj,esp-idf/esp_timer/CMakeFiles/__idf_esp_timer.dir/src/system_time.c.obj +libesp_wifi.a,esp_adapter.c.obj,esp-idf/esp_wifi/CMakeFiles/__idf_esp_wifi.dir/esp32c2/esp_adapter.c.obj +libfreertos.a,list.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/list.c.obj +libfreertos.a,port.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/portable/riscv/port.c.obj +libfreertos.a,port_common.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/portable/port_common.c.obj +libfreertos.a,port_systick.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/portable/port_systick.c.obj +libfreertos.a,queue.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/queue.c.obj +libfreertos.a,tasks.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/tasks.c.obj +libhal.a,brownout_hal.c.obj,esp-idf/hal/CMakeFiles/__idf_hal.dir/esp32c2/brownout_hal.c.obj +libhal.a,efuse_hal.c.obj,esp-idf/hal/CMakeFiles/__idf_hal.dir/efuse_hal.c.obj +libhal.a,efuse_hal.c.obj,esp-idf/hal/CMakeFiles/__idf_hal.dir/esp32c2/efuse_hal.c.obj +libheap.a,heap_caps.c.obj,esp-idf/heap/CMakeFiles/__idf_heap.dir/heap_caps.c.obj +libheap.a,multi_heap.c.obj,./esp-idf/heap/CMakeFiles/__idf_heap.dir/multi_heap.c.obj +liblog.a,log_freertos.c.obj,esp-idf/log/CMakeFiles/__idf_log.dir/log_freertos.c.obj +liblog.a,log.c.obj,esp-idf/log/CMakeFiles/__idf_log.dir/log.c.obj +libmbedcrypto.a,esp_mem.c.obj,esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/$IDF_PATH/components/mbedtls/port/esp_mem.c.obj +libnewlib.a,assert.c.obj,esp-idf/newlib/CMakeFiles/__idf_newlib.dir/assert.c.obj +libnewlib.a,heap.c.obj,esp-idf/newlib/CMakeFiles/__idf_newlib.dir/heap.c.obj +libnewlib.a,locks.c.obj,esp-idf/newlib/CMakeFiles/__idf_newlib.dir/locks.c.obj +libnewlib.a,reent_init.c.obj,esp-idf/newlib/CMakeFiles/__idf_newlib.dir/reent_init.c.obj +libnewlib.a,time.c.obj,esp-idf/newlib/CMakeFiles/__idf_newlib.dir/time.c.obj +libpthread.a,pthread.c.obj,esp-idf/pthread/CMakeFiles/__idf_pthread.dir/pthread.c.obj +libriscv.a,interrupt.c.obj,esp-idf/riscv/CMakeFiles/__idf_riscv.dir/interrupt.c.obj +libspi_flash.a,flash_brownout_hook.c.obj,esp-idf/spi_flash/CMakeFiles/__idf_spi_flash.dir/flash_brownout_hook.c.obj +libspi_flash.a,flash_ops.c.obj,esp-idf/spi_flash/CMakeFiles/__idf_spi_flash.dir/flash_ops.c.obj +libspi_flash.a,spi_flash_os_func_app.c.obj,esp-idf/spi_flash/CMakeFiles/__idf_spi_flash.dir/spi_flash_os_func_app.c.obj +libspi_flash.a,spi_flash_os_func_noos.c.obj,esp-idf/spi_flash/CMakeFiles/__idf_spi_flash.dir/spi_flash_os_func_noos.c.obj diff --git a/components/espressif__cmake_utilities/scripts/relinker/relinker.py b/components/espressif__cmake_utilities/scripts/relinker/relinker.py new file mode 100755 index 0000000..151b877 --- /dev/null +++ b/components/espressif__cmake_utilities/scripts/relinker/relinker.py @@ -0,0 +1,311 @@ +#!/usr/bin/env python3 +# +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 + + +import logging +import argparse +import csv +import os +import subprocess +import sys +import re +from io import StringIO +import configuration + +sys.path.append(os.environ['IDF_PATH'] + '/tools/ldgen') +sys.path.append(os.environ['IDF_PATH'] + '/tools/ldgen/ldgen') +from entity import EntityDB + +espidf_objdump = None + +def lib_secs(lib, file, lib_path): + new_env = os.environ.copy() + new_env['LC_ALL'] = 'C' + dump = StringIO(subprocess.check_output([espidf_objdump, '-h', lib_path], env=new_env).decode()) + dump.name = lib + + sections_infos = EntityDB() + sections_infos.add_sections_info(dump) + + secs = sections_infos.get_sections(lib, file.split('.')[0] + '.c') + if len(secs) == 0: + secs = sections_infos.get_sections(lib, file.split('.')[0]) + if len(secs) == 0: + raise ValueError('Failed to get sections from lib %s'%(lib_path)) + + return secs + +def filter_secs(secs_a, secs_b): + new_secs = list() + for s_a in secs_a: + for s_b in secs_b: + if s_b in s_a: + new_secs.append(s_a) + return new_secs + +def strip_secs(secs_a, secs_b): + secs = list(set(secs_a) - set(secs_b)) + secs.sort() + return secs + +def func2sect(func): + if ' ' in func: + func_l = func.split(' ') + else: + func_l = list() + func_l.append(func) + + secs = list() + for l in func_l: + if '.iram1.' not in l: + secs.append('.literal.%s'%(l,)) + secs.append('.text.%s'%(l, )) + else: + secs.append(l) + return secs + +class filter_c: + def __init__(self, file): + lines = open(file).read().splitlines() + self.libs_desc = '' + self.libs = '' + for l in lines: + if ') .iram1 EXCLUDE_FILE(*' in l and ') .iram1.*)' in l: + desc = '\(EXCLUDE_FILE\((.*)\) .iram1 ' + self.libs_desc = re.search(desc, l)[1] + self.libs = self.libs_desc.replace('*', '') + return + + def match(self, lib): + if lib in self.libs: + print('Remove lib %s'%(lib)) + return True + return False + + def add(self): + return self.libs_desc + +class target_c: + def __init__(self, lib, lib_path, file, fsecs): + self.lib = lib + self.file = file + + self.lib_path = lib_path + self.fsecs = func2sect(fsecs) + self.desc = '*%s:%s.*'%(lib, file.split('.')[0]) + + secs = lib_secs(lib, file, lib_path) + if '.iram1.' in self.fsecs[0]: + self.secs = filter_secs(secs, ('.iram1.', )) + else: + self.secs = filter_secs(secs, ('.iram1.', '.text.', '.literal.')) + self.isecs = strip_secs(self.secs, self.fsecs) + + def __str__(self): + s = 'lib=%s\nfile=%s\lib_path=%s\ndesc=%s\nsecs=%s\nfsecs=%s\nisecs=%s\n'%(\ + self.lib, self.file, self.lib_path, self.desc, self.secs, self.fsecs,\ + self.isecs) + return s + +class relink_c: + def __init__(self, input, library_file, object_file, function_file, sdkconfig_file, missing_function_info): + self.filter = filter_c(input) + + libraries = configuration.generator(library_file, object_file, function_file, sdkconfig_file, missing_function_info, espidf_objdump) + self.targets = list() + for i in libraries.libs: + lib = libraries.libs[i] + + if self.filter.match(lib.name): + continue + + for j in lib.objs: + obj = lib.objs[j] + self.targets.append(target_c(lib.name, lib.path, obj.name, + ' '.join(obj.sections()))) + # for i in self.targets: + # print(i) + self.__transform__() + + def __transform__(self): + iram1_exclude = list() + iram1_include = list() + flash_include = list() + + for t in self.targets: + secs = filter_secs(t.fsecs, ('.iram1.', )) + if len(secs) > 0: + iram1_exclude.append(t.desc) + + secs = filter_secs(t.isecs, ('.iram1.', )) + if len(secs) > 0: + iram1_include.append(' %s(%s)'%(t.desc, ' '.join(secs))) + + secs = t.fsecs + if len(secs) > 0: + flash_include.append(' %s(%s)'%(t.desc, ' '.join(secs))) + + self.iram1_exclude = ' *(EXCLUDE_FILE(%s %s) .iram1.*) *(EXCLUDE_FILE(%s %s) .iram1)' % \ + (self.filter.add(), ' '.join(iram1_exclude), \ + self.filter.add(), ' '.join(iram1_exclude)) + self.iram1_include = '\n'.join(iram1_include) + self.flash_include = '\n'.join(flash_include) + + logging.debug('IRAM1 Exclude: %s'%(self.iram1_exclude)) + logging.debug('IRAM1 Include: %s'%(self.iram1_include)) + logging.debug('Flash Include: %s'%(self.flash_include)) + + def __replace__(self, lines): + def is_iram_desc(l): + if '*(.iram1 .iram1.*)' in l or (') .iram1 EXCLUDE_FILE(*' in l and ') .iram1.*)' in l): + return True + return False + + iram_start = False + flash_done = False + + for i in range(0, len(lines) - 1): + l = lines[i] + if '.iram0.text :' in l: + logging.debug('start to process .iram0.text') + iram_start = True + elif '.dram0.data :' in l: + logging.debug('end to process .iram0.text') + iram_start = False + elif is_iram_desc(l): + if iram_start: + lines[i] = '%s\n%s\n'%(self.iram1_exclude, self.iram1_include) + elif '(.stub .gnu.warning' in l: + if not flash_done: + lines[i] = '%s\n\n%s'%(self.flash_include, l) + elif self.flash_include in l: + flash_done = True + else: + if iram_start: + new_l = self._replace_func(l) + if new_l: + lines[i] = new_l + + return lines + + def _replace_func(self, l): + for t in self.targets: + if t.desc in l: + S = '.literal .literal.* .text .text.*' + if S in l: + if len(t.isecs) > 0: + return l.replace(S, ' '.join(t.isecs)) + else: + return ' ' + + S = '%s(%s)'%(t.desc, ' '.join(t.fsecs)) + if S in l: + return ' ' + + replaced = False + for s in t.fsecs: + s2 = s + ' ' + if s2 in l: + l = l.replace(s2, '') + replaced = True + s2 = s + ')' + if s2 in l: + l = l.replace(s2, ')') + replaced = True + if '( )' in l or '()' in l: + return ' ' + if replaced: + return l + else: + index = '*%s:(EXCLUDE_FILE'%(t.lib) + if index in l and t.file.split('.')[0] not in l: + for m in self.targets: + index = '*%s:(EXCLUDE_FILE'%(m.lib) + if index in l and m.file.split('.')[0] not in l: + l = l.replace('EXCLUDE_FILE(', 'EXCLUDE_FILE(%s '%(m.desc)) + if len(m.isecs) > 0: + l += '\n %s(%s)'%(m.desc, ' '.join(m.isecs)) + return l + + return False + + def save(self, input, output): + lines = open(input).read().splitlines() + lines = self.__replace__(lines) + open(output, 'w+').write('\n'.join(lines)) + +def main(): + argparser = argparse.ArgumentParser(description='Relinker script generator') + + argparser.add_argument( + '--input', '-i', + help='Linker template file', + type=str) + + argparser.add_argument( + '--output', '-o', + help='Output linker script', + type=str) + + argparser.add_argument( + '--library', '-l', + help='Library description directory', + type=str) + + argparser.add_argument( + '--object', '-b', + help='Object description file', + type=str) + + argparser.add_argument( + '--function', '-f', + help='Function description file', + type=str) + + argparser.add_argument( + '--sdkconfig', '-s', + help='sdkconfig file', + type=str) + + argparser.add_argument( + '--objdump', '-g', + help='GCC objdump command', + type=str) + + argparser.add_argument( + '--debug', '-d', + help='Debug level(option is \'debug\')', + default='no', + type=str) + + argparser.add_argument( + '--missing_function_info', + help='Print error information instead of throwing exception when missing function', + default=False, + type=bool) + + args = argparser.parse_args() + + if args.debug == 'debug': + logging.basicConfig(level=logging.DEBUG) + + logging.debug('input: %s'%(args.input)) + logging.debug('output: %s'%(args.output)) + logging.debug('library: %s'%(args.library)) + logging.debug('object: %s'%(args.object)) + logging.debug('function: %s'%(args.function)) + logging.debug('sdkconfig:%s'%(args.sdkconfig)) + logging.debug('objdump: %s'%(args.objdump)) + logging.debug('debug: %s'%(args.debug)) + logging.debug('missing_function_info: %s'%(args.missing_function_info)) + + global espidf_objdump + espidf_objdump = args.objdump + + relink = relink_c(args.input, args.library, args.object, args.function, args.sdkconfig, args.missing_function_info) + relink.save(args.input, args.output) + +if __name__ == '__main__': + main() diff --git a/components/espressif__cmake_utilities/test_apps/CMakeLists.txt b/components/espressif__cmake_utilities/test_apps/CMakeLists.txt new file mode 100644 index 0000000..4ac13eb --- /dev/null +++ b/components/espressif__cmake_utilities/test_apps/CMakeLists.txt @@ -0,0 +1,8 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components" + "../../cmake_utilities") +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(cmake_utilities_test_apps) \ No newline at end of file diff --git a/components/espressif__cmake_utilities/test_apps/components/TEST-component2/CMakeLists.txt b/components/espressif__cmake_utilities/test_apps/components/TEST-component2/CMakeLists.txt new file mode 100644 index 0000000..6d9ee69 --- /dev/null +++ b/components/espressif__cmake_utilities/test_apps/components/TEST-component2/CMakeLists.txt @@ -0,0 +1,10 @@ +idf_component_register( SRC_DIRS "." + INCLUDE_DIRS "." + REQUIRES cmake_utilities) + +include(gcc) +include(gen_compressed_ota) +include(gen_single_bin) +include(package_manager) +include(relinker) +cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR}) \ No newline at end of file diff --git a/components/espressif__cmake_utilities/test_apps/components/TEST-component2/idf_component.yml b/components/espressif__cmake_utilities/test_apps/components/TEST-component2/idf_component.yml new file mode 100644 index 0000000..5a0b9df --- /dev/null +++ b/components/espressif__cmake_utilities/test_apps/components/TEST-component2/idf_component.yml @@ -0,0 +1,6 @@ +version: "3.2.1" +description: Test2 for cmake utilities +url: https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities +issues: https://github.com/espressif/esp-iot-solution/issues +dependencies: + idf: ">=4.1" \ No newline at end of file diff --git a/components/espressif__cmake_utilities/test_apps/components/TEST-component2/test_component2.c b/components/espressif__cmake_utilities/test_apps/components/TEST-component2/test_component2.c new file mode 100644 index 0000000..3cb6555 --- /dev/null +++ b/components/espressif__cmake_utilities/test_apps/components/TEST-component2/test_component2.c @@ -0,0 +1,16 @@ +#include + +int test_component2_version_major() +{ + return TEST_COMPONENT2_VER_MAJOR; +} + +int test_component2_version_minor() +{ + return TEST_COMPONENT2_VER_MINOR; +} + +int test_component2_version_patch() +{ + return TEST_COMPONENT2_VER_PATCH; +} diff --git a/components/espressif__cmake_utilities/test_apps/components/TEST-component2/test_component2.h b/components/espressif__cmake_utilities/test_apps/components/TEST-component2/test_component2.h new file mode 100644 index 0000000..1323ccb --- /dev/null +++ b/components/espressif__cmake_utilities/test_apps/components/TEST-component2/test_component2.h @@ -0,0 +1,14 @@ +#include +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +int test_component2_version_major(); +int test_component2_version_minor(); +int test_component2_version_patch(); + +#ifdef __cplusplus +} +#endif diff --git a/components/espressif__cmake_utilities/test_apps/components/test_component1/CMakeLists.txt b/components/espressif__cmake_utilities/test_apps/components/test_component1/CMakeLists.txt new file mode 100644 index 0000000..6d9ee69 --- /dev/null +++ b/components/espressif__cmake_utilities/test_apps/components/test_component1/CMakeLists.txt @@ -0,0 +1,10 @@ +idf_component_register( SRC_DIRS "." + INCLUDE_DIRS "." + REQUIRES cmake_utilities) + +include(gcc) +include(gen_compressed_ota) +include(gen_single_bin) +include(package_manager) +include(relinker) +cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR}) \ No newline at end of file diff --git a/components/espressif__cmake_utilities/test_apps/components/test_component1/idf_component.yml b/components/espressif__cmake_utilities/test_apps/components/test_component1/idf_component.yml new file mode 100644 index 0000000..cc5a946 --- /dev/null +++ b/components/espressif__cmake_utilities/test_apps/components/test_component1/idf_component.yml @@ -0,0 +1,6 @@ +version: "1.2.3" +description: Test1 for cmake utilities +url: https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities +issues: https://github.com/espressif/esp-iot-solution/issues +dependencies: + idf: ">=4.1" \ No newline at end of file diff --git a/components/espressif__cmake_utilities/test_apps/components/test_component1/test_component1.c b/components/espressif__cmake_utilities/test_apps/components/test_component1/test_component1.c new file mode 100644 index 0000000..7f607e0 --- /dev/null +++ b/components/espressif__cmake_utilities/test_apps/components/test_component1/test_component1.c @@ -0,0 +1,16 @@ +#include + +int test_component1_version_major() +{ + return TEST_COMPONENT1_VER_MAJOR; +} + +int test_component1_version_minor() +{ + return TEST_COMPONENT1_VER_MINOR; +} + +int test_component1_version_patch() +{ + return TEST_COMPONENT1_VER_PATCH; +} diff --git a/components/espressif__cmake_utilities/test_apps/components/test_component1/test_component1.h b/components/espressif__cmake_utilities/test_apps/components/test_component1/test_component1.h new file mode 100644 index 0000000..794cc49 --- /dev/null +++ b/components/espressif__cmake_utilities/test_apps/components/test_component1/test_component1.h @@ -0,0 +1,14 @@ +#include +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +int test_component1_version_major(); +int test_component1_version_minor(); +int test_component1_version_patch(); + +#ifdef __cplusplus +} +#endif diff --git a/components/espressif__cmake_utilities/test_apps/main/CMakeLists.txt b/components/espressif__cmake_utilities/test_apps/main/CMakeLists.txt new file mode 100644 index 0000000..4d89cab --- /dev/null +++ b/components/espressif__cmake_utilities/test_apps/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRC_DIRS "." + INCLUDE_DIRS "." + REQUIRES unity test_utils test_component1 TEST-component2) \ No newline at end of file diff --git a/components/espressif__cmake_utilities/test_apps/main/test_cmake_utilities.c b/components/espressif__cmake_utilities/test_apps/main/test_cmake_utilities.c new file mode 100644 index 0000000..9c2cb95 --- /dev/null +++ b/components/espressif__cmake_utilities/test_apps/main/test_cmake_utilities.c @@ -0,0 +1,59 @@ +/* + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "freertos/FreeRTOS.h" +#include "esp_system.h" +#include "esp_log.h" +#include "unity.h" +#include "test_component1.h" +#include "test_component2.h" + + +/* USB PIN fixed in esp32-s2, can not use io matrix */ +#define TEST_MEMORY_LEAK_THRESHOLD (-400) + +TEST_CASE("Test package manager version", "[cmake_utilities][package_manager]") +{ + esp_log_level_set("*", ESP_LOG_INFO); + TEST_ASSERT_EQUAL_INT(test_component1_version_major(), 1); + TEST_ASSERT_EQUAL_INT(test_component1_version_minor(), 2); + TEST_ASSERT_EQUAL_INT(test_component1_version_patch(), 3); + TEST_ASSERT_EQUAL_INT(test_component2_version_major(), 3); + TEST_ASSERT_EQUAL_INT(test_component2_version_minor(), 2); + TEST_ASSERT_EQUAL_INT(test_component2_version_patch(), 1); +} + +static size_t before_free_8bit; +static size_t before_free_32bit; + +static void check_leak(size_t before_free, size_t after_free, const char *type) +{ + ssize_t delta = after_free - before_free; + printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta); + TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak"); +} + +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); +} + +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); + check_leak(before_free_8bit, after_free_8bit, "8BIT"); + check_leak(before_free_32bit, after_free_32bit, "32BIT"); +} + +void app_main(void) +{ + printf("Cmake Utilities TEST \n"); + unity_run_menu(); +} diff --git a/components/espressif__cmake_utilities/test_apps/pytest_cmake_utilities.py b/components/espressif__cmake_utilities/test_apps/pytest_cmake_utilities.py new file mode 100644 index 0000000..3b188bf --- /dev/null +++ b/components/espressif__cmake_utilities/test_apps/pytest_cmake_utilities.py @@ -0,0 +1,20 @@ +''' +Steps to run these cases: +- Build + - . ${IDF_PATH}/export.sh + - pip install idf_build_apps + - python tools/build_apps.py tools/cmake_utilities/test_apps -t esp32s2 +- Test + - pip install -r tools/requirements/requirement.pytest.txt + - pytest tools/cmake_utilities/test_apps --target esp32s2 +''' + +import pytest +from pytest_embedded import Dut + +@pytest.mark.target('esp32s3') +@pytest.mark.env('generic') +def test_cmake_utilities(dut: Dut)-> None: + dut.expect_exact('Press ENTER to see the list of tests.') + dut.write('*') + dut.expect_unity_test_output(timeout = 1000) diff --git a/dependencies.lock b/dependencies.lock index 474ba19..c67e2f9 100644 --- a/dependencies.lock +++ b/dependencies.lock @@ -1,9 +1,9 @@ dependencies: espressif/button: - component_hash: c3ee3ba339a3848977496d0157008ae574a24fc59f54d27c93ab51b14446a2fb + component_hash: null source: - service_url: https://api.components.espressif.com/ - type: service + path: /home/yu/Source_Space/ESP32_Project_Space/Air_58Printer/components/espressif__button + type: local version: 3.3.1 espressif/cmake_utilities: component_hash: 351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f @@ -16,6 +16,6 @@ dependencies: source: type: idf version: 5.3.0 -manifest_hash: 8a1ae27e5898eea96375edcb6f3e3ddddb69486f7a9f0b944b59cf7e1f4f5e84 +manifest_hash: 9a1ad333c087c0f6ba914b30dad014f27f8198c5ae062a2cb9a1a61b1a4126b0 target: esp32c3 version: 1.0.0