ESP32 : FTDI 2232 HL + Gdb setup

FTDI 2232


I've redone the wiring of the FTDI so that it's a bit cleaner, with shorter wires

The 3 pins connector is for serial. Why bother ? there is already one on the ESP32 ?
Because each time you reset /stop the chip, the serial usb device disappears and you have to restart the serial console

The one on the FTDI will stay present, so you won't loose the connection

The pinout is  on the left connector:

ESP32 FTDI SIGNAL
GND - GND GND
13     - AD0 TCK
12     - AD1 TDI
14     - AD3 TMS
15     - AD2 TDO

and on the right connector

ESP32 FTDI SIGNAL
GND - GND
RXD - BD0 
TXD - BD1 

GDB

I played a bit with the normal gdb+openOcd setup, it does not work really well.
On the over hand, PlatformIO works without a hitch, so the hardware is fine.

After looking on the tubes, I ended up doing something a bit convoluted :
  • Extract  a .bin from the elf using esptool  (arduino-cmake-stm32 in esp32 mode does that)
  • Extract a .debug from the elf using objcopy
  • Flash the .bin file using the unusual command mon program_esp32 
  • Load the symbol from the debug file, and.... it works :)
Assuming you have the .elf file and the .img.bin file , the following script will do everything automatically :

#
SDK=/home/fx/Arduino/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-
script=$(mktemp /tmp/esp32_gdb.XXXXXXXXX)
EXE=`realpath $1`
BIN=${EXE/elf/img.bin}
${SDK}objcopy --only-keep-debug ${EXE} ${EXE}.debug
DEBUG=${EXE}.debug
echo "EXE =$EXE BIN=$BIN DEBUG=$DEBUG"

cat > ${script} << EOF
target remote :3333
mon reset halt
mon program_esp32 $BIN 0x10000 verify
flushregs

symbol-file   ${DEBUG}
thb app_main
EOF
#/home/fx/Arduino/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb  -x /home/fx/esp32b.gdb  $@
${SDK}gdb -x ${script} 

Img.bin file

I'm using the experimental arduino-cmake-stm32 esp32 mode, so it does generate the .img.bin file automatically.
If not, the gist of it is  :

cp ${PLATFORM_PATH}//tools/partitions/default.csv partitions.csv
python ${PLATFORM_PATH}/tools/gen_esp32part.py --flash-size ${ESP32_FLASH_SIZE}MB -q partitions.csv ${TARGET_NAME}.partitions.bin
python ${PLATFORM_PATH}/tools/esptool/esptool.py --chip esp32 elf2image --flash_mode ${ESP32_FLASH_MODE} --flash_freq ${ESP32_FLASH_SPEED} --flash_size ${ESP32_FLASH_SIZE}MB -o ${TARGET_NAME}.img.bin ${TARGET_NAME}.elf






Comments

Popular posts from this blog

Component tester with STM32 : Part 1 ADC, Resistor

Fixing the INA3221

INA3221, weird wiring