Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to write flash #375

Open
zrz4066 opened this issue Nov 18, 2021 · 1 comment
Open

Failed to write flash #375

zrz4066 opened this issue Nov 18, 2021 · 1 comment

Comments

@zrz4066
Copy link

zrz4066 commented Nov 18, 2021

function save_parameter save data to flash and it will write well at the first time。It will failed to write on the second time

fn save_parameter(flash: &mut FlashWriter, ir_par: IrParameter) -> bool {
    let mut v: [u8; 128] = [0; 128];
    let mut offset = 0;
    let head_array = ir_par.header.to_be_bytes();
    let debug_array = ir_par.debugOn.to_le_bytes();
    let ir_calval_array = ir_par.ir_calval.to_le_bytes();
    let ir_maxval_array = ir_par.ir_maxval.to_le_bytes();
    let n_percent_array = ir_par.nPercent.to_le_bytes();
    for i in 0..head_array.len() {
        v[offset] = head_array[i];
        offset += 1;
    }

    for i in 0..debug_array.len() {
        v[offset] = debug_array[i];
        offset += 1;
    }
    for i in 0..ir_calval_array.len() {
        v[offset] = ir_calval_array[i];
        offset += 1;
    }
    for i in 0..ir_maxval_array.len() {
        v[offset] = ir_maxval_array[i];
        offset += 1;
    }
    for i in 0..n_percent_array.len() {
        v[offset] = n_percent_array[i];
        offset += 1;
    }
    //flash.change_verification(false);
    //.change_verification(false)
    flash.erase(FLASH_WRITE_START_ADDR, 1024).unwrap();
    //flash.page_erase(FLASH_WRITE_START_ADDR);//.unwrap();
    match flash.write(FLASH_WRITE_START_ADDR, &v) {
        Ok(_ret) => true,
        Err(_e) => false,
    };
    false
}
@TheZoq2
Copy link
Member

TheZoq2 commented Nov 18, 2021

That's interesting. I don't quite remember the details of how flash works so I may not be of much help ATM. Do you have access to a debugger (rtt, itm etc.) or perhaps just a serial port so you could print the error being produced rather than just throwing it away. That would at least give some clues as to what might be going wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants