MSPM0L1117 Dual-Bank Flash in Practice: 128KB Partitioning Strategy and OTA Upgrade Pitfall Avoidance Guide

Hong Kong STY Technology Co., Limited 57

Did your OTA upgrade brick the device again? 128KB of flash memory should be sufficient, yet partitioning leads to numerous pitfalls—Bootloader encroaches on application space, power loss causes firmware loss, and rollback mechanisms are missing. The MSPM0L1117's dual-bank flash architecture was designed for reliable OTA updates, but the official manual never explains how to achieve optimal partitioning for a 128KB capacity. Based on real-world mass-production projects, this article dissects the underlying logic of Bank A/B switching and presents a practical partitioning scheme along with fault-tolerant upgrade design.

Analysis of the MSPM0L1117 Dual-Bank Flash Architecture

MSPM0L1117 Flash Memory Map Bank A (Low 64KB) 0x0000_0000 - 0x0000_FFFF App Code / Data Config Area (Shared) Reserved / Bootloader Bank B (High 64KB) 0x0001_0000 - 0x0001_FFFF Application Code / Data Config Area (Shared) Bootloader (Fixed) BANK_SWAP

The MSPM0L1117's 128KB Flash uses a physical dual-bank design, with Bank A and Bank B mirroring each other and supporting hardware-level address remapping. The core advantage of this architecture is that the current running firmware does not need to be interrupted during an upgrade, truly enabling "upgrade while running."

128KB Bank A/B Physical Mapping and Protection Mechanism

The dual-bank physical address space ranges from 0x0000_0000 to 0x0001_FFFF, with Bank A fixed at the lower 64 KB (0x0000_0000–0x0000_FFFF) and Bank B occupying the upper 64 KB (0x0001_0000–0x0001_FFFF). The BANK_SWAP bit in the critical FLASH_CONF register controls runtime bank switching; after switching, address 0 seen by the CPU actually points to the other physical bank.

The protection mechanism has three levels: sector-level erase/write protection (32 sectors × 4 KB), bank-level read-only lock, and global debug port disable. During mass production, it is recommended to enable BSL (Bootloader Security Level) locking to prevent unauthorized reading of upgrade packages.

RWW Feature and Interrupt Safe Window

Read-While-Write allows the CPU to execute code from Bank A while writing new firmware to Bank B. However, there are key constraints: read and write operations cannot be performed in parallel within the same bank, and an erase operation will block all accesses to that bank for approximately 20 ms. The interrupt service routine must reside in the currently active bank; otherwise, a bus error will occur.

Practical recommendation: Copy the critical interrupt vector table to SRAM, and during the upgrade, disable non-essential interrupts, keeping only the watchdog timer and communication timeout timer enabled.

128KB Partitioning Strategy: Optimal Solution for Three Types of Scenarios

Partitioning is the first critical step determining the success or failure of OTA. Although 128 KB may seem ample, after accounting for the bootloader, configuration area, and log area, the actual available space for the application is often reduced to less than 50%.

Symmetric Dual-Partition Scheme (60 KB + 60 KB): Standard OTA Scenarios

The 8KB bootloader is fixed at the top of the Flash memory (0x0001_F000-0x0001_FFFF), with the remaining 120KB evenly divided. Each 60KB section accommodates application code and data, while an 8KB shared configuration area stores the version number, upgrade flag, and rollback count. This scheme is suitable for applications under 45KB in size that require frequent full upgrades.

RegionAddress RangeSizeDescription
Bank A0x0000_0000-0x0000_EFFF60KBRunning area or upgrade target area
Bank B0x0001_0000-0x0001_EFFF60KBRunning area or upgrade target area
Configuration Area0x0000_F000-0x0000_F7FF2KBShared by both banks, with power-loss protection
Bootloader0x0001_F000-0x0001_FFFF4KBNon-upgradable, hardware-locked

Asymmetric partitioning scheme (48KB+80KB): Large application + streamlined bootloader

When the application grows beyond 55KB, the symmetric scheme becomes insufficient. Bank A is compressed to 48KB as a "golden firmware" backup area, while Bank B is expanded to 80KB to host the main application. The bootloader is streamlined to 4KB, retaining only communication, verification, and switching functions; application upgrades use differential packages.

This scheme sacrifices rollback flexibility—older versions in Bank A have limited functionality—but gains a 33% increase in main application space. It is suitable for consumer-grade products with rapid feature iterations and large single updates.

OTA upgrade link design and state machine implementation

Reliable OTA is not as simple as "download and reboot"; it requires a full-process state machine and exception recovery.

Three-phase state machine: Download-Verification-Switching

State definitions: IDLE→DOWNLOADING→VERIFYING→READY→SWAPPING→COMMITTED; any timeout or error at any stage triggers RECOVERY. Key design: A configuration flag is written before each state transition, and upon power-up, the flag is read to restore context.

The verification process employs dual safeguards: CRC-32 plus digital signature. The transport-layer CRC detects bit errors, while RSA-1024 or HMAC-SHA256 validates firmware authenticity. The MSPM0L1117's TRNG true random number generator provides entropy for key derivation.

Power-loss safety and write-interrupt recovery mechanism

Inherent advantage of the dual-bank architecture: The active bank remains unchanged during updates, so even if power is lost at any moment, the system restarts from the original bank. The only vulnerable window occurs within 100 μs after writing the BANK_SWAP bit; during this period, an external FRAM or EEPROM must be used to store a "swap initiated" flag.

Interrupt recovery uses a "dual flag + sequence number" strategy: the configuration area maintains current_seq and target_seq; when they are equal, it indicates a stable state; when they differ, it indicates a switching process. After switching is complete, the first startup of the new bank requires explicit commit; otherwise, it will automatically roll back upon the next reboot.

Dual version number structure and atomic switch flag

The version number is designed as 64 bits: the upper 32 bits represent the major version (semantic), and the lower 32 bits represent the build timestamp. The configuration area stores both active_version and pending_version; during switching, only pending_version is updated. Upon successful startup of the new firmware, an atomic commit is performed—copying pending to active—and the entire process is non-interruptible.

Illegal firmware detection and automatic rollback logic

After the new Bank firmware starts, it enters a "trial period": self-test must be completed within the watchdog timeout window and a heartbeat must be reported via communication. If the report is not submitted on time or the self-test fails, the Bootloader clears the switch flag, forcing a return to the original Bank on the next cold start. This mechanism blocks the path to bricking and isolates faults within a single Boot cycle.

Practical Pitfall Avoidance: Five High-Frequency Troubleshooting Scenarios

In mass production projects, the following issues repeatedly occur, consuming significant debugging man-hours.

Erase Timeout Conflicts with Watchdog

A typical 4KB sector erase takes 15–25 ms; if the watchdog period is set to 20 ms, failing to feed the watchdog during erasure can cause an immediate reset. Solution: Temporarily extend the watchdog to 100 ms before erasing, or adopt an intermittent mode of "erasing a small segment and feeding the watchdog once." A better approach is to split the erase task into the main loop and execute it using an RTOS idle hook.

Flash Life Balancing and Wear Counting

The MSPM0L1117's Flash is rated for 100,000 erase/write cycles, but frequent updates to the configuration area become a bottleneck. In practice: each upgrade writes to the configuration area about 20 times, consuming 20% of its lifespan after a thousand upgrades. Countermeasures: employ wear-leveling algorithms in the configuration area with dual backups alternating writes; or connect an external I²C EEPROM to store high-frequency update data.

Verification and Mass Production Checklist

Before implementation, the solution must pass boundary testing, and initial version deployment must be controlled during mass production.

Boundary Testing: Full-Capacity Writing and Abnormal Power-Outage Simulation

Test Item 1: Fill a Bank to 100% capacity (each byte non-0xFF) and verify that erase-write-verify all pass. Test Item 2: Use a programmable power supply to simulate random power outages across four stages—power-up, operation, erase, and switching—1,000 cycles each, and record the startup success rate. Goal: abnormal power-outage recovery rate ≥ 99.9%.

Production Line Burning and Initial Version Deployment Process

During the first burning on the production line, the Bootloader, initial firmware for Bank A, and the "Bank A valid" flag must be written simultaneously. Bank B remains erased (all 0xFF); when the Bootloader detects that only one bank is valid, it automatically synchronizes the image, ensuring dual-bank redundancy capability right out of the factory.

Key Summary

  • MSPM0L1117 Dual-Bank Flash Memoryrequires careful allocation of its 128KB capacity: a symmetric scheme (60+60KB) suits standard applications, while an asymmetric scheme (48+80KB) supports large-application differential upgrade scenarios.
  • The state machine must cover the entire path from DOWNLOADING to COMMITTED, persisting flags at each transition point to restore context after power loss.
  • Version management uses a dual-bank, dual-sequence-number design; new firmware is atomically committed only after passing the "trial" phase, blocking paths to bricked devices.
  • Watchdog and erase timing conflicts are hidden killers in mass production; ensure a safety margin of at least three times or adopt an intermittent watchdog feeding strategy.
  • Wear leveling in the configuration area cannot be ignored; upgrades in the thousands quickly hit the Flash endurance limit, so we recommend offloading to an external EEPROM.

Frequently Asked Questions

Can the 128KB dual-bank flash memory of the MSPM0L1117 support running different versions simultaneously on A and B?

No. The dual banks operate in a mutually exclusive manner, with only one bank mapped to address 0 at any given time. The term "dual-bank" refers to storage redundancy, not concurrent execution. Version switching must be performed via the hardware BANK_SWAP bit, accompanied by a system reset and context reconstruction.

How should communication interruptions during OTA updates be handled?

Download phase interruption: After the timeout timer triggers, clear the flag and retain the received data for continued transmission or full re-download. Verification phase interruption: If fully received, continue local verification; otherwise, revert to the download state. Switching phase interruption: This is the most critical; it relies on atomic flags in the configuration area. Upon reboot, the Bootloader determines whether the switch has completed; if not, maintain the original bank.

MSPM0L1117SRHBRCan the Bootloader upgrade itself?

The official BSL area is hardware-locked and cannot be upgraded on-site, but a user-defined Bootloader can be placed in an erasable area. It is recommended to hardwire the 4KB core loader into the BSL, place complex protocol parsing in the user area, and use a jump table to achieve functional expansion, avoiding access to protected areas.

How can we verify that the new firmware will not brick the device before switching?

Leveraging RWW characteristics: After writing the new firmware to Bank B, calculate the instruction CRC at its entry address and compare it with the expected value. A more thorough approach is to build a "minimal self-test image" within Bank B—a purely computational code that does not rely on peripherals—so that the bootloader jumps to execute verification before officially switching.

Under a 128KB capacity, is differential upgrading superior to full upgrading?

The differential package size is typically reduced to 15–30% of the full version, but the old version must be retained in Flash as the baseline. In a 128KB scenario, if symmetric partitioning is used, the differential baseline and output must coexist in a single bank, resulting in limited actual savings. In asymmetric schemes, Bank A is fixed as the baseline while Bank B receives the differential output; this yields significant benefits and is recommended when used with bsdiff or MTF algorithms.