pub fn program(
        &self,
        mut flash: Flasher,
        mut chip_erase: Option<bool>,
        smart_flash: bool,
        fast_verify: bool,
        keep_unwritten: bool,
    ) -> Result<(), FlashBuilderError> {
        // Disable smart options if attempting to read erased sectors will fail.
        let (smart_flash, fast_verify, keep_unwritten) =
            if !flash.region().are_erased_sectors_readable {
                (false, false, false)
            } else {
                (smart_flash, fast_verify, keep_unwritten)
            };

        if self.flash_operations.is_empty() {
            // Nothing to do.
            return Ok(());
        }

        let mut sectors = vec![];

        // Convert the list of flash operations into flash sectors and pages.
        self.build_sectors_and_pages(&mut flash, &mut sectors, keep_unwritten)?;
        if sectors.is_empty() || sectors[0].pages.is_empty() {
            // Nothing to do.
            return Ok(());
        }

        log::debug!("Smart Flash enabled: {:?}", smart_flash);
        // If smart flash was set to false then mark all pages as requiring programming.
        if !smart_flash {
            Self::mark_all_pages_for_programming(&mut sectors);
        }

        // If the flash algo doesn't support erase all, disable chip erase.
        if flash.flash_algorithm().pc_erase_all.is_none() {
            chip_erase = Some(false);
        }

        let (_chip_erase_count, chip_erase_program_time) =
            self.compute_chip_erase_pages_and_weight(&mut sectors, flash.region());
        let sector_erase_min_program_time =
            self.compute_sector_erase_pages_weight_min(&mut sectors);

        // If chip_erase hasn't been specified determine if chip erase is faster
        // than page erase regardless of contents
        if chip_erase.is_none() && (chip_erase_program_time < sector_erase_min_program_time) {
            chip_erase = Some(true);
        }

        if Some(true) != chip_erase {
            let (_sector_erase_count, page_program_time) =
                self.compute_sector_erase_pages_and_weight(&mut flash, &mut sectors, fast_verify)?;
            if chip_erase.is_none() {
                chip_erase = Some(chip_erase_program_time < page_program_time);
            }
        }

        log::debug!("Full Chip Erase enabled: {:?}", chip_erase);
        log::debug!(
            "Double Buffering enabled: {:?}",
            self.enable_double_buffering
        );
        if Some(true) == chip_erase {
            if flash.double_buffering_supported() && self.enable_double_buffering {
                self.chip_erase_program_double_buffer(&mut flash, &sectors)?;
            } else {
                self.chip_erase_program(&mut flash, &sectors)?;
            };
        } else if flash.double_buffering_supported() && self.enable_double_buffering {
            self.sector_erase_program_double_buffer(&mut flash, &mut sectors)?;
        } else {
            // WORKING: We debug this atm.
            self.sector_erase_program(&mut flash, &sectors)?;
        }

        Ok(())
    }
/// Determine fastest method of flashing and then run flash programming.
///
/// Data must have already been added with add_data
/// TODO: Not sure if this works as intended ...
Determine fastest method of flashing and then run flash programming.
Data must have already been added with add_data
TODO: Not sure if this works as intended
Determine fastest method of flashing and then run flash programming . Data must have already been added with add_data TODO : Not sure if this works as intended
pub fn program(
        &self,
        mut flash: Flasher,
        mut chip_erase: Option<bool>,
        smart_flash: bool,
        fast_verify: bool,
        keep_unwritten: bool,
    ) -> Result<(), FlashBuilderError> {
        // Disable smart options if attempting to read erased sectors will fail.
        let (smart_flash, fast_verify, keep_unwritten) =
            if !flash.region().are_erased_sectors_readable {
                (false, false, false)
            } else {
                (smart_flash, fast_verify, keep_unwritten)
            };
        if self.flash_operations.is_empty() {
            // Nothing to do.
            return Ok(());
        }
        let mut sectors = vec![];
        // Convert the list of flash operations into flash sectors and pages.
        self.build_sectors_and_pages(&mut flash, &mut sectors, keep_unwritten)?;
        if sectors.is_empty() || sectors[0].pages.is_empty() {
            // Nothing to do.
            return Ok(());
        }
        log::debug!("Smart Flash enabled: {:?}", smart_flash);
        // If smart flash was set to false then mark all pages as requiring programming.
        if !smart_flash {
            Self::mark_all_pages_for_programming(&mut sectors);
        }
        // If the flash algo doesn't support erase all, disable chip erase.
        if flash.flash_algorithm().pc_erase_all.is_none() {
            chip_erase = Some(false);
        }
        let (_chip_erase_count, chip_erase_program_time) =
            self.compute_chip_erase_pages_and_weight(&mut sectors, flash.region());
        let sector_erase_min_program_time =
            self.compute_sector_erase_pages_weight_min(&mut sectors);
        // If chip_erase hasn't been specified determine if chip erase is faster
        // than page erase regardless of contents
        if chip_erase.is_none() && (chip_erase_program_time < sector_erase_min_program_time) {
            chip_erase = Some(true);
        }
        if Some(true) != chip_erase {
            let (_sector_erase_count, page_program_time) =
                self.compute_sector_erase_pages_and_weight(&mut flash, &mut sectors, fast_verify)?;
            if chip_erase.is_none() {
                chip_erase = Some(chip_erase_program_time < page_program_time);
            }
        }
        log::debug!("Full Chip Erase enabled: {:?}", chip_erase);
        log::debug!(
            "Double Buffering enabled: {:?}",
            self.enable_double_buffering
        );
        if Some(true) == chip_erase {
            if flash.double_buffering_supported() && self.enable_double_buffering {
                self.chip_erase_program_double_buffer(&mut flash, &sectors)?;
            } else {
                self.chip_erase_program(&mut flash, &sectors)?;
            };
        } else if flash.double_buffering_supported() && self.enable_double_buffering {
            self.sector_erase_program_double_buffer(&mut flash, &mut sectors)?;
        } else {
            // WORKING: We debug this atm.
            self.sector_erase_program(&mut flash, &sectors)?;
        }
        Ok(())
    }
pub fn program ( & self , mut flash : Flasher , mut chip_erase : Option < bool > , smart_flash : bool , fast_verify : bool , keep_unwritten : bool , ) -> Result < ( ) , FlashBuilderError > { // Disable smart options if attempting to read erased sectors will fail. let ( smart_flash , fast_verify , keep_unwritten ) = if ! flash . region ( ) . are_erased_sectors_readable { ( false , false , false ) } else { ( smart_flash , fast_verify , keep_unwritten ) } ; if self . flash_operations . is_empty ( ) { // Nothing to do. return Ok ( ( ) ) ; } let mut sectors = vec ! [ ] ; // Convert the list of flash operations into flash sectors and pages. self . build_sectors_and_pages ( & mut flash , & mut sectors , keep_unwritten ) ? ; if sectors . is_empty ( ) || sectors [ 0 ] . pages . is_empty ( ) { // Nothing to do. return Ok ( ( ) ) ; } log :: debug ! ( " " smart_flash ) ; // If smart flash was set to false then mark all pages as requiring programming. if ! smart_flash { Self :: mark_all_pages_for_programming ( & mut sectors ) ; } // If the flash algo doesn't support erase all, disable chip erase. if flash . flash_algorithm ( ) . pc_erase_all . is_none ( ) { chip_erase = Some ( false ) ; } let ( _chip_erase_count , chip_erase_program_time ) = self . compute_chip_erase_pages_and_weight ( & mut sectors , flash . region ( ) ) ; let sector_erase_min_program_time = self . compute_sector_erase_pages_weight_min ( & mut sectors ) ; // If chip_erase hasn't been specified determine if chip erase is faster // than page erase regardless of contents if chip_erase . is_none ( ) && ( chip_erase_program_time < sector_erase_min_program_time ) { chip_erase = Some ( true ) ; } if Some ( true ) != chip_erase { let ( _sector_erase_count , page_program_time ) = self . compute_sector_erase_pages_and_weight ( & mut flash , & mut sectors , fast_verify ) ? ; if chip_erase . is_none ( ) { chip_erase = Some ( chip_erase_program_time < page_program_time ) ; } } log :: debug ! ( " " chip_erase ) ; log :: debug ! ( " " self enable_double_buffering ) ; if Some ( true ) == chip_erase { if flash . double_buffering_supported ( ) && self . enable_double_buffering { self . chip_erase_program_double_buffer ( & mut flash , & sectors ) ? ; } else { self . chip_erase_program ( & mut flash , & sectors ) ? ; } ; } else if flash . double_buffering_supported ( ) && self . enable_double_buffering { self . sector_erase_program_double_buffer ( & mut flash , & mut sectors ) ? ; } else { // WORKING: We debug this atm. self . sector_erase_program ( & mut flash , & sectors ) ? ; } Ok ( ( ) ) }
Determine fastest method of flashing and then run flash programming.
Determine fastest method of flashing and then run flash programming .
&self
flash
Flasher
chip_erase
Option<bool>
smart_flash
bool
fast_verify
bool
keep_unwritten
bool