Skip to content

Commit

Permalink
Merge branch 'espressif:master' into main_work
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2866 authored Feb 1, 2024
2 parents 643220f + bc9f2a6 commit 8938bb7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
30 changes: 24 additions & 6 deletions esptool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,13 @@ def add_spi_flash_subparsers(
"Keeping initial baud rate %d" % initial_baud
)

def _define_spi_conn(spi_connection):
"""Prepare SPI configuration string and value for flash_spi_attach()"""
clk, q, d, hd, cs = spi_connection
spi_config_txt = f"CLK:{clk}, Q:{q}, D:{d}, HD:{hd}, CS:{cs}"
value = (hd << 24) | (cs << 18) | (d << 12) | (q << 6) | clk
return spi_config_txt, value

# Override the common SPI flash parameter stuff if configured to do so
if hasattr(args, "spi_connection") and args.spi_connection is not None:
spi_config = args.spi_connection
Expand All @@ -790,15 +797,26 @@ def add_spi_flash_subparsers(
esp.check_spi_connection(args.spi_connection)
# Encode the pin numbers as a 32-bit integer with packed 6-bit values,
# the same way the ESP ROM takes them
clk, q, d, hd, cs = args.spi_connection
spi_config = f"CLK:{clk}, Q:{q}, D:{d}, HD:{hd}, CS:{cs}"
value = (hd << 24) | (cs << 18) | (d << 12) | (q << 6) | clk
spi_config, value = _define_spi_conn(args.spi_connection)
print(f"Configuring SPI flash mode ({spi_config})...")
esp.flash_spi_attach(value)
elif args.no_stub:
print("Enabling default SPI flash mode...")
# ROM loader doesn't enable flash unless we explicitly do it
esp.flash_spi_attach(0)
if esp.CHIP_NAME != "ESP32" or esp.secure_download_mode:
print("Enabling default SPI flash mode...")
# ROM loader doesn't enable flash unless we explicitly do it
esp.flash_spi_attach(0)
else:
# ROM doesn't attach in-package flash chips
spi_chip_pads = esp.get_chip_spi_pads()
spi_config_txt, value = _define_spi_conn(spi_chip_pads)
if spi_chip_pads != (0, 0, 0, 0, 0):
print(
"Attaching flash from eFuses' SPI pads configuration"
f"({spi_config_txt})..."
)
else:
print("Enabling default SPI flash mode...")
esp.flash_spi_attach(value)

# XMC chip startup sequence
XMC_VENDOR_ID = 0x20
Expand Down
17 changes: 17 additions & 0 deletions esptool/targets/esp32.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class ESP32ROM(ESPLoader):
SPI_MISO_DLEN_OFFS = 0x2C
EFUSE_RD_REG_BASE = 0x3FF5A000

EFUSE_BLK0_RDATA3_REG_OFFS = EFUSE_RD_REG_BASE + 0x00C
EFUSE_BLK0_RDATA5_REG_OFFS = EFUSE_RD_REG_BASE + 0x014

EFUSE_DIS_DOWNLOAD_MANUAL_ENCRYPT_REG = EFUSE_RD_REG_BASE + 0x18
EFUSE_DIS_DOWNLOAD_MANUAL_ENCRYPT = 1 << 7 # EFUSE_RD_DISABLE_DL_ENCRYPT

Expand Down Expand Up @@ -277,6 +280,20 @@ def get_chip_features(self):

return features

def get_chip_spi_pads(self):
"""Read chip spi pad config
return: clk, q, d, hd, cd
"""
efuse_blk0_rdata5 = self.read_reg(self.EFUSE_BLK0_RDATA5_REG_OFFS)
spi_pad_clk = efuse_blk0_rdata5 & 0x1F
spi_pad_q = (efuse_blk0_rdata5 >> 5) & 0x1F
spi_pad_d = (efuse_blk0_rdata5 >> 10) & 0x1F
spi_pad_cs = (efuse_blk0_rdata5 >> 15) & 0x1F

efuse_blk0_rdata3_reg = self.read_reg(self.EFUSE_BLK0_RDATA3_REG_OFFS)
spi_pad_hd = (efuse_blk0_rdata3_reg >> 4) & 0x1F
return spi_pad_clk, spi_pad_q, spi_pad_d, spi_pad_hd, spi_pad_cs

def read_efuse(self, n):
"""Read the nth word of the ESP3x EFUSE region."""
return self.read_reg(self.EFUSE_RD_REG_BASE + (4 * n))
Expand Down

0 comments on commit 8938bb7

Please sign in to comment.