HAL_ChibiOS: fixed merge errors with hal.flash usage

This commit is contained in:
Andrew Tridgell 2019-04-22 09:28:53 +10:00
parent 33908f06a5
commit 6d3160b473
4 changed files with 8 additions and 10 deletions

View File

@ -11,20 +11,20 @@ public:
uint32_t getpagesize(uint32_t page) override { return stm32_flash_getpagesize(page); } uint32_t getpagesize(uint32_t page) override { return stm32_flash_getpagesize(page); }
uint32_t getnumpages(void) override { return stm32_flash_getnumpages(); } uint32_t getnumpages(void) override { return stm32_flash_getnumpages(); }
bool erasepage(uint32_t page) override { bool erasepage(uint32_t page) override {
chMtxLock(&sem); sem.take(HAL_SEMAPHORE_BLOCK_FOREVER);
bool ret = stm32_flash_erasepage(page); bool ret = stm32_flash_erasepage(page);
chMtxUnlock(&sem); sem.give();
return ret; return ret;
} }
bool write(uint32_t addr, const void *buf, uint32_t count) override { bool write(uint32_t addr, const void *buf, uint32_t count) override {
chMtxLock(&sem); sem.take(HAL_SEMAPHORE_BLOCK_FOREVER);
bool ret = (stm32_flash_write(addr, buf, count) == count); bool ret = (stm32_flash_write(addr, buf, count) == count);
chMtxUnlock(&sem); sem.give();
return ret; return ret;
} }
void keep_unlocked(bool set) override { stm32_flash_keep_unlocked(set); } void keep_unlocked(bool set) override { stm32_flash_keep_unlocked(set); }
bool ispageerased(uint32_t page) override { return stm32_flash_ispageerased(page); } bool ispageerased(uint32_t page) override { return stm32_flash_ispageerased(page); }
private: private:
mutex_t sem; Semaphore sem;
}; };

View File

@ -269,7 +269,7 @@ bool Storage::_flash_write_data(uint8_t sector, uint32_t offset, const uint8_t *
(unsigned)sector, (unsigned)offset, (unsigned)length, (unsigned)ok); (unsigned)sector, (unsigned)offset, (unsigned)length, (unsigned)ok);
} }
} }
return ret; return false;
#else #else
return false; return false;
#endif #endif

View File

@ -63,7 +63,7 @@ private:
#ifdef STORAGE_FLASH_PAGE #ifdef STORAGE_FLASH_PAGE
AP_FlashStorage _flash{_buffer, AP_FlashStorage _flash{_buffer,
hal.flash->getpagesize(STORAGE_FLASH_PAGE), stm32_flash_getpagesize(STORAGE_FLASH_PAGE),
FUNCTOR_BIND_MEMBER(&Storage::_flash_write_data, bool, uint8_t, uint32_t, const uint8_t *, uint16_t), FUNCTOR_BIND_MEMBER(&Storage::_flash_write_data, bool, uint8_t, uint32_t, const uint8_t *, uint16_t),
FUNCTOR_BIND_MEMBER(&Storage::_flash_read_data, bool, uint8_t, uint32_t, uint8_t *, uint16_t), FUNCTOR_BIND_MEMBER(&Storage::_flash_read_data, bool, uint8_t, uint32_t, uint8_t *, uint16_t),
FUNCTOR_BIND_MEMBER(&Storage::_flash_erase_sector, bool, uint8_t), FUNCTOR_BIND_MEMBER(&Storage::_flash_erase_sector, bool, uint8_t),

View File

@ -216,10 +216,8 @@ bool Util::flash_bootloader()
hal.console->printf("Flashing %s @%08x\n", fw_name, (unsigned int)addr); hal.console->printf("Flashing %s @%08x\n", fw_name, (unsigned int)addr);
const uint8_t max_attempts = 10; const uint8_t max_attempts = 10;
for (uint8_t i=0; i<max_attempts; i++) { for (uint8_t i=0; i<max_attempts; i++) {
void *context = hal.scheduler->disable_interrupts_save();
bool ok = hal.flash->write(addr, fw, fw_size); bool ok = hal.flash->write(addr, fw, fw_size);
hal.scheduler->restore_interrupts(context); if (!ok) {
if (written == -1 || written < fw_size) {
hal.console->printf("Flash failed! (attempt=%u/%u)\n", hal.console->printf("Flash failed! (attempt=%u/%u)\n",
i+1, i+1,
max_attempts); max_attempts);