adafruit / adafruit/Adafruit_TinyUSB_Arduino

CFG_TUSB_DEBUG=2 Serial deadlock on nRF52840

Open
#419 0 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
C
Stars
654
Forks
183
PR merge metrics
No merged PRs in 30d

Description

### Operating System

MacOS

### Arduino IDE version

1.18.19

### Board

Feather nRF52840 Express

### ArduinoCore version

1.6.1

### TinyUSB Library version

3.1.3

### Sketch as ATTACHED TXT

examples/HID/hid_boot_keyboard

### Compiled Log as ATTACHED TXT

[hid_boot_keyboard.build.log.txt](https://github.com/adafruit/Adafruit_TinyUSB_Arduino/files/15366824/hid_boot_keyboard.build.log.txt)

### What happened ?

Debug output halts partway through TinyUSB initialization. The host cannot enumerate the device. Attaching with GDB shows what appears an infinite loop inside FreeRTOS, due to a corrupted task list.

### How to reproduce ?

* Open the hid_boot_keyboard example sketch.
* Select Debug level 2 and Debug port Serial1
* Compile and upload the sketch
* Monitor output from Serial1
* Observe that debug output seems truncated, and host does not enumerate the device

### Debug Log

```
USBD init on controller 0
sizeof(usbd_device_t) = 56
sizeof(dcd_event_t) = 12
sizeof(tu_fifo_t) = 20
sizeof(tu_edpt_stream_t) = 112
CDC init
MSC init
HID init
VIDEO init
MIDI init
VENDOR init
dcd init
Power USB event: Detected
```

Normal debug log, via SEGGER RTT, on this host continues with:

```
Power USB event: Detected
Power USB event: Ready
USBD Bus Reset : Full Speed

USBD Setup Received 80 06 00 01 00 00 08 00
Get Descriptor Device
Queue EP 80 with 8 bytes ...
USBD Xfer Complete on EP 80 with 8 bytes
Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Bus Reset : Full Speed
```

etc.

Note that SEGGER RTT output currently requires fixing an include statement on nRF52, plus adding `-DUSE_SEGGER_RTT` to defines.

### Screenshots

Backtrace from GDB after deadlock:

```
#0 0x00031132 in vListInsert (pxList=pxList@entry=0x2000a1bc,
pxNewListItem=0x200076f0 )
at /Users/tlyu/Library/Arduino15/packages/adafruit/hardware/nrf52/1.6.1/cores/nRF5/freertos/Source/list.c:150
#1 0x0002f300 in vTaskPlaceOnEventList (
pxEventList=pxEventList@entry=0x2000a1bc, xTicksToWait=4294967295)
at /Users/tlyu/Library/Arduino15/packages/adafruit/hardware/nrf52/1.6.1/cores/nRF5/freertos/Source/tasks.c:2935
#2 0x0002e474 in xQueueSemaphoreTake (xQueue=0x2000a198,
xTicksToWait=, xTicksToWait@entry=4294967295)
at /Users/tlyu/Library/Arduino15/packages/adafruit/hardware/nrf52/1.6.1/cores/nRF5/freertos/Source/queue.c:1533
#3 0x00030986 in Uart::write (size=, buffer=,
this=)
at /Users/tlyu/Library/Arduino15/packages/adafruit/hardware/nrf52/1.6.1/cores/nRF5/Uart.cpp:243
#4 Uart::write (this=0x2000762c ,
buffer=0x2003fe50 "Power USB event: Ready\r\n",
buffer@entry=0x2003fe30 ")
at /Users/tlyu/Library/Arduino15/packages/adafruit/hardware/nrf52/1.6.1/cores/nRF5/Print.h:53
--Type for more, q to quit, c to continue without paging--
#6 log_printf (format=0x35f40 "Power USB event: %s\r\n")
at /Users/tlyu/Library/Arduino15/packages/adafruit/hardware/nrf52/1.6.1/libraries/Adafruit_TinyUSB_Arduino/src/arduino/Adafruit_TinyUSB_API.cpp:89
#7 0x0002ce36 in tusb_hal_nrf_power_event (event=2)
at /Users/tlyu/Library/Arduino15/packages/adafruit/hardware/nrf52/1.6.1/libraries/Adafruit_TinyUSB_Arduino/src/portable/nordic/nrf5x/dcd_nrf5x.c:985
#8
#9 0x0002fdc2 in vPortStartFirstTask ()
at /Users/tlyu/Library/Arduino15/packages/adafruit/hardware/nrf52/1.6.1/cores/nRF5/freertos/portable/GCC/nrf52/port.c:53
#10 0x0002fad2 in xPortStartScheduler ()
at /Users/tlyu/Library/Arduino15/packages/adafruit/hardware/nrf52/1.6.1/cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis.c:240
#11 0x200076d8 in _loopHandle ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce examples/HID/hid_boot_keyboard with Debug level 2 and Serial1, then compare the truncated output with the SEGGER RTT sequence. Start at Adafruit_TinyUSB_API.cpp:89 and portable/nordic/nrf5x/dcd_nrf5x.c:985, following the backtrace into the nRF52 core's Uart.cpp and FreeRTOS files. Done means initialization completes and the nRF52840 enumerates while serial debug remains enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.