Skip to content

Commit

Permalink
ESP32: Update to ESP-IDF 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rojer committed Dec 27, 2020
1 parent 6b279b3 commit 8fd9925
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 102 deletions.
12 changes: 7 additions & 5 deletions platforms/esp32/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,16 @@ COMPONENT_DIRS = $(APP_PATH)/components \
$(MGOS_PATH)/third_party \
/opt
# Explicitly specify SDK components to build.
SDK_COMPONENTS = app_trace app_update bootloader bootloader_support cxx driver efuse espcoredump \
esp_adc_cal esp_event esp32 esp_ringbuf esptool_py ethernet expat freertos heap \
log lwip micro-ecc newlib nvs_flash partition_table pthread soc \
spi_flash smartconfig_ack tcpip_adapter vfs wpa_supplicant xtensa-debug-module
SDK_COMPONENTS = app_trace app_update bootloader bootloader_support cxx driver efuse esp32 \
esp_common esp_event esp_gdbstub esp_ipc esp_netif \
esp_ringbuf esp_rom esp_system esp_timer espcoredump esptool_py \
freertos heap log lwip micro-ecc newlib nvs_flash partition_table \
pthread soc spi_flash vfs xtensa xtensa-debug-module

MGOS_MAIN_COMPONENT ?= mosapp

COMPONENTS = $(SDK_COMPONENTS) $(MGOS_MAIN_COMPONENT) spiffs $(ESP_IDF_EXTRA_COMPONENTS)
# sort used to remove duplicates, we don't really care about order.
COMPONENTS = $(sort $(SDK_COMPONENTS) $(MGOS_MAIN_COMPONENT) $(ESP_IDF_EXTRA_COMPONENTS))

ESPFLASHMODE = qio
ESPFLASHSIZE = 4MB
Expand Down
2 changes: 1 addition & 1 deletion platforms/esp32/sdk.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker.io/mgos/esp32-build:3.3-r6
docker.io/mgos/esp32-build:4.2-r1
51 changes: 22 additions & 29 deletions platforms/esp32/sdkconfig
Original file line number Diff line number Diff line change
@@ -1,52 +1,45 @@
# Overrides applied over defconfig
# Additional changes can be made via ESP_IDF_SDKCONFIG_OPTS

CONFIG_ESPTOOLPY_FLASHSIZE_2MB=
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=n
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
CONFIG_PARTITION_TABLE_SINGLE_APP=
CONFIG_PARTITION_TABLE_SINGLE_APP=n
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="src/partitions_mgos.csv"
CONFIG_PARTITION_TABLE_FILENAME="src/partitions_mgos.csv"
CONFIG_OPTIMIZATION_LEVEL_DEBUG=
CONFIG_OPTIMIZATION_LEVEL_RELEASE=y
CONFIG_COMPILER_OPTIMIZATION_SIZE=y

CONFIG_ESP32_ENABLE_COREDUMP_TO_UART=y
CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=
CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=n
CONFIG_ESP32_ENABLE_COREDUMP=y
CONFIG_ESP32_CORE_DUMP_UART_DELAY=0
CONFIG_ESP32_CORE_DUMP_LOG_LEVEL=1
CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=4096
CONFIG_TASK_WDT_PANIC=y
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096
CONFIG_ESP_TASK_WDT_PANIC=y
CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=0

CONFIG_WIFI_ENABLED=y
CONFIG_SW_COEXIST_ENABLE=
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=4
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=16
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER=
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=16
CONFIG_ESP32_WIFI_NVS_ENABLED=y
CONFIG_ESP32_WIFI_RX_BA_WIN=4

CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y
CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION=
CONFIG_EMAC_TASK_PRIORITY=20
CONFIG_FREERTOS_USE_TRACE_FACILITY=y
CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE=y
CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=
CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=n
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y
CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG=y
CONFIG_TIMER_TASK_STACK_DEPTH=3072
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=
CONFIG_TCPIP_TASK_STACK_SIZE=3072
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=n
CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096

CONFIG_ESP32_XTAL_FREQ_40=
CONFIG_ESP32_XTAL_FREQ_26=
CONFIG_ESP32_XTAL_FREQ_40=n
CONFIG_ESP32_XTAL_FREQ_26=n
CONFIG_ESP32_XTAL_FREQ_AUTO=y
CONFIG_ESP32_XTAL_FREQ=0

CONFIG_FLASHMODE_DIO=
CONFIG_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHMODE_DIO=n
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y

CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=n

# Workaround for https://github.com/espressif/esp-idf/issues/6322
CONFIG_SPI_FLASH_USE_LEGACY_IMPL=y

# Required to be able to update boot loader.
CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED=y
2 changes: 1 addition & 1 deletion platforms/esp32/src/esp32_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <stdlib.h>
#include <string.h>

#include "esp_intr.h"
#include "esp_intr_alloc.h"
#include "sdkconfig.h"

#include "mgos_bitbang.h"
Expand Down
69 changes: 10 additions & 59 deletions platforms/esp32/src/esp32_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
#include <string.h>
#include <unistd.h>

#include "esp32/rom/ets_sys.h"
#include "esp32/rom/spi_flash.h"
#include "esp_attr.h"
#include "esp_debug_helpers.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "esp_log.h"
#include "esp_ota_ops.h"
#include "esp_panic.h"
#include "esp_spi_flash.h"
#include "esp_system.h"
#include "esp_task_wdt.h"
#include "nvs_flash.h"
#include "rom/ets_sys.h"
#include "rom/spi_flash.h"
#include "soc/efuse_reg.h"

#include "common/cs_dbg.h"
Expand All @@ -51,56 +50,6 @@
#include "esp32_updater.h"
#endif

esp_err_t esp32_wifi_ev(system_event_t *event);

void esp32_system_event_handler_default(system_event_t *event) WEAK;
void esp32_system_event_handler_default(system_event_t *event) {
(void) event;
}

esp_err_t event_handler(void *ctx, system_event_t *event) {
switch (event->event_id) {
#ifdef MGOS_HAVE_WIFI
case SYSTEM_EVENT_STA_START:
case SYSTEM_EVENT_STA_STOP:
case SYSTEM_EVENT_STA_GOT_IP:
case SYSTEM_EVENT_STA_CONNECTED:
case SYSTEM_EVENT_STA_DISCONNECTED:
case SYSTEM_EVENT_AP_START:
case SYSTEM_EVENT_AP_STOP:
case SYSTEM_EVENT_AP_STACONNECTED:
case SYSTEM_EVENT_AP_STADISCONNECTED:
case SYSTEM_EVENT_SCAN_DONE:
return esp32_wifi_ev(event);
break;
#endif
#ifdef MGOS_HAVE_ETHERNET
case SYSTEM_EVENT_ETH_START:
case SYSTEM_EVENT_ETH_STOP:
break;
case SYSTEM_EVENT_ETH_CONNECTED: {
mgos_net_dev_event_cb(MGOS_NET_IF_TYPE_ETHERNET, 0,
MGOS_NET_EV_CONNECTED);
break;
}
case SYSTEM_EVENT_ETH_DISCONNECTED: {
mgos_net_dev_event_cb(MGOS_NET_IF_TYPE_ETHERNET, 0,
MGOS_NET_EV_DISCONNECTED);
break;
}
case SYSTEM_EVENT_ETH_GOT_IP: {
mgos_net_dev_event_cb(MGOS_NET_IF_TYPE_ETHERNET, 0,
MGOS_NET_EV_IP_ACQUIRED);
break;
}
#endif
default:
LOG(LL_INFO, ("event: %d", event->event_id));
esp32_system_event_handler_default(event);
}
return ESP_OK;
}

