File tree 4 files changed +54
-7
lines changed
4 files changed +54
-7
lines changed Original file line number Diff line number Diff line change @@ -829,11 +829,14 @@ def add_spi_flash_subparsers(
829
829
)
830
830
831
831
if esp .secure_download_mode :
832
- print ("Chip is %s in Secure Download Mode" % esp . CHIP_NAME )
832
+ print (f "Chip is { esp . CHIP_NAME } in Secure Download Mode" )
833
833
else :
834
- print ("Chip is %s" % (esp .get_chip_description ()))
835
- print ("Features: %s" % ", " .join (esp .get_chip_features ()))
836
- print ("Crystal is %dMHz" % esp .get_crystal_freq ())
834
+ print (f"Chip is { esp .get_chip_description ()} " )
835
+ print (f"Features: { ', ' .join (esp .get_chip_features ())} " )
836
+ print (f"Crystal is { esp .get_crystal_freq ()} MHz" )
837
+ usb_mode = esp .get_usb_mode ()
838
+ if usb_mode is not None :
839
+ print (f"USB mode: { usb_mode } " )
837
840
read_mac (esp , args )
838
841
839
842
if not args .no_stub :
Original file line number Diff line number Diff line change @@ -1047,9 +1047,34 @@ def get_uart_no(self):
1047
1047
"""
1048
1048
Read the UARTDEV_BUF_NO register to get the number of the currently used console
1049
1049
"""
1050
- if self .cache ["uart_no" ] is None :
1051
- self .cache ["uart_no" ] = self .read_reg (self .UARTDEV_BUF_NO ) & 0xFF
1052
- return self .cache ["uart_no" ]
1050
+ # Some ESP chips do not have this register
1051
+ try :
1052
+ if self .cache ["uart_no" ] is None :
1053
+ self .cache ["uart_no" ] = self .read_reg (self .UARTDEV_BUF_NO ) & 0xFF
1054
+ return self .cache ["uart_no" ]
1055
+ except AttributeError :
1056
+ return None
1057
+
1058
+ def uses_usb_jtag_serial (self ):
1059
+ """
1060
+ Check if the chip uses USB JTAG/SERIAL mode.
1061
+ """
1062
+ return False
1063
+
1064
+ def uses_usb_otg (self ):
1065
+ """
1066
+ Check if the chip uses USB OTG mode.
1067
+ """
1068
+ return False
1069
+
1070
+ def get_usb_mode (self ):
1071
+ """
1072
+ Get the USB mode of the chip: USB-Serial/JTAG or USB-OTG. If the usb_mode is None, external USB-UART is used.
1073
+ """
1074
+ usb_jtag_serial = self .uses_usb_jtag_serial ()
1075
+ usb_otg = self .uses_usb_otg ()
1076
+
1077
+ return "USB-Serial/JTAG" if usb_jtag_serial else "USB-OTG" if usb_otg else None
1053
1078
1054
1079
@classmethod
1055
1080
def parse_flash_size_arg (cls , arg ):
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ class ESP32H2ROM(ESP32C6ROM):
24
24
RTC_CNTL_SWD_WPROTECT_REG = DR_REG_LP_WDT_BASE + 0x0024 # LP_WDT_SWD_WPROTECT_REG
25
25
RTC_CNTL_SWD_WKEY = 0x50D83AA1 # LP_WDT_SWD_WKEY, same as WDT key in this case
26
26
27
+ UARTDEV_BUF_NO = 0x4084FEFC # Variable in ROM .bss which indicates the port in use
28
+ UARTDEV_BUF_NO_USB_JTAG_SERIAL = 3 # The above var when USB-JTAG/Serial is used
29
+
27
30
FLASH_FREQUENCY = {
28
31
"48m" : 0xF ,
29
32
"24m" : 0x0 ,
Original file line number Diff line number Diff line change @@ -1353,6 +1353,22 @@ def test_auto_detect(self):
1353
1353
self ._check_output (output )
1354
1354
1355
1355
1356
+ class TestUSBMode (EsptoolTestCase ):
1357
+ @pytest .mark .quick_test
1358
+ def test_usb_mode (self ):
1359
+ output = self .run_esptool ("chip_id" )
1360
+ expected_usb_mode = (
1361
+ "USB-OTG"
1362
+ if os .environ .get ("ESPTOOL_TEST_USB_OTG" ) == "1"
1363
+ else "USB-Serial/JTAG"
1364
+ if arg_preload_port
1365
+ else None
1366
+ )
1367
+
1368
+ if expected_usb_mode :
1369
+ assert f"USB mode: { expected_usb_mode } " in output
1370
+
1371
+
1356
1372
@pytest .mark .flaky (reruns = 5 )
1357
1373
@pytest .mark .skipif (arg_preload_port is not False , reason = "USB-to-UART bridge only" )
1358
1374
@pytest .mark .skipif (os .name == "nt" , reason = "Linux/MacOS only" )
You can’t perform that action at this time.
0 commit comments