non blocking flash on f7 dual bank 2MB (#2749)
* f7 dual bank flash * only start thread if necessary
This commit is contained in:
parent
f2fdea33fb
commit
080d901222
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
// Base MCU
|
||||
void baseMCUInit(void);
|
||||
void jump_to_bootloader();
|
||||
bool allowFlashWhileRunning();
|
||||
|
||||
// ADC
|
||||
#if HAL_USE_ADC
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue