Skip to content

Commit d191d88

Browse files
committed
esp32: Add support to build with ESP-IDF v4.1.1.
ESP-IDF v4.0.2 is still supported. Signed-off-by: Damien George <[email protected]>
1 parent e017f27 commit d191d88

File tree

6 files changed

+48
-19
lines changed

6 files changed

+48
-19
lines changed

ports/esp32/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ 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 v4.0.2, although other IDF v4 versions may also
32-
work.
31+
Currently MicroPython supports v4.0.2 and v4.1.1,
32+
although other IDF v4 versions may also work.
3333

3434
To install the ESP-IDF the full instructions can be found at the
3535
[Espressif Getting Started guide](https://docs.espressif.com/projects/esp-idf/en/v4.0.2/get-started/index.html#installation-step-by-step).
@@ -50,6 +50,7 @@ To check out a copy of the IDF use git clone:
5050
$ git clone -b v4.0.2 --recursive https://github.com/espressif/esp-idf.git
5151
```
5252

53+
You can replace `v4.0.2` with `v4.1.1` or any other supported version.
5354
(You don't need a full recursive clone; see the `ci_esp32_setup` function in
5455
`tools/ci.sh` in this repository for more detailed set-up commands.)
5556

ports/esp32/machine_uart.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@
3636
#include "py/mperrno.h"
3737
#include "modmachine.h"
3838

39+
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 1, 0)
40+
#define UART_INV_TX UART_INVERSE_TXD
41+
#define UART_INV_RX UART_INVERSE_RXD
42+
#define UART_INV_RTS UART_INVERSE_RTS
43+
#define UART_INV_CTS UART_INVERSE_CTS
44+
#else
45+
#define UART_INV_TX UART_SIGNAL_TXD_INV
46+
#define UART_INV_RX UART_SIGNAL_RXD_INV
47+
#define UART_INV_RTS UART_SIGNAL_RTS_INV
48+
#define UART_INV_CTS UART_SIGNAL_CTS_INV
49+
#endif
50+
51+
#define UART_INV_MASK (UART_INV_TX | UART_INV_RX | UART_INV_RTS | UART_INV_CTS)
52+
3953
typedef struct _machine_uart_obj_t {
4054
mp_obj_base_t base;
4155
uart_port_t uart_num;
@@ -68,28 +82,28 @@ STATIC void machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_pri
6882
if (self->invert) {
6983
mp_printf(print, ", invert=");
7084
uint32_t invert_mask = self->invert;
71-
if (invert_mask & UART_INVERSE_TXD) {
85+
if (invert_mask & UART_INV_TX) {
7286
mp_printf(print, "INV_TX");
73-
invert_mask &= ~UART_INVERSE_TXD;
87+
invert_mask &= ~UART_INV_TX;
7488
if (invert_mask) {
7589
mp_printf(print, "|");
7690
}
7791
}
78-
if (invert_mask & UART_INVERSE_RXD) {
92+
if (invert_mask & UART_INV_RX) {
7993
mp_printf(print, "INV_RX");
80-
invert_mask &= ~UART_INVERSE_RXD;
94+
invert_mask &= ~UART_INV_RX;
8195
if (invert_mask) {
8296
mp_printf(print, "|");
8397
}
8498
}
85-
if (invert_mask & UART_INVERSE_RTS) {
99+
if (invert_mask & UART_INV_RTS) {
86100
mp_printf(print, "INV_RTS");
87-
invert_mask &= ~UART_INVERSE_RTS;
101+
invert_mask &= ~UART_INV_RTS;
88102
if (invert_mask) {
89103
mp_printf(print, "|");
90104
}
91105
}
92-
if (invert_mask & UART_INVERSE_CTS) {
106+
if (invert_mask & UART_INV_CTS) {
93107
mp_printf(print, "INV_CTS");
94108
}
95109
}
@@ -238,7 +252,7 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
238252
}
239253

240254
// set line inversion
241-
if (args[ARG_invert].u_int & ~UART_LINE_INV_MASK) {
255+
if (args[ARG_invert].u_int & ~UART_INV_MASK) {
242256
mp_raise_ValueError(MP_ERROR_TEXT("invalid inversion mask"));
243257
}
244258
self->invert = args[ARG_invert].u_int;
@@ -380,10 +394,10 @@ STATIC const mp_rom_map_elem_t machine_uart_locals_dict_table[] = {
380394
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
381395
{ MP_ROM_QSTR(MP_QSTR_sendbreak), MP_ROM_PTR(&machine_uart_sendbreak_obj) },
382396

383-
{ MP_ROM_QSTR(MP_QSTR_INV_TX), MP_ROM_INT(UART_INVERSE_TXD) },
384-
{ MP_ROM_QSTR(MP_QSTR_INV_RX), MP_ROM_INT(UART_INVERSE_RXD) },
385-
{ MP_ROM_QSTR(MP_QSTR_INV_RTS), MP_ROM_INT(UART_INVERSE_RTS) },
386-
{ MP_ROM_QSTR(MP_QSTR_INV_CTS), MP_ROM_INT(UART_INVERSE_CTS) },
397+
{ MP_ROM_QSTR(MP_QSTR_INV_TX), MP_ROM_INT(UART_INV_TX) },
398+
{ MP_ROM_QSTR(MP_QSTR_INV_RX), MP_ROM_INT(UART_INV_RX) },
399+
{ MP_ROM_QSTR(MP_QSTR_INV_RTS), MP_ROM_INT(UART_INV_RTS) },
400+
{ MP_ROM_QSTR(MP_QSTR_INV_CTS), MP_ROM_INT(UART_INV_CTS) },
387401
};
388402

389403
STATIC MP_DEFINE_CONST_DICT(machine_uart_locals_dict, machine_uart_locals_dict_table);

ports/esp32/main/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ set(IDF_COMPONENTS
104104
xtensa
105105
)
106106

107+
if(IDF_VERSION_MINOR GREATER_EQUAL 1)
108+
list(APPEND IDF_COMPONENTS esp_netif)
109+
endif()
110+
107111
# Register the main IDF component.
108112
idf_component_register(
109113
SRCS

ports/esp32/modnetwork.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "esp_wifi.h"
4646
#include "esp_log.h"
4747
#include "lwip/dns.h"
48-
#include "tcpip_adapter.h"
4948
#include "mdns.h"
5049

5150
#if !MICROPY_ESP_IDF_4
@@ -55,6 +54,12 @@
5554

5655
#include "modnetwork.h"
5756

57+
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 1, 0)
58+
#define DNS_MAIN TCPIP_ADAPTER_DNS_MAIN
59+
#else
60+
#define DNS_MAIN ESP_NETIF_DNS_MAIN
61+
#endif
62+
5863
#define MODNETWORK_INCLUDE_CONSTANTS (1)
5964

6065
NORETURN void _esp_exceptions(esp_err_t e) {
@@ -491,7 +496,7 @@ STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
491496
tcpip_adapter_ip_info_t info;
492497
tcpip_adapter_dns_info_t dns_info;
493498
tcpip_adapter_get_ip_info(self->if_id, &info);
494-
tcpip_adapter_get_dns_info(self->if_id, TCPIP_ADAPTER_DNS_MAIN, &dns_info);
499+
tcpip_adapter_get_dns_info(self->if_id, DNS_MAIN, &dns_info);
495500
if (n_args == 1) {
496501
// get
497502
mp_obj_t tuple[4] = {
@@ -526,14 +531,14 @@ STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
526531
_esp_exceptions(e);
527532
}
528533
ESP_EXCEPTIONS(tcpip_adapter_set_ip_info(self->if_id, &info));
529-
ESP_EXCEPTIONS(tcpip_adapter_set_dns_info(self->if_id, TCPIP_ADAPTER_DNS_MAIN, &dns_info));
534+
ESP_EXCEPTIONS(tcpip_adapter_set_dns_info(self->if_id, DNS_MAIN, &dns_info));
530535
} else if (self->if_id == WIFI_IF_AP) {
531536
esp_err_t e = tcpip_adapter_dhcps_stop(WIFI_IF_AP);
532537
if (e != ESP_OK && e != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED) {
533538
_esp_exceptions(e);
534539
}
535540
ESP_EXCEPTIONS(tcpip_adapter_set_ip_info(WIFI_IF_AP, &info));
536-
ESP_EXCEPTIONS(tcpip_adapter_set_dns_info(WIFI_IF_AP, TCPIP_ADAPTER_DNS_MAIN, &dns_info));
541+
ESP_EXCEPTIONS(tcpip_adapter_set_dns_info(WIFI_IF_AP, DNS_MAIN, &dns_info));
537542
ESP_EXCEPTIONS(tcpip_adapter_dhcps_start(WIFI_IF_AP));
538543
}
539544
} else {

ports/esp32/modsocket.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#include "py/stream.h"
4747
#include "py/mperrno.h"
4848
#include "lib/netutils/netutils.h"
49-
#include "tcpip_adapter.h"
5049
#include "mdns.h"
5150
#include "modnetwork.h"
5251

@@ -181,7 +180,12 @@ static int _socket_getaddrinfo3(const char *nodename, const char *servname,
181180
memcpy(nodename_no_local, nodename, nodename_len - local_len);
182181
nodename_no_local[nodename_len - local_len] = '\0';
183182

183+
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 1, 0)
184184
struct ip4_addr addr = {0};
185+
#else
186+
esp_ip4_addr_t addr = {0};
187+
#endif
188+
185189
esp_err_t err = mdns_query_a(nodename_no_local, MDNS_QUERY_TIMEOUT_MS, &addr);
186190
if (err != ESP_OK) {
187191
if (err == ESP_ERR_NOT_FOUND) {

ports/esp32/uart.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <stdio.h>
3030

3131
#include "driver/uart.h"
32+
#include "soc/uart_periph.h"
3233

3334
#include "py/runtime.h"
3435
#include "py/mphal.h"

0 commit comments

Comments
 (0)