Closed CookiePLMonster closed 1 month ago
Upon closer inspection, this appears to be caused by the FreeRTOS idle task being starved by this idle task: https://freertos.org/Documentation/02-Kernel/02-Kernel-features/01-Tasks-and-co-routines/03-Task-priorities
Each task is assigned a priority from 0 to ( configMAX_PRIORITIES - 1 ), where configMAX_PRIORITIES is defined within FreeRTOSConfig.h. Low priority numbers denote low priority tasks. The idle task has priority zero (tskIDLE_PRIORITY).
Furi threads at Idle priority have priority 1, not 0, so yielding from them will never give time to the idle task. Hence, these values
typedef enum {
FuriThreadPriorityNone = 0, /**< Uninitialized, choose system default */
FuriThreadPriorityIdle = 1, /**< Idle priority */
may need fixing - perhaps PriorityNone
should become -1
, or those Furi priorities need to be bumped one notch up, and priority - 1
should be passed to FreeRTOS? In fact FuriThreadPriorityNone
is unused currently, it's probably only a 'reasonable default'.
EDIT:
furi_thread_start
does UBaseType_t priority = thread->priority ? thread->priority : FuriThreadPriorityNormal;
, so the notion of "None" priority should just go IMO and furi_thread_alloc
should default the priority
field to FuriThreadPriorityNormal
instead.
Describe the bug.
This bug report only mentions the Direct Draw debug app, since it's the easiest to reproduce this issue on that app - however, appears to happen in any other app that is running at an idle priority and only uses yielding to relinquish CPU time.
Attempting to run qFlipper when a Direct Draw debug app runs, then terminating it, and attempting to either:
returns in these actions locking up and failing.
ufbt cli
gets stuck atand never shows the Flipper logo prompt, deployments halt, qFlipper cannot detect the Flipper.
Terminating the app "unstucks" the connections. Also this does not happen with all serial connections, CLI can be started as many times as I wish - the state only locks up after running qFlipper.
As far as I can tell, this is not related to direct drawing, rather to the thread priorities again - as replacing
furi_thread_yield()
withfuri_delay_tick(2)
resolves this issue. However, since the app thread is running at an Idle priority, it should make space for any other task that needs CPU time, I think?Reproduction
ufbt cli
- notice the command goes through and it shows a Flipper prompt.ufbt cli
again - notice it gets stuck at--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
.Target
f7 running on stable 1.0.1 firmware
Logs
No response
Anything else?
No response