enum mgos_init_result mgos_freertos_pre_init(void) {
enum mgos_init_result r;

Expand All @@ -115,7 +64,7 @@ enum mgos_init_result mgos_freertos_pre_init(void) {

LOG(LL_INFO, ("ESP-IDF %s", esp_get_idf_version()));
LOG(LL_INFO,
("Boot partition: %s; flash: %uM", esp_ota_get_boot_partition()->label,
("Boot partition: %s; flash: %uM", esp_ota_get_running_partition()->label,
g_rom_flashchip.chip_size / 1048576));

{
Expand Down Expand Up @@ -152,8 +101,10 @@ static IRAM void sdk_putc(char c) {
ets_write_char_uart(c);
}

void mgos_cd_putc(int c) {
panicPutChar(c);
extern void panic_print_char(char c);

IRAM void mgos_cd_putc(int c) {
ets_write_char_uart(c);
}

extern void cs_log_lock(void);
Expand Down Expand Up @@ -194,11 +145,11 @@ static int sdk_debug_vprintf(esp_log_level_t level, const char *fmt,

void app_main(void) {
nvs_flash_init();
tcpip_adapter_init();
ets_install_putc1(sdk_putc);
ets_install_putc2(NULL);
esp_log_set_vprintf(sdk_debug_vprintf);
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
esp_event_loop_create_default();
esp_netif_init();
/* Scheduler is already running at this point */
mgos_freertos_run_mgos_task(false /* start_scheduler */);
/* Unlike other platforms, we return and abandon this task. */
Expand Down
3 changes: 2 additions & 1 deletion platforms/esp32/src/esp32_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@

#include "driver/periph_ctrl.h"
#include "driver/uart.h"
#include "esp32/rom/uart.h"
#include "esp_attr.h"
#include "esp_intr_alloc.h"
#include "rom/uart.h"
#include "soc/dport_access.h"
#include "soc/uart_reg.h"

#include "common/cs_dbg.h"
Expand Down
13 changes: 8 additions & 5 deletions tools/docker/esp32/Dockerfile-esp32-build
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,28 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -q \
python-pkg-resources python3-pkg-resources \
python-pyparsing python3-pyparsing \
python-setuptools python3-setuptools \
python-pip python3-pip \
rsync && \
apt-get clean

RUN pip install reedsolo bitstring ecdsa

RUN useradd -d /opt/Espressif -m -s /bin/bash user && chown -R user /opt

ARG TOOLCHAIN_VERSION
RUN cd /opt/Espressif && wget -q https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-$TOOLCHAIN_VERSION.tar.gz && \
tar xzf xtensa-esp32-elf-linux64-$TOOLCHAIN_VERSION.tar.gz && \
rm xtensa-esp32-elf-linux64-$TOOLCHAIN_VERSION.tar.gz
RUN cd /opt/Espressif && wget -q https://dl.espressif.com/dl/$TOOLCHAIN_VERSION.tar.gz && \
tar xzf $TOOLCHAIN_VERSION.tar.gz && \
rm $TOOLCHAIN_VERSION.tar.gz
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/Espressif/xtensa-esp32-elf/bin
ADD ct_path.sh /etc/profile.d

ARG DOCKER_TAG
RUN git clone --recursive --branch $DOCKER_TAG https://github.com/mongoose-os/esp-idf /opt/Espressif/esp-idf
RUN git clone -j 8 --branch $DOCKER_TAG --depth 1 --recursive --shallow-submodules https://github.com/mongoose-os/esp-idf /opt/Espressif/esp-idf
RUN cd /opt/Espressif/esp-idf && git tag v$DOCKER_TAG
ENV IDF_PATH=/opt/Espressif/esp-idf

# Pre-build configuration tools
RUN cd $IDF_PATH/tools/kconfig && make conf-idf mconf-idf
RUN cd $IDF_PATH/tools/kconfig && make conf-idf

ADD rom.bin rom.elf /opt/Espressif/rom/

Expand Down
2 changes: 1 addition & 1 deletion tools/docker/esp32/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DOCKERFILES = esp32-build
SPIFFS_CONFIG_PATH = /vfs-fs-spiffs/include/esp32
TOOLCHAIN_VERSION = 1.22.0-96-g2852398-5.2.0
TOOLCHAIN_VERSION = xtensa-esp32-elf-gcc8_4_0-esp-2020r3-linux-amd64
DOCKER_FLAGS = --build-arg=TOOLCHAIN_VERSION=$(TOOLCHAIN_VERSION) \
--build-arg=DOCKER_TAG=$(DOCKER_TAG)

Expand Down

0 comments on commit 8fd9925

Please sign in to comment.