Browse Source

esp32: Add support for IDF version v5.2.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
pull/13775/head
Daniël van de Giessen 8 months ago
committed by Damien George
parent
commit
d6176c1f5e
  1. 2
      ports/esp32/README.md
  2. 7
      ports/esp32/machine_uart.c
  3. 9
      ports/esp32/modnetwork_globals.h
  4. 14
      ports/esp32/mpthreadport.c
  5. 4
      ports/esp32/network_common.c
  6. 22
      ports/esp32/network_wlan.c
  7. 3
      ports/esp32/uart.c

2
ports/esp32/README.md

@ -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.
Currently MicroPython supports v5.0.4, v5.0.5, v5.1.2, v5.2.0.
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).

7
ports/esp32/machine_uart.c

@ -306,7 +306,12 @@ static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
}
self->flowcontrol = args[ARG_flow].u_int;
}
check_esp_err(uart_set_hw_flow_ctrl(self->uart_num, self->flowcontrol, UART_FIFO_LEN - UART_FIFO_LEN / 4));
#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));
}
static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {

9
ports/esp32/modnetwork_globals.h

@ -34,6 +34,10 @@
#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
@ -69,6 +73,11 @@
{ 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)},
{ MP_ROM_QSTR(MP_QSTR_STAT_ASSOC_FAIL), MP_ROM_INT(WIFI_REASON_ASSOC_FAIL)},

14
ports/esp32/mpthreadport.c

@ -41,6 +41,12 @@
#define MP_THREAD_DEFAULT_STACK_SIZE (MP_THREAD_MIN_STACK_SIZE + 1024)
#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
#define FREERTOS_TASK_DELETE_HOOK vTaskPreDeletionHook
#else
#define FREERTOS_TASK_DELETE_HOOK vPortCleanUpTCB
#endif
// this structure forms a linked list, one node per active thread
typedef struct _mp_thread_t {
TaskHandle_t id; // system id of thread
@ -70,7 +76,7 @@ void mp_thread_init(void *stack, uint32_t stack_len) {
// memory barrier to ensure above data is committed
__sync_synchronize();
// vPortCleanUpTCB needs the thread ready after thread_mutex is ready
// FREERTOS_TASK_DELETE_HOOK needs the thread ready after thread_mutex is ready
thread = &thread_entry0;
}
@ -179,7 +185,7 @@ void mp_thread_finish(void) {
// This is called from the FreeRTOS idle task and is not within Python context,
// so MP_STATE_THREAD is not valid and it does not have the GIL.
void vPortCleanUpTCB(void *tcb) {
void FREERTOS_TASK_DELETE_HOOK(void *tcb) {
if (thread == NULL) {
// threading not yet initialised
return;
@ -235,7 +241,7 @@ void mp_thread_deinit(void) {
// No tasks left to delete
break;
} else {
// Call FreeRTOS to delete the task (it will call vPortCleanUpTCB)
// Call FreeRTOS to delete the task (it will call FREERTOS_TASK_DELETE_HOOK)
vTaskDelete(id);
}
}
@ -243,7 +249,7 @@ void mp_thread_deinit(void) {
#else
void vPortCleanUpTCB(void *tcb) {
void FREERTOS_TASK_DELETE_HOOK(void *tcb) {
}
#endif // MICROPY_PY_THREAD

4
ports/esp32/network_common.c

@ -168,7 +168,9 @@ static mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_phy_mode_obj, 0, 1, esp_phy_mode);
#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)
#if 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");

22
ports/esp32/network_wlan.c

@ -113,6 +113,20 @@ 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";
break;
case WIFI_REASON_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD:
// No AP with authmode within given threshold exists, or it may have momentarily dropped out; try to reconnect.
message = "no AP with authmode within threshold found";
break;
case WIFI_REASON_NO_AP_FOUND_W_COMPATIBLE_SECURITY:
// 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";
@ -353,6 +367,14 @@ 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);

3
ports/esp32/uart.c

@ -36,6 +36,7 @@
#include <stdio.h>
#include "driver/uart.h" // For uart_get_sclk_freq()
#include "hal/uart_hal.h"
#include "soc/uart_periph.h"
static void uart_irq_handler(void *arg);
@ -50,7 +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, 3, 0)
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
uart_sclk_t sclk;
#else
soc_module_clk_t sclk;

Loading…
Cancel
Save