MB3hel / AUVControlBoard

Vectored 6-DOF motion controller for AUVs.
https://mb3hel.github.io/AUVControlBoard/
2 stars 2 forks source link

Deadlock on USB Write #1

Closed MB3hel closed 1 year ago

MB3hel commented 2 years ago

Summary:

Versions Tested: v1, v2

Versions Impacted: v1, v2

Details:

USB communication does not seem to work with debug builds. This impacts v1 and v2 in different ways.

v1 deadlocks. In usbd.c (tinyusb src) the variable _usbd_mutex is zero when usbd_edpt_claim is called. This causes a null handle to be passed to FreeRTOS causing the program to deadlock in configASSERT.

v2 does not deadlock, but USB does not initialize properly (improperly detected by computer).

MB3hel commented 1 year ago

Disabling some compiler settings leads to different results. Likely some form of race condition or out of order initialization.

Compile / link flags disabled:

-ffunction-sections
-fdata-sections
-mlong-calls
-Wl,--gc-sections

New behavior:

MB3hel commented 1 year ago

Possibly caused by a stack overflow occurring (undetected) and having data get overwritten later because it's using memory that doesn't actually belong to the task. This would be a race condition based on task creation order and also explains the wide variation of behavior.

Stack size currently used is smaller than TinyUSB example uses.

MB3hel commented 1 year ago

Problem solved on both platforms (with original and reduced compile options) by increasing stack size for TinyUSB device task. Some restructuring also occurred.