stm32f1xx-hal
stm32f1xx-hal copied to clipboard
Failed to write flash
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
}
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.