Skip to content

Keep afatfs_poll out of scheduler() to free F7 ITCM_RAM - #12169

Merged
sensei-hacker merged 1 commit into
iNavFlight:maintenance-10.xfrom
sensei-hacker:itcm-noinline-afatfs-poll
Oct 18, 2026
Merged

sensei-hacker merged 1 commit into
iNavFlight:maintenance-10.xfrom
sensei-hacker:itcm-noinline-afatfs-poll

Conversation

@sensei-hacker

Copy link
Copy Markdown
Member

Summary

On F7 targets, scheduler() is FAST_CODE, and LTO inlines afatfs_poll() into it through taskRunRealtimeCallbacks(). The SD-card state machine therefore takes ITCM_RAM although it only runs on the idle path and waits on a card that is far slower than the code.

Design

afatfs_poll() is marked NOINLINE, so it stays in flash behind one call from scheduler(). NOINLINE expands to nothing on targets without ITCM_RAM, so only F7 and H7 change. Behaviour is unchanged; this only affects code placement.

This matters now because KAKUTEF7 has about 150 B of ITCM_RAM left, and data-ready reads on F7 (#12065) add about 190 B to the FAST_CODE functions and overflow it by 40 B.

Testing

Built with stock linker scripts, compared with the parent commit:

Target ITCM_RAM before ITCM_RAM after FLASH1
KAKUTEF7 16232 B 15288 B (-944) -84 B
MATEKF722SE 12360 B 11432 B (-928) -80 B

MATEKF405, MATEKH743 and SITL also build. The firmware unit tests pass (620/620).

Not tested: SD-card logging on hardware, in SITL or otherwise. The change does not alter control flow, but nobody has run the SD path with it.

Code review

Reviewed with the inav-code-review agent: no critical or important findings.

…-card code

LTO inlines afatfs_poll() into scheduler() through taskRunRealtimeCallbacks().
scheduler() is FAST_CODE, so the SD-card state machine was linked into ITCM_RAM
although it only runs on the idle path and waits on a much slower card.

Marking afatfs_poll() NOINLINE keeps it in flash behind a single call. The
macro expands to nothing on targets without ITCM_RAM, so only F7 and H7 change.
ITCM_RAM use drops by 944 B on KAKUTEF7 (16232 to 15288) and 928 B on
MATEKF722SE (12360 to 11432); flash is about 80 B smaller on both.
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can move or hide resolved findings to focus on what still needs action

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Keep SD-card polling out of scheduler ITCM on F7 and H7

✨ Enhancement 🕐 Less than 10 minutes

Grey Divider

AI Description

• Prevent SD-card polling from being inlined into the FAST_CODE scheduler on F7 and H7.
• Keep the polling code in flash to free ITCM_RAM without changing filesystem behavior.
Diagram

graph TD
    scheduler["FAST_CODE scheduler"] --> callbacks["Realtime callbacks"] --> poll["Filesystem polling"] --> sdcard["SD card work"]
    scheduler --> itcm[("ITCM RAM")]
    poll --> flash[("Flash code")]
Loading
High-Level Assessment

Keep the targeted NOINLINE annotation: it prevents this large, idle-path function from consuming scheduler ITCM without constraining other realtime callbacks. Marking the entire callback function NOINLINE would impose a broader inlining restriction.

Files changed (1) +3 / -1

Enhancement (1) +3 / -1
asyncfatfs.cPrevent afatfs_poll from inlining into the scheduler +3/-1

Prevent afatfs_poll from inlining into the scheduler

• Adds NOINLINE to afatfs_poll and documents the ITCM rationale. The macro applies the attribute on F7 and H7 and expands to nothing on other targets.

src/main/io/asyncfatfs/asyncfatfs.c

@github-actions

Copy link
Copy Markdown

RAM / Flash usage vs. base commit 01a7aa3 — commit f7feede

Using the nearest available size baseline: this build contains base commit 29ec86e, which has no stored baseline yet, so the deltas also include what was merged to the base since 01a7aa3.

Target Flash Δ RAM Δ
MATEKF405 ±0 B (±0.00%) CCM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)
MATEKF722 -80 B (-0.02%) ITCM_RAM: -928 B (-7.40%)
RAM: ±0 B (±0.00%)
TCM: ±0 B (±0.00%)
MATEKF765 -72 B (-0.01%) DTCM_RAM: ±0 B (±0.00%)
SRAM1: ±0 B (±0.00%)
MATEKH743 +8 B (+0.00%) D2_RAM: ±0 B (±0.00%)
DTCM_RAM: ±0 B (±0.00%)
ITCM_RAM: -952 B (-5.80%)
RAM: ±0 B (±0.00%)

See RAM/flash optimization guide for techniques to reduce usage.

@github-actions

Copy link
Copy Markdown

Test firmware build ready — commit f7feede

Download firmware for PR #12169

251 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

@sensei-hacker
sensei-hacker merged commit 13ebed9 into iNavFlight:maintenance-10.x Oct 18, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant