Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/{esp8266,esp32}: cleanup of SPI Flash configuration #18387

Merged
merged 6 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boards/esp32-heltec-lora32-v2/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion boards/esp32-mh-et-live-minikit/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion boards/esp32-olimex-evb/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down
2 changes: 1 addition & 1 deletion boards/esp32-wroom-32/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion boards/esp8266-esp-12x/include/arduino_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion boards/esp8266-olimex-mod/include/arduino_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion boards/esp8266-sparkfun-thing/include/arduino_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 22 additions & 6 deletions cpu/esp32/Makefile.include
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -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__
Expand Down
8 changes: 5 additions & 3 deletions cpu/esp32/bootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down
22 changes: 8 additions & 14 deletions cpu/esp32/bootloader/sdkconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down
22 changes: 6 additions & 16 deletions cpu/esp32/include/sdkconfig_esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
2 changes: 1 addition & 1 deletion cpu/esp32/periph/gpio_arch_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 3 additions & 2 deletions cpu/esp8266/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion cpu/esp8266/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 14 additions & 11 deletions cpu/esp_common/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions makefiles/tools/esptool.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down