embassy-rp

Crates

git

Versions

rp235xa

Flavors

embassy_rp::rom_data

Function flash_range_erase

Source
pub unsafe extern "C" fn flash_range_erase(
    addr: u32,
    count: usize,
    block_size: u32,
    block_cmd: u8,
)
Expand description

Erase count bytes, starting at addr (offset from start of flash).

Optionally, pass a block erase command e.g. D8h block erase, and the size of the block erased by this command — this function will use the larger block erase where possible, for much higher erase speed. addr must be aligned to a 4096-byte sector, and count must be a multiple of 4096 bytes.

This is a low-level flash API, and no validation of the arguments is performed. See flash_op() for a higher-level API which checks alignment, flash bounds and partition permissions, and can transparently apply a runtime-to-storage address translation.

The QSPI device must be in a serial command state before calling this API, which can be achieved by calling connect_internal_flash() followed by flash_exit_xip(). After the erase, the flash cache should be flushed via flash_flush_cache() to ensure the modified flash data is visible to cached XIP accesses.

Finally, the original XIP mode should be restored by copying the saved XIP setup function from bootram into SRAM, and executing it: the bootrom provides a default function which restores the flash mode/clkdiv discovered during flash scanning, and user programs can override this with their own XIP setup function.

For the duration of the erase operation, QMI is in direct mode (Section 12.14.5) and attempting to access XIP from DMA, the debugger or the other core will return a bus fault. XIP becomes accessible again once the function returns.

Supported architectures: ARM-S, RISC-V

§Safety

This is a low-level C function. It may be difficult to call safely from Rust. If in doubt, check the rp235x datasheet for details and do your own safety evaluation.