RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

pkg/lwip: use sys/event for handling ISR and bhp

Open maribu opened this issue 2 years ago • 6 comments

Contribution description

This is many providing infrastructure for later use, specifically for making use of the netdev_driver_t::confirm_send(). However, as a positive side-effect, this should prevent lost IRQs. (E.g. consider one netdev saturating the message queue. If now a second netdev would also need its ISR being run, it cannot enqueue its message and the IRQ is lost.)

Testing procedure

The expected failure mode is that no network operation is possible when the ISRs are not being run correctly. I ran make LWIP=1 BOARD=nucleo-f767zi -C examples/gcoap and could still successfully ping the board.

Issues/PRs references

Contains https://github.com/RIOT-OS/RIOT/pull/18357

maribu avatar Jul 22 '22 12:07 maribu

Rebased to include the whitespace only style fixes. This no longer depends on other PRs.

maribu avatar Aug 03 '22 08:08 maribu

This needs a rebase.

benpicco avatar Sep 18 '22 15:09 benpicco

@jia200x: This now largely reverts https://github.com/RIOT-OS/RIOT/pull/18465 and replaces the bhp_msg with bhp_event.

From a quick look into the bhp code, I think this should be correctly wired up to just work. But I do not have the hardware to actually test this.

maribu avatar Sep 19 '22 10:09 maribu

@jia200x: This now largely reverts https://github.com/RIOT-OS/RIOT/pull/18465 and replaces the bhp_msg with bhp_event.

this is definitely the way to go, thanks!

Note that you could also just use event directly, as proposed during the RIOT summit (@kaspar030). The idea of the BHP module was to provide mechanism-agnostic BHP processing. However, we agreed that there's no reason to process IRQ events with a mechanism other than event, so we will likely remove the bhp_xxx modules anyway.

jia200x avatar Sep 19 '22 11:09 jia200x

This breaks RX for me (both wired and wireless) when applied on top of 4b87a300c0ecaa583336f441616f5b7f146059fb

I use BOARD=esp32-ethernet-kit-v1_2 LWIP_IPV4=1 make -C examples/paho-mqtt/ flash

yarrick avatar Sep 19 '22 19:09 yarrick

OK, I just rebased to see if the issue is a result of changes to master being incompatible. However, it works just fine on ARM. I assume that there are some peculiarities in ESP that cause trouble. I will see if I can track them down.

maribu avatar Sep 21 '22 09:09 maribu

Hm any news on this?

benpicco avatar Oct 19 '22 21:10 benpicco

Hm any news on this?

I'm still having trouble to get OpenOCD up an running to be able to properly debug the issue on ESP. (I even gave up on using upstream OpenOCD and used openocd-esp32. Unlike upstream OpenOCD this could indeed flash the ESP32 Ethernet Kit via the FTDI bit-banging JTAG interface. But debugging shows the same errors as the upstream version. Did I mention that the state of the software on ESP is extremely frustrating?)

maribu avatar Oct 20 '22 08:10 maribu

@gschorcht might know more about how to debug esp32

benpicco avatar Oct 20 '22 10:10 benpicco

OK, then let me provide some details on the problem first:

$ USEMODULE=esp_jtag make BOARD=esp32-ethernet-kit-v1_2 BUILD_IN_DOCKER=1 PROGRAMMER=openocd OPENOCD=openocd-esp32 -C examples/default/ flash debug
[...]
### Starting Debugging ###
Open On-Chip Debugger v0.11.0-snapshot (2022-10-17-17:23)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Reading symbols from /home/maribu/Repos/software/RIOT/examples/default/bin/esp32-ethernet-kit-v1_2/default.elf...
Remote debugging using :3333
Remote 'g' packet reply is too long (expected 180 bytes, got 420 bytes): 00040040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000004004096fec51c2500060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
(gdb) start
Temporary breakpoint 1 at 0x400d0024: file /data/riotbuild/riotbase/examples/default/main.c, line 37.
Starting program: /home/maribu/Repos/software/RIOT/examples/default/bin/esp32-ethernet-kit-v1_2/default.elf 
warning: Selected architecture xtensa is not compatible with reported target architecture i386:x86-64
warning: Target-supplied registers are not supported by the current architecture
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x400d0024
Full log output
$ USEMODULE=esp_jtag make BOARD=esp32-ethernet-kit-v1_2 BUILD_IN_DOCKER=1 PROGRAMMER=openocd OPENOCD=openocd-esp32 -C examples/default/ flash debug
make: Entering directory '/home/maribu/Repos/software/RIOT/examples/default'
printf: ‘’: Invalid argument
Launching build container using image "docker.io/riot/riotbuild:latest".
podman run --rm --tty --userns keep-id -v '/etc/zoneinfo/Europe/Berlin:/etc/localtime:ro' -v '/home/maribu/Repos/software/RIOT:/data/riotbuild/riotbase:delegated' -v '/home/maribu/.cargo/registry:/data/riotbuild/.cargo/registry:delegated' -v '/home/maribu/.cargo/git:/data/riotbuild/.cargo/git:delegated' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'RIOTPROJECT=/data/riotbuild/riotbase' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles'    -v '/home/maribu/Repos/software/boards/riot:/data/riotbuild/external/riot:delegated' -v '/home/maribu/Repos/software/miot-pcbs/RIOT/boards:/data/riotbuild/external/boards:delegated'  -e 'BOARD=esp32-ethernet-kit-v1_2' -e 'PROGRAMMER=openocd' -e 'DISABLE_MODULE=' -e 'DEFAULT_MODULE=' -e 'FEATURES_REQUIRED=' -e 'FEATURES_BLACKLIST=' -e 'FEATURES_OPTIONAL=periph_rtc' -e 'USEMODULE=esp_jtag ps saul_default shell shell_cmds_default' -e 'USEPKG='  -w '/data/riotbuild/riotbase/examples/default/' 'docker.io/riot/riotbuild:latest' make 'BOARD=esp32-ethernet-kit-v1_2' 'PROGRAMMER=openocd'  'EXTERNAL_BOARD_DIRS=/data/riotbuild/external/riot /data/riotbuild/external/boards'  
Building application "default" for "esp32-ethernet-kit-v1_2" with MCU "esp32".

"make" -C /data/riotbuild/riotbase/pkg/esp32_sdk/ 
"make" -C /data/riotbuild/riotbase/boards/common/init
"make" -C /data/riotbuild/riotbase/boards/esp32-ethernet-kit-v1_2
"make" -C /data/riotbuild/riotbase/boards/esp32-ethernet-kit-v1_0
"make" -C /data/riotbuild/riotbase/boards/common/esp32
"make" -C /data/riotbuild/riotbase/core
"make" -C /data/riotbuild/riotbase/core/lib
"make" -C /data/riotbuild/riotbase/cpu/esp32
"make" -C /data/riotbuild/riotbase/cpu/esp32/bootloader
esptool.py v3.2-dev
Merged 1 ELF section
"make" -C /data/riotbuild/riotbase/cpu/esp32/esp-idf
"make" -C /data/riotbuild/riotbase/cpu/esp32/esp-idf/common
"make" -C /data/riotbuild/riotbase/cpu/esp32/esp-idf/efuse
"make" -C /data/riotbuild/riotbase/cpu/esp32/esp-idf/gpio
"make" -C /data/riotbuild/riotbase/cpu/esp32/esp-idf-api
"make" -C /data/riotbuild/riotbase/cpu/esp32/freertos
"make" -C /data/riotbuild/riotbase/cpu/esp32/periph
"make" -C /data/riotbuild/riotbase/cpu/esp_common
"make" -C /data/riotbuild/riotbase/cpu/esp_common/esp-xtensa
"make" -C /data/riotbuild/riotbase/cpu/esp_common/freertos
"make" -C /data/riotbuild/riotbase/cpu/esp_common/periph
"make" -C /data/riotbuild/riotbase/cpu/esp_common/vendor
"make" -C /data/riotbuild/riotbase/cpu/esp_common/vendor/xtensa
"make" -C /data/riotbuild/riotbase/drivers
"make" -C /data/riotbuild/riotbase/drivers/periph_common
"make" -C /data/riotbuild/riotbase/drivers/rtt_rtc
"make" -C /data/riotbuild/riotbase/drivers/saul
"make" -C /data/riotbuild/riotbase/drivers/saul/init_devs
"make" -C /data/riotbuild/riotbase/sys
"make" -C /data/riotbuild/riotbase/sys/auto_init
"make" -C /data/riotbuild/riotbase/sys/div
"make" -C /data/riotbuild/riotbase/sys/fmt
"make" -C /data/riotbuild/riotbase/sys/isrpipe
"make" -C /data/riotbuild/riotbase/sys/libc
"make" -C /data/riotbuild/riotbase/sys/luid
"make" -C /data/riotbuild/riotbase/sys/newlib_syscalls_default
"make" -C /data/riotbuild/riotbase/sys/phydat
"make" -C /data/riotbuild/riotbase/sys/pm_layered
"make" -C /data/riotbuild/riotbase/sys/preprocessor
"make" -C /data/riotbuild/riotbase/sys/ps
"make" -C /data/riotbuild/riotbase/sys/random
"make" -C /data/riotbuild/riotbase/sys/rtc_utils
"make" -C /data/riotbuild/riotbase/sys/saul_reg
"make" -C /data/riotbuild/riotbase/sys/shell
"make" -C /data/riotbuild/riotbase/sys/shell/cmds
"make" -C /data/riotbuild/riotbase/sys/stdio_uart
"make" -C /data/riotbuild/riotbase/sys/tsrb
esptool.py v3.2-dev
Merged 1 ELF section
Parsing CSV input...
   text	  data	   bss	   dec	   hex	filename
  61307	 14068	  7142	 82517	 14255	/data/riotbuild/riotbase/examples/default/bin/esp32-ethernet-kit-v1_2/default.elf
/home/maribu/Repos/software/RIOT/dist/tools/openocd/openocd.sh flash /home/maribu/Repos/software/RIOT/examples/default/bin/esp32-ethernet-kit-v1_2/default.elf.bin
### Flashing Target ###
Binfile detected, adding ROM base address: 0x00000000
Flashing with IMAGE_OFFSET: 0x00010000
Open On-Chip Debugger v0.11.0-snapshot (2022-10-17-17:23)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
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 : starting gdb server for esp32.cpu0 on 0
Info : Listening on port 37955 for gdb connections
Info : [esp32.cpu0] Target halted, PC=0x40000400, debug_reason=00000001
Info : [esp32.cpu0] Reset cause (3) - (Software core reset)
Info : Set GDB target to 'esp32.cpu0'
Error: Exception reading cpenable!
Info : [esp32.cpu1] Target halted, PC=0x00000000, debug_reason=00000000
Info : [esp32.cpu1] Reset cause (14) - (CPU1 reset by CPU0)
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0  esp32.cpu0         esp32      little esp32.cpu0         halted
 1* esp32.cpu1         esp32      little esp32.cpu1         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] requesting target halt and executing a soft reset
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] Reset cause (3) - (Software core reset)
Info : [esp32.cpu1] requesting target halt and executing a soft reset
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.
Error: Exception reading cpenable!
Info : [esp32.cpu1] Target halted, PC=0x00000000, debug_reason=00000000
Info : [esp32.cpu1] Reset cause (14) - (CPU1 reset by CPU0)
Info : [esp32.cpu0] Reset cause (3) - (Software core reset)
Installing Bootloader at 0x1000
Info : [esp32.cpu0] Target halted, PC=0x40092612, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 10 KB
Info : Flash mapping 1: 0x20020 -> 0x400d0020, 41 KB
Info : [esp32.cpu0] Target halted, PC=0x40092612, debug_reason=00000001
Info : Auto-detected flash bank 'esp32.cpu1.flash' size 4096 KB
Info : Using flash bank 'esp32.cpu1.flash' size 4096 KB
Info : [esp32.cpu0] Target halted, PC=0x40092612, debug_reason=00000001
Info : PROF: Erased 20480 bytes in 339.303 ms
Info : PROF: Compressed 20480 bytes to 11768 bytes in 1.164000ms
Info : PROF: Data transferred in 42.812 ms @ 268.434 KB/s
Info : [esp32.cpu0] Target halted, PC=0x40092612, debug_reason=00000001
Info : PROF: Wrote 20480 bytes in 752.042 ms (data transfer time included)
auto erase enabled
wrote 20480 bytes from file /home/maribu/Repos/software/RIOT/examples/default/bin/esp32-ethernet-kit-v1_2/esp_bootloader/bootloader.bin in 1.331497s (15.021 KiB/s)

Installing partition table at 0x8000
Info : [esp32.cpu0] Target halted, PC=0x40092612, debug_reason=00000001
Info : PROF: Erased 4096 bytes in 151.619 ms
Info : PROF: Compressed 4096 bytes to 82 bytes in 0.213000ms
Info : PROF: Data transferred in 12.564 ms @ 6.37362 KB/s
Info : [esp32.cpu0] Target halted, PC=0x40092612, debug_reason=00000001
Info : PROF: Wrote 4096 bytes in 680.696 ms (data transfer time included)
auto erase enabled
wrote 4096 bytes from file /home/maribu/Repos/software/RIOT/examples/default/bin/esp32-ethernet-kit-v1_2/partitions.bin in 0.832787s (4.803 KiB/s)

Info : [esp32.cpu0] Target halted, PC=0x40092612, debug_reason=00000001
Info : PROF: Erased 110592 bytes in 1362.1 ms
Info : PROF: Compressed 110592 bytes to 50543 bytes in 5.447000ms
Info : PROF: Data transferred in 392.83 ms @ 125.648 KB/s
Info : [esp32.cpu0] Target halted, PC=0x40092612, debug_reason=00000001
Info : PROF: Wrote 110592 bytes in 1220.37 ms (data transfer time included)
auto erase enabled
wrote 110592 bytes from file /home/maribu/Repos/software/RIOT/examples/default/bin/esp32-ethernet-kit-v1_2/default.elf.bin in 2.588321s (41.726 KiB/s)

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] requesting target halt and executing a soft reset
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] Reset cause (3) - (Software core reset)
Info : [esp32.cpu1] requesting target halt and executing a soft reset
Info : [esp32.cpu0] Core was reset.
Info : [esp32.cpu1] Debug controller was reset.
Info : [esp32.cpu1] Core was reset.
Info : [esp32.cpu0] Target halted, PC=0x4000921A, debug_reason=00000000
Info : [esp32.cpu0] Reset cause (3) - (Software core reset)
Error: Exception reading cpenable!
Info : [esp32.cpu1] Target halted, PC=0x00000000, debug_reason=00000000
Info : [esp32.cpu1] Reset cause (14) - (CPU1 reset by CPU0)
shutdown command invoked
Done flashing
/home/maribu/Repos/software/RIOT/dist/tools/openocd/openocd.sh debug /home/maribu/Repos/software/RIOT/examples/default/bin/esp32-ethernet-kit-v1_2/default.elf
### Starting Debugging ###
Open On-Chip Debugger v0.11.0-snapshot (2022-10-17-17:23)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Reading symbols from /home/maribu/Repos/software/RIOT/examples/default/bin/esp32-ethernet-kit-v1_2/default.elf...
Remote debugging using :3333
Remote 'g' packet reply is too long (expected 180 bytes, got 420 bytes): 00040040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000004004096fec51c2500060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
(gdb) start
Temporary breakpoint 1 at 0x400d0024: file /data/riotbuild/riotbase/examples/default/main.c, line 37.
Starting program: /home/maribu/Repos/software/RIOT/examples/default/bin/esp32-ethernet-kit-v1_2/default.elf 
warning: Selected architecture xtensa is not compatible with reported target architecture i386:x86-64
warning: Target-supplied registers are not supported by the current architecture
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x400d0024

maribu avatar Oct 20 '22 10:10 maribu

OK, then let me provide some details on the problem first:

I don't have any problem on esp32-wrover-kit board to flash the board and to start the debugger with openocd in current master:

USEMODULE=esp_jtag PROGRAMMER=openocd BOARD=esp32-wrover-kit make -C tests/shell flash debug
[...]
### Flashing Target ###
Binfile detected, adding ROM base address: 0x00000000
Flashing with IMAGE_OFFSET: 0x00010000
Open On-Chip Debugger  v0.11.0-esp32-20211220 (2021-12-20-15:42)
[...]
### Starting Debugging ###
Open On-Chip Debugger  v0.11.0-esp32-20211220 (2021-12-20-15:42)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Reading symbols from /home/gs/src/RIOT-Xtensa-ESP.esp-idf-4.4/tests/shell/bin/esp32-wrover-kit/tests_shell.elf...
Remote debugging using :3333
0x40000400 in ?? ()

Did you use the toolchain and the openocd-esp32 version that are pulled by the install script dist/tools/epstools/install.sh?

The following message in your log indicates an incompatibility between the openocd-esp32 and the gdb you are using:

Remote 'g' packet reply is too long (expected 180 bytes, got 420 bytes): 00040040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000004004096fec51c2500060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

gschorcht avatar Oct 20 '22 12:10 gschorcht

OK, so make debug doesn't run gdb-multiarch but rather the hosts GDB.. :-(

maribu avatar Oct 20 '22 13:10 maribu

It does select gdb-multiarch. However upstream GDB doesn't work with ESP's xtensa MCUs:

(gdb) set architecture xtensa
warning: Selected architecture xtensa is not compatible with reported target architecture i386:x86-64
The target architecture is set to "xtensa".

https://github.com/espressif/xtensa-overlays provides patches for each and every MCU product line including for GDB. So with gdb-multiarch I can debug x86_64, x86, ARMv7, ARMv8, z80, 8080, AVR, MSP430, MISP, RISC-V (in any flavor), and so on and so on. But for Espressif's MCUs I apparently now need one magic GDB for every product line? They gotta be kidding me...

maribu avatar Oct 20 '22 18:10 maribu

But for Espressif's MCUs I apparently now need one magic GDB for every product line?

I never tried to use the upstream version of the toolchain. Due to a bunch of problems I had to build the Xtensa toolchains that are working with the binary blobs and the ESP-IDF provided by Espressif, I decided to use the install/setup scripts to make it as easy as possible to download and use the toolchains from Espressif which work out of the box. The Zephyr project does it in same way. I didn't check, but I guess Arduino IDE does it in same way too.

gschorcht avatar Oct 21 '22 05:10 gschorcht

any news on this?

jia200x avatar Nov 21 '22 17:11 jia200x

It still breaks RX on my board (on top of 4c1684f61671138eb9c)

yarrick avatar Nov 23 '22 21:11 yarrick

Since I now have both the hardware (ESP32-Ethernet-Kit_A_V1.2) and the software (magic OpenOCD + magic GDB), I should be able to trace down why this causes regressions on the ESP32. I will hopefully find time for that next week or so.

maribu avatar Nov 23 '22 23:11 maribu

This breaks RX for me (both wired and wireless) when applied on top of 4b87a30

Hm, is there something special to reproduce the problem? I tried to reproduce the problem with WiFi and esp32-wrover-kit.

USEMODULE=esp_wifi WIFI_SSID=... WIFI_PASS=... BOARD=esp32-wrover-kit LWIP_IPV4=1 make -j8 -C examples/paho-mqtt/ flash

It seems to work for me:

> con 192.168.178.46
mqtt_example: Connecting to MQTT Broker from 192.168.178.46 1883
mqtt_example: Trying to connect to 192.168.178.46 , port: 1883
user: clientId: password:
mqtt_example: Connection successfully
> 
> sub temp
mqtt_example: Subscribing to temp
mqtt_example: Now subscribed to temp, QOS 0
> 
> paho_mqtt_example: message received on topic temp: 25

gschorcht avatar Nov 24 '22 17:11 gschorcht

Any news on this?

benpicco avatar Feb 22 '23 14:02 benpicco