Browse Source

HAL_PX4: cope with failed flash writes

we need to recover from possible bad flash
master
Andrew Tridgell 8 years ago
parent
commit
979ee67c19
  1. 14
      libraries/AP_HAL_PX4/Storage.cpp
  2. 1
      libraries/AP_HAL_PX4/Storage.h

14
libraries/AP_HAL_PX4/Storage.cpp

@ -267,7 +267,19 @@ void PX4Storage::_flash_write(uint16_t line) @@ -267,7 +267,19 @@ void PX4Storage::_flash_write(uint16_t line)
bool PX4Storage::_flash_write_data(uint8_t sector, uint32_t offset, const uint8_t *data, uint16_t length)
{
size_t base_address = up_progmem_getaddress(_flash_page+sector);
return up_progmem_write(base_address+offset, data, length) == length;
bool ret = up_progmem_write(base_address+offset, data, length) == length;
if (!ret && _flash_erase_ok()) {
// we are getting flash write errors while disarmed. Try
// re-writing all of flash
uint32_t now = AP_HAL::millis();
if (now - _last_re_init_ms > 5000) {
_last_re_init_ms = now;
bool ok = _flash.re_initialise();
printf("Storage: failed at %u:%u for %u - re-init %u\n",
sector, offset, length, (unsigned)ok);
}
}
return ret;
}
/*

1
libraries/AP_HAL_PX4/Storage.h

@ -46,6 +46,7 @@ private: @@ -46,6 +46,7 @@ private:
Bitmask _dirty_mask{PX4_STORAGE_NUM_LINES};
perf_counter_t _perf_storage;
perf_counter_t _perf_errors;
uint32_t _last_re_init_ms;
#if !USE_FLASH_STORAGE
int _fd = -1;

Loading…
Cancel
Save