Skip to content

Commit 6e5d8d0

Browse files
projectgusdpgeorge
authored andcommitted
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 <[email protected]>
1 parent 82e382a commit 6e5d8d0

16 files changed

+13
-123
lines changed

ports/esp32/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ manage the ESP32 microcontroller, as well as a way to manage the required
2828
build environment and toolchains needed to build the firmware.
2929

3030
The ESP-IDF changes quickly and MicroPython only supports certain versions.
31-
Currently MicroPython supports v5.0.4, v5.0.5, v5.1.2, v5.2.0, v5.2.2, v5.3.
31+
Currently MicroPython supports v5.2, v5.2.2, and v5.3.
3232

3333
To install the ESP-IDF the full instructions can be found at the
3434
[Espressif Getting Started guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html#installation-step-by-step).

ports/esp32/machine_dac.c

-27
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,13 @@
3434
#if MICROPY_PY_MACHINE_DAC
3535

3636
#include "driver/gpio.h"
37-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
3837
#include "driver/dac_oneshot.h"
39-
#else
40-
#include "driver/dac.h"
41-
#define DAC_CHAN_0 DAC_CHANNEL_1
42-
#define DAC_CHAN_1 DAC_CHANNEL_2
43-
#endif
4438

4539
typedef struct _mdac_obj_t {
4640
mp_obj_base_t base;
4741
gpio_num_t gpio_id;
4842
dac_channel_t dac_id;
49-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
5043
dac_oneshot_handle_t dac_oneshot_handle;
51-
#endif
5244
} mdac_obj_t;
5345

5446
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
7769
mp_raise_ValueError(MP_ERROR_TEXT("invalid Pin for DAC"));
7870
}
7971

80-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
8172
dac_oneshot_config_t dac_oneshot_config = {.chan_id = self->dac_id};
8273
check_esp_err(dac_oneshot_new_channel(&dac_oneshot_config, (dac_oneshot_handle_t *)&self->dac_oneshot_handle));
8374
check_esp_err(dac_oneshot_output_voltage(self->dac_oneshot_handle, 0));
8475
return MP_OBJ_FROM_PTR(self);
85-
#else
86-
esp_err_t err = dac_output_enable(self->dac_id);
87-
if (err == ESP_OK) {
88-
err = dac_output_voltage(self->dac_id, 0);
89-
}
90-
if (err == ESP_OK) {
91-
return MP_OBJ_FROM_PTR(self);
92-
}
93-
mp_raise_ValueError(MP_ERROR_TEXT("parameter error"));
94-
#endif
9576
}
9677

9778
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) {
10687
mp_raise_ValueError(MP_ERROR_TEXT("value out of range"));
10788
}
10889

109-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
11090
check_esp_err(dac_oneshot_output_voltage(self->dac_oneshot_handle, value));
11191
return mp_const_none;
112-
#else
113-
esp_err_t err = dac_output_voltage(self->dac_id, value);
114-
if (err == ESP_OK) {
115-
return mp_const_none;
116-
}
117-
mp_raise_ValueError(MP_ERROR_TEXT("parameter error"));
118-
#endif
11992
}
12093
MP_DEFINE_CONST_FUN_OBJ_2(mdac_write_obj, mdac_write);
12194

ports/esp32/machine_pwm.c

-43
Original file line numberDiff line numberDiff line change
@@ -211,39 +211,6 @@ static void configure_channel(machine_pwm_obj_t *self) {
211211
}
212212
}
213213

214-
// Temporary workaround for ledc_find_suitable_duty_resolution function only being added in IDF V5.2
215-
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
216-
static uint32_t ledc_find_suitable_duty_resolution(uint32_t src_clk_freq, uint32_t timer_freq) {
217-
// This implementation is based on the one used in Micropython v1.23
218-
219-
// Find the highest bit resolution for the requested frequency
220-
unsigned int freq = src_clk_freq;
221-
222-
int divider = (freq + timer_freq / 2) / timer_freq; // rounded
223-
if (divider == 0) {
224-
divider = 1;
225-
}
226-
float f = (float)freq / divider; // actual frequency
227-
if (f <= 1.0) {
228-
f = 1.0;
229-
}
230-
freq = (unsigned int)roundf((float)freq / f);
231-
232-
unsigned int res = 0;
233-
for (; freq > 1; freq >>= 1) {
234-
++res;
235-
}
236-
if (res == 0) {
237-
res = 1;
238-
} else if (res > HIGHEST_PWM_RES) {
239-
// Limit resolution to HIGHEST_PWM_RES to match units of our duty
240-
res = HIGHEST_PWM_RES;
241-
}
242-
243-
return res;
244-
}
245-
#endif
246-
247214
static void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_config_t *timer) {
248215
esp_err_t err;
249216
if (freq != timer->freq_hz) {
@@ -265,20 +232,10 @@ static void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf
265232
}
266233
#endif
267234
uint32_t src_clk_freq = 0;
268-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
269235
err = esp_clk_tree_src_get_freq_hz(timer->clk_cfg, ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &src_clk_freq);
270236
if (err != ESP_OK) {
271237
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("unable to query source clock frequency %d"), (int)timer->clk_cfg);
272238
}
273-
#else
274-
// Simplified fallback logic for IDF V5.0.x, for targets with APB only.
275-
src_clk_freq = APB_CLK_FREQ; // 80 MHz
276-
#if SOC_LEDC_SUPPORT_REF_TICK
277-
if (timer->clk_cfg == LEDC_USE_REF_TICK) {
278-
src_clk_freq = REF_CLK_FREQ; // 1 MHz
279-
}
280-
#endif // SOC_LEDC_SUPPORT_REF_TICK
281-
#endif // ESP_IDF_VERSION
282239

283240
timer->duty_resolution = ledc_find_suitable_duty_resolution(src_clk_freq, timer->freq_hz);
284241

ports/esp32/machine_uart.c

-4
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,7 @@ static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
399399
}
400400
self->flowcontrol = args[ARG_flow].u_int;
401401
}
402-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
403402
uint8_t uart_fifo_len = UART_HW_FIFO_LEN(self->uart_num);
404-
#else
405-
uint8_t uart_fifo_len = UART_FIFO_LEN;
406-
#endif
407403
check_esp_err(uart_set_hw_flow_ctrl(self->uart_num, self->flowcontrol, uart_fifo_len - uart_fifo_len / 4));
408404
}
409405

ports/esp32/main_esp32/idf_component.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
dependencies:
33
espressif/mdns: "~1.1.0"
44
idf:
5-
version: ">=5.0.4"
5+
version: ">=5.2.0"

ports/esp32/main_esp32c3/idf_component.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
dependencies:
33
espressif/mdns: "~1.1.0"
44
idf:
5-
version: ">=5.0.4"
5+
version: ">=5.2.0"

ports/esp32/main_esp32c6/idf_component.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
dependencies:
33
espressif/mdns: "~1.1.0"
44
idf:
5-
version: ">=5.1.0"
5+
version: ">=5.2.0"

ports/esp32/main_esp32s2/idf_component.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ dependencies:
33
espressif/mdns: "~1.1.0"
44
espressif/esp_tinyusb: "~1.0.0"
55
idf:
6-
version: ">=5.0.4"
6+
version: ">=5.2.0"

ports/esp32/main_esp32s3/idf_component.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ dependencies:
33
espressif/mdns: "~1.1.0"
44
espressif/esp_tinyusb: "~1.0.0"
55
idf:
6-
version: ">=5.0.4"
6+
version: ">=5.2.0"

ports/esp32/modesp32.c

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ static mp_obj_t esp32_wake_on_touch(const mp_obj_t wake) {
5353
if (machine_rtc_config.ext0_pin != -1) {
5454
mp_raise_ValueError(MP_ERROR_TEXT("no resources"));
5555
}
56-
// mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("touchpad wakeup not available for this version of ESP-IDF"));
5756

5857
machine_rtc_config.wake_on_touch = mp_obj_is_true(wake);
5958
return mp_const_none;

ports/esp32/modmachine.c

+5-18
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,11 @@ static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
110110
mp_raise_ValueError(MP_ERROR_TEXT("frequency must be 20MHz, 40MHz, 80Mhz, 160MHz or 240MHz"));
111111
#endif
112112
}
113-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
114-
esp_pm_config_t pm;
115-
#else
116-
#if CONFIG_IDF_TARGET_ESP32
117-
esp_pm_config_esp32_t pm;
118-
#elif CONFIG_IDF_TARGET_ESP32C3
119-
esp_pm_config_esp32c3_t pm;
120-
#elif CONFIG_IDF_TARGET_ESP32C6
121-
esp_pm_config_esp32c6_t pm;
122-
#elif CONFIG_IDF_TARGET_ESP32S2
123-
esp_pm_config_esp32s2_t pm;
124-
#elif CONFIG_IDF_TARGET_ESP32S3
125-
esp_pm_config_esp32s3_t pm;
126-
#endif
127-
#endif
128-
pm.max_freq_mhz = freq;
129-
pm.min_freq_mhz = freq;
130-
pm.light_sleep_enable = false;
113+
esp_pm_config_t pm = {
114+
.max_freq_mhz = freq,
115+
.min_freq_mhz = freq,
116+
.light_sleep_enable = false,
117+
};
131118
esp_err_t ret = esp_pm_configure(&pm);
132119
if (ret != ESP_OK) {
133120
mp_raise_ValueError(NULL);

ports/esp32/modnetwork_globals.h

-6
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,9 @@
3333
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_WPA3_PSK), MP_ROM_INT(WIFI_AUTH_WPA2_WPA3_PSK) },
3434
{ MP_ROM_QSTR(MP_QSTR_AUTH_WAPI_PSK), MP_ROM_INT(WIFI_AUTH_WAPI_PSK) },
3535
{ MP_ROM_QSTR(MP_QSTR_AUTH_OWE), MP_ROM_INT(WIFI_AUTH_OWE) },
36-
#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)
3736
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA3_ENT_192), MP_ROM_INT(WIFI_AUTH_WPA3_ENT_192) },
38-
#endif
39-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
4037
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA3_EXT_PSK), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK) },
4138
{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA3_EXT_PSK_MIXED_MODE), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE) },
42-
#endif
4339
{ MP_ROM_QSTR(MP_QSTR_AUTH_MAX), MP_ROM_INT(WIFI_AUTH_MAX) },
4440
#endif
4541

@@ -75,11 +71,9 @@
7571
{ MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(STAT_GOT_IP)},
7672
// Errors from the ESP-IDF
7773
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND)},
78-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
7974
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND_IN_RSSI_THRESHOLD), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD)},
8075
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD)},
8176
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND_W_COMPATIBLE_SECURITY), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND_W_COMPATIBLE_SECURITY)},
82-
#endif
8377
{ MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(WIFI_REASON_AUTH_FAIL)},
8478
{ MP_ROM_QSTR(MP_QSTR_STAT_BEACON_TIMEOUT), MP_ROM_INT(WIFI_REASON_BEACON_TIMEOUT)},
8579
#if !MICROPY_PREVIEW_VERSION_2

ports/esp32/mpthreadport.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define MP_THREAD_DEFAULT_STACK_SIZE (MP_THREAD_MIN_STACK_SIZE + MICROPY_STACK_CHECK_MARGIN)
4242
#define MP_THREAD_PRIORITY (ESP_TASK_PRIO_MIN + 1)
4343

44-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0) && !CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
44+
#if !CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
4545
#define FREERTOS_TASK_DELETE_HOOK vTaskPreDeletionHook
4646
#else
4747
#define FREERTOS_TASK_DELETE_HOOK vPortCleanUpTCB

ports/esp32/network_lan.c

-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
#include "py/runtime.h"
3131
#include "py/mphal.h"
3232

33-
#include "esp_idf_version.h"
34-
3533
#if MICROPY_PY_NETWORK_LAN
3634

3735
#include "esp_eth.h"

ports/esp32/network_wlan.c

+1-11
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ static void network_wlan_wifi_event_handler(void *event_handler_arg, esp_event_b
113113
// AP may not exist, or it may have momentarily dropped out; try to reconnect.
114114
message = "no AP found";
115115
break;
116-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
117116
case WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD:
118117
// No AP with RSSI within given threshold exists, or it may have momentarily dropped out; try to reconnect.
119118
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
126125
// No AP with compatible security exists, or it may have momentarily dropped out; try to reconnect.
127126
message = "no AP with compatible security found";
128127
break;
129-
#endif
130128
case WIFI_REASON_AUTH_FAIL:
131129
// Password may be wrong, or it just failed to connect; try to reconnect.
132130
message = "authentication failed";
@@ -367,14 +365,12 @@ static mp_obj_t network_wlan_status(size_t n_args, const mp_obj_t *args) {
367365
return MP_OBJ_NEW_SMALL_INT(STAT_GOT_IP);
368366
} else if (wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND) {
369367
return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_NO_AP_FOUND);
370-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
371368
} else if (wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD) {
372369
return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD);
373370
} else if (wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD) {
374371
return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD);
375372
} else if (wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND_W_COMPATIBLE_SECURITY) {
376373
return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_NO_AP_FOUND_W_COMPATIBLE_SECURITY);
377-
#endif
378374
} else if ((wifi_sta_disconn_reason == WIFI_REASON_AUTH_FAIL) || (wifi_sta_disconn_reason == WIFI_REASON_CONNECTION_FAIL)) {
379375
// wrong password
380376
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[] = {
761757
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA2_WPA3), MP_ROM_INT(WIFI_AUTH_WPA2_WPA3_PSK) },
762758
{ MP_ROM_QSTR(MP_QSTR_SEC_WAPI), MP_ROM_INT(WIFI_AUTH_WAPI_PSK) },
763759
{ MP_ROM_QSTR(MP_QSTR_SEC_OWE), MP_ROM_INT(WIFI_AUTH_OWE) },
764-
#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)
765760
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA3_ENT_192), MP_ROM_INT(WIFI_AUTH_WPA3_ENT_192) },
766-
#endif
767-
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
768761
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA3_EXT_PSK), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK) },
769762
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA3_EXT_PSK_MIXED_MODE), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE) },
770-
#endif
771763
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
772764
{ MP_ROM_QSTR(MP_QSTR_SEC_DPP), MP_ROM_INT(WIFI_AUTH_DPP) },
773765
#endif
@@ -782,10 +774,8 @@ static MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);
782774
_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");
783775
#elif ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
784776
_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");
785-
#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)
786-
_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");
787777
#else
788-
_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");
778+
#error "Error in macro logic, all supported versions should be covered."
789779
#endif
790780

791781
MP_DEFINE_CONST_OBJ_TYPE(

ports/esp32/uart.c

-4
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ static void uart_irq_handler(void *arg);
5151

5252
void uart_stdout_init(void) {
5353
uart_hal_context_t repl_hal = REPL_HAL_DEFN();
54-
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
55-
uart_sclk_t sclk;
56-
#else
5754
soc_module_clk_t sclk;
58-
#endif
5955
uint32_t sclk_freq;
6056

6157
uart_hal_get_sclk(&repl_hal, &sclk); // To restore SCLK after uart_hal_init() resets it

0 commit comments

Comments
 (0)