Skip to content

eraseSection

Signatures

  • bool SPIFlash::eraseSection(uint32_t _addr, uint32_t _sz)
  • bool SPIFram::eraseSection(uint32_t _addr, uint32_t _sz)

What It Is For

Clear a contiguous region starting at _addr spanning _sz bytes.

Parameters

  • _addr: Start address for region clear.
  • _sz: Region size in bytes.

Behavior Details

On flash, this resolves to sector/block erase operations and is essential before rewriting programmed bits. On FRAM, this is library-level clear behavior.

Return Semantics

Returns true when clear operation completed successfully.

Failure Behavior

Invalid ranges, protected states, busy chip state, or unsupported erase granularity can cause failure.

Common Mistakes

  • Erasing too small a region before rewriting larger payloads.
  • Assuming section erase aligns exactly to your object boundaries.
  • Not accounting for erase latency in time-sensitive loops.

Choosing Between Similar APIs

  • Use eraseSection() when object size is known and may span multiple sectors.
  • Use eraseSector()/block erases for explicit granularity control.
  • Prefer smallest erase scope that still covers your write region.

Example

uint32_t len = sizeof(Config);
flash.eraseSection(addr, len);