Skip to content

Run app_main at osPriorityRealtime so Module threads start after initialization - #9

Merged
Jiu-xiao merged 1 commit into
devfrom
fix/default-task-realtime
Oct 5, 2026
Merged

Jiu-xiao merged 1 commit into
devfrom
fix/default-task-realtime

Conversation

@Jiu-xiao

@Jiu-xiao Jiu-xiao commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

app_main runs in the default task at osPriorityNormal (24). With configMAX_PRIORITIES 56 the LibXR priorities are MEDIUM 22, HIGH 33 and REALTIME 44, so a HIGH or REALTIME thread created in a Module constructor preempts app_main while later Modules are not constructed yet. DevC, F103 and OpenCR call app_main() in main() before the scheduler starts, so their initialization is never preempted.

The default task now runs at osPriorityRealtime (48), above every LibXR level; app_main ends in XRobotMain(), which loops on Thread::Sleep(1000), so after initialization the task wakes only once a second and sleeps again.

Check: CubeMX regenerated the project from the edited .ioc; the only source change is the priority in Core/Src/freertos.c. Not run on hardware yet; to be verified on an MC02 board before merging.

Summary by Sourcery

Ensure application startup completes before LibXR threads can preempt module initialization.

Bug Fixes:

  • Prevent module initialization from being interrupted by higher-priority LibXR threads before all modules are constructed.

Enhancements:

  • Run the FreeRTOS default task at realtime priority so application initialization completes before worker threads run, then leave the task sleeping.

Chores:

  • Regenerate the CubeMX project configuration to reflect the default task priority change.

…ialization

app_main runs in the default task at osPriorityNormal (24). With configMAX_PRIORITIES 56 the LibXR levels are MEDIUM 22, HIGH 33 and REALTIME 44, so a HIGH or REALTIME thread created by a Module constructor preempted app_main before the remaining Modules were constructed. The other FreeRTOS BSPs call app_main() before the scheduler starts. The default task now runs at osPriorityRealtime (48); app_main sleeps once initialization is done.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Jiu-xiao, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 12 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 4, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR raises the FreeRTOS default task to osPriorityRealtime, above the LibXR thread priorities, preventing Module-created HIGH or REALTIME threads from preempting app_main during sequential initialization; the generated project metadata was updated accordingly.

Sequence diagram for prioritized app initialization

sequenceDiagram
    participant Scheduler
    participant defaultTask
    participant ModuleThreads

    Scheduler->>defaultTask: app_main()
    Note over defaultTask: osPriorityRealtime 48
    defaultTask->>ModuleThreads: Construct Modules and create threads
    Note over ModuleThreads: LibXR HIGH 33 and REALTIME 44
    ModuleThreads-->>defaultTask: Initialization continues
    defaultTask->>defaultTask: Thread::Sleep(UINT32_MAX)
    Note over defaultTask: Sleeps after initialization
Loading

File-Level Changes

Change Details Files
Raise the FreeRTOS default task priority so initialization completes before LibXR worker threads can run.
  • Change the generated default task priority from osPriorityNormal to osPriorityRealtime.
  • Keep app_main’s post-initialization behavior unchanged, allowing it to sleep indefinitely after setup.
  • Regenerate and update the CubeMX project configuration to preserve the priority setting.
Core/Src/freertos.c
CtrBoard-H7_ALL.ioc

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Jiu-xiao
Jiu-xiao merged commit e8bcaca into dev Oct 5, 2026
5 checks passed
@Jiu-xiao
Jiu-xiao deleted the fix/default-task-realtime branch October 5, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant