You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/03/04 02:28:28 UTC
[incubator-nuttx] 01/02: xtensa/esp32: Add more flash options to
esptool.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 77302f9d3a019e0f1be9ff89a5560c7b4f328ca5
Author: Abdelatif Guettouche <ab...@espressif.com>
AuthorDate: Mon Mar 1 14:03:50 2021 +0100
xtensa/esp32: Add more flash options to esptool.
Signed-off-by: Abdelatif Guettouche <ab...@espressif.com>
---
arch/xtensa/src/esp32/Kconfig | 39 +++++++++++++++++++++++++++++
tools/esp32/Config.mk | 57 ++++++++++++++++++++++++++++++++++---------
2 files changed, 84 insertions(+), 12 deletions(-)
diff --git a/arch/xtensa/src/esp32/Kconfig b/arch/xtensa/src/esp32/Kconfig
index bcce5f8..36bbba8 100644
--- a/arch/xtensa/src/esp32/Kconfig
+++ b/arch/xtensa/src/esp32/Kconfig
@@ -111,6 +111,12 @@ config ESP32_FLASH_16M
bool
default n
+config ESP32_FLASH_DETECT
+ bool "Auto-detect FLASH size"
+ default y
+ help
+ Auto detect flash size when flashing.
+
config ESP32_PSRAM_8M
bool
default n
@@ -130,6 +136,39 @@ config ESP32_ESP32DXWDXX
default n
select ESP32_DUAL_CPU
+choice ESP32_FLASH_MODE
+ prompt "SPI FLASH mode"
+ default ESP32_FLASH_MODE_DIO
+ help
+ These options control how many I/O pins are used for communication with the attached SPI flash chip.
+ The option selected here is then used by esptool when flashing.
+
+ config ESP32_FLASH_MODE_DIO
+ bool "Dual IO (DIO)"
+ config ESP32_FLASH_MODE_DOUT
+ bool "Dual Output (DOUT)"
+ config ESP32_FLASH_MODE_QIO
+ bool "Quad IO (QIO)"
+ config ESP32_FLASH_MODE_QOUT
+ bool "Quad Output (QOUT)"
+endchoice # ESP32_FLASH_MODE
+
+choice ESP32_FLASH_FREQ
+ prompt "SPI FLASH frequency"
+ default ESP32_FLASH_FREQ_40M
+ help
+ SPI FLASH frequency
+
+ config ESP32_FLASH_FREQ_80M
+ bool "80 MHz"
+ config ESP32_FLASH_FREQ_40M
+ bool "40 MHz"
+ config ESP32_FLASH_FREQ_26M
+ bool "26 MHz"
+ config ESP32_FLASH_FREQ_20M
+ bool "20 MHz"
+endchoice # ESP32_FLASH_FREQ
+
choice ESP32_DEFAULT_CPU_FREQ
prompt "CPU frequency"
default ESP32_DEFAULT_CPU_FREQ_240
diff --git a/tools/esp32/Config.mk b/tools/esp32/Config.mk
index 19d2460..45700a2 100644
--- a/tools/esp32/Config.mk
+++ b/tools/esp32/Config.mk
@@ -22,6 +22,46 @@
# and assemble source files and to insert the resulting object files into an
# archive. These replace the default definitions at tools/Config.mk
+ifeq ($(CONFIG_ESP32_FLASH_2M),y)
+ FLASH_SIZE := 2MB
+else ifeq ($(CONFIG_ESP32_FLASH_4M),y)
+ FLASH_SIZE := 4MB
+else ifeq ($(CONFIG_ESP32_FLASH_8M),y)
+ FLASH_SIZE := 8MB
+else ifeq ($(CONFIG_ESP32_FLASH_16M),y)
+ FLASH_SIZE := 16MB
+endif
+
+ifeq ($(CONFIG_ESP32_FLASH_MODE_DIO),y)
+ FLASH_MODE := dio
+else ifeq ($(CONFIG_ESP32_FLASH_MODE_DOUT),y)
+ FLASH_MODE := dout
+else ifeq ($(CONFIG_ESP32_FLASH_MODE_QIO),y)
+ FLASH_MODE := qio
+else ifeq ($(CONFIG_ESP32_FLASH_MODE_QOUT),y)
+ FLASH_MODE := qout
+endif
+
+ifeq ($(CONFIG_ESP32_FLASH_FREQ_80M),y)
+ FLASH_FREQ := 80m
+else ifeq ($(CONFIG_ESP32_FLASH_FREQ_40M),y)
+ FLASH_FREQ := 40m
+else ifeq ($(CONFIG_ESP32_FLASH_FREQ_26M),y)
+ FLASH_FREQ := 26m
+else ifeq ($(CONFIG_ESP32_FLASH_FREQ_20M),y)
+ FLASH_FREQ := 20m
+endif
+
+ESPTOOL_FLASH_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ)
+ESPTOOL_ELF2IMG_OPTS := $(ESPTOOL_FLASH_OPTS)
+
+ifeq ($(CONFIG_ESP32_FLASH_DETECT),y)
+ ESPTOOL_WRITEFLASH_OPTS := -fs detect -fm $(FLASH_MODE) -ff $(FLASH_FREQ)
+else
+ ESPTOOL_WRITEFLASH_OPTS := $(ESPTOOL_FLASH_OPTS)
+endif
+
+
ifdef ESPTOOL_BINDIR
BL_OFFSET=0x1000
PT_OFFSET=0x8000
@@ -31,16 +71,6 @@ ifdef ESPTOOL_BINDIR
FLASH_PT=$(PT_OFFSET) $(PARTITION_TABLE)
endif
-ifeq ($(CONFIG_ESP32_FLASH_2M),y)
- FLASH_SIZE="2MB"
-else ifeq ($(CONFIG_ESP32_FLASH_4M),y)
- FLASH_SIZE="4MB"
-else ifeq ($(CONFIG_ESP32_FLASH_8M),y)
- FLASH_SIZE="8MB"
-else ifeq ($(CONFIG_ESP32_FLASH_16M),y)
- FLASH_SIZE="16MB"
-endif
-
ifeq ($(CONFIG_ESP32_QEMU_IMAGE),y)
MK_QEMU_IMG=$(TOPDIR)/tools/esp32/mk_qemu_img.sh -b $(BOOTLOADER) -p $(PARTITION_TABLE)
else
@@ -63,7 +93,7 @@ define POSTBUILD
echo "Missing Flash memory size configuration for the ESP32 chip."; \
exit 1; \
fi
- esptool.py --chip esp32 elf2image --flash_mode dio --flash_size $(FLASH_SIZE) -o nuttx.bin nuttx
+ esptool.py -c esp32 elf2image $(ESPTOOL_ELF2IMG_OPTS) -o nuttx.bin nuttx
$(Q) echo "Generated: nuttx.bin (ESP32 compatible)"
$(Q) $(MK_QEMU_IMG)
endef
@@ -75,10 +105,13 @@ ESPTOOL_BAUD ?= 921600
# DOWNLOAD -- Download binary image via esptool.py
define DOWNLOAD
+
+ $(eval ESPTOOL_BINS := $(FLASH_BL) $(FLASH_PT) 0x10000 $(1).bin)
+
$(Q) if [ -z $(ESPTOOL_PORT) ]; then \
echo "DOWNLOAD error: Missing serial port device argument."; \
echo "USAGE: make download ESPTOOL_PORT=<port> [ ESPTOOL_BAUD=<baud> ] [ ESPTOOL_BINDIR=<dir> ]"; \
exit 1; \
fi
- esptool.py --chip esp32 --port $(ESPTOOL_PORT) --baud $(ESPTOOL_BAUD) write_flash $(FLASH_BL) $(FLASH_PT) 0x10000 $(1).bin
+ esptool.py -c esp32 -p $(ESPTOOL_PORT) -b $(ESPTOOL_BAUD) write_flash $(ESPTOOL_WRITEFLASH_OPTS) $(ESPTOOL_BINS)
endef