ricardoquesada / bluepad32

Bluetooth gamepad, mouse and keyboard support for ESP32 and PicoW
https://bluepad32.readthedocs.io/
Other
566 stars 59 forks source link

[Bug]: Pico SIGTRAP in Switch IMU parsing #86

Closed ricardoquesada closed 6 months ago

ricardoquesada commented 6 months ago

What happened?

develop branch as of today. Try to pair a genuine Switch controller. While parsing the factory IMU calibration it crashes with SIGTRAT.

Works Ok with ESP32 and Posix.

Aligment issue (???)

Program received signal SIGTRAP, Trace/breakpoint trap.
isr_pendsv () at /opt/src/rpi/pico-sdk/src/rp2_common/pico_standard_link/crt0.S:100
100     decl_isr_bkpt isr_pendsv
(gdb) bt
#0  isr_pendsv () at /opt/src/rpi/pico-sdk/src/rp2_common/pico_standard_link/crt0.S:100
#1  <signal handler called>
#2  process_reply_read_spi_factory_imu_calibration (d=d@entry=0x20002898 <g_devices>,
    data=data@entry=0x2000be25 <hci_packet_with_pre_buffer+33> "\016\377\211\377\220\001", len=len@entry=24)
    at /home/riq/progs/bluepad32/src/components/bluepad32/parser/uni_hid_parser_switch.c:568
#3  0x1002c5e8 in process_reply_spi_flash_read (d=d@entry=0x20002898 <g_devices>, r=r@entry=0x2000be11 <hci_packet_with_pre_buffer+13>, len=len@entry=49)
    at /home/riq/progs/bluepad32/src/components/bluepad32/parser/uni_hid_parser_switch.c:646
#4  0x1002c658 in process_input_subcmd_reply (d=0x20002898 <g_devices>, report=report@entry=0x2000be11 <hci_packet_with_pre_buffer+13> "!x\216",
    len=len@entry=49) at /home/riq/progs/bluepad32/src/components/bluepad32/parser/uni_hid_parser_switch.c:689
#5  0x1002c926 in uni_hid_parser_switch_parse_input_report (d=<optimized out>, report=0x2000be11 <hci_packet_with_pre_buffer+13> "!x\216", len=49)
    at /home/riq/progs/bluepad32/src/components/bluepad32/parser/uni_hid_parser_switch.c:400
#6  0x10024ca0 in uni_hid_parse_input_report (d=0x20002898 <g_devices>, report=report@entry=0x2000be11 <hci_packet_with_pre_buffer+13> "!x\216",
    report_len=report_len@entry=49) at /home/riq/progs/bluepad32/src/components/bluepad32/parser/uni_hid_parser.c:26
#7  0x10026ba8 in uni_bt_bredr_on_l2cap_data_packet (channel=channel@entry=66, packet=packet@entry=0x2000be10 <hci_packet_with_pre_buffer+12> "\241!x\216",
    size=size@entry=50) at /home/riq/progs/bluepad32/src/components/bluepad32/bt/uni_bt_bredr.c:522
#8  0x1002331a in uni_bt_packet_handler (packet_type=<optimized out>, channel=66, packet=0x2000be10 <hci_packet_with_pre_buffer+12> "\241!x\216",
    size=<optimized out>) at /home/riq/progs/bluepad32/src/components/bluepad32/bt/uni_bt.c:479
#9  0x10014e44 in l2cap_dispatch_to_channel (channel=<optimized out>, type=type@entry=6 '\006',
    data=data@entry=0x2000be10 <hci_packet_with_pre_buffer+12> "\241!x\216", size=<optimized out>) at /opt/src/rpi/pico-sdk/lib/btstack/src/l2cap.c:1120
#10 0x10016f6a in l2cap_acl_classic_handler_for_channel (l2cap_channel=0x2000d000 <l2cap_channel_storage+720>,
    packet=packet@entry=0x2000be08 <hci_packet_with_pre_buffer+4> "\v 6", size=size@entry=58) at /opt/src/rpi/pico-sdk/lib/btstack/src/l2cap.c:4613
#11 0x100188ae in l2cap_acl_classic_handler (handle=handle@entry=11, packet=packet@entry=0x2000be08 <hci_packet_with_pre_buffer+4> "\v 6", size=size@entry=58)
    at /opt/src/rpi/pico-sdk/lib/btstack/src/l2cap.c:4670
#12 0x10018e7e in l2cap_acl_handler (packet_type=<optimized out>, channel=<optimized out>, packet=0x2000be08 <hci_packet_with_pre_buffer+4> "\v 6", size=58)
    at /opt/src/rpi/pico-sdk/lib/btstack/src/l2cap.c:4749
#13 0x1000e8a6 in hci_emit_acl_packet (packet=packet@entry=0x2000be08 <hci_packet_with_pre_buffer+4> "\v 6", size=size@entry=58)
    at /opt/src/rpi/pico-sdk/lib/btstack/src/hci.c:7568
#14 0x10013ed2 in acl_handler (packet=packet@entry=0x2000be08 <hci_packet_with_pre_buffer+4> "\v 6", size=size@entry=58)
    at /opt/src/rpi/pico-sdk/lib/btstack/src/hci.c:1246
#15 0x10014052 in packet_handler (packet_type=2 '\002', packet=0x2000be08 <hci_packet_with_pre_buffer+4> "\v 6", size=58)
    at /opt/src/rpi/pico-sdk/lib/btstack/src/hci.c:4491
#16 0x10019bf8 in hci_transport_cyw43_process () at /opt/src/rpi/pico-sdk/src/rp2_common/pico_cyw43_driver/btstack_hci_transport_cyw43.c:146
--Type <RET> for more, q to quit, c to continue without paging--
#17 0x10019c24 in hci_transport_data_source_process (ds=<optimized out>, callback_type=<optimized out>) at /opt/src/rpi/pico-sdk/src/rp2_common/pico_cyw43_driver/btstack_hci_transport_cyw43.c:49
#18 0x1000de10 in btstack_run_loop_base_poll_data_sources () at /opt/src/rpi/pico-sdk/lib/btstack/src/btstack_run_loop.c:166
#19 0x10019a34 in btstack_work_pending (context=<optimized out>, worker=<optimized out>) at /opt/src/rpi/pico-sdk/src/rp2_common/pico_btstack/btstack_run_loop_async_context.c:139
#20 0x100090b4 in async_context_base_execute_once (self=self@entry=0x20000f70 <cyw43_async_context_threadsafe_background>) at /opt/src/rpi/pico-sdk/src/rp2_common/pico_async_context/async_context_base.c:101
#21 0x10008b8a in process_under_lock (self=self@entry=0x20000f70 <cyw43_async_context_threadsafe_background>) at /opt/src/rpi/pico-sdk/src/rp2_common/pico_async_context/async_context_threadsafe_background.c:251
#22 0x10008d3a in low_priority_irq_handler () at /opt/src/rpi/pico-sdk/src/rp2_common/pico_async_context/async_context_threadsafe_background.c:293
#23 <signal handler called>
#24 best_effort_wfe_or_timeout (timeout_timestamp=...) at /opt/src/rpi/pico-sdk/src/common/pico_time/time.c:447
#25 0x200000fc in sem_acquire_block_until (sem=0x20000fa8 <cyw43_async_context_threadsafe_background+56>, until=...) at /opt/src/rpi/pico-sdk/src/common/pico_sync/sem.c:54
#26 0x10008d58 in async_context_threadsafe_background_wait_for_work_until (self_base=<optimized out>, until=...) at /opt/src/rpi/pico-sdk/src/rp2_common/pico_async_context/async_context_threadsafe_background.c:310
#27 0x10019728 in async_context_wait_for_work_until (until=..., context=<optimized out>) at /opt/src/rpi/pico-sdk/src/rp2_common/pico_async_context/include/pico/async_context.h:424
#28 btstack_run_loop_async_context_execute () at /opt/src/rpi/pico-sdk/src/rp2_common/pico_btstack/btstack_run_loop_async_context.c:86
#29 0x1000e0b2 in btstack_run_loop_execute () at /opt/src/rpi/pico-sdk/lib/btstack/src/btstack_run_loop.c:310
#30 0x10000306 in main () at /home/riq/progs/bluepad32/examples/pico_w/src/main.c:38

Bluepad32 Version

I don't know

Bluepad32 version custom

Example: Using Git develop branch commit hash #xxxxxxx

Bluepad32 Platform

None

Platform version

E.g: Arduino IDE 2.1.0, or ESP-IDF v4.4.4, or CircuitPython 8.0.0, etc.

Controller

issues

Microcontroller

ESP32

Microcontroller board

ESP32-S3-WROOM1 DevKit from Lolin. This is the store URL: https://example.com

OS

None

Relevant log output

No response

Relevant sketch

No response