diff --git a/boards/esp32-heltec-lora32-v2/include/periph_conf.h b/boards/esp32-heltec-lora32-v2/include/periph_conf.h index 3655b5eb84..5ec6a49088 100644 --- a/boards/esp32-heltec-lora32-v2/include/periph_conf.h +++ b/boards/esp32-heltec-lora32-v2/include/periph_conf.h @@ -152,7 +152,7 @@ #define UART0_TXD GPIO1 /**< direct I/O pin for UART_DEV(0) TxD, can't be changed */ #define UART0_RXD GPIO3 /**< direct I/O pin for UART_DEV(0) RxD, can't be changed */ -#if FLASH_MODE_DOUT || FLASH_MODE_DIO || DOXYGEN +#if CONFIG_FLASHMODE_DOUT || CONFIG_FLASHMODE_DIO || DOXYGEN #ifndef UART1_TXD #define UART1_TXD GPIO10 /**< direct I/O pin for UART_DEV(1) TxD */ #endif diff --git a/boards/esp32-mh-et-live-minikit/include/periph_conf.h b/boards/esp32-mh-et-live-minikit/include/periph_conf.h index 15fe2760ae..ab19f89237 100644 --- a/boards/esp32-mh-et-live-minikit/include/periph_conf.h +++ b/boards/esp32-mh-et-live-minikit/include/periph_conf.h @@ -145,7 +145,7 @@ #define UART0_TXD GPIO1 /**< direct I/O pin for UART_DEV(0) TxD, can't be changed */ #define UART0_RXD GPIO3 /**< direct I/O pin for UART_DEV(0) RxD, can't be changed */ -#if FLASH_MODE_DOUT || FLASH_MODE_DIO || DOXYGEN +#if CONFIG_FLASHMODE_DOUT || CONFIG_FLASHMODE_DIO || DOXYGEN #ifndef UART1_TXD #define UART1_TXD GPIO10 /**< direct I/O pin for UART_DEV(1) TxD */ #endif diff --git a/boards/esp32-olimex-evb/include/periph_conf.h b/boards/esp32-olimex-evb/include/periph_conf.h index 3f3cfe610d..6d921cf739 100644 --- a/boards/esp32-olimex-evb/include/periph_conf.h +++ b/boards/esp32-olimex-evb/include/periph_conf.h @@ -129,7 +129,7 @@ extern "C" { * as PWM channels with `PWM_DEV(0)`. */ #ifndef PWM0_GPIOS -#if FLASH_MODE_DOUT || FLASH_MODE_DIO || DOXYGEN +#if CONFIG_FLASHMODE_DOUT || CONFIG_FLASHMODE_DIO || DOXYGEN #define PWM0_GPIOS { GPIO9, GPIO10 } #else #error Configuration problem: Flash mode qio or qout is used, \ diff --git a/boards/esp32-wroom-32/include/periph_conf.h b/boards/esp32-wroom-32/include/periph_conf.h index 98b3ab80e3..8a245a7e4b 100644 --- a/boards/esp32-wroom-32/include/periph_conf.h +++ b/boards/esp32-wroom-32/include/periph_conf.h @@ -182,7 +182,7 @@ extern "C" { #define UART0_TXD GPIO1 /**< direct I/O pin for UART_DEV(0) TxD, can't be changed */ #define UART0_RXD GPIO3 /**< direct I/O pin for UART_DEV(0) RxD, can't be changed */ -#if FLASH_MODE_DOUT || FLASH_MODE_DIO || DOXYGEN +#if CONFIG_FLASHMODE_DOUT || CONFIG_FLASHMODE_DIO || DOXYGEN #ifndef UART1_TXD #define UART1_TXD GPIO10 /**< direct I/O pin for UART_DEV(1) TxD */ #endif diff --git a/boards/esp8266-esp-12x/include/arduino_board.h b/boards/esp8266-esp-12x/include/arduino_board.h index 07465013ec..c8e2e62dfb 100644 --- a/boards/esp8266-esp-12x/include/arduino_board.h +++ b/boards/esp8266-esp-12x/include/arduino_board.h @@ -39,7 +39,7 @@ static const gpio_t arduino_pinmap[] = { GPIO3, /* ARDUINO_PIN_1 (TxD) */ GPIO0, /* ARDUINO_PIN_2 */ GPIO2, /* ARDUINO_PIN_3 */ - #if defined(FLASH_MODE_QIO) || defined(FLASH_MODE_QOUT) + #if defined(CONFIG_FLASHMODE_QIO) || defined(CONFIG_FLASHMODE_QOUT) GPIO9, /* ARDUINO_PIN_4 */ GPIO10, /* ARDUINO_PIN_5 */ #else diff --git a/boards/esp8266-olimex-mod/include/arduino_board.h b/boards/esp8266-olimex-mod/include/arduino_board.h index 7da0540f29..188618a3f3 100644 --- a/boards/esp8266-olimex-mod/include/arduino_board.h +++ b/boards/esp8266-olimex-mod/include/arduino_board.h @@ -37,7 +37,7 @@ static const gpio_t arduino_pinmap[] = { GPIO3, /* ARDUINO_PIN_1 (TxD) */ GPIO0, /* ARDUINO_PIN_2 */ GPIO4, /* ARDUINO_PIN_3 */ - #if defined(FLASH_MODE_QIO) || defined(FLASH_MODE_QOUT) + #if defined(CONFIG_FLASHMODE_QIO) || defined(CONFIG_FLASHMODE_QOUT) GPIO9, /* ARDUINO_PIN_4 */ GPIO10, /* ARDUINO_PIN_5 */ #else diff --git a/boards/esp8266-sparkfun-thing/include/arduino_board.h b/boards/esp8266-sparkfun-thing/include/arduino_board.h index c7949427be..7a65bf89d6 100644 --- a/boards/esp8266-sparkfun-thing/include/arduino_board.h +++ b/boards/esp8266-sparkfun-thing/include/arduino_board.h @@ -37,7 +37,7 @@ static const gpio_t arduino_pinmap[] = { GPIO3, /* ARDUINO_PIN_1 (TxD) */ GPIO0, /* ARDUINO_PIN_2 */ GPIO4, /* ARDUINO_PIN_3 */ - #if defined(FLASH_MODE_QIO) || defined(FLASH_MODE_QOUT) + #if defined(CONFIG_FLASHMODE_QIO) || defined(CONFIG_FLASHMODE_QOUT) GPIO9, /* ARDUINO_PIN_4 */ GPIO10, /* ARDUINO_PIN_5 */ #else diff --git a/cpu/esp32/Makefile.include b/cpu/esp32/Makefile.include index 4670311f95..367bec1387 100644 --- a/cpu/esp32/Makefile.include +++ b/cpu/esp32/Makefile.include @@ -1,14 +1,17 @@ # ESP32x specific flashing options FLASH_CHIP = $(CPU_FAM) + +# Serial flasher config as used by the ESP-IDF, be careful when overriding them. +# They have to be exported to use same values in subsequent makefiles. ifeq (esp32,$(CPU_FAM)) - FLASH_MODE ?= dout - FLASH_FREQ = 40m # DO NOT CHANGE - FLASH_SIZE ?= 4 + export FLASH_MODE ?= dout + export FLASH_FREQ ?= 40m + export FLASH_SIZE ?= 2 BOOTLOADER_POS = 0x1000 else ifeq (esp32c3,$(CPU_FAM)) - FLASH_MODE ?= dio - FLASH_FREQ = 80m # DO NOT CHANGE - FLASH_SIZE ?= 4 + export FLASH_MODE ?= dio + export FLASH_FREQ ?= 80m + export FLASH_SIZE ?= 2 BOOTLOADER_POS = 0x0000 else $(error Unkwnown ESP32x SoC variant (family)) @@ -112,6 +115,19 @@ CFLAGS += -DCONFIG_IDF_TARGET_$(call uppercase_and_underscore,$(CPU_FAM)) CFLAGS += -DESP_PLATFORM CFLAGS += -DLOG_TAG_IN_BRACKETS +# extend CFLAGS by the corresponding FLASH_FREQ +ifeq (20m,$(FLASH_FREQ)) + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHFREQ_20M +else ifeq (26m,$(FLASH_FREQ)) + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHFREQ_26M +else ifeq (40m,$(FLASH_FREQ)) + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHFREQ_40M +else ifeq (80m,$(FLASH_FREQ)) + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHFREQ_80M +else ifeq (120m,$(FLASH_FREQ)) + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHFREQ_120M +endif + # shortcuts used by ESP-IDF CFLAGS += -Dasm=__asm CFLAGS += -Dtypeof=__typeof__ diff --git a/cpu/esp32/bootloader/Makefile b/cpu/esp32/bootloader/Makefile index e1607b5be3..e45c87c439 100644 --- a/cpu/esp32/bootloader/Makefile +++ b/cpu/esp32/bootloader/Makefile @@ -155,6 +155,8 @@ INCLUDES = \ -I$(ESP32_SDK_DIR)/components/spi_flash/include/spi_flash \ # +# include CFLAGS from cpu/esp_common/Makefile.include including the defines of +# CONFIG_ESPTOOLPY_FLASHFREQ_* and CONFIG_FLASHMODE_* CFLAGS = -include '$(RIOTBUILD_CONFIG_HEADER_C)' \ ifneq (,$(filter riscv32%,$(TARGET_ARCH))) @@ -313,9 +315,9 @@ FLASH_CHIP = $(CPU_FAM) ESPTOOL ?= $(RIOTTOOLS)/esptools/esptool_v3.2.py # TODO: These should be exported/configurable from the app side. That would # require to export these values. -FLASH_MODE ?= dout -FLASH_FREQ ?= 40m -FLASH_SIZE ?= 4 +FLASH_MODE ?= dio # ESP-IDF uses dio as default flash mode for the bootloader +FLASH_FREQ ?= 40m # lowest frequency all ESP32x SoC support +FLASH_SIZE ?= 2 # smallesrt size all ESP32x SoC support # We use esptool to extract a version 1 app from the bootloader.elf. This is # like the regular objdump binary file but it contains a 16 byte header which diff --git a/cpu/esp32/bootloader/sdkconfig.h b/cpu/esp32/bootloader/sdkconfig.h index 27fead5ab1..a627e97f1e 100644 --- a/cpu/esp32/bootloader/sdkconfig.h +++ b/cpu/esp32/bootloader/sdkconfig.h @@ -63,20 +63,14 @@ extern "C" { #endif #endif -#if FLASH_MODE_QIO -#define CONFIG_FLASHMODE_QIO 1 -#define CONFIG_ESPTOOLPY_FLASHMODE_QIO 1 -#elif FLASH_MODE_QOUT -#define CONFIG_FLASHMODE_QOUT 1 -#define CONFIG_ESPTOOLPY_FLASHMODE_QOUT 1 -#elif FLASH_MODE_DIO -#define CONFIG_FLASHMODE_DIO 1 -#define CONFIG_ESPTOOLPY_FLASHMODE_DIO 1 -#elif FLASH_MODE_DOUT -#define CONFIG_FLASHMODE_DOUT 1 -#define CONFIG_ESPTOOLPY_FLASHMODE_DOUT 1 -#else -#error "Unknown flash mode selected." +/** + * Serial flasher config (defined by CFLAGS, only sanity check here) + */ +#if !defined(CONFIG_FLASHMODE_DOUT) && \ + !defined(CONFIG_FLASHMODE_DIO) && \ + !defined(CONFIG_FLASHMODE_QOUT) && \ + !defined(CONFIG_FLASHMODE_QIO) +#error "Flash mode not configured" #endif /* diff --git a/cpu/esp32/include/sdkconfig_esp32.h b/cpu/esp32/include/sdkconfig_esp32.h index 838e754af4..628b1fffe6 100644 --- a/cpu/esp32/include/sdkconfig_esp32.h +++ b/cpu/esp32/include/sdkconfig_esp32.h @@ -183,23 +183,13 @@ extern "C" { #define CONFIG_ETH_DMA_TX_BUFFER_NUM 10 /** - * Serial flasher config (DO NOT CHANGE) + * Serial flasher config (defined by CFLAGS, only sanity check here) */ -#define CONFIG_ESPTOOLPY_FLASHFREQ_40M 1 -#if defined(FLASH_MODE_QIO) -#define CONFIG_FLASHMODE_QIO 1 -#define CONFIG_ESPTOOLPY_FLASHMODE_QIO 1 -#elif defined(FLASH_MODE_QOUT) -#define CONFIG_FLASHMODE_QOUT 1 -#define CONFIG_ESPTOOLPY_FLASHMODE_QOUT 1 -#elif defined(FLASH_MODE_DIO) -#define CONFIG_FLASHMODE_DIO 1 -#define CONFIG_ESPTOOLPY_FLASHMODE_DIO 1 -#elif defined(FLASH_MODE_DOUT) -#define CONFIG_FLASHMODE_DOUT 1 -#define CONFIG_ESPTOOLPY_FLASHMODE_DOUT 1 -#else -#error "Unknown flash mode selected." +#if !defined(CONFIG_FLASHMODE_DOUT) && \ + !defined(CONFIG_FLASHMODE_DIO) && \ + !defined(CONFIG_FLASHMODE_QOUT) && \ + !defined(CONFIG_FLASHMODE_QIO) +#error "Flash mode not configured" #endif /** diff --git a/cpu/esp32/periph/gpio_arch_esp32.c b/cpu/esp32/periph/gpio_arch_esp32.c index 034af61645..ba7a2c06ad 100644 --- a/cpu/esp32/periph/gpio_arch_esp32.c +++ b/cpu/esp32/periph/gpio_arch_esp32.c @@ -83,7 +83,7 @@ gpio_pin_usage_t _gpio_pin_usage [GPIO_PIN_NUMOF] = { _SPIF, /* GPIO6 is used as direct I/O SPI SCK for Flash */ _SPIF, /* GPIO7 is used as direct I/O SPI MISO for Flash */ _SPIF, /* GPIO8 is used as direct I/O SPI MOSI for Flash */ - #if defined(FLASH_MODE_QIO) || defined(FLASH_MODE_QOUT) + #if defined(CONFIG_FLASHMODE_QIO) || defined(CONFIG_FLASHMODE_QOUT) /* in qio and qout mode these pins are used in Flash */ _SPIF, /* GPIO9 is used as direct I/O SPI HD for Flash */ _SPIF, /* GPIO10 is used as direct I/O SPI WP for Flash */ diff --git a/cpu/esp8266/Makefile.include b/cpu/esp8266/Makefile.include index 72afb252e7..daa32a61cd 100644 --- a/cpu/esp8266/Makefile.include +++ b/cpu/esp8266/Makefile.include @@ -4,10 +4,11 @@ CFLAGS_OPT ?= -O2 # ESP8266 specific flashing options +# DO NOT CHANGE, ESP8266/ESP8285 modules only work with dout and 26m FLASH_CHIP = esp8266 FLASH_OPTS = --version 3 -FLASH_MODE = dout # DO NOT CHANGE, ESP8266/ESP8285 modules only work with dout -FLASH_FREQ = 26m # DO NOT CHANGE +FLASH_MODE = dout +FLASH_FREQ = 26m FLASH_SIZE ?= 1 BOOTLOADER_POS = 0x0000 diff --git a/cpu/esp8266/periph/gpio.c b/cpu/esp8266/periph/gpio.c index 0bedcfd360..1644670965 100644 --- a/cpu/esp8266/periph/gpio.c +++ b/cpu/esp8266/periph/gpio.c @@ -62,7 +62,7 @@ gpio_pin_usage_t _gpio_pin_usage [GPIO_PIN_NUMOF] = _SPIF, /* gpio6 SPI flash CLK */ _SPIF, /* gpio7 SPI flash MISO */ _SPIF, /* gpio8 SPI flash MOSI */ - #if defined(FLASH_MODE_QIO) || defined(FLASH_MODE_QOUT) + #if defined(CONFIG_FLASHMODE_QIO) || defined(CONFIG_FLASHMODE_QOUT) _SPIF, /* gpio9 SPI flash HD (qio/qout flash mode) */ _SPIF, /* gpio10 SPI flash WP (qio/qout flash mode) */ #else diff --git a/cpu/esp_common/Makefile.include b/cpu/esp_common/Makefile.include index ba6455ef4c..15538f9a69 100644 --- a/cpu/esp_common/Makefile.include +++ b/cpu/esp_common/Makefile.include @@ -78,20 +78,23 @@ ifneq (,$(filter lwip,$(USEMODULE))) CFLAGS += -DTCPIP_THREAD_PRIO=5 endif -# if SPI RAM is enabled, the qout flash mode has to be used -_FLASH_MODE_PREV := $(FLASH_MODE) -ifneq (,$(filter esp_spi_ram,$(USEMODULE))) - FLASH_MODE = qout +# extend CFLAGS by the corresponding CONFIG_FLASHMODE_* defines +ifeq (dout,$(FLASH_MODE)) + CFLAGS += -DCONFIG_FLASHMODE_DOUT + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHMODE_DOUT +else ifeq (dio,$(FLASH_MODE)) + CFLAGS += -DCONFIG_FLASHMODE_DIO + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHMODE_DIO +else ifeq (qout,$(FLASH_MODE)) + CFLAGS += -DCONFIG_FLASHMODE_QOUT + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHMODE_QUOT +else ifeq (qio,$(FLASH_MODE)) + CFLAGS += -DCONFIG_FLASHMODE_QIO + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHMODE_QIO else - FLASH_MODE = $(_FLASH_MODE_PREV) + $(error Undefined FLASH_MODE, possible values are: dout, dio, qout and qio) endif -# set CFLAG for the correspondant FLASH_MODE -CFLAGS += $(if $(findstring qout,$(FLASH_MODE)),-DFLASH_MODE_QOUT=1) -CFLAGS += $(if $(findstring qio,$(FLASH_MODE)),-DFLASH_MODE_QIO=1) -CFLAGS += $(if $(findstring dio,$(FLASH_MODE)),-DFLASH_MODE_DIO=1) -CFLAGS += $(if $(findstring dout,$(FLASH_MODE)),-DFLASH_MODE_DOUT=1) - ARCHIVES += -lg -lc LINKFLAGS += $(CFLAGS_OPT) $(CFLAGS_DBG) diff --git a/makefiles/tools/esptool.inc.mk b/makefiles/tools/esptool.inc.mk index 022b731f50..ef632d35db 100644 --- a/makefiles/tools/esptool.inc.mk +++ b/makefiles/tools/esptool.inc.mk @@ -8,6 +8,12 @@ ifeq ($(CPU),esp8266) # Full path to the bootloader binary. In the ESP32 case this is set by the # esp_bootloader module. BOOTLOADER_BIN ?= $(RIOTCPU)/$(CPU)/bin/bootloader$(BOOTLOADER_COLOR)$(BOOTLOADER_INFO).bin +else + # ESP-IDF uses dio as flash mode for esptool.py when qout or qio mode are + # configured to always boot in dual SPI mode + ifneq (,$(filter qout qio,$(FLASH_MODE))) + FLASH_MODE = dio + endif endif ESPTOOL ?= $(RIOTTOOLS)/esptools/esptool.py