esp32: Drop support for ESP-IDF below V5.2.0.

Specifically, remove all conditional compilation for these earlier versions
and change the idf_component.yml specifiers to require >=5.2.0.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
Angus Gratton
2024-11-01 16:32:48 +11:00
committed by Damien George
parent 82e382a399
commit 6e5d8d0093
16 changed files with 13 additions and 123 deletions

View File

@@ -28,7 +28,7 @@ manage the ESP32 microcontroller, as well as a way to manage the required
build environment and toolchains needed to build the firmware.
The ESP-IDF changes quickly and MicroPython only supports certain versions.
Currently MicroPython supports v5.0.4, v5.0.5, v5.1.2, v5.2.0, v5.2.2, v5.3.
Currently MicroPython supports v5.2, v5.2.2, and v5.3.
To install the ESP-IDF the full instructions can be found at the
[Espressif Getting Started guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html#installation-step-by-step).

View File

@@ -34,21 +34,13 @@
#if MICROPY_PY_MACHINE_DAC
#include "driver/gpio.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
#include "driver/dac_oneshot.h"
#else
#include "driver/dac.h"
#define DAC_CHAN_0 DAC_CHANNEL_1
#define DAC_CHAN_1 DAC_CHANNEL_2
#endif
typedef struct _mdac_obj_t {
mp_obj_base_t base;
gpio_num_t gpio_id;
dac_channel_t dac_id;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
dac_oneshot_handle_t dac_oneshot_handle;
#endif
} mdac_obj_t;
static mdac_obj_t mdac_obj[] = {
@@ -77,21 +69,10 @@ static mp_obj_t mdac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
mp_raise_ValueError(MP_ERROR_TEXT("invalid Pin for DAC"));
}
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
dac_oneshot_config_t dac_oneshot_config = {.chan_id = self->dac_id};
check_esp_err(dac_oneshot_new_channel(&dac_oneshot_config, (dac_oneshot_handle_t *)&self->dac_oneshot_handle));
check_esp_err(dac_oneshot_output_voltage(self->dac_oneshot_handle, 0));
return MP_OBJ_FROM_PTR(self);
#else
esp_err_t err = dac_output_enable(self->dac_id);
if (err == ESP_OK) {
err = dac_output_voltage(self->dac_id, 0);
}
if (err == ESP_OK) {
return MP_OBJ_FROM_PTR(self);
}
mp_raise_ValueError(MP_ERROR_TEXT("parameter error"));
#endif
}
static void mdac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
@@ -106,16 +87,8 @@ static mp_obj_t mdac_write(mp_obj_t self_in, mp_obj_t value_in) {
mp_raise_ValueError(MP_ERROR_TEXT("value out of range"));
}
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
check_esp_err(dac_oneshot_output_voltage(self->dac_oneshot_handle, value));
return mp_const_none;
#else
esp_err_t err = dac_output_voltage(self->dac_id, value);
if (err == ESP_OK) {
return mp_const_none;
}
mp_raise_ValueError(MP_ERROR_TEXT("parameter error"));
#endif
}
MP_DEFINE_CONST_FUN_OBJ_2(mdac_write_obj, mdac_write);

View File

@@ -211,39 +211,6 @@ static void configure_channel(machine_pwm_obj_t *self) {
}
}
// Temporary workaround for ledc_find_suitable_duty_resolution function only being added in IDF V5.2
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
static uint32_t ledc_find_suitable_duty_resolution(uint32_t src_clk_freq, uint32_t timer_freq) {
// This implementation is based on the one used in Micropython v1.23
// Find the highest bit resolution for the requested frequency
unsigned int freq = src_clk_freq;
int divider = (freq + timer_freq / 2) / timer_freq; // rounded
if (divider == 0) {
divider = 1;
}
float f = (float)freq / divider; // actual frequency
if (f <= 1.0) {
f = 1.0;
}
freq = (unsigned int)roundf((float)freq / f);
unsigned int res = 0;
for (; freq > 1; freq >>= 1) {
++res;
}
if (res == 0) {
res = 1;
} else if (res > HIGHEST_PWM_RES) {
// Limit resolution to HIGHEST_PWM_RES to match units of our duty
res = HIGHEST_PWM_RES;
}
return res;
}
#endif
static void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_config_t *timer) {
esp_err_t err;
if (freq != timer->freq_hz) {
@@ -265,20 +232,10 @@ static void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf
}
#endif
uint32_t src_clk_freq = 0;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
err = esp_clk_tree_src_get_freq_hz(timer->clk_cfg, ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &src_clk_freq);
if (err != ESP_OK) {
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("unable to query source clock frequency %d"), (int)timer->clk_cfg);
}
#else
// Simplified fallback logic for IDF V5.0.x, for targets with APB only.
src_clk_freq = APB_CLK_FREQ; // 80 MHz
#if SOC_LEDC_SUPPORT_REF_TICK
if (timer->clk_cfg == LEDC_USE_REF_TICK) {
src_clk_freq = REF_CLK_FREQ; // 1 MHz
}
#endif // SOC_LEDC_SUPPORT_REF_TICK
#endif // ESP_IDF_VERSION
timer->duty_resolution = ledc_find_suitable_duty_resolution(src_clk_freq, timer->freq_hz);

