1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #16911 from yarrick/esp_jtag

cpu/esp32: Add openocd programming support
This commit is contained in:
Gunar Schorcht 2021-10-26 01:24:27 +02:00 committed by GitHub
commit 697c44811a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 125 additions and 38 deletions

View File

@ -2,4 +2,8 @@
# configure the serial interface # configure the serial interface
PORT_LINUX ?= /dev/ttyUSB1 PORT_LINUX ?= /dev/ttyUSB1
ifneq (,$(filter esp_jtag,$(USEMODULE)))
OPENOCD_CONFIG ?= board/esp32-ethernet-kit-3.3v.cfg
endif
include $(RIOTBOARD)/common/esp32/Makefile.include include $(RIOTBOARD)/common/esp32/Makefile.include

View File

@ -102,9 +102,22 @@ Since the USB bridge based on FDI FT2232HL provides a JTAG interface for debuggi
To use the JTAG interface, the `esp_jtag` module must be used to disable the `SPI_DEV(0)` which normally uses the GPIOs for the JTAG signals. To use the JTAG interface, the `esp_jtag` module must be used to disable the `SPI_DEV(0)` which normally uses the GPIOs for the JTAG signals.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
USEMODULE=esp_jtag make flash BOARD=esp32-ethernet-kit-v1_X ... USEMODULE+=esp_jtag make flash BOARD=esp32-ethernet-kit-v1_X ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Furthermore the function switches (DIP switches) for the JTAG signals must be set to ON. Furthermore the function switches (DIP switches) for the JTAG signals must be set to ON.
To flash using OpenOCD, install the [openocd-esp32](https://github.com/espressif/openocd-esp32) fork.
Export where openocd is located and then flash with PROGRAMMER set:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export OPENOCD="~/openocd-esp32/src/openocd -s ~/openocd-esp32/tcl"
PROGRAMMER=openocd USEMODULE+=esp_jtag make flash BOARD=esp32-ethernet-kit-v1_X
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To start a debugging session (board will be reset, but not flashed):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export OPENOCD="~/openocd-esp32/src/openocd -s ~/openocd-esp32/tcl"
PROGRAMMER=openocd USEMODULE+=esp_jtag make debug BOARD=esp32-ethernet-kit-v1_X
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Back to table of contents](#esp32_ethernet_kit_toc) [Back to table of contents](#esp32_ethernet_kit_toc)
*/ */

View File

@ -15,11 +15,11 @@ config BOARD_ESP32_WROVER_KIT
select HAS_ARDUINO select HAS_ARDUINO
select HAS_ESP_RTC_TIMER_32K select HAS_ESP_RTC_TIMER_32K
select HAS_ESP_SPI_RAM select HAS_ESP_SPI_RAM
select HAS_ESP_JTAG
select HAS_PERIPH_ADC select HAS_PERIPH_ADC
select HAS_PERIPH_I2C select HAS_PERIPH_I2C
select HAS_PERIPH_PWM select HAS_PERIPH_PWM
select HAS_PERIPH_SPI select HAS_PERIPH_SPI
select HAS_SDCARD_SPI select HAS_SDCARD_SPI
select MODULE_ESP_JTAG
source "$(RIOTBOARD)/common/esp32/Kconfig" source "$(RIOTBOARD)/common/esp32/Kconfig"

View File

@ -2,4 +2,7 @@ ifneq (,$(filter disp_dev,$(USEMODULE)))
USEMODULE += ili9341 USEMODULE += ili9341
endif endif
# Sets up configuration for openocd
USEMODULE += esp_jtag
include $(RIOTBOARD)/common/esp32/Makefile.dep include $(RIOTBOARD)/common/esp32/Makefile.dep

View File

@ -11,7 +11,6 @@ FEATURES_PROVIDED += periph_spi
# unique features provided by the board # unique features provided by the board
FEATURES_PROVIDED += sdcard_spi FEATURES_PROVIDED += sdcard_spi
FEATURES_PROVIDED += esp_jtag
FEATURES_PROVIDED += esp_spi_ram FEATURES_PROVIDED += esp_spi_ram
FEATURES_PROVIDED += esp_rtc_timer_32k FEATURES_PROVIDED += esp_rtc_timer_32k

View File

@ -3,4 +3,8 @@ PSEUDOMODULES += esp32_wrover_kit_camera
# configure the serial interface # configure the serial interface
PORT_LINUX ?= /dev/ttyUSB1 PORT_LINUX ?= /dev/ttyUSB1
ifneq (,$(filter esp_jtag,$(USEMODULE)))
OPENOCD_CONFIG ?= board/esp32-wrover-kit-3.3v.cfg
endif
include $(RIOTBOARD)/common/esp32/Makefile.include include $(RIOTBOARD)/common/esp32/Makefile.include

View File

@ -289,6 +289,25 @@ convenient way for On-Chip debugging. Please refer the
[ESP-IDF Programming Guide](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/jtag-debugging/index.html) [ESP-IDF Programming Guide](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/jtag-debugging/index.html)
for details on how to setup and how to use ESP-WROVER-KIT and OpenOCD. for details on how to setup and how to use ESP-WROVER-KIT and OpenOCD.
To use the JTAG interface, the `esp_jtag` module must be enabled.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
USEMODULE+=esp_jtag make flash BOARD=esp32-wrover-kit ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To flash using OpenOCD, install the [openocd-esp32](https://github.com/espressif/openocd-esp32) fork.
The OpenOCD configuration selected by default is for using JTAG via the FTDI chip.
Export where openocd is located and then flash with PROGRAMMER set:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export OPENOCD="~/openocd-esp32/src/openocd -s ~/openocd-esp32/tcl"
PROGRAMMER=openocd USEMODULE+=esp_jtag make flash BOARD=esp32-wrover-kit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To start a debugging session (board will be reset, but not flashed):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export OPENOCD="~/openocd-esp32/src/openocd -s ~/openocd-esp32/tcl"
PROGRAMMER=openocd USEMODULE+=esp_jtag make debug BOARD=esp32-wrover-kit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Back to table of contents](#esp32_wrover_kit_toc) [Back to table of contents](#esp32_wrover_kit_toc)
## Other Documentation Resources {#esp32_wrover_kit_other-resources} ## Other Documentation Resources {#esp32_wrover_kit_other-resources}

View File

@ -79,3 +79,17 @@ endif
ifneq (,$(filter cpp,$(FEATURES_USED))) ifneq (,$(filter cpp,$(FEATURES_USED)))
ARCHIVES += -lstdc++ ARCHIVES += -lstdc++
endif endif
ifneq (,$(filter esp_jtag,$(USEMODULE)))
PROGRAMMERS_SUPPORTED += openocd
PARTITION_POS = 0x8000
OPENOCD_PRE_FLASH_CMDS = -c 'echo "Installing Bootloader at $(BOOTLOADER_POS)"' \
-c 'flash write_image erase "$(RIOTCPU)/$(CPU)/bin/bootloader.bin" $(BOOTLOADER_POS) bin' \
-c 'echo "Installing partition table at $(PARTITION_POS)"' \
-c 'flash write_image erase "$(BINDIR)/partitions.bin" $(PARTITION_POS) bin'
IMAGE_OFFSET = 0x10000
# Flash checksumming not supported on xtensa
OPENOCD_SKIP_VERIFY = yes
# Without resets debug target fails with 'Target not examined yet'
OPENOCD_DBG_EXTRA_CMD += -c 'reset halt'
endif

View File

@ -108,3 +108,45 @@ PROGRAMMER ?= esptool
# Add esptool in the list supported programmers # Add esptool in the list supported programmers
PROGRAMMERS_SUPPORTED += esptool PROGRAMMERS_SUPPORTED += esptool
# The ELFFILE is defined by default in $(RIOTBASE)/Makefile.include but only
# after this file is included, so we need ELFFILE defined earlier.
# This is used to create new make rules in this file (based on FLASHFILE)
# and can't be deferred.
ELFFILE ?= $(BINDIR)/$(APPLICATION).elf
FLASHFILE ?= $(ELFFILE).bin
ESPTOOL ?= $(RIOTTOOLS)/esptool/esptool.py
# This is the binary that ends up programmed in the flash.
$(ELFFILE).bin: $(ELFFILE)
$(Q)$(ESPTOOL) --chip $(FLASH_CHIP) elf2image --flash_mode $(FLASH_MODE) \
--flash_size $(FLASH_SIZE)MB --flash_freq $(FLASH_FREQ) $(FLASH_OPTS) \
-o $@ $<
# Convert .elf and .csv to .bin files at build time, but make them available for
# tests at flash time. These can't be added to FLASHDEPS because they depend on
# on ELFFILE and would trigger a rebuild with "flash-only".
BUILD_FILES += $(FLASHFILE) $(BINDIR)/partitions.bin
TEST_EXTRA_FILES += $(FLASHFILE) $(BINDIR)/partitions.bin
# Default partition table with no OTA. Can be replaced with a custom partition
# table setting PARTITION_TABLE_CSV.
PARTITION_TABLE_CSV ?= $(BINDIR)/partitions.csv
$(BINDIR)/partitions.csv: $(FLASHFILE)
$(Q)printf "\n" > $(BINDIR)/partitions.csv
$(Q)printf "nvs, data, nvs, 0x9000, 0x6000\n" >> $@
$(Q)printf "phy_init, data, phy, 0xf000, 0x1000\n" >> $@
$(Q)printf "factory, app, factory, 0x10000, " >> $@
$(Q)ls -l $< | awk '{ print $$5 }' >> $@
$(BINDIR)/partitions.bin: $(PARTITION_TABLE_CSV)
$(Q)python3 $(RIOTTOOLS)/esptool/gen_esp32part.py --verify $< $@
# Convert .elf and .csv to .bin files at build time, but make them available for
# tests at flash time. These can't be added to FLASHDEPS because they depend on
# on ELFFILE and would trigger a rebuild with "flash-only".
BUILD_FILES += $(FLASHFILE) $(BINDIR)/partitions.bin
TEST_EXTRA_FILES += $(FLASHFILE) $(BINDIR)/partitions.bin

View File

@ -113,6 +113,8 @@
: ${OPENOCD_CMD_RESET_RUN:="-c 'reset run'"} : ${OPENOCD_CMD_RESET_RUN:="-c 'reset run'"}
# Select core on multi-core processors. # Select core on multi-core processors.
: ${OPENOCD_CORE:=} : ${OPENOCD_CORE:=}
# Set to any value to skip verifying after flashing.
: ${OPENOCD_SKIP_VERIFY:=}
# This is an optional offset to the base address that can be used to flash an # This is an optional offset to the base address that can be used to flash an
# image in a different location than it is linked at. This feature can be useful # image in a different location than it is linked at. This feature can be useful
# when flashing images for firmware swapping/remapping boot loaders. # when flashing images for firmware swapping/remapping boot loaders.
@ -328,6 +330,9 @@ do_flash() {
exit $RETVAL exit $RETVAL
fi fi
fi fi
if [ -z "${OPENOCD_SKIP_VERIFY}" ]; then
OPENOCD_VERIFY="-c 'verify_image \"${IMAGE_FILE}\" ${IMAGE_OFFSET}'"
fi
# In case of binary file, IMAGE_OFFSET should include the flash base address # In case of binary file, IMAGE_OFFSET should include the flash base address
# This allows flashing normal binary files without env configuration # This allows flashing normal binary files without env configuration
@ -358,7 +363,7 @@ do_flash() {
${OPENOCD_PRE_FLASH_CMDS} \ ${OPENOCD_PRE_FLASH_CMDS} \
-c 'flash write_image erase \"${IMAGE_FILE}\" ${IMAGE_OFFSET} ${IMAGE_TYPE}' \ -c 'flash write_image erase \"${IMAGE_FILE}\" ${IMAGE_OFFSET} ${IMAGE_TYPE}' \
${OPENOCD_PRE_VERIFY_CMDS} \ ${OPENOCD_PRE_VERIFY_CMDS} \
-c 'verify_image \"${IMAGE_FILE}\" ${IMAGE_OFFSET}' \ ${OPENOCD_VERIFY} \
-c 'reset run' \ -c 'reset run' \
-c 'shutdown'" && -c 'shutdown'" &&
echo 'Done flashing' echo 'Done flashing'

View File

@ -9,19 +9,6 @@ BOOTLOADER_BIN = bootloader$(BOOTLOADER_COLOR)$(BOOTLOADER_INFO).bin
ESPTOOL ?= $(RIOTTOOLS)/esptool/esptool.py ESPTOOL ?= $(RIOTTOOLS)/esptool/esptool.py
# The ELFFILE is defined by default in $(RIOTBASE)/Makefile.include but only
# after the $(PROGRAMMER).inc.mk file is included, so we need ELFFILE defined
# earlier. This is used to create new make rules in this file (based on
# FLASHFILE) and can't be deferred.
ELFFILE ?= $(BINDIR)/$(APPLICATION).elf
FLASHFILE ?= $(ELFFILE).bin
# Convert .elf and .csv to .bin files at build time, but make them available for
# tests at flash time. These can't be added to FLASHDEPS because they depend on
# on ELFFILE and would trigger a rebuild with "flash-only".
BUILD_FILES += $(FLASHFILE) $(BINDIR)/partitions.bin
TEST_EXTRA_FILES += $(FLASHFILE) $(BINDIR)/partitions.bin
# flasher configuration # flasher configuration
ifneq (,$(filter esp_qemu,$(USEMODULE))) ifneq (,$(filter esp_qemu,$(USEMODULE)))
FLASHER = FLASHER =
@ -38,26 +25,6 @@ else
FFLAGS += 0x10000 $(FLASHFILE) FFLAGS += 0x10000 $(FLASHFILE)
endif endif
# This is the binary that ends up programmed in the flash.
$(ELFFILE).bin: $(ELFFILE)
$(Q)$(ESPTOOL) --chip $(FLASH_CHIP) elf2image --flash_mode $(FLASH_MODE) \
--flash_size $(FLASH_SIZE)MB --flash_freq $(FLASH_FREQ) $(FLASH_OPTS) \
-o $@ $<
# Default partition table with no OTA. Can be replaced with a custom partition
# table setting PARTITION_TABLE_CSV.
PARTITION_TABLE_CSV ?= $(BINDIR)/partitions.csv
$(BINDIR)/partitions.csv: $(FLASHFILE)
$(Q)printf "\n" > $(BINDIR)/partitions.csv
$(Q)printf "nvs, data, nvs, 0x9000, 0x6000\n" >> $@
$(Q)printf "phy_init, data, phy, 0xf000, 0x1000\n" >> $@
$(Q)printf "factory, app, factory, 0x10000, " >> $@
$(Q)ls -l $< | awk '{ print $$5 }' >> $@
$(BINDIR)/partitions.bin: $(PARTITION_TABLE_CSV)
$(Q)python3 $(RIOTTOOLS)/esptool/gen_esp32part.py --verify $< $@
.PHONY: esp-qemu .PHONY: esp-qemu
esp-qemu: esp-qemu:

View File

@ -49,13 +49,30 @@ ifneq (,$(OPENOCD_CMD_RESET_RUN))
$(call target-export-variables,reset,OPENOCD_CMD_RESET_RUN) $(call target-export-variables,reset,OPENOCD_CMD_RESET_RUN)
endif endif
OPENOCD_FLASH_TARGETS = flash flash-only OPENOCD_DEBUG_TARGETS = debug debugr debug-server
ifneq (,$(OPENOCD_DBG_EXTRA_CMD))
# Export OPENOCD_DBG_EXTRA_CMD only to the flash/flash-only target
$(call target-export-variables,$(OPENOCD_DEBUG_TARGETS),OPENOCD_DBG_EXTRA_CMD)
endif
OPENOCD_FLASH_TARGETS = flash flash-only flashr
ifneq (,$(IMAGE_OFFSET))
# Export IMAGE_OFFSET only to the flash/flash-only target
$(call target-export-variables,$(OPENOCD_FLASH_TARGETS),IMAGE_OFFSET)
endif
ifneq (,$(OPENOCD_PRE_VERIFY_CMDS)) ifneq (,$(OPENOCD_PRE_VERIFY_CMDS))
# Export OPENOCD_PRE_VERIFY_CMDS only to the flash/flash-only target # Export OPENOCD_PRE_VERIFY_CMDS only to the flash/flash-only target
$(call target-export-variables,$(OPENOCD_FLASH_TARGETS),OPENOCD_PRE_VERIFY_CMDS) $(call target-export-variables,$(OPENOCD_FLASH_TARGETS),OPENOCD_PRE_VERIFY_CMDS)
endif endif
ifneq (,$(OPENOCD_SKIP_VERIFY))
# Export OPENOCD_SKIP_VERIFY only to the flash/flash-only target
$(call target-export-variables,$(OPENOCD_FLASH_TARGETS),OPENOCD_SKIP_VERIFY)
endif
ifneq (,$(OPENOCD_PRE_FLASH_CMDS)) ifneq (,$(OPENOCD_PRE_FLASH_CMDS))
# Export OPENOCD_PRE_FLASH_CMDS only to the flash/flash-only targets # Export OPENOCD_PRE_FLASH_CMDS only to the flash/flash-only targets
$(call target-export-variables,$(OPENOCD_FLASH_TARGETS),OPENOCD_PRE_FLASH_CMDS) $(call target-export-variables,$(OPENOCD_FLASH_TARGETS),OPENOCD_PRE_FLASH_CMDS)