← Back to Pull requests

fix(PeriphDrivers): Fix MAX32657 flash physical address for TrustZone builds #1642

Closed
unknown closed this pull request without merging on Nov 19, 2026 12:25 UTC
View on GitHub
unknown unknown commented on Oct 29, 2026 05:20 UTC
Author

Description

MXC_FLC_ME30_GetPhysicalAddress() turns a flash address into the offset the flash controller expects in FLC_ADDR. It works out that offset from MXC_FLASH_MEM_BASE/MXC_FLASH_MEM_SIZE, but on the MAX32657 those describe only the flash region of the current build, set by max32657_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 |

  • Info block: the offset was placed after the current build's region rather than after the whole flash. In a default Secure TrustZone build, an info-block write or erase lands at 0x80000, the first page of the Non-Secure image, and no error is returned.

  • Main flash: masking with (MXC_FLASH_MEM_SIZE - 1) only works for a power-of-two region that starts at physical 0. With a custom split such as 0x60000, any address with bit 17 set gets the wrong offset; 0x11020000 maps 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.c already does) and subtract MXC_PHY_FLASH_MEM_BASE. The info block is placed after MXC_PHY_FLASH_MEM_SIZE.

    The expected offsets come from the MAX32657 User Guide (preliminary, 01/21/2025):

  • Table 7-1: writes and erases use a physical offset where page N starts at 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.

  • Section 6.2.1: "The information block is mapped physically to the end of the internal flash memory", with info-block offset 0x30 at physical 0x0010 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


  • Hardware (MAX32657EVKIT). A single-image test program erases page 31 and writes a 16-byte marker at 0x1103E000, then checks page 15 (0x1101E000). Results were confirmed over UART and by reading flash directly over J-Link. The flash driver was built from main (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/0x1E000 directly with MXC_FLC_RevA_PageErase() cleared 0x1103E000/0x1101E000, matching UG Table 7-1. The info block was not touched on hardware.

    Checklist Before Requesting Review

  • PR Title follows correct guidelines.

  • Description of changes and all other relevant information.

  • (Optional) Link any related GitHub issues using a keyword

  • (Optional) Provide info on any relevant functional testing/validation. For API changes or significant features, this is not optional.
  • Diff: 469 lines (+351 / -118) across 5 files Reviewer: ttmut Review duration: 30665m
    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
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.7% (MEDIUM) · Higher = larger blast radius
    45.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.8% · Safe to merge
    19.8%