mirror of
https://github.com/espressif/esptool.git
synced 2025-10-20 22:09:59 +08:00
feat: print usb mode when output chip info
This commit is contained in:
@@ -829,11 +829,14 @@ def main(argv=None, esp=None):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if esp.secure_download_mode:
|
if esp.secure_download_mode:
|
||||||
print("Chip is %s in Secure Download Mode" % esp.CHIP_NAME)
|
print(f"Chip is {esp.CHIP_NAME} in Secure Download Mode")
|
||||||
else:
|
else:
|
||||||
print("Chip is %s" % (esp.get_chip_description()))
|
print(f"Chip is {esp.get_chip_description()}")
|
||||||
print("Features: %s" % ", ".join(esp.get_chip_features()))
|
print(f"Features: {', '.join(esp.get_chip_features())}")
|
||||||
print("Crystal is %dMHz" % esp.get_crystal_freq())
|
print(f"Crystal is {esp.get_crystal_freq()}MHz")
|
||||||
|
usb_mode = esp.get_usb_mode()
|
||||||
|
if usb_mode is not None:
|
||||||
|
print(f"USB mode: {usb_mode}")
|
||||||
read_mac(esp, args)
|
read_mac(esp, args)
|
||||||
|
|
||||||
if not args.no_stub:
|
if not args.no_stub:
|
||||||
|
@@ -1047,9 +1047,34 @@ class ESPLoader(object):
|
|||||||
"""
|
"""
|
||||||
Read the UARTDEV_BUF_NO register to get the number of the currently used console
|
Read the UARTDEV_BUF_NO register to get the number of the currently used console
|
||||||
"""
|
"""
|
||||||
if self.cache["uart_no"] is None:
|
# Some ESP chips do not have this register
|
||||||
self.cache["uart_no"] = self.read_reg(self.UARTDEV_BUF_NO) & 0xFF
|
try:
|
||||||
return self.cache["uart_no"]
|
if self.cache["uart_no"] is None:
|
||||||
|
self.cache["uart_no"] = self.read_reg(self.UARTDEV_BUF_NO) & 0xFF
|
||||||
|
return self.cache["uart_no"]
|
||||||
|
except AttributeError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def uses_usb_jtag_serial(self):
|
||||||
|
"""
|
||||||
|
Check if the chip uses USB JTAG/SERIAL mode.
|
||||||
|
"""
|
||||||
|
return False
|
||||||
|
|
||||||
|
def uses_usb_otg(self):
|
||||||
|
"""
|
||||||
|
Check if the chip uses USB OTG mode.
|
||||||
|
"""
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_usb_mode(self):
|
||||||
|
"""
|
||||||
|
Get the USB mode of the chip: USB-Serial/JTAG or USB-OTG. If the usb_mode is None, external USB-UART is used.
|
||||||
|
"""
|
||||||
|
usb_jtag_serial = self.uses_usb_jtag_serial()
|
||||||
|
usb_otg = self.uses_usb_otg()
|
||||||
|
|
||||||
|
return "USB-Serial/JTAG" if usb_jtag_serial else "USB-OTG" if usb_otg else None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_flash_size_arg(cls, arg):
|
def parse_flash_size_arg(cls, arg):
|
||||||
|
@@ -24,6 +24,9 @@ class ESP32H2ROM(ESP32C6ROM):
|
|||||||
RTC_CNTL_SWD_WPROTECT_REG = DR_REG_LP_WDT_BASE + 0x0024 # LP_WDT_SWD_WPROTECT_REG
|
RTC_CNTL_SWD_WPROTECT_REG = DR_REG_LP_WDT_BASE + 0x0024 # LP_WDT_SWD_WPROTECT_REG
|
||||||
RTC_CNTL_SWD_WKEY = 0x50D83AA1 # LP_WDT_SWD_WKEY, same as WDT key in this case
|
RTC_CNTL_SWD_WKEY = 0x50D83AA1 # LP_WDT_SWD_WKEY, same as WDT key in this case
|
||||||
|
|
||||||
|
UARTDEV_BUF_NO = 0x4084FEFC # Variable in ROM .bss which indicates the port in use
|
||||||
|
UARTDEV_BUF_NO_USB_JTAG_SERIAL = 3 # The above var when USB-JTAG/Serial is used
|
||||||
|
|
||||||
FLASH_FREQUENCY = {
|
FLASH_FREQUENCY = {
|
||||||
"48m": 0xF,
|
"48m": 0xF,
|
||||||
"24m": 0x0,
|
"24m": 0x0,
|
||||||
|
@@ -1353,6 +1353,22 @@ class TestAutoDetect(EsptoolTestCase):
|
|||||||
self._check_output(output)
|
self._check_output(output)
|
||||||
|
|
||||||
|
|
||||||
|
class TestUSBMode(EsptoolTestCase):
|
||||||
|
@pytest.mark.quick_test
|
||||||
|
def test_usb_mode(self):
|
||||||
|
output = self.run_esptool("chip_id")
|
||||||
|
expected_usb_mode = (
|
||||||
|
"USB-OTG"
|
||||||
|
if os.environ.get("ESPTOOL_TEST_USB_OTG") == "1"
|
||||||
|
else "USB-Serial/JTAG"
|
||||||
|
if arg_preload_port
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
|
if expected_usb_mode:
|
||||||
|
assert f"USB mode: {expected_usb_mode}" in output
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.flaky(reruns=5)
|
@pytest.mark.flaky(reruns=5)
|
||||||
@pytest.mark.skipif(arg_preload_port is not False, reason="USB-to-UART bridge only")
|
@pytest.mark.skipif(arg_preload_port is not False, reason="USB-to-UART bridge only")
|
||||||
@pytest.mark.skipif(os.name == "nt", reason="Linux/MacOS only")
|
@pytest.mark.skipif(os.name == "nt", reason="Linux/MacOS only")
|
||||||
|
Reference in New Issue
Block a user