non blocking flash on f7 dual bank 2MB (#2749)

* f7 dual bank flash

* only start thread if necessary
This commit is contained in:
Matthew Kennedy 2021-05-28 23:05:29 -06:00 committed by GitHub
parent f2fdea33fb
commit 080d901222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 8 deletions

View File

@ -55,3 +55,6 @@
#undef ENABLE_PERF_TRACE
#define ENABLE_PERF_TRACE TRUE
// F7 may have dual bank, so flash on its own (low priority) thread so as to not block any other operations
#define EFI_FLASH_WRITE_THREAD TRUE

View File

@ -63,8 +63,10 @@ void setNeedToWriteConfiguration(void) {
needToWriteConfiguration = true;
#if EFI_FLASH_WRITE_THREAD
// Signal the flash writer thread to wake up and write at its leisure
flashWriteSemaphore.signal();
if (allowFlashWhileRunning()) {
// Signal the flash writer thread to wake up and write at its leisure
flashWriteSemaphore.signal();
}
#endif // EFI_FLASH_WRITE_THREAD
}
@ -73,15 +75,13 @@ bool getNeedToWriteConfiguration(void) {
}
void writeToFlashIfPending() {
// with a flash write thread, the schedule happens directly from
// setNeedToWriteConfiguration, so there's nothing to do here
#if !EFI_FLASH_WRITE_THREAD
if (!getNeedToWriteConfiguration()) {
// with a flash write thread, the schedule happens directly from
// setNeedToWriteConfiguration, so there's nothing to do here
if (allowFlashWhileRunning() || !getNeedToWriteConfiguration()) {
return;
}
writeToFlashNow();
#endif
}
// Erase and write a copy of the configuration at the specified address
@ -254,7 +254,9 @@ void initFlash() {
addConsoleAction("rewriteconfig", rewriteConfig);
#if EFI_FLASH_WRITE_THREAD
chThdCreateStatic(flashWriteStack, sizeof(flashWriteStack), PRIO_FLASH_WRITE, flashWriteThread, nullptr);
if (allowFlashWhileRunning()) {
chThdCreateStatic(flashWriteStack, sizeof(flashWriteStack), PRIO_FLASH_WRITE, flashWriteThread, nullptr);
}
#endif
}

View File

@ -238,6 +238,10 @@ CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx) {
#endif /* EFI_CAN_SUPPORT */
bool allowFlashWhileRunning() {
return false;
}
size_t flashSectorSize(flashsector_t sector) {
// sectors 0..11 are the 1st memory bank (1Mb), and 12..23 are the 2nd (the same structure).
if (sector <= 3 || (sector >= 12 && sector <= 15))

View File

@ -230,6 +230,10 @@ CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx) {
#endif /* EFI_CAN_SUPPORT */
bool allowFlashWhileRunning() {
return false;
}
size_t flashSectorSize(flashsector_t sector) {
// sectors 0..11 are the 1st memory bank (1Mb), and 12..23 are the 2nd (the same structure).
if (sector <= 3 || (sector >= 12 && sector <= 15))

View File

@ -9,6 +9,7 @@
// Base MCU
void baseMCUInit(void);
void jump_to_bootloader();
bool allowFlashWhileRunning();
// ADC
#if HAL_USE_ADC

View File

@ -7,6 +7,11 @@
#include "flash_int.h"
bool allowFlashWhileRunning() {
// Never allow flash while running on F4, dual bank not implemented.
return false;
}
size_t flashSectorSize(flashsector_t sector) {
// sectors 0..11 are the 1st memory bank (1Mb), and 12..23 are the 2nd (the same structure).
if (sector <= 3 || (sector >= 12 && sector <= 15))

View File

@ -49,6 +49,11 @@ static DeviceType determineDevice() {
return DeviceType::Unknown;
}
bool allowFlashWhileRunning() {
// Allow flash-while-running if dual bank mode is enabled, and we're a 2MB device (ie, no code located in second bank)
return determineDevice() == DeviceType::DualBank2MB;
}
// See ST AN4826
size_t flashSectorSize(flashsector_t sector) {
// 1MB devices have 8 sectors per bank

View File

@ -7,6 +7,11 @@
#include "flash_int.h"
bool allowFlashWhileRunning() {
// We only support dual bank H7, so always allow flash while running.
return true;
}
size_t flashSectorSize(flashsector_t sector) {
// All sectors on H7 are 128k
return 128 * 1024;