diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index d7d43fc..6105a4e 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -351,7 +351,7 @@ def extract_link_args(target_config): args = click.parser.split_arg_string(fragment) if fragment_role == "flags": link_args["LINKFLAGS"].extend(args) - elif fragment_role == "libraries": + elif fragment_role in ("libraries", "libraryPath"): if fragment.startswith("-l"): link_args["LIBS"].extend(args) elif fragment.startswith("-L"): @@ -1104,6 +1104,7 @@ def install_python_deps(): "pyparsing": "~=3.0.9" if IDF5 else ">=2.0.3,<2.4.0", "kconfiglib": "~=14.1.0" if IDF5 else "~=13.7.1", "idf-component-manager": "~=1.2.3" if IDF5 else "~=1.0", + "esp-idf-kconfig": "~=1.2.0" } python_exe_path = get_python_exe() @@ -1543,7 +1544,7 @@ if "__test" not in COMMAND_LINE_TARGETS or env.GetProjectOption( # Add include dirs from PlatformIO build system to project CPPPATH so # they're visible to PIOBUILDFILES project_env.AppendUnique( - CPPPATH=["$PROJECT_INCLUDE_DIR", "$PROJECT_SRC_DIR"] + CPPPATH=["$PROJECT_INCLUDE_DIR", "$PROJECT_SRC_DIR", "$PROJECT_DIR"] + get_project_lib_includes(env) ) diff --git a/examples/espidf-ulp-adc/main/ulp_adc_example_main.c b/examples/espidf-ulp-adc/main/ulp_adc_example_main.c index 6b3ff56..8821283 100644 --- a/examples/espidf-ulp-adc/main/ulp_adc_example_main.c +++ b/examples/espidf-ulp-adc/main/ulp_adc_example_main.c @@ -9,17 +9,20 @@ #include #include +#include #include "esp_sleep.h" -#include "nvs.h" -#include "nvs_flash.h" #include "soc/rtc_cntl_reg.h" #include "soc/sens_reg.h" #include "driver/gpio.h" #include "driver/rtc_io.h" -#include "driver/dac.h" -#include "esp32/ulp.h" +#include "ulp.h" #include "ulp_main.h" #include "esp_adc/adc_oneshot.h" +#include "ulp/example_config.h" +#include "ulp_adc.h" + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start"); extern const uint8_t ulp_main_bin_end[] asm("_binary_ulp_main_bin_end"); @@ -42,15 +45,21 @@ void app_main(void) init_ulp_program(); } else { printf("Deep sleep wakeup\n"); - printf("ULP did %d measurements since last reset\n", ulp_sample_counter & UINT16_MAX); - printf("Thresholds: low=%d high=%d\n", ulp_low_thr, ulp_high_thr); + printf("ULP did %"PRIu32" measurements since last reset\n", ulp_sample_counter & UINT16_MAX); + printf("Thresholds: low=%"PRIu32" high=%"PRIu32"\n", ulp_low_thr, ulp_high_thr); ulp_last_result &= UINT16_MAX; - printf("Value=%d was %s threshold\n", ulp_last_result, + printf("Value=%"PRIu32" was %s threshold\n", ulp_last_result, ulp_last_result < ulp_low_thr ? "below" : "above"); } printf("Entering deep sleep\n\n"); start_ulp_program(); ESP_ERROR_CHECK( esp_sleep_enable_ulp_wakeup() ); + +#if !CONFIG_IDF_TARGET_ESP32 + /* RTC peripheral power domain needs to be kept on to keep SAR ADC related configs during sleep */ + esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); +#endif + esp_deep_sleep_start(); } @@ -60,35 +69,31 @@ static void init_ulp_program(void) (ulp_main_bin_end - ulp_main_bin_start) / sizeof(uint32_t)); ESP_ERROR_CHECK(err); - //-------------ADC1 Init---------------// - adc_oneshot_unit_handle_t adc1_handle; - adc_oneshot_unit_init_cfg_t init_config1 = { - .unit_id = ADC_UNIT_1, + ulp_adc_cfg_t cfg = { + .adc_n = EXAMPLE_ADC_UNIT, + .channel = EXAMPLE_ADC_CHANNEL, + .width = EXAMPLE_ADC_WIDTH, + .atten = EXAMPLE_ADC_ATTEN, .ulp_mode = ADC_ULP_MODE_FSM, }; - ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &adc1_handle)); - //-------------ADC1 Channel Config---------------// - // Note: when changing channel here, also change 'adc_channel' constant in adc.S - adc_oneshot_chan_cfg_t config = { - .bitwidth = ADC_BITWIDTH_DEFAULT, - .atten = ADC_ATTEN_DB_11, - }; - ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, ADC_CHANNEL_6, &config)); + ESP_ERROR_CHECK(ulp_adc_init(&cfg)); - /* Set low and high thresholds, approx. 1.35V - 1.75V*/ - ulp_low_thr = 1500; - ulp_high_thr = 2000; + ulp_low_thr = EXAMPLE_ADC_LOW_TRESHOLD; + ulp_high_thr = EXAMPLE_ADC_HIGH_TRESHOLD; /* Set ULP wake up period to 20ms */ ulp_set_wakeup_period(0, 20000); +#if CONFIG_IDF_TARGET_ESP32 /* Disconnect GPIO12 and GPIO15 to remove current drain through - * pullup/pulldown resistors. + * pullup/pulldown resistors on modules which have these (e.g. ESP32-WROVER) * GPIO12 may be pulled high to select flash voltage. */ rtc_gpio_isolate(GPIO_NUM_12); rtc_gpio_isolate(GPIO_NUM_15); +#endif // CONFIG_IDF_TARGET_ESP32 + esp_deep_sleep_disable_rom_logging(); // suppress boot messages } diff --git a/examples/espidf-ulp-adc/ulp/adc.S b/examples/espidf-ulp-adc/ulp/adc.S index 1b59cce..b96f51c 100644 --- a/examples/espidf-ulp-adc/ulp/adc.S +++ b/examples/espidf-ulp-adc/ulp/adc.S @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ /* ULP Example: using ADC in deep sleep This example code is in the Public Domain (or CC0 licensed, at your option.) @@ -22,9 +27,9 @@ */ #include "soc/rtc_cntl_reg.h" #include "soc/soc_ulp.h" +#include "example_config.h" - /* ADC1 channel 6, GPIO34 */ - .set adc_channel, 6 + .set adc_channel, EXAMPLE_ADC_CHANNEL /* Configure the number of ADC samples to average on each measurement. For convenience, make it a power of 2. */ diff --git a/examples/espidf-ulp-adc/ulp/example_config.h b/examples/espidf-ulp-adc/ulp/example_config.h new file mode 100644 index 0000000..baa86dd --- /dev/null +++ b/examples/espidf-ulp-adc/ulp/example_config.h @@ -0,0 +1,16 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#pragma once + +/* Ints are used here to be able to include the file in assembly as well */ +#define EXAMPLE_ADC_CHANNEL 6 // ADC_CHANNEL_6, GPIO34 on ESP32, GPIO7 on ESP32-S3 +#define EXAMPLE_ADC_UNIT 0 // ADC_UNIT_1 +#define EXAMPLE_ADC_ATTEN 3 // ADC_ATTEN_DB_11 +#define EXAMPLE_ADC_WIDTH 0 // ADC_BITWIDTH_DEFAULT + +/* Set low and high thresholds, approx. 1.35V - 1.75V*/ +#define EXAMPLE_ADC_LOW_TRESHOLD 1500 +#define EXAMPLE_ADC_HIGH_TRESHOLD 2000 diff --git a/platform.json b/platform.json index be4cd44..d2cc34a 100644 --- a/platform.json +++ b/platform.json @@ -34,28 +34,28 @@ "type": "toolchain", "owner": "espressif", "version": "8.4.0+2021r2-patch5", - "optionalVersions": ["11.2.0+2022r1"] + "optionalVersions": ["12.2.0+20230208"] }, "toolchain-xtensa-esp32s2": { "type": "toolchain", "optional": true, "owner": "espressif", "version": "8.4.0+2021r2-patch5", - "optionalVersions": ["11.2.0+2022r1"] + "optionalVersions": ["12.2.0+20230208"] }, "toolchain-xtensa-esp32s3": { "type": "toolchain", "optional": true, "owner": "espressif", "version": "8.4.0+2021r2-patch5", - "optionalVersions": ["11.2.0+2022r1"] + "optionalVersions": ["12.2.0+20230208"] }, "toolchain-riscv32-esp": { "type": "toolchain", "optional": true, "owner": "espressif", "version": "8.4.0+2021r2-patch5", - "optionalVersions": ["11.2.0+2022r1"] + "optionalVersions": ["12.2.0+20230208"] }, "toolchain-esp32ulp": { "type": "toolchain", @@ -79,7 +79,7 @@ "type": "framework", "optional": true, "owner": "platformio", - "version": "~3.50002.0", + "version": "~3.50100.0", "optionalVersions": ["~3.40405.0"] }, "tool-esptoolpy": { diff --git a/platform.py b/platform.py index 0e4de86..6e43311 100644 --- a/platform.py +++ b/platform.py @@ -111,7 +111,7 @@ class Espressif32Platform(PlatformBase): "xtensa-esp32s3", "riscv32-esp" ): - self.packages["toolchain-%s" % target]["version"] = "11.2.0+2022r1" + self.packages["toolchain-%s" % target]["version"] = "12.2.0+20230208" for available_mcu in ("esp32", "esp32s2", "esp32s3"): if available_mcu == mcu: