fn retry_flash<F>(
    testchannel: &CombinedTestChannel,
    target_info: &TargetInfo,
    probe_info: &DebugProbeInfo,
    flash: F,
) -> Result<(), Box<dyn Error>>
where
    F: Fn(Session) -> Result<(), Box<dyn Error>>,
{
    let mut probe = testchannel.take_probe_owned();
    let _ = probe.set_speed(8000);
    let session = probe.attach(&target_info.name);

    if session.is_ok() {
        let flash_result = flash(session.unwrap());
        match flash_result {
            Ok(_) => return Ok(()),
            Err(err) => log::warn!(
                "Failed to flash target {} with probe {}: {}\nRetrying with attach-under-reset",
                target_info.name,
                probe_info.identifier,
                err
            ),
        }
    } else {

        let err = session.unwrap_err();
        log::warn!(
            "Failed to flash target {} with probe {}: {}, {:?}\nRetrying with attach-under-reset",
            target_info.name,
            probe_info.identifier,
            err,
            err.source()
        ) 
    }

    let mut probe = probe_info.open()?;
    let _ = probe.set_speed(8000);
    let session = probe.attach_under_reset(&target_info.name)?;

    flash(session)
}
/// Retries the provided flash function with option attach-under-reset if it fails without
Retries the provided flash function with option attach-under-reset if it fails without
Retries the provided flash function with option attach - under - reset if it fails without
fn retry_flash<F>(
    testchannel: &CombinedTestChannel,
    target_info: &TargetInfo,
    probe_info: &DebugProbeInfo,
    flash: F,
) -> Result<(), Box<dyn Error>>
where
    F: Fn(Session) -> Result<(), Box<dyn Error>>,
{
    let mut probe = testchannel.take_probe_owned();
    let _ = probe.set_speed(8000);
    let session = probe.attach(&target_info.name);
    if session.is_ok() {
        let flash_result = flash(session.unwrap());
        match flash_result {
            Ok(_) => return Ok(()),
            Err(err) => log::warn!(
                "Failed to flash target {} with probe {}: {}\nRetrying with attach-under-reset",
                target_info.name,
                probe_info.identifier,
                err
            ),
        }
    } else {
        let err = session.unwrap_err();
        log::warn!(
            "Failed to flash target {} with probe {}: {}, {:?}\nRetrying with attach-under-reset",
            target_info.name,
            probe_info.identifier,
            err,
            err.source()
        ) 
    }
    let mut probe = probe_info.open()?;
    let _ = probe.set_speed(8000);
    let session = probe.attach_under_reset(&target_info.name)?;
    flash(session)
}
fn retry_flash < F > ( testchannel : & CombinedTestChannel , target_info : & TargetInfo , probe_info : & DebugProbeInfo , flash : F , ) -> Result < ( ) , Box < dyn Error > > where F : Fn ( Session ) -> Result < ( ) , Box < dyn Error > > , { let mut probe = testchannel . take_probe_owned ( ) ; let _ = probe . set_speed ( 8000 ) ; let session = probe . attach ( & target_info . name ) ; if session . is_ok ( ) { let flash_result = flash ( session . unwrap ( ) ) ; match flash_result { Ok ( _ ) => return Ok ( ( ) ) , Err ( err ) => log :: warn ! ( " \n " target_info name probe_info identifier err ) , } } else { let err = session . unwrap_err ( ) ; log :: warn ! ( " \n " target_info name probe_info identifier err err source ( ) ) } let mut probe = probe_info . open ( ) ? ; let _ = probe . set_speed ( 8000 ) ; let session = probe . attach_under_reset ( & target_info . name ) ? ; flash ( session ) }
Retries the provided flash function with option attach-under-reset if it fails without
Retries the provided flash function with option attach - under - reset if it fails without
testchannel
&CombinedTestChannel
target_info
&TargetInfo
probe_info
&DebugProbeInfo
flash
F