Skip to content

Glasgow does not support Espressif esptool - possible to convert to applet? #575

@victorhooi

Description

@victorhooi

This is related to the Discord chat from here:

https://discord.com/channels/613131135903596547/613461005392936961/1239057227055239269

tl;dr - glasgow does not work in UART mode with ESP devices. @whitequark suggested easiest fix may be to simply implement the esptool functionality as an applet.

I was trying to use the glasgow UART support with esptool, which is the official Espressif tool for interacting with ESPXX/ESPXXXX bootloaders.

This was how I started glasgow in UART mode:

victorhooi@Victors-MacBook-Pro-3 ~/c/g/firmware (main)> glasgow run uart -V 3.3 --pin-tx 1 --pin-rx 0 -b 9600 pty
I: g.device.hardware: device already has bitstream ID 75401762f86c41aae9f5996a07c0b632
I: g.cli: running handler for applet 'uart'
I: g.applet.interface.uart: port(s) A, B voltage set to 3.3 V
/dev/ttys012
W: g.applet.interface.uart: 24 frame errors detected

This is the error I got with esptool:

victorhooi@Victors-MacBook-Pro-3 ~/c/g/firmware (main)> esptool.py -p /dev/ttys012 flash_id
esptool.py v4.7.0
Serial port /dev/ttys012
Connecting...
Failed to get PID of a device on /dev/ttys012, using standard reset sequence.

Traceback (most recent call last):
  File "/opt/homebrew/bin/esptool.py", line 37, in <module>
    esptool._main()
  File "/opt/homebrew/Cellar/esptool/4.7.0_1/libexec/lib/python3.12/site-packages/esptool/__init__.py", line 1139, in _main
    main()
  File "/opt/homebrew/Cellar/esptool/4.7.0_1/libexec/lib/python3.12/site-packages/esptool/__init__.py", line 712, in main
    esp = esp or get_default_connected_device(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/esptool/4.7.0_1/libexec/lib/python3.12/site-packages/esptool/__init__.py", line 1018, in get_default_connected_device
    _esp = detect_chip(
           ^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/esptool/4.7.0_1/libexec/lib/python3.12/site-packages/esptool/__init__.py", line 1018, in get_default_connected_device
    _esp = detect_chip(
           ^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/esptool/4.7.0_1/libexec/lib/python3.12/site-packages/esptool/cmds.py", line 97, in detect_chip
    detect_port.connect(connect_mode, connect_attempts, detecting=True)
  File "/opt/homebrew/Cellar/esptool/4.7.0_1/libexec/lib/python3.12/site-packages/esptool/loader.py", line 678, in connect
    last_error = self._connect_attempt(reset_strategy, mode)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/esptool/4.7.0_1/libexec/lib/python3.12/site-packages/esptool/loader.py", line 563, in _connect_attempt
    reset_strategy()  # Reset the chip to bootloader (download mode)
    ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/esptool/4.7.0_1/libexec/lib/python3.12/site-packages/esptool/reset.py", line 83, in __call__
    self._setDTRandRTS(False, False)
  File "/opt/homebrew/Cellar/esptool/4.7.0_1/libexec/lib/python3.12/site-packages/esptool/reset.py", line 48, in _setDTRandRTS
    "I", fcntl.ioctl(self.port.fileno(), TIOCMGET, struct.pack("I", 0))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 25] Inappropriate ioctl for device

And for comparison - here is esptool working using a tigard as the UART device:

victorhooi@Victors-MacBook-Pro-3 ~/c/g/firmware (main) [2]> esptool.py -p /dev/tty.usbserial-TG1001d00 flash_id
esptool.py v4.7.0
Serial port /dev/tty.usbserial-TG1001d00
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting...
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 48:e7:29:49:1b:19
Uploading stub...
Running stub...
Stub running...
Manufacturer: ef
Device: 4014
Detected flash size: 1MB
Hard resetting via RTS pin...

@whitequark suggested this might be due to some tricks esptool is doing with DTR/RST, and the fact that Glasgow is using a pty (versus the Tigard which uses a real tty at the hardware level).

Metadata

Metadata

Assignees

No one assigned

    Labels

    appletComponent: applet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions