Month: May 2021

Compiling CANable cangaroo for Linux

In my previous post I commented about the Cando device that I bought from Aliexpress.

Although it is described as a Cando, it is not related to the commercial CAN Analyzer CANdo, maybe the Chinese vendor did it to confuse the user. In fact it is a clone of the CANable device.

The CANable team created a nice interface to use the device, it is called “cangaroo”:
https://canable.io/getting-started.html#cangaroo

They have an executable program for Windows, but don’t have a pre-compiled version for Linux.

Here I’ll describe the steps to do it:

$ git clone https://github.com/normaldotcom/cangaroo
$ sudo apt-get install build-essential git qt5-qmake qtbase5-dev libnl-3-dev libnl-route-3-dev
$ sudo apt install libqt5charts5-dev
$ cd cangaroo
$ qmake -qt=qt5
$ make

Probably it will fail if you care using a recent Linux kernel:

g++ -c -pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_CHARTS_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_XML_LIB -DQT_CORE_LIB -I. -isystem /usr/include/libnl3 -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCharts -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtXml -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I../build/moc -I../build/ui -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o ../build/o/unix/SocketCanInterface.o driver/SocketCanDriver/SocketCanInterface.cpp
driver/SocketCanDriver/SocketCanInterface.cpp: In member function ‘virtual bool SocketCanInterface::readMessage(CanMessage&, unsigned int)’:
driver/SocketCanDriver/SocketCanInterface.cpp:428:28: error: ‘SIOCGSTAMPNS’ was not declared in this scope; did you mean ‘SIOCGSTAMP_OLD’?
428 | if (ioctl(_fd, SIOCGSTAMPNS, &ts_rcv) == 0) {
| ^~~~
| SIOCGSTAMP_OLD
driver/SocketCanDriver/SocketCanInterface.cpp:436:24: error: ‘SIOCGSTAMP’ was not declared in this scope; did you mean ‘SIOCSARP’?
436 | ioctl(_fd, SIOCGSTAMP, &tv_rcv);
| ^~~~ | SIOCSARP driver/SocketCanDriver/SocketCanInterface.cpp: In member function ‘virtual void SocketCanInterface::sendMessage(const CanMessage&)’: driver/SocketCanDriver/SocketCanInterface.cpp:396:9: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result [-Wunused-result] 396 | ::write(_fd, &frame, sizeof(struct can_frame)); | ~^~~~~~~~~~~
make[1]: *** [Makefile:1298: ../build/o/unix/SocketCanInterface.o] Error 1

It is easy to fix, open the file SocketCanInterface.cpp :

$ vi src/driver/SocketCanDriver/SocketCanInterface.cpp

And add this header line:

#include <linux/sockios.h>

Then execute make again:

$ make

And you run the application this way:

$ ./bin/cangaroo

You can also copy it to /usr/local/bin to be able to call it from anyware:

$ sudo cp ./bin/cangaroo /usr/local/bin/

CANDO: Chineware CAN Anazyler

I bought a CANDO board from Aliexpress to use as CAN Anazyler, it was detected correctly by Linux:

[ 4193.476104] usb 1-2: new full-speed USB device number 7 using xhci_hcd
[ 4193.625776] usb 1-2: New USB device found, idVendor=1d50, idProduct=606f, bcdDevice= 0.00
[ 4193.625780] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 4193.625782] usb 1-2: Product: Cando
[ 4193.625783] usb 1-2: Manufacturer: ABF
[ 4193.625784] usb 1-2: SerialNumber: 758AXXX0EXX
[ 4193.663090] CAN device driver interface
[ 4193.669922] gs_usb 1-2:1.0: Configuring for 1 interfaces
[ 4193.670579] usbcore: registered new interface driver gs_usb

You can downlad the software here: https://github.com/codenocold/microbus

This is the link of the board: https://aliexpress.com/item/4001105748495.html

Update: I discovered that this device is just a clone of the Open-Source CANable project, see my post about it: https://acassis.wordpress.com/2021/05/27/compiling-canable-cangaroo-for-linux/

Quectel M95 works on NuttX

NuttShell (NSH) NuttX-9.1.0
nsh> pppd &
pppd [3:100]
nsh> chat: ATZ

~�}#�!}%}!} }$=�~~�}#�!}%}"} }$Y(~+++
Call Ready
ATE1
OK
chat: OK
ATZ
OK
chat: cmd 1, arg ON

chat: cmd 4, arg 30

chat: ATE1

chat: OK AT+QACCM=0,0

ATE1
OK
chat: OK AT+CGDCONT=1,"IP","tim.br"

AT+QACCM=0,0
OK
chat: OK ATD99**1#

AT+CGDCONT=1,"IP","tim.br"
OK
chat: CONNECT
ATD99**1#
CONNECT

nsh> ifconfig
ppp0 Link encap:TUN at UP
inet addr:100.97.122.249 DRaddr:192.168.254.254 Mask:0.0.0.0

nsh> ping 8.8.8.8
PING 8.8.8.8 56 bytes of data
56 bytes from 8.8.8.8: icmp_seq=0 time=800 ms
56 bytes from 8.8.8.8: icmp_seq=1 time=690 ms
56 bytes from 8.8.8.8: icmp_seq=2 time=720 ms
56 bytes from 8.8.8.8: icmp_seq=3 time=610 ms
56 bytes from 8.8.8.8: icmp_seq=4 time=640 ms
56 bytes from 8.8.8.8: icmp_seq=5 time=670 ms
56 bytes from 8.8.8.8: icmp_seq=6 time=560 ms
56 bytes from 8.8.8.8: icmp_seq=7 time=590 ms
56 bytes from 8.8.8.8: icmp_seq=8 time=620 ms
56 bytes from 8.8.8.8: icmp_seq=9 time=650 ms
10 packets transmitted, 10 received, 0% packet loss, time 10100 ms
nsh>

This is my defconfig:

# CONFIG_ARCH_FPU is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDPARMS is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="xxxxx-zz0035"
CONFIG_ARCH_BOARD_XXXXX_ZZ0035=y
CONFIG_ARCH_CHIP="stm32l4"
CONFIG_ARCH_CHIP_STM32L496RE=y
CONFIG_ARCH_CHIP_STM32L4=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARMV7M_STACKCHECK=y
CONFIG_BOARD_LOOPSPERMSEC=8499
CONFIG_BUILTIN=y
CONFIG_CLOCK_MONOTONIC=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_XXXXX_ZZ0035_QUECTEL_M95=y
CONFIG_EXAMPLES_ABNTCODI=y
CONFIG_EXAMPLES_ALARM=y
CONFIG_EXAMPLES_PPPD=y
CONFIG_EXAMPLES_RANDOM=y
CONFIG_FS_PROCFS=y
CONFIG_FS_PROCFS_REGISTER=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_I2C=y
CONFIG_I2CTOOL_MAXBUS=4
CONFIG_I2CTOOL_MINBUS=1
CONFIG_I2C_RESET=y
CONFIG_INTELHEX_BINARY=y
CONFIG_MAX_TASKS=16
CONFIG_MAX_WDOGPARMS=2
CONFIG_MM_REGIONS=2
CONFIG_NET=y
CONFIG_NETDEVICES=y
CONFIG_NETDEV_LATEINIT=y
CONFIG_NETUTILS_PPPD_PAP=y
CONFIG_NET_ARP_SEND=y
CONFIG_NET_ICMP=y
CONFIG_NET_ICMP_SOCKET=y
CONFIG_NET_ROUTE=y
CONFIG_NET_SOCKOPTS=y
CONFIG_NET_TCP=y
CONFIG_NET_UDP=y
CONFIG_NFILE_DESCRIPTORS=8
CONFIG_NFILE_STREAMS=8
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_MQ_MSGS=4
CONFIG_PREALLOC_TIMERS=4
CONFIG_PREALLOC_WDOGS=8
CONFIG_RAM_SIZE=98304
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_RR_INTERVAL=200
CONFIG_RTC_ALARM=y
CONFIG_RTC_DATETIME=y
CONFIG_RTC_DRIVER=y
CONFIG_RTC_IOCTL=y
CONFIG_RTC_NALARMS=2
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SERIAL_TERMIOS=y
CONFIG_SPI=y
CONFIG_STACK_COLORATION=y
CONFIG_STM32L4_DISABLE_IDLE_SLEEP_DURING_DEBUG=y
CONFIG_STM32L4_DMA1=y
CONFIG_STM32L4_DMA2=y
CONFIG_STM32L4_PWR=y
CONFIG_STM32L4_RNG=y
CONFIG_STM32L4_RTC=y
CONFIG_STM32L4_SAI1PLL=y
CONFIG_STM32L4_SRAM2_HEAP=y
CONFIG_STM32L4_UART4=y
CONFIG_STM32L4_USART2=y
CONFIG_STM32L4_USART3=y
CONFIG_SYSTEM_I2CTOOL=y
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_PING=y
CONFIG_SYSTEM_STACKMONITOR=y
CONFIG_SYSTEM_TEE=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_TESTING_OSTEST=y
CONFIG_UART4_SERIAL_CONSOLE=y
CONFIG_USART2_BAUD=110
CONFIG_USART3_IFLOWCONTROL=y
CONFIG_USART3_OFLOWCONTROL=y
CONFIG_USER_ENTRYPOINT="nsh_main"
CONFIG_WDOG_INTRESERVE=1

