Skip to main content

program

Function program 

Source
pub fn program(
    usbdev: &UsbDev,
    driver: Driver,
    chip: &str,
    elf: &Path,
    erase: Erase,
    on_progress: impl FnMut(Progress),
) -> Result<(), String>
Expand description

Erases as erase says, programs and verifies elf in one session, clears FLASH_SR.PEMPTY on an STM32L4 if it is set, and starts the image with a debugger jump to its vector table (STM32_Programmer_CLI’s -g 0x08000000). One session, so no reset falls between the erase and the program.

The counterpart of qtprogram’s STM32_Programmer_CLI program call. chip comes from chip_for; on_progress is called synchronously with Progress events. Blocks until the image is running or an error ends the session; a full L432 image takes seconds, longer through Driver::FieldSafe.

The tag is held in reset to attach, so whatever it was doing ends. The image is started by setting SP and PC from the vector table and resuming the core, not by a reset, so the first boot after programming is not a cold boot; the tag’s next reset boots it normally.

§Errors

A message if the attach fails, the range erase fails, programming or verification fails, PEMPTY will not clear, or the core cannot be started. A failure after the erase leaves the tag with partly erased or programmed flash, which another program call repairs.