ricardoquesada / bluepad32

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

[Bug]: Division by Zero when Connecting JoyCon #44

Closed khoehne closed 1 year ago

khoehne commented 1 year ago

What happened?

While using the template https://gitlab.com/ricardoquesada/esp-idf-arduino-bluepad32-template and trying to connect a right JoyCon an unhandled Dvision by Zero Exception forces the ESP32 to restart.

See log output.

Bluepad32 Version

3.8.3

Bluepad32 version custom

Example: Using Git develop branch commit hash #xxxxxxx

Bluepad32 Platform

Arduino ESP-IDF

Platform version

ESP-IDF v4.4.5

Controller

Right Joycon

ESP32 chip

ESP32

ESP32 board

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

OS

Windows

Relevant log output

--- WARNING: GDB cannot open serial ports accessed as COMx
--- Using \\.\COM17 instead...
--- idf_monitor on \\.\COM17 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6660
load:0x40078000,len:15060
load:0x40080400,len:3824
0x40080400: _init at ??:?

entry 0x4008069c
I (27) boot: ESP-IDF -128-NOTFOUND 2nd stage bootloader
I (27) boot: compile time 13:03:48
I (27) boot: Multicore bootloader
I (31) boot: chip revision: v3.1
I (35) boot.esp32: SPI Speed      : 40MHz
I (40) boot.esp32: SPI Mode       : DIO
I (44) boot.esp32: SPI Flash Size : 4MB
I (49) boot: Enabling RNG early entropy source...
I (54) boot: Partition Table:
I (58) boot: ## Label            Usage          Type ST Offset   Length
I (65) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (72) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (80) boot:  2 factory          factory app      00 00 00010000 00100000
I (87) boot:  3 coredump         Unknown data     01 03 00110000 00010000
I (95) boot: End of partition table
I (99) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=1e604h (124420) map
I (153) esp_image: segment 1: paddr=0002e62c vaddr=3ffbdb60 size=019ech (  6636) load
I (155) esp_image: segment 2: paddr=00030020 vaddr=400d0020 size=6f860h (456800) map
I (324) esp_image: segment 3: paddr=0009f888 vaddr=3ffbf54c size=03c14h ( 15380) load
I (330) esp_image: segment 4: paddr=000a34a4 vaddr=40080000 size=1902ch (102444) load
I (385) boot: Loaded app from partition at offset 0x10000
I (385) boot: Disabling RNG early entropy source...
I (396) cpu_start: Multicore app
I (397) cpu_start: Pro cpu up.
I (397) cpu_start: Starting app cpu, entry point is 0x400813e0
0x400813e0: call_start_cpu1 at C:/Espressif/frameworks/esp-idf-v4.4/components/esp_system/port/cpu_start.c:151

I (0) cpu_start: App cpu up.
I (417) cpu_start: Pro cpu start user code
I (417) cpu_start: cpu freq: 160000000
I (417) cpu_start: Application information:
I (421) cpu_start: Project name:     app-template
I (427) cpu_start: App version:      1
I (431) cpu_start: Compile time:     Sep  6 2023 15:49:03
I (437) cpu_start: ELF file SHA256:  3204b908d80d3976...
I (443) cpu_start: ESP-IDF:          -128-NOTFOUND
I (449) cpu_start: Min chip rev:     v0.0
I (453) cpu_start: Max chip rev:     v3.99
I (458) cpu_start: Chip rev:         v3.1
I (463) heap_init: Initializing. RAM available for dynamic allocation:
I (470) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (476) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (482) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (488) heap_init: At 3FFD29E0 len 0000D620 (53 KiB): DRAM
I (495) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (501) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (507) heap_init: At 4009902C len 00006FD4 (27 KiB): IRAM
I (515) spi_flash: detected chip: generic
I (518) spi_flash: flash io: dio
I (523) esp_core_dump_flash: Init core dump to flash
I (528) esp_core_dump_flash: Found partition 'coredump' @ 110000 65536 bytes
I (555) esp_core_dump_flash: Core dump data checksum is correct
I (555) esp_core_dump_flash: Found core dump 16292 bytes in flash @ 0x110000
luepad32 (C) 2016-2023 Ricardo Quesada and contributors.
Version: v3.8.3
BTStack: Copyright (C) 2017 BlueKitchen GmbH.
Platform: Arduino
Max connected gamepads: 4
BR/EDR support: enabled
BLE support: enabled
Device ID SDP service record size: 64
Gap security level: 2
Periodic Inquiry: max=5, min=4, len=3
I (648) BTDM_INIT: BT controller compile version [7c67f29]
I (655) system_api: Base MAC address is not set
I (659) system_api: read default base MAC address from EFUSE
I (666) BTDM_INIT: Bluetooth MAC: b0:a7:32:27:7b:1a
I (674) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
Bluetooth Allowlist: Disabled
I (1256) console: Command history disabled

Type 'help' to get the list of commands.
Use UP/DOWN arrows to navigate through command history.
Press TAB when typing command name to auto-complete.
BTstack up and running at B0:A7:32:27:7B:1A
HCI not ready, cannot send packet, will again try later. Current state idx=1
BR/EDR scan -> 1
BLE scan -> 1
Firmware: Bluepad32 for Arduino v3.8.3
BD Addr: B0:A7:32:27:7B:1A
Deleting stored BR/EDR link keys:
.
Deleting stored BLE link keys:
.
bp32> Device found: 70:F0:88:DD:41:A4 with COD: 0x002508, pageScan 1, clock offset 0x6c52, rssi 190 dBm, name 'Joy-Con (R)'
Creating device: 70:F0:88:DD:41:A4 (idx=0)
uni_bt_process_fsm, bd addr:70:F0:88:DD:41:A4,  state: 4, incoming:0
Device detected as Nintendo Switch Pro controller: 0x28
uni_bt_process_fsm: Guess controller from name
uni_bt_process_fsm: Starting L2CAP connection
Device found: 70:F0:88:DD:41:A4 with COD: 0x002508, pageScan 1, clock offset 0x6c52, rssi 196 dBm, name 'Joy-Con (R)'
Device already added, waiting (current state=0x09)...
uni_bt_process_fsm, bd addr:70:F0:88:DD:41:A4,  state: 9, incoming:0
--> HCI_EVENT_CONNECTION_COMPLETE
SM_EVENT_PAIRING_STARTED
Identity resolving failed for 70:F0:88:DD:41:A4

--> HCI_EVENT_LINK_KEY_REQUEST:
Device found: 70:F0:88:DD:41:A4 with COD: 0x002508, pageScan 1, clock offset 0x6c52, rssi 190 dBm, name 'Joy-Con (R)'
Device already added, waiting (current state=0x09)...
uni_bt_process_fsm, bd addr:70:F0:88:DD:41:A4,  state: 9, incoming:0
Device found: 70:F0:88:DD:41:A4 with COD: 0x002508, pageScan 1, clock offset 0x6c52, rssi 190 dBm, name 'Joy-Con (R)'
Device already added, waiting (current state=0x09)...
uni_bt_process_fsm, bd addr:70:F0:88:DD:41:A4,  state: 9, incoming:0
SSP User Confirmation Request with numeric value '142039'
SSP User Confirmation Auto accept
--> HCI_EVENT_AUTHENTICATION_COMPLETE_EVENT: status=0, handle=0x0081
L2CAP_EVENT_CHANNEL_OPENED (channel=0x0041)
PSM: 0x0011, local CID=0x0041, remote CID=0x0040, handle=0x0081, incoming=0, local MTU=1691, remote MTU=800, addr=70:F0:88:DD:41:A4
HID Control opened, cid 0x41
uni_bt_process_fsm, bd addr:70:F0:88:DD:41:A4,  state: 10, incoming:0
uni_bt_process_fsm: Create L2CAP interrupt connection
L2CAP_EVENT_CHANNEL_OPENED (channel=0x0042)
PSM: 0x0013, local CID=0x0042, remote CID=0x0041, handle=0x0081, incoming=0, local MTU=1691, remote MTU=800, addr=70:F0:88:DD:41:A4
HID Interrupt opened, cid 0x42
Device 70:F0:88:DD:41:A4 is connected
uni_bt_process_fsm, bd addr:70:F0:88:DD:41:A4,  state: 12, incoming:0
uni_bt_process_fsm: Device is ready
Switch: setup timer timeout, failed state: 0x02
Switch: IMU report enabled
Switch: Firmware version: 3.145. Controller type=2
Switch: IMU calibration info: accel.offset=-6341,0,0, accel.scale=-6656,0,-6341, gyro.offset=0,0,0, gyro.scale=13371,13371,13371
Guru Meditation Error: Core  0 panic'ed (IntegerDivideByZero). Exception was unhandled.

Core  0 register dump:
PC      : 0x400dd919  PS      : 0x00060730  A0      : 0x800d9c50  A1      : 0x3ffbbb00
0x400dd919: parse_imu at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/bluepad32/uni_hid_parser_switch.c:715
 (inlined by) parse_report_30 at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/bluepad32/uni_hid_parser_switch.c:771
 (inlined by) uni_hid_parser_switch_parse_input_report at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/bluepad32/uni_hid_parser_switch.c:396

A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000000  A5      : 0x0000343b
A6      : 0x3ffc5250  A7      : 0x00000001  A8      : 0x3ffc5264  A9      : 0x00000000
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x00000000  A13     : 0x00000000
A14     : 0x3ffbbb24  A15     : 0x00000000  SAR     : 0x0000000e  EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000
0x4000c46c: memset in ROM

0x4000c477: memset in ROM

Backtrace: 0x400dd916:0x3ffbbb00 0x400d9c4d:0x3ffbbb90 0x400dfd8d:0x3ffbbc20 0x400d8051:0x3ffbbc40 0x400f4669:0x3ffbbc60 0x400f02b2:0x3ffbbce0 0x400f5976:0x3ffbbda0 0x400f8ac6:0x3ffbbdd0 0x400ead8f:0x3ffbbe00 0x400df4ab:0x3ffbbe20 0x400d8f1d:0x3ffbbe40 0x400d7c5f:0x3ffbbe60 0x4013dc77:0x3ffbbe80
0x400dd916: parse_imu at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/bluepad32/uni_hid_parser_switch.c:715
 (inlined by) parse_report_30 at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/bluepad32/uni_hid_parser_switch.c:771
 (inlined by) uni_hid_parser_switch_parse_input_report at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/bluepad32/uni_hid_parser_switch.c:396

0x400d9c4d: uni_hid_parse_input_report at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/bluepad32/uni_hid_parser.c:41

0x400dfd8d: uni_bt_bredr_on_l2cap_data_packet at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/bluepad32/uni_bt_bredr.c:535

0x400d8051: uni_bt_packet_handler at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/bluepad32/uni_bt.c:363

0x400f4669: l2cap_dispatch_to_channel at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/btstack/src/l2cap.c:1120
 (inlined by) l2cap_acl_classic_handler_for_channel at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/btstack/src/l2cap.c:4617
 (inlined by) l2cap_acl_classic_handler at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/btstack/src/l2cap.c:4674
 (inlined by) l2cap_acl_handler at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/btstack/src/l2cap.c:4753
 (inlined by) l2cap_acl_handler at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/btstack/src/l2cap.c:4741

0x400f02b2: hci_emit_acl_packet at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/btstack/src/hci.c:7568
 (inlined by) acl_handler at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/btstack/src/hci.c:1246
 (inlined by) packet_handler at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/btstack/src/hci.c:4493

0x400f5976: transport_deliver_packets at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/btstack/btstack_port_esp32.c:191

0x400f8ac6: btstack_run_loop_freertos_execute at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/btstack/platform/freertos/btstack_run_loop_freertos.c:172

0x400ead8f: btstack_run_loop_execute at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/btstack/src/btstack_run_loop.c:310

0x400df4ab: uni_main at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/bluepad32/uni_main.c:53

0x400d8f1d: uni_esp32_main at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/bluepad32/uni_esp32.c:64

0x400d7c5f: app_main at C:/Users/kevin/OneDrive/Source/Espidf/BobbyBluetoothCtrl/components/bluepad32/uni_platform_arduino.c:442

0x4013dc77: main_task at C:/Espressif/frameworks/esp-idf-v4.4/components/freertos/port/port_common.c:141

ELF file SHA256: 3204b908d80d3976

I (11762) esp_core_dump_flash: Save core dump to flash...
I (11768) esp_core_dump_flash: Erase flash 16384 bytes @ 0x110000
I (11840) esp_core_dump_flash: Write end offset 0x3f64, check sum length 4
I (11841) esp_core_dump_flash: Core dump has been saved to flash.
Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6660
load:0x40078000,len:15060
load:0x40080400,len:3824
0x40080400: _init at ??:?

entry 0x4008069c
I (27) boot: ESP-IDF -128-NOTFOUND 2nd stage bootloader
I (27) boot: compile time 13:03:48
I (27) boot: Multicore bootloader
I (31) boot: chip revision: v3.1
I (35) boot.esp32: SPI Speed      : 40MHz
I (40) boot.esp32: SPI Mode       : DIO
I (44) boot.esp32: SPI Flash Size : 4MB
I (49) boot: Enabling RNG early entropy source...
I (54) boot: Partition Table:
I (58) boot: ## Label            Usage          Type ST Offset   Length
I (65) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (72) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (80) boot:  2 factory          factory app      00 00 00010000 00100000
I (87) boot:  3 coredump         Unknown data     01 03 00110000 00010000
I (95) boot: End of partition table
I (99) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=1e604h (124420) map
I (152) esp_image: segment 1: paddr=0002e62c vaddr=3ffbdb60 size=019ech (  6636) load
I (155) esp_image: segment 2: paddr=00030020 vaddr=400d0020 size=6f860h (456800) map
I (323) esp_image: segment 3: paddr=0009f888 vaddr=3ffbf54c size=03c14h ( 15380) load
I (330) esp_image: segment 4: paddr=000a34a4 vaddr=40080000 size=1902ch (102444) load
I (385) boot: Loaded app from partition at offset 0x10000
I (385) boot: Disabling RNG early entropy source...
I (396) cpu_start: Multicore app
I (396) cpu_start: Pro cpu up.
I (397) cpu_start: Starting app cpu, entry point is 0x400813e0
0x400813e0: call_start_cpu1 at C:/Espressif/frameworks/esp-idf-v4.4/components/esp_system/port/cpu_start.c:151

I (388) cpu_start: App cpu up.
I (417) cpu_start: Pro cpu start user code
I (417) cpu_start: cpu freq: 160000000
I (417) cpu_start: Application information:
I (421) cpu_start: Project name:     app-template
I (427) cpu_start: App version:      1
I (431) cpu_start: Compile time:     Sep  6 2023 15:49:03
I (437) cpu_start: ELF file SHA256:  3204b908d80d3976...
I (443) cpu_start: ESP-IDF:          -128-NOTFOUND
I (449) cpu_start: Min chip rev:     v0.0
I (453) cpu_start: Max chip rev:     v3.99 
I (458) cpu_start: Chip rev:         v3.1
I (463) heap_init: Initializing. RAM available for dynamic allocation:
I (470) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (476) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (482) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (488) heap_init: At 3FFD29E0 len 0000D620 (53 KiB): DRAM
I (495) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (501) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (507) heap_init: At 4009902C len 00006FD4 (27 KiB): IRAM
I (515) spi_flash: detected chip: generic
I (518) spi_flash: flash io: dio
I (523) esp_core_dump_flash: Init core dump to flash
I (528) esp_core_dump_flash: Found partition 'coredump' @ 110000 65536 bytes
I (555) esp_core_dump_flash: Core dump data checksum is correct
I (555) esp_core_dump_flash: Found core dump 16228 bytes in flash @ 0x110000
luepad32 (C) 2016-2023 Ricardo Quesada and contributors.
Version: v3.8.3
BTStack: Copyright (C) 2017 BlueKitchen GmbH.
Platform: Arduino
Max connected gamepads: 4
BR/EDR support: enabled
BLE support: enabled
Device ID SDP service record size: 64
Gap security level: 2
Periodic Inquiry: max=5, min=4, len=3
I (652) BTDM_INIT: BT controller compile version [7c67f29]
I (659) system_api: Base MAC address is not set
I (663) system_api: read default base MAC address from EFUSE
I (669) BTDM_INIT: Bluetooth MAC: b0:a7:32:27:7b:1a
I (677) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
Bluetooth Allowlist: Disabled
I (1262) console: Command history disabled

Type 'help' to get the list of commands.
Use UP/DOWN arrows to navigate through command history.
Press TAB when typing command name to auto-complete.
BTstack up and running at B0:A7:32:27:7B:1A
HCI not ready, cannot send packet, will again try later. Current state idx=1
BR/EDR scan -> 1
BLE scan -> 1
Firmware: Bluepad32 for Arduino v3.8.3
BD Addr: B0:A7:32:27:7B:1A
Deleting stored BR/EDR link keys:
70:F0:88:DD:41:A4 - type 4, key: 0B 15 CE 1F 67 32 79 96 02 29 31 DA C1 73 59 12
.
Deleting stored BLE link keys:
.
bp32> --> HCI_EVENT_CONNECTION_REQUEST: link_type = 1 <--
Creating device: 70:F0:88:DD:41:A4 (idx=0)
on_hci_connection_request from: address = 70:F0:88:DD:41:A4, cod=0x0508
--> HCI_EVENT_ROLE_CHANGE
--> HCI_EVENT_CONNECTION_COMPLETE
SM_EVENT_PAIRING_STARTED
Identity resolving failed for 70:F0:88:DD:41:A4

--> HCI_EVENT_LINK_KEY_REQUEST:
Device cannot connect in time, deleting:
        btaddr: 70:F0:88:DD:41:A4
        bt: handle=128 (ACL), ctrl_cid=0x0000, intr_cid=0x0000, cod=0x00000508, flags=0x00000100, incoming=1
        model: vid=0x0000, pid=0x0000, model='Unknown', name=''
        battery: 0 / 255, type=unknown
Disconnecting device: 70:F0:88:DD:41:A4
connection 70:F0:88:DD:41:A4 already in state 0, ignoring
Deleting device: 70:F0:88:DD:41:A4
--> HCI_EVENT_DISCONNECTION_COMPLETE

Relevant sketch

No specific sketch. Just the raw example code for arduino-idf
ricardoquesada commented 1 year ago

fixed https://gitlab.com/ricardoquesada/bluepad32/-/commit/fe8abb6e636e17231ed00c3f9724c957381e459e