I am trying to use a Jlink programmer (arm V9) to upload to the ESP32 via the Uart connection using a Mac computer.
I have confirmed that the programmer sends and receives via Rx and Tx and I am able to program the modules the same way with another usb to serial adapter (mcp2200 based). And I am able to see the serial logs from modules that I programmed with my old programmer.
Where could the problem be in this case? Is there a specific setting required to make PlatformIO handle the serial connection via the jlink programmer correctly?
Thanks,
Nestor
Did you put the ESP32 explicitly into bootloader mode so that it can talk to the UART bootloader? Usually USB-to-Serial adapters utilize the DTR and RTS lines to toggle the EN and GPIO0 pins of the ESP32 in the right order to make it reboot into bootloaderm mode. If you don’t have that connected or available on the JLink, you have to make put it in bootloader mode by yourself. Just ground the GPIO0 pin and powercycle your ESP32, then try uploading again.
Thank you for the feedback! Yes, I have a switch soldered to the boot pin and power cycling the ESP32 before trying to upload. This worked fine with my old mcp2200 programmer.
What’s the full error message when you upload?
Have you tried lower upload speeds, e.g.,
upload_speed = 115200
in the platformio.ini?
I have…
here my log:
Configuring upload protocol…
AVAILABLE: cmsis-dap, esp-bridge, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port…
Auto-detected: /dev/cu.usbmodem0000696527941
Uploading .pio/build/nina_w10/firmware.bin
esptool.py v4.5.1
Serial port /dev/cu.usbmodem0000696527941
Connecting…
A fatal error occurred: Failed to connect to ESP32: No serial data received.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html
*** [upload] Error 2
However, did confirm that the serial connection works both ways with the programmer. When I connect an ESP32 that is already flashed then I can see the serial logs. And I used a 2nd serial adapter on another computer to make sure serial data is being sent via the jlink programmer.
Technically this only confirms that the JLink RX ← ESP32 TX direction works, not JLink TX → ESP32 RX. Are you sure the pins are connected correctly? Does it need any level shifting?
When you reboot the ESP32 with the GPIO0 connected to GND and have a serial monitor open at 115200 baud, what is the output?
I get this log when I reboot the ESP32:
rst:0x1 (POWERON_RESET),boot:0x20 (DOWNLOAD_BOOT(UART0/UART1/SDIO_FEI_FEO_V2))
waiting for download
I am positive that I have the wiring correct since I can send information from the Jlink TX into another serial adapter and I am able to use the other serial adapter to program the ESP32 using the same ESP32 RX…
To my understanding the Jlink adapter uses the Vref pin to adjust the levels, could RX work but not TX if this was the case? I cold scope the levels and compare to my other adapter. However, I feel like there is smtg driver related going on where the Jlink driver maybe doesn’t pass on the start signal of the programming transmission in one or the other direction..
Can you check that there’s continuity between JLink TX and ESP32 RXD0 pin, along with the voltage level put out the by the JLink?
It all seems good.
I guess I could make a small test program that sends serial messages back and forth between the ESP32 and the computer to verify 100% that the connection is fine both ways.
Using https://esptool.spacehuhn.com/ and a Chrome browser, is it able to connect to the board?
It seems to find it but the hard reset fails:
Connecting…
Connected successfully.
Try hard reset.
Error: Couldn’t sync to ESP. Try resetting.
If I disconnect the ESP32 or don’t put it into boot loader it gets stuck on Connecting…
I am wondering if it’s just the character(set) used for the hard reset that is not being passed on by the Jlink adapter.
Interesting. The only last thing I can think of is to update the firmware running on your JLink with the official software (JLinkConfig), see https://kb.segger.com/J-Link_-_Firmware. Otherwise I have no idea what could be wrong here.
Thank you for sending the info and sharing your feedback! So I checked the Jlink Firmware with the configurator and it’s up-to-date.
For a sanity check I also wired up a different BLE module (BL652, based on the nrf52). I can program this one with the Jlink adapter over UART no problem.
I feel like there is an issue between the esptool and jlink. looking at the communication protocol it seems like there is a quite a bit going on to hard reset and identify the ESP32 chip before the firmware is uploaded. Possibly one of these commands either doesn’t get handled by Jlink or espprog defaults to JTAG upload as soon as it identifies the Jlink device.
The reset logic uses DTR/RTS signals of a USB-to-UART adapter to reset the ESP32 – but if the board is already reset into bootloader mode, there should be no need for that.
I am referring to this protocol which comes into play once the device is in bootloader mode:
I feel like either the esptool defaults to jtag mode when it sees the jlink adapter or the jlink adapter suppresses certain commands or characters via uart.