fix(PeriphDrivers): Fix MAX32657 flash physical address for TrustZone builds #1642
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.46) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 469 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.368
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1642"
general
weight: 0.35
ttmut
Description
MXC_FLC_ME30_GetPhysicalAddress()turns a flash address into the offset the flash controller expects inFLC_ADDR. It works out that offset fromMXC_FLASH_MEM_BASE/MXC_FLASH_MEM_SIZE, but on the MAX32657 those describe only the flash region of the current build, set bymax32657_memory.mk. That works for a single-image build, where the region is the whole 1 MiB, but gives wrong offsets in TrustZone builds:| Build | Address | Expected offset | Before | After |
|---|---|---|---|---|
| TrustZone Secure (default split) |
0x12000000(info block) |0x100000|0x080000|0x100000|| TrustZone Secure (custom
S_FLASH_SIZE=0x60000) |0x11020000|0x020000|0x000000|0x020000|| TrustZone Secure (custom
S_FLASH_SIZE=0x60000) |0x12000000(info block) |0x100000|0x060000|0x100000|0x80000, the first page of the Non-Secure image, and no error is returned.(MXC_FLASH_MEM_SIZE - 1)only works for a power-of-two region that starts at physical 0. With a custom split such as0x60000, any address with bit 17 set gets the wrong offset;0x11020000maps to page 0, the Secure vector table.The fix computes the offset from the physical flash map instead: clear bit 28 (the security alias bit, as
mpc_me30.calready does) and subtractMXC_PHY_FLASH_MEM_BASE. The info block is placed afterMXC_PHY_FLASH_MEM_SIZE.The expected offsets come from the MAX32657 User Guide (preliminary, 01/21/2025):
N × 0x2000(0x000000–0x0FFFFF). The Secure and Non-Secure addresses are two views of the same flash, so the offset doesn't depend on which one is used.0x30at physical0x0010 0030.Single-image builds are unaffected: for every flash and info-block address they get the same offsets as before. The PR also strips trailing whitespace in the
MXC_FLC_ME30_Flash_Operation()comment.Testing
0x1103E000, then checks page 15 (0x1101E000). Results were confirmed over UART and by reading flash directly over J-Link. The flash driver was built frommain(old) and from this branch (new), each with the single-image size and with a TrustZone Secure custom-split size (MXC_FLASH_MEM_SIZE=0x60000):| Driver | Size | Offset for
0x1103E000| Marker written to ||---|---|---|---|
| old |
0x100000|0x03E000| page 31 (correct) || new |
0x100000|0x03E000| page 31 (correct) || old |
0x60000|0x01E000| page 15 (wrong page) || new |
0x60000|0x03E000| page 31 (correct) |Erasing physical offsets
0x3E000/0x1E000directly withMXC_FLC_RevA_PageErase()cleared0x1103E000/0x1101E000, matching UG Table 7-1. The info block was not touched on hardware.Checklist Before Requesting Review