This is the modification I did in my apps/examples/pppd/pppd_main.c

diff --git a/examples/pppd/pppd_main.c b/examples/pppd/pppd_main.c
index b91b9fd7..186d1845 100644
--- a/examples/pppd/pppd_main.c
+++ b/examples/pppd/pppd_main.c
@@ -54,7 +54,8 @@ static FAR const char connect_script[] =
  "ECHO ON "
  "TIMEOUT 30 "
  "\"\" ATE1 "
- "OK AT+CGDCONT=1,\\"IP\\",\\"internet\\" "
+ "OK AT+QACCM=0,0 "
+ "OK AT+CGDCONT=1,\\"IP\\",\\"tim.br\\" "
  "OK ATD99**1# "
  "CONNECT \c";
@@ -76,10 +77,10 @@ int main(int argc, char *argv[])
  {
  .disconnect_script = disconnect_script,
  .connect_script = connect_script,
- .ttyname = "/dev/ttyS1",
+ .ttyname = "/dev/ttyS2",
 #ifdef CONFIG_NETUTILS_PPPD_PAP
- .pap_username = "user",
- .pap_password = "pass",
+ .pap_username = "tim",
+ .pap_password = "tim",
 #endif
};

Testing Quectel M95 modem

ABCDF
stm32l4_rng_initialize: Initializing RNG

NuttShell (NSH) NuttX-9.1.0
nsh> ls /dev
/dev:
console
null
random
ttyS0
ttyS1
ttyS2
tun
nsh> ifconfig

nsh> pppd &
pppd [3:100]
nsh> chat_tokenise: "" ATZ OK \c
tok_on_delimiter: (0)
tok_on_delimiter: ATZ (0)
tok_on_delimiter: OK (0)
tok_on_delimiter: (1)
chat_tokenise: result 0
chat_internalise: (L)
chat_internalise: (R) ATZ
chat_internalise: (L) OK
chat_internalise: (R)
chat_internalise: result 0, rhs 0
chat_tokens_free: tokens freed
chat_line_run: type 1, rhs ATZ

chachat_expect: result 0
chat_flush: starting
chat_readb: poll timed out
chat_flush: done
chat_send: wrote 5 out of 5 bytes of 'ATZ
'
chat_line_run: type 1, rhs
t: ATZ

chat: OK
chat_readb: poll timed out
chat_expect: result -116
chat_script_run: Script result -116, exited on line 1
chat_tokenise: ECHO ON TIMEOUT 30 "" ATE1 OK AT+QACCM=0,0 OK AT+CGDCONT=1,\"IP\",\"tim.brc
tok_on_delimiter: ECHO (0)
tok_on_delimiter: ON (0)
tok_on_delimiter: TIMEOUT (0)
tok_on_delimiter: 30 (0)
tok_on_delimiter: (0)
tok_on_delimiter: ATE1 (0)
tok_on_delimiter: OK (0)
tok_on_delimiter: AT+QACCM=0,0 (0)
tok_on_delimiter: OK (0)
tok_on_delimiter: AT+CGDCONT=1,"IP","tim.br" (0)
tok_on_delimiter: OK (0)
tok_on_delimiter: ATD991# (0) tok_on_delimiter: CONNECT (0) tok_on_delimiter: (1) chat_tokenise: result 0 chat_internalise: (L) ECHO chat_internalise: (R) ON chat_internalise: (L) TIMEOUT chat_internalise: (R) 30 chat_internalise: (L) chat_internalise: (R) ATE1 chat_internalise: (L) OK chat_internalise: (R) AT+QACCM=0,0 chat_internalise: (L) OK chat_internalise: (R) AT+CGDCONT=1,"IP","tim.br" chat_internalise: (L) OK chat_internalise: (R) ATD991#
chat_internalise: (L) CONNECT
chat_internalise: (R)
chat_internalise: result 0, rhs 0
chat_tokens_free: tokens freed
chat_line_run: type 0, rhs ON

chachat_line_run: type 0, rhs 30

t: cmd 1chat_line_run: timeout is 30 s
chat_line_run: type 1, rhs ATE1

, arg chat_expect: result 0
chat_flush: starting
chat_readb: poll timed out
chat_flush: done
Ochat_send: wrote 6 out of 6 bytes of 'ATE1
'
chat_line_run: type 1, rhs AT+QACCM=0,0

N

chat: cmd 4, arg 30

chat: ATE1

chat: OK AT+QACCM=0,0

chat_readb: poll timed out
chat_expect: result -116
chat_script_run: Script result -116, exited on line 3

Debugging ESP32-S2 using OpenOCD and GDB (part 3)

The only way I got it working was build and flashing the esp-idf hello_main example for ESP32S2 and then:

$ esp32s2openocd -c "set ESP_RTOS none" -f esp32s2_saola.cfg -c "init; halt"
Open On-Chip Debugger v0.10.0-esp32-20210401-13-g5d011fa5 (2021-05-12-12:41)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
none
adapter speed: 3000 kHz

Info : clock speed 3000 kHz
Info : JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Core was reset.
Info : Listening on port 3333 for gdb connections
Info : esp32s2: Target halted, PC=0x400902BE, debug_reason=00000000
Info : Detected ESP32-S2 chip
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f000020, 23 KB
Info : Flash mapping 1: 0x20020 -> 0x40080020, 66 KB
Info : Using flash bank 'esp32s2.irom' size 68 KB
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f000020, 23 KB
Info : Flash mapping 1: 0x20020 -> 0x40080020, 66 KB
Info : Using flash bank 'esp32s2.irom' size 68 KB
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f000020, 23 KB
Info : Flash mapping 1: 0x20020 -> 0x40080020, 66 KB
Info : Using flash bank 'esp32s2.drom' size 24 KB
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f000020, 23 KB
Info : Flash mapping 1: 0x20020 -> 0x40080020, 66 KB
Info : Using flash bank 'esp32s2.drom' size 24 KB
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections

In the second terminal:

$ xtensa-esp32s2-elf-gdb nuttx
GNU gdb (crosstool-NG esp-2020r3) 8.1.0.20180627-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-build_pc-linux-gnu --target=xtensa-esp32s2-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type "help".
Type "apropos word" to search for commands related to "word"…
Reading symbols from nuttx…done.
(gdb) target extended-remote :3333
Remote debugging using :3333
0x400902be in ?? ()
(gdb) mon reset halt
JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
esp32s2: Debug controller was reset.
esp32s2: Core was reset.
esp32s2: Target halted, PC=0x4000FCD5, debug_reason=00000000
esp32s2: Core was reset.
esp32s2: Target halted, PC=0x40000400, debug_reason=00000000
(gdb) flushregs
Register cache flushed.
(gdb) b nx_start
Breakpoint 1 at 0x40080b80: file init/nx_start.c, line 353.
(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.
esp32s2: Target halted, PC=0x40080B80, debug_reason=00000001

Breakpoint 1, nx_start () at init/nx_start.c:353
353 {
(gdb)

Debugging ESP32 using OpenOCD and GDB

Run OpenOCD in the first terminal:

$ openocd -s tcl -c 'set ESP_RTOS none' -f interface/ftdi/esp32_devkitj_v1.cfg -f target/esp32.cfg
Open On-Chip Debugger v0.10.0-esp32-20210401-13-g5d011fa5 (2021-05-12-12:41)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
none
adapter speed: 20000 kHz

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 20000 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32.cpu0: Debug controller was reset.
Info : esp32.cpu0: Core was reset.
Info : Listening on port 3333 for gdb connections
Info : esp32.cpu0: Debug controller was reset.
Info : esp32.cpu0: Debug controller was reset.
Info : esp32.cpu0: Debug controller was reset.
Info : accepting 'gdb' connection on tcp/3333
Info : esp32.cpu0: Target halted, PC=0x400E692C, debug_reason=00000000
Info : Set GDB target to 'esp32.cpu0'
Info : esp32.cpu0: Target halted, PC=0x4009290A, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 7 KB
Info : Flash mapping 1: 0x20020 -> 0x400d0020, 96 KB
Info : esp32.cpu0: Target halted, PC=0x4009290A, debug_reason=00000001
Info : Auto-detected flash bank 'esp32.cpu0.flash' size 4096 KB
Info : Using flash bank 'esp32.cpu0.flash' size 4096 KB
Info : esp32.cpu0: Target halted, PC=0x4009290A, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 7 KB
Info : Flash mapping 1: 0x20020 -> 0x400d0020, 96 KB
Info : Using flash bank 'esp32.cpu0.irom' size 100 KB
Info : esp32.cpu0: Target halted, PC=0x4009290A, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 7 KB
Info : Flash mapping 1: 0x20020 -> 0x400d0020, 96 KB
Info : Using flash bank 'esp32.cpu0.drom' size 8 KB
Info : New GDB Connection: 1, Target esp32.cpu0, state: halted
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32.cpu0: Debug controller was reset.
Info : esp32.cpu0: Core was reset.
Info : esp32.cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
Info : esp32.cpu0: Core was reset.
Info : esp32.cpu0: Target halted, PC=0x40000400, debug_reason=00000000
Info : esp32.cpu1: Debug controller was reset.
Info : esp32.cpu1: Core was reset.
Info : esp32.cpu1: Target halted, PC=0x40000400, debug_reason=00000000
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32.cpu0: Debug controller was reset.
Info : esp32.cpu0: Core was reset.
Info : esp32.cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
Info : esp32.cpu0: Core was reset.
Info : esp32.cpu0: Target halted, PC=0x40000400, debug_reason=00000000
Info : esp32.cpu1: Debug controller was reset.
Info : esp32.cpu1: Core was reset.
Info : esp32.cpu1: Target halted, PC=0x40000400, debug_reason=00000000
Info : esp32.cpu0: Target halted, PC=0x400D0A59, debug_reason=00000001
Info : Set GDB target to 'esp32.cpu0'

In the second terminal run xtensa gdb:

$ xtensa-esp32-elf-gdb nuttx
GNU gdb (crosstool-NG esp-2020r2) 8.1.0.20180627-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-build_pc-linux-gnu --target=xtensa-esp32-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type "help".
Type "apropos word" to search for commands related to "word"…
Reading symbols from nuttx…done.

(gdb) target extended-remote :3333
Remote debugging using :3333
up_idle () at chip/esp32_idle.c:206
206 }

(gdb) mon reset halt
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
esp32.cpu0: Debug controller was reset.
esp32.cpu0: Core was reset.
esp32.cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
esp32.cpu0: Core was reset.
esp32.cpu0: Target halted, PC=0x40000400, debug_reason=00000000
esp32.cpu1: Debug controller was reset.
esp32.cpu1: Core was reset.
esp32.cpu1: Target halted, PC=0x40000400, debug_reason=00000000

(gdb) flushregs
Register cache flushed.

(gdb) b nx_start
Breakpoint 1 at 0x400d0a59: file init/nx_start.c, line 354.

(gdb) mon reset init
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
esp32.cpu0: Debug controller was reset.
esp32.cpu0: Core was reset.
esp32.cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
esp32.cpu0: Core was reset.
esp32.cpu0: Target halted, PC=0x40000400, debug_reason=00000000
esp32.cpu1: Debug controller was reset.
esp32.cpu1: Core was reset.
esp32.cpu1: Target halted, PC=0x40000400, debug_reason=00000000

(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.
esp32.cpu0: Target halted, PC=0x400D0A59, debug_reason=00000001
Set GDB target to 'esp32.cpu0'

Breakpoint 1, nx_start () at init/nx_start.c:354
354 int cpu = 0;
(gdb)

Debugging ESP32-S2 with OpenOCD and GDB part 2

This is the OpenOCD command session:

$ esp32s2openocd -s tcl -c 'set ESP_RTOS none' -f esp32s2_saola.cfg -c "init; reset halt"
Open On-Chip Debugger v0.10.0-esp32-20210401-13-g5d011fa5 (2021-05-12-12:41)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
none
adapter speed: 3000 kHz

Info : clock speed 3000 kHz
Info : JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Target halted, PC=0x4001AA90, debug_reason=00000000
Info : Detected ESP32-S2 chip
Info : Listening on port 3333 for gdb connections
Info : JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Core was reset.
Info : esp32s2: Target halted, PC=0x4000729B, debug_reason=00000000
Info : esp32s2: Core was reset.
Info : esp32s2: Target halted, PC=0x40000400, debug_reason=00000000
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : accepting 'gdb' connection on tcp/3333
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Error: Failed to get flash maps (-6)!
Warn : Application image is invalid! Check configured binary flash offset 'appimage_offset'.
Warn : Failed to get flash mappings (-4)!
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Info : Auto-detected flash bank 'esp32s2.flash' size 4096 KB
Info : Using flash bank 'esp32s2.flash' size 4096 KB
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Error: Failed to get flash maps (-6)!
Warn : Application image is invalid! Check configured binary flash offset 'appimage_offset'.
Warn : Failed to get flash mappings (-4)!
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Info : Using flash bank 'esp32s2.irom' size 0 KB
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Error: Failed to get flash maps (-6)!
Warn : Application image is invalid! Check configured binary flash offset 'appimage_offset'.
Warn : Failed to get flash mappings (-4)!
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Info : Using flash bank 'esp32s2.drom' size 0 KB
Warn : negative reply, retrying
invalid command name "nuttx.pid_offset"
invalid command name "nuttx.xcpreg_offset"
invalid command name "nuttx.state_offset"
invalid command name "nuttx.name_offset"
invalid command name "nuttx.name_size"
Info : JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Core was reset.
Info : esp32s2: Target halted, PC=0x40007286, debug_reason=00000000
Info : esp32s2: Core was reset.
Info : esp32s2: Target halted, PC=0x40000400, debug_reason=00000000
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : The target is not running when halt was requested, stopping GDB.
Warn : target esp32s2 is not halted (gdb fileio)
Warn : xtensa_write_memory: esp32s2: target not halted
Error: esp32s2: Failed to read insn (-304)!
Error: esp32s2: Failed to remove SW breakpoint (-304)!
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Target halted, PC=0x4001126A, debug_reason=00000000
Info : dropped 'gdb' connection

This is the GDB terminal session:

$ xtensa-esp32-elf-gdb nuttx
GNU gdb (crosstool-NG esp-2020r2) 8.1.0.20180627-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-build_pc-linux-gnu --target=xtensa-esp32-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type "help".
Type "apropos word" to search for commands related to "word"…
Reading symbols from nuttx…done.
(gdb) target extended-remote :3333
Remote debugging using :3333
0x40000400 in ?? ()
(gdb) symbol-file nuttx
Load new symbol table from "nuttx"? (y or n) y
Reading symbols from nuttx…done.
invalid command name "nuttx.pid_offset"
invalid command name "nuttx.xcpreg_offset"
invalid command name "nuttx.state_offset"
invalid command name "nuttx.name_offset"
invalid command name "nuttx.name_size"
(gdb) mon reset halt
JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
esp32s2: Debug controller was reset.
esp32s2: Core was reset.
esp32s2: Target halted, PC=0x40007286, debug_reason=00000000
esp32s2: Core was reset.
esp32s2: Target halted, PC=0x40000400, debug_reason=00000000
(gdb) flushregs
Register cache flushed.
(gdb) b __start
Breakpoint 1 at 0x400226b8: file chip/esp32s2_start.c, line 77.
(gdb) c
Continuing.
esp32s2: Debug controller was reset.
esp32s2: Debug controller was reset.
esp32s2: Debug controller was reset.
esp32s2: Debug controller was reset.
esp32s2: Debug controller was reset.
esp32s2: Debug controller was reset.
esp32s2: Debug controller was reset.
esp32s2: Debug controller was reset.
^C
The target is not running when halt was requested, stopping GDB.
Program received signal SIGINT, Interrupt.
0x40000400 in ?? ()
(gdb) quit
A debugging session is active.
Inferior 1 [Remote target] will be detached.
Quit anyway? (y or n) y
Detaching from program: /comum/workspace/Espressif/NuttX/nuttx/nuttx, Remote target

Debugging ESP32-S2 with OpenOCD and GDB

$ openocd -f esp32s2_saola.cfg
Open On-Chip Debugger v0.10.0-esp32-20210401-13-g5d011fa5 (2021-05-12-12:41)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
adapter speed: 3000 kHz

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 3000 kHz
Info : JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Target halted, PC=0x40000400, debug_reason=00000000
Info : Detected ESP32-S2 chip
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
Warn : No symbols for FreeRTOS!
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Error: Failed to get flash maps (-6)!
Warn : Application image is invalid! Check configured binary flash offset 'appimage_offset'.
Warn : Failed to get flash mappings (-4)!
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Info : Auto-detected flash bank 'esp32s2.flash' size 4096 KB
Info : Using flash bank 'esp32s2.flash' size 4096 KB
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Error: Failed to get flash maps (-6)!
Warn : Application image is invalid! Check configured binary flash offset 'appimage_offset'.
Warn : Failed to get flash mappings (-4)!
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Info : Using flash bank 'esp32s2.irom' size 0 KB
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Error: Failed to get flash maps (-6)!
Warn : Application image is invalid! Check configured binary flash offset 'appimage_offset'.
Warn : Failed to get flash mappings (-4)!
Info : esp32s2: Target halted, PC=0x40031CAA, debug_reason=00000001
Info : Using flash bank 'esp32s2.drom' size 0 KB
Warn : negative reply, retrying
Warn : RTOS FreeRTOS not detected. (GDB could not find symbol 'pxCurrentTCB')
Warn : RTOS FreeRTOS not detected. (GDB could not find symbol 'pxCurrentTCB')
Warn : RTOS FreeRTOS not detected. (GDB could not find symbol 'pxCurrentTCB')
invalid command name "nuttx.pid_offset"
invalid command name "nuttx.xcpreg_offset"
invalid command name "nuttx.state_offset"
invalid command name "nuttx.name_offset"
invalid command name "nuttx.name_size"
Info : JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Core was reset.
Info : esp32s2: Target halted, PC=0x40007299, debug_reason=00000000
Info : esp32s2: Core was reset.
Info : esp32s2: Target halted, PC=0x40000400, debug_reason=00000000
Info : JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Core was reset.
Info : esp32s2: Target halted, PC=0x4000F99B, debug_reason=00000000
Info : esp32s2: Core was reset.
Info : esp32s2: Target halted, PC=0x40000400, debug_reason=00000000
Warn : address 0x400804b0 not writable
Error: esp32s2: Failed to write breakpoint instruction (-4)!
Error: esp32s2: Failed to add SW breakpoint!
Error: can't add breakpoint: unknown reason

In another terminal execute:

$ xtensa-esp32-elf-gdb nuttx
GNU gdb (crosstool-NG esp-2020r2) 8.1.0.20180627-git
Copyright (C) 2018 Free Software Foundation, Inc.
…
Reading symbols from nuttx…done.

(gdb) target extended-remote :3333
Remote debugging using :3333
0x4001276f in ?? ()

(gdb) symbol-file nuttx
Load new symbol table from "nuttx"? (y or n) y
Reading symbols from nuttx…done.
invalid command name "nuttx.pid_offset"
invalid command name "nuttx.xcpreg_offset"
invalid command name "nuttx.state_offset"
invalid command name "nuttx.name_offset"
invalid command name "nuttx.name_size"

(gdb) set remote hardware-watchpoint-limit 2

(gdb) mon reset halt
JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
esp32s2: Debug controller was reset.
esp32s2: Core was reset.
esp32s2: Target halted, PC=0x40007299, debug_reason=00000000
esp32s2: Core was reset.
esp32s2: Target halted, PC=0x40000400, debug_reason=00000000

(gdb) flushregs
Register cache flushed.

(gdb) b __start
Breakpoint 1 at 0x400226b8: file chip/esp32s2_start.c, line 77.

(gdb) b nx_start
Breakpoint 2 at 0x400804b0: file init/nx_start.c, line 353.

(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /comum/workspace/Espressif/NuttX/nuttx/nuttx
Warning:
Cannot insert breakpoint 2.
Cannot access memory at address 0x400804b0

Command aborted.

(gdb) c
Continuing.
Warning:
Cannot insert breakpoint 2.
Cannot access memory at address 0x400804b0

Command aborted.
(gdb)