esp32: Add support to build with ESP-IDF v4.1.1.
ESP-IDF v4.0.2 is still supported. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
e017f276f7
commit
d191d88cab
@ -28,8 +28,8 @@ manage the ESP32 microcontroller, as well as a way to manage the required
|
|||||||
build environment and toolchains needed to build the firmware.
|
build environment and toolchains needed to build the firmware.
|
||||||
|
|
||||||
The ESP-IDF changes quickly and MicroPython only supports certain versions.
|
The ESP-IDF changes quickly and MicroPython only supports certain versions.
|
||||||
Currently MicroPython supports v4.0.2, although other IDF v4 versions may also
|
Currently MicroPython supports v4.0.2 and v4.1.1,
|
||||||
work.
|
although other IDF v4 versions may also work.
|
||||||
|
|
||||||
To install the ESP-IDF the full instructions can be found at the
|
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/v4.0.2/get-started/index.html#installation-step-by-step).
|
[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:
|
|||||||
$ git clone -b v4.0.2 --recursive https://github.com/espressif/esp-idf.git
|
$ git clone -b v4.0.2 --recursive https://github.com/espressif/esp-idf.git
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can replace `v4.0.2` with `v4.1.1` or any other supported version.
|
||||||
(You don't need a full recursive clone; see the `ci_esp32_setup` function in
|
(You don't need a full recursive clone; see the `ci_esp32_setup` function in
|
||||||
`tools/ci.sh` in this repository for more detailed set-up commands.)
|
`tools/ci.sh` in this repository for more detailed set-up commands.)
|
||||||
|
|
||||||
|
@ -36,6 +36,20 @@
|
|||||||
#include "py/mperrno.h"
|
#include "py/mperrno.h"
|
||||||
#include "modmachine.h"
|
#include "modmachine.h"
|
||||||
|
|
||||||
|
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 1, 0)
|
||||||
|
#define UART_INV_TX UART_INVERSE_TXD
|
||||||
|
#define UART_INV_RX UART_INVERSE_RXD
|
||||||
|
#define UART_INV_RTS UART_INVERSE_RTS
|
||||||
|
#define UART_INV_CTS UART_INVERSE_CTS
|
||||||
|
#else
|
||||||
|
#define UART_INV_TX UART_SIGNAL_TXD_INV
|
||||||
|
#define UART_INV_RX UART_SIGNAL_RXD_INV
|
||||||
|
#define UART_INV_RTS UART_SIGNAL_RTS_INV
|
||||||
|
#define UART_INV_CTS UART_SIGNAL_CTS_INV
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define UART_INV_MASK (UART_INV_TX | UART_INV_RX | UART_INV_RTS | UART_INV_CTS)
|
||||||
|
|
||||||
typedef struct _machine_uart_obj_t {
|
typedef struct _machine_uart_obj_t {
|
||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
uart_port_t uart_num;
|
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
|
|||||||
if (self->invert) {
|
if (self->invert) {
|
||||||
mp_printf(print, ", invert=");
|
mp_printf(print, ", invert=");
|
||||||
uint32_t invert_mask = self->invert;
|
uint32_t invert_mask = self->invert;
|
||||||
if (invert_mask & UART_INVERSE_TXD) {
|
if (invert_mask & UART_INV_TX) {
|
||||||
mp_printf(print, "INV_TX");
|
mp_printf(print, "INV_TX");
|
||||||
invert_mask &= ~UART_INVERSE_TXD;
|
invert_mask &= ~UART_INV_TX;
|
||||||
if (invert_mask) {
|
if (invert_mask) {
|
||||||
mp_printf(print, "|");
|
mp_printf(print, "|");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (invert_mask & UART_INVERSE_RXD) {
|
if (invert_mask & UART_INV_RX) {
|
||||||
mp_printf(print, "INV_RX");
|
mp_printf(print, "INV_RX");
|
||||||
invert_mask &= ~UART_INVERSE_RXD;
|
invert_mask &= ~UART_INV_RX;
|
||||||
if (invert_mask) {
|
if (invert_mask) {
|
||||||
mp_printf(print, "|");
|
mp_printf(print, "|");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (invert_mask & UART_INVERSE_RTS) {
|
if (invert_mask & UART_INV_RTS) {
|
||||||
mp_printf(print, "INV_RTS");
|
mp_printf(print, "INV_RTS");
|
||||||
invert_mask &= ~UART_INVERSE_RTS;
|
invert_mask &= ~UART_INV_RTS;
|
||||||
if (invert_mask) {
|
if (invert_mask) {
|
||||||
mp_printf(print, "|");
|
mp_printf(print, "|");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (invert_mask & UART_INVERSE_CTS) {
|
if (invert_mask & UART_INV_CTS) {
|
||||||
mp_printf(print, "INV_CTS");
|
mp_printf(print, "INV_CTS");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,7 +252,7 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set line inversion
|
// set line inversion
|
||||||
if (args[ARG_invert].u_int & ~UART_LINE_INV_MASK) {
|
if (args[ARG_invert].u_int & ~UART_INV_MASK) {
|
||||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid inversion mask"));
|
mp_raise_ValueError(MP_ERROR_TEXT("invalid inversion mask"));
|
||||||
}
|
}
|
||||||
self->invert = args[ARG_invert].u_int;
|
self->invert = args[ARG_invert].u_int;
|
||||||
@ -380,10 +394,10 @@ STATIC const mp_rom_map_elem_t machine_uart_locals_dict_table[] = {
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_sendbreak), MP_ROM_PTR(&machine_uart_sendbreak_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_sendbreak), MP_ROM_PTR(&machine_uart_sendbreak_obj) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_INV_TX), MP_ROM_INT(UART_INVERSE_TXD) },
|
{ MP_ROM_QSTR(MP_QSTR_INV_TX), MP_ROM_INT(UART_INV_TX) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_INV_RX), MP_ROM_INT(UART_INVERSE_RXD) },
|
{ MP_ROM_QSTR(MP_QSTR_INV_RX), MP_ROM_INT(UART_INV_RX) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_INV_RTS), MP_ROM_INT(UART_INVERSE_RTS) },
|
{ MP_ROM_QSTR(MP_QSTR_INV_RTS), MP_ROM_INT(UART_INV_RTS) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_INV_CTS), MP_ROM_INT(UART_INVERSE_CTS) },
|
{ MP_ROM_QSTR(MP_QSTR_INV_CTS), MP_ROM_INT(UART_INV_CTS) },
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC MP_DEFINE_CONST_DICT(machine_uart_locals_dict, machine_uart_locals_dict_table);
|
STATIC MP_DEFINE_CONST_DICT(machine_uart_locals_dict, machine_uart_locals_dict_table);
|
||||||
|
@ -104,6 +104,10 @@ set(IDF_COMPONENTS
|
|||||||
xtensa
|
xtensa
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(IDF_VERSION_MINOR GREATER_EQUAL 1)
|
||||||
|
list(APPEND IDF_COMPONENTS esp_netif)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Register the main IDF component.
|
# Register the main IDF component.
|
||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS
|
SRCS
|
||||||
|
@ -45,7 +45,6 @@
|
|||||||
#include "esp_wifi.h"
|
#include "esp_wifi.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "lwip/dns.h"
|
#include "lwip/dns.h"
|
||||||
#include "tcpip_adapter.h"
|
|
||||||
#include "mdns.h"
|
#include "mdns.h"
|
||||||
|
|
||||||
#if !MICROPY_ESP_IDF_4
|
#if !MICROPY_ESP_IDF_4
|
||||||
@ -55,6 +54,12 @@
|
|||||||
|
|
||||||
#include "modnetwork.h"
|
#include "modnetwork.h"
|
||||||
|
|
||||||
|
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 1, 0)
|
||||||
|
#define DNS_MAIN TCPIP_ADAPTER_DNS_MAIN
|
||||||
|
#else
|
||||||
|
#define DNS_MAIN ESP_NETIF_DNS_MAIN
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MODNETWORK_INCLUDE_CONSTANTS (1)
|
#define MODNETWORK_INCLUDE_CONSTANTS (1)
|
||||||
|
|
||||||
NORETURN void _esp_exceptions(esp_err_t e) {
|
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) {
|
|||||||
tcpip_adapter_ip_info_t info;
|
tcpip_adapter_ip_info_t info;
|
||||||
tcpip_adapter_dns_info_t dns_info;
|
tcpip_adapter_dns_info_t dns_info;
|
||||||
tcpip_adapter_get_ip_info(self->if_id, &info);
|
tcpip_adapter_get_ip_info(self->if_id, &info);
|
||||||
tcpip_adapter_get_dns_info(self->if_id, TCPIP_ADAPTER_DNS_MAIN, &dns_info);
|
tcpip_adapter_get_dns_info(self->if_id, DNS_MAIN, &dns_info);
|
||||||
if (n_args == 1) {
|
if (n_args == 1) {
|
||||||
// get
|
// get
|
||||||
mp_obj_t tuple[4] = {
|
mp_obj_t tuple[4] = {
|
||||||
@ -526,14 +531,14 @@ STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
|
|||||||
_esp_exceptions(e);
|
_esp_exceptions(e);
|
||||||
}
|
}
|
||||||
ESP_EXCEPTIONS(tcpip_adapter_set_ip_info(self->if_id, &info));
|
ESP_EXCEPTIONS(tcpip_adapter_set_ip_info(self->if_id, &info));
|
||||||
ESP_EXCEPTIONS(tcpip_adapter_set_dns_info(self->if_id, TCPIP_ADAPTER_DNS_MAIN, &dns_info));
|
ESP_EXCEPTIONS(tcpip_adapter_set_dns_info(self->if_id, DNS_MAIN, &dns_info));
|
||||||
} else if (self->if_id == WIFI_IF_AP) {
|
} else if (self->if_id == WIFI_IF_AP) {
|
||||||
esp_err_t e = tcpip_adapter_dhcps_stop(WIFI_IF_AP);
|
esp_err_t e = tcpip_adapter_dhcps_stop(WIFI_IF_AP);
|
||||||
if (e != ESP_OK && e != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED) {
|
if (e != ESP_OK && e != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED) {
|
||||||
_esp_exceptions(e);
|
_esp_exceptions(e);
|
||||||
}
|
}
|
||||||
ESP_EXCEPTIONS(tcpip_adapter_set_ip_info(WIFI_IF_AP, &info));
|
ESP_EXCEPTIONS(tcpip_adapter_set_ip_info(WIFI_IF_AP, &info));
|
||||||
ESP_EXCEPTIONS(tcpip_adapter_set_dns_info(WIFI_IF_AP, TCPIP_ADAPTER_DNS_MAIN, &dns_info));
|
ESP_EXCEPTIONS(tcpip_adapter_set_dns_info(WIFI_IF_AP, DNS_MAIN, &dns_info));
|
||||||
ESP_EXCEPTIONS(tcpip_adapter_dhcps_start(WIFI_IF_AP));
|
ESP_EXCEPTIONS(tcpip_adapter_dhcps_start(WIFI_IF_AP));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
#include "py/stream.h"
|
#include "py/stream.h"
|
||||||
#include "py/mperrno.h"
|
#include "py/mperrno.h"
|
||||||
#include "lib/netutils/netutils.h"
|
#include "lib/netutils/netutils.h"
|
||||||
#include "tcpip_adapter.h"
|
|
||||||
#include "mdns.h"
|
#include "mdns.h"
|
||||||
#include "modnetwork.h"
|
#include "modnetwork.h"
|
||||||
|
|
||||||
@ -181,7 +180,12 @@ static int _socket_getaddrinfo3(const char *nodename, const char *servname,
|
|||||||
memcpy(nodename_no_local, nodename, nodename_len - local_len);
|
memcpy(nodename_no_local, nodename, nodename_len - local_len);
|
||||||
nodename_no_local[nodename_len - local_len] = '\0';
|
nodename_no_local[nodename_len - local_len] = '\0';
|
||||||
|
|
||||||
|
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 1, 0)
|
||||||
struct ip4_addr addr = {0};
|
struct ip4_addr addr = {0};
|
||||||
|
#else
|
||||||
|
esp_ip4_addr_t addr = {0};
|
||||||
|
#endif
|
||||||
|
|
||||||
esp_err_t err = mdns_query_a(nodename_no_local, MDNS_QUERY_TIMEOUT_MS, &addr);
|
esp_err_t err = mdns_query_a(nodename_no_local, MDNS_QUERY_TIMEOUT_MS, &addr);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
if (err == ESP_ERR_NOT_FOUND) {
|
if (err == ESP_ERR_NOT_FOUND) {
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#include "soc/uart_periph.h"
|
||||||
|
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user