View File

@@ -399,11 +399,7 @@ static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
}
self->flowcontrol = args[ARG_flow].u_int;
}
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
uint8_t uart_fifo_len = UART_HW_FIFO_LEN(self->uart_num);
#else
uint8_t uart_fifo_len = UART_FIFO_LEN;
#endif
check_esp_err(uart_set_hw_flow_ctrl(self->uart_num, self->flowcontrol, uart_fifo_len - uart_fifo_len / 4));
}

View File

@@ -2,4 +2,4 @@
dependencies:
espressif/mdns: "~1.1.0"
idf:
version: ">=5.0.4"
version: ">=5.2.0"

View File

@@ -2,4 +2,4 @@
dependencies:
espressif/mdns: "~1.1.0"
idf:
version: ">=5.0.4"
version: ">=5.2.0"

View File

@@ -2,4 +2,4 @@
dependencies:
espressif/mdns: "~1.1.0"
idf:
version: ">=5.1.0"
version: ">=5.2.0"

View File

@@ -3,4 +3,4 @@ dependencies:
espressif/mdns: "~1.1.0"
espressif/esp_tinyusb: "~1.0.0"
idf:
version: ">=5.0.4"
version: ">=5.2.0"

View File

@@ -3,4 +3,4 @@ dependencies:
espressif/mdns: "~1.1.0"
espressif/esp_tinyusb: "~1.0.0"
idf:
version: ">=5.0.4"
version: ">=5.2.0"

View File

@@ -53,7 +53,6 @@ static mp_obj_t esp32_wake_on_touch(const mp_obj_t wake) {
if (machine_rtc_config.ext0_pin != -1) {
mp_raise_ValueError(MP_ERROR_TEXT("no resources"));
}
// mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("touchpad wakeup not available for this version of ESP-IDF"));
machine_rtc_config.wake_on_touch = mp_obj_is_true(wake);
return mp_const_none;

View File

@@ -110,24 +110,11 @@ static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
mp_raise_ValueError(MP_ERROR_TEXT("frequency must be 20MHz, 40MHz, 80Mhz, 160MHz or 240MHz"));
#endif
}
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
esp_pm_config_t pm;
#else
#if CONFIG_IDF_TARGET_ESP32
esp_pm_config_esp32_t pm;
#elif CONFIG_IDF_TARGET_ESP32C3
esp_pm_config_esp32c3_t pm;
#elif CONFIG_IDF_TARGET_ESP32C6
esp_pm_config_esp32c6_t pm;
#elif CONFIG_IDF_TARGET_ESP32S2
esp_pm_config_esp32s2_t pm;
#elif CONFIG_IDF_TARGET_ESP32S3
esp_pm_config_esp32s3_t pm;
#endif
#endif
pm.max_freq_mhz = freq;
pm.min_freq_mhz = freq;
pm.light_sleep_enable = false;
esp_pm_config_t pm = {
.max_freq_mhz = freq,
.min_freq_mhz = freq,
.light_sleep_enable = false,
};
esp_err_t ret = esp_pm_configure(&pm);
if (ret != ESP_OK) {
mp_raise_ValueError(NULL);

View File

@@ -33,13 +33,9 @@
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_WPA3_PSK), MP_ROM_INT(WIFI_AUTH_WPA2_WPA3_PSK) },
{ MP_ROM_QSTR(MP_QSTR_AUTH_WAPI_PSK), MP_ROM_INT(WIFI_AUTH_WAPI_PSK) },
{ MP_ROM_QSTR(MP_QSTR_AUTH_OWE), MP_ROM_INT(WIFI_AUTH_OWE) },
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 5) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) || ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 2)
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA3_ENT_192), MP_ROM_INT(WIFI_AUTH_WPA3_ENT_192) },
#endif
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA3_EXT_PSK), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK) },
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA3_EXT_PSK_MIXED_MODE), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE) },
#endif
{ MP_ROM_QSTR(MP_QSTR_AUTH_MAX), MP_ROM_INT(WIFI_AUTH_MAX) },
#endif
@@ -75,11 +71,9 @@
{ MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(STAT_GOT_IP)},
// Errors from the ESP-IDF
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND)},
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND_IN_RSSI_THRESHOLD), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD)},
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD)},
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND_W_COMPATIBLE_SECURITY), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND_W_COMPATIBLE_SECURITY)},
#endif
{ MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(WIFI_REASON_AUTH_FAIL)},
{ MP_ROM_QSTR(MP_QSTR_STAT_BEACON_TIMEOUT), MP_ROM_INT(WIFI_REASON_BEACON_TIMEOUT)},
#if !MICROPY_PREVIEW_VERSION_2

View File

@@ -41,7 +41,7 @@
#define MP_THREAD_DEFAULT_STACK_SIZE (MP_THREAD_MIN_STACK_SIZE + MICROPY_STACK_CHECK_MARGIN)
#define MP_THREAD_PRIORITY (ESP_TASK_PRIO_MIN + 1)
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0) && !CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
#if !CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
#define FREERTOS_TASK_DELETE_HOOK vTaskPreDeletionHook
#else
#define FREERTOS_TASK_DELETE_HOOK vPortCleanUpTCB

View File

@@ -30,8 +30,6 @@
#include "py/runtime.h"
#include "py/mphal.h"
#include "esp_idf_version.h"
#if MICROPY_PY_NETWORK_LAN
#include "esp_eth.h"

View File

@@ -113,7 +113,6 @@ static void network_wlan_wifi_event_handler(void *event_handler_arg, esp_event_b
// AP may not exist, or it may have momentarily dropped out; try to reconnect.
message = "no AP found";
break;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
case WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD:
// No AP with RSSI within given threshold exists, or it may have momentarily dropped out; try to reconnect.
message = "no AP with RSSI within threshold found";
@@ -126,7 +125,6 @@ static void network_wlan_wifi_event_handler(void *event_handler_arg, esp_event_b
// No AP with compatible security exists, or it may have momentarily dropped out; try to reconnect.
message = "no AP with compatible security found";
break;
#endif
case WIFI_REASON_AUTH_FAIL:
// Password may be wrong, or it just failed to connect; try to reconnect.
message = "authentication failed";
@@ -367,14 +365,12 @@ static mp_obj_t network_wlan_status(size_t n_args, const mp_obj_t *args) {
return MP_OBJ_NEW_SMALL_INT(STAT_GOT_IP);
} else if (wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND) {
return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_NO_AP_FOUND);
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
} else if (wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD) {
return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD);
} else if (wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD) {
return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD);
} else if (wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND_W_COMPATIBLE_SECURITY) {
return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_NO_AP_FOUND_W_COMPATIBLE_SECURITY);
#endif
} else if ((wifi_sta_disconn_reason == WIFI_REASON_AUTH_FAIL) || (wifi_sta_disconn_reason == WIFI_REASON_CONNECTION_FAIL)) {
// wrong password
return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_AUTH_FAIL);
@@ -761,13 +757,9 @@ static const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA2_WPA3), MP_ROM_INT(WIFI_AUTH_WPA2_WPA3_PSK) },
{ MP_ROM_QSTR(MP_QSTR_SEC_WAPI), MP_ROM_INT(WIFI_AUTH_WAPI_PSK) },
{ MP_ROM_QSTR(MP_QSTR_SEC_OWE), MP_ROM_INT(WIFI_AUTH_OWE) },
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 5) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) || ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 2)
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA3_ENT_192), MP_ROM_INT(WIFI_AUTH_WPA3_ENT_192) },
#endif
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA3_EXT_PSK), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK) },
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA3_EXT_PSK_MIXED_MODE), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE) },
#endif
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
{ MP_ROM_QSTR(MP_QSTR_SEC_DPP), MP_ROM_INT(WIFI_AUTH_DPP) },
#endif
@@ -782,10 +774,8 @@ static MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);
_Static_assert(WIFI_AUTH_MAX == 14, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types_generic.h");
#elif ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
_Static_assert(WIFI_AUTH_MAX == 13, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h");
#elif ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 5) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) || ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 2)
_Static_assert(WIFI_AUTH_MAX == 11, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h");
#else
_Static_assert(WIFI_AUTH_MAX == 10, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h");
#error "Error in macro logic, all supported versions should be covered."
#endif
MP_DEFINE_CONST_OBJ_TYPE(

View File

@@ -51,11 +51,7 @@ static void uart_irq_handler(void *arg);
void uart_stdout_init(void) {
uart_hal_context_t repl_hal = REPL_HAL_DEFN();
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
uart_sclk_t sclk;
#else
soc_module_clk_t sclk;
#endif
uint32_t sclk_freq;
uart_hal_get_sclk(&repl_hal, &sclk); // To restore SCLK after uart_hal_init() resets it