at_start_f435: enable MFS for internal flash (#5687)

* Rename EFI_INTERNAL_FLASH to EFI_STORAGE_INT_FLASH

This define enables use of RE custom flash driver for storing
settings to internal flash.

* at_start_f435: enable MFS for settings storing in internal flash

* MRE: fix special build

* kinetis: fix flash_int.cpp vs flash_int.c mess

* at32: allow allowFlashWhileRunning()

* flash_main: supress warning
This commit is contained in:
Andrey G 2023-11-03 20:08:35 +03:00 committed by GitHub
parent 3b6c9feea5
commit ed8af771ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 131 additions and 50 deletions

View File

@ -6,7 +6,7 @@ rem https://github.com/rusefi/rusefi/issues/684
rem this board has only 512K flash so using custom FLASH_ADDR
rem You probably want "flash0 : org = 0x08000000, len = 450K" in the .ld file
set EXTRA_PARAMS=-DDUMMY -DEFI_COMMUNICATION_PIN=Gpio::B9 -DSTM32_RTCPRE_VALUE=25 ^
-DEFI_INTERNAL_FLASH=FALSE ^
-DEFI_STORAGE_INT_FLASH=FALSE ^
-DHAL_USE_RTC=FALSE ^
-DBOARD_OTG_NOVBUSSENS ^
-DFLASH_ADDR=0x08075000

View File

@ -1,5 +1,7 @@
# List of all the board related files.
BOARDCPPSRC = $(BOARD_DIR)/board_configuration.cpp
BOARDCPPSRC = $(BOARD_DIR)/board_configuration.cpp \
$(BOARD_DIR)/board_storage.cpp
DDEFS += -DLED_CRITICAL_ERROR_BRAIN_PIN=Gpio::D13
DDEFS += -DLED_PIN_MODE=OM_INVERTED
@ -18,6 +20,11 @@ BOARDINC = $(CHIBIOS)/os/hal/boards/AT_START_F435/
# Configuration directorys
CONFDIR = $(PROJECT_DIR)/hw_layer/ports/at32/at32f4/cfg
# This board uses ChibiOS MFS driver on internal flash
DDEFS += -DEFI_STORAGE_INT_FLASH=FLASE -DHAL_USE_EFL=TRUE -DEFI_STORAGE_MFS=TRUE
# This board has chip with dual-bank flash, bank 2 can be flashed in background
DDEFS += -DEFI_FLASH_WRITE_THREAD=TRUE
DDEFS += -DFIRMWARE_ID=\"at_start_f435\"
DDEFS += -DDEFAULT_ENGINE_TYPE=engine_type_e::MINIMAL_PINS
DDEFS += -DSHORT_BOARD_NAME=at_start_f435 -DSTATIC_BOARD_ID=STATIC_BOARD_ID_AT_START_F435

View File

@ -0,0 +1,39 @@
/**
* @file boards/subaru_eg33/board_storage.h
*
* @brief Storage configuration file
*
* @date Nov 03, 2023
* @author Andrey Gusakov, 2023
*/
#include "pch.h"
/* This board stores settings in internal flash bank 2 */
#if EFI_STORAGE_MFS == TRUE
#include "hal_mfs.h"
/* use 128K + 128K on bank 2 for settings */
const MFSConfig mfscfg1 = {
.flashp = (BaseFlash *)&EFLD2,
.erased = 0xFFFFFFFFU,
.bank_size = 128U * 1024U,
.bank0_start = 0U,
.bank0_sectors = 32U,
.bank1_start = 32U,
.bank1_sectors = 32U
};
void boardInitMfs()
{
/* Starting EFL driver.*/
eflStart(&EFLD2, NULL);
}
const MFSConfig *boardGetMfsConfig()
{
return &mfscfg1;
}
#endif /* EFI_STORAGE_MFS == TRUE */

View File

@ -83,7 +83,7 @@
#define TRIGGER_EXTREME_LOGGING FALSE
#define EFI_INTERNAL_FLASH TRUE
#define EFI_STORAGE_INT_FLASH TRUE
/**
* Flex Non Volatile Memory is faster than flash

View File

@ -90,7 +90,7 @@
#define TRIGGER_EXTREME_LOGGING FALSE
#define EFI_INTERNAL_FLASH TRUE
#define EFI_STORAGE_INT_FLASH TRUE
/**
* Usually you need shaft position input, but maybe you do not need it?

View File

@ -158,10 +158,15 @@
#define TRIGGER_EXTREME_LOGGING FALSE
#ifndef EFI_INTERNAL_FLASH
#define EFI_INTERNAL_FLASH TRUE
#ifndef EFI_STORAGE_INT_FLASH
#define EFI_STORAGE_INT_FLASH TRUE
#endif
#ifndef EFI_STORAGE_MFS
#define EFI_STORAGE_MFS FALSE
#endif
/**
* Usually you need shaft position input, but maybe you do not need it?
*/
@ -449,14 +454,6 @@
#define GPS_SERIAL_DEVICE &SD1
#define GPS_SERIAL_SPEED 38400
#ifndef EFI_STORAGE_INT_FLASH
#define EFI_STORAGE_INT_FLASH TRUE
#endif
#ifndef EFI_STORAGE_MFS
#define EFI_STORAGE_MFS FALSE
#endif
#ifndef EFI_SENT_SUPPORT
#define EFI_SENT_SUPPORT FALSE
#endif

View File

@ -316,9 +316,9 @@ void requestBurn() {
#if !EFI_UNIT_TEST
onBurnRequest();
#if EFI_INTERNAL_FLASH
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
setNeedToWriteConfiguration();
#endif
#endif /* (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE) */
#endif // !EFI_UNIT_TEST
}

View File

@ -66,7 +66,7 @@
#include "periodic_task.h"
#endif /* EFI_PROD_CODE */
#if EFI_INTERNAL_FLASH
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
#include "flash_main.h"
#endif
@ -307,10 +307,10 @@ extern int totalLoggedBytes;
} else if (consoleByteArrived) {
offTimeMs = 100;
onTimeMs = 33;
#if EFI_INTERNAL_FLASH
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
} else if (getNeedToWriteConfiguration()) {
offTimeMs = onTimeMs = 500;
#endif // EFI_INTERNAL_FLASH
#endif /* (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE) */
} else {
onTimeMs =
#if EFI_USB_SERIAL
@ -567,9 +567,9 @@ static void updateFlags() {
engine->outputChannels.isTriggerError = isTriggerErrorNow();
#endif // EFI_PROD_CODE
#if EFI_INTERNAL_FLASH
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
engine->outputChannels.needBurn = getNeedToWriteConfiguration();
#endif /* EFI_INTERNAL_FLASH */
#endif /* (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE) */
}
// sensor state for EFI Analytics Tuner Studio

View File

@ -644,7 +644,8 @@ void loadConfiguration() {
prepareVoidConfiguration(&activeConfiguration);
#endif /* EFI_ACTIVE_CONFIGURATION_IN_FLASH */
#if EFI_INTERNAL_FLASH
/* If board have any storage */
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
if (IGNORE_FLASH_CONFIGURATION) {
engineConfiguration->engineType = DEFAULT_ENGINE_TYPE;
resetConfigurationExt(engineConfiguration->engineType);
@ -654,11 +655,11 @@ void loadConfiguration() {
// if flash state does not look right.
readFromFlash();
}
#else // not EFI_INTERNAL_FLASH
#else
// This board doesn't load configuration, initialize the default
engineConfiguration->engineType = DEFAULT_ENGINE_TYPE;
resetConfigurationExt(engineConfiguration->engineType);
#endif /* EFI_INTERNAL_FLASH */
#endif /* (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE) */
// Force any board configuration options that humans shouldn't be able to change
setBoardConfigOverrides();

View File

@ -459,9 +459,9 @@ static void handleCommandX14(uint16_t index) {
return;
case TS_WRITE_FLASH:
// cmd_write_config
#if EFI_INTERNAL_FLASH
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
writeToFlashNow();
#endif /* EFI_INTERNAL_FLASH */
#endif /* (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE) */
return;
#if EFI_EMULATE_POSITION_SENSORS
case 0xD:
@ -502,8 +502,10 @@ static void handleCommandX14(uint16_t index) {
return;
case 0x15:
#if EFI_PROD_CODE
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
extern bool burnWithoutFlash;
burnWithoutFlash = true;
#endif /* (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE) */
#endif // EFI_PROD_CODE
return;
default:

View File

@ -192,9 +192,9 @@ static void doPeriodicSlowCallback() {
*
* todo: allow writing if 2nd bank of flash is used
*/
#if EFI_INTERNAL_FLASH
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
writeToFlashIfPending();
#endif /* EFI_INTERNAL_FLASH */
#endif /* (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE) */
}
if (engine->rpmCalculator.isStopped()) {
@ -207,9 +207,9 @@ static void doPeriodicSlowCallback() {
engine->periodicSlowCallback();
#else /* if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */
#if EFI_INTERNAL_FLASH
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
writeToFlashIfPending();
#endif /* EFI_INTERNAL_FLASH */
#endif /* (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE) */
#endif /* EFI_SHAFT_POSITION_INPUT */
#if EFI_TCU

View File

@ -9,7 +9,8 @@
#include "pch.h"
#if EFI_INTERNAL_FLASH
/* If any setting storage is exist */
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
#include "mpu_util.h"
#include "flash_main.h"
@ -213,8 +214,9 @@ static FlashState validatePersistentState() {
}
}
#if EFI_STORAGE_INT_FLASH == TRUE
/**
* Read single copy of rusEFI configuration from flash
* Read single copy of rusEFI configuration from interan flash using custom driver
*/
static FlashState readOneConfigurationCopy(flashaddr_t address) {
efiPrintf("readFromFlash %x", address);
@ -228,6 +230,7 @@ static FlashState readOneConfigurationCopy(flashaddr_t address) {
return validatePersistentState();
}
#endif
/**
* this method could and should be executed before we have any
@ -357,4 +360,4 @@ void initFlash() {
#endif
}
#endif /* EFI_INTERNAL_FLASH */
#endif /* (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE) */

View File

@ -31,9 +31,9 @@
#include "electronic_throttle.h"
#endif // EFI_ELECTRONIC_THROTTLE_BODY
#if EFI_INTERNAL_FLASH
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
#include "flash_main.h"
#endif // EFI_INTERNAL_FLASH
#endif /* (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE) */
#if EFI_ENGINE_SNIFFER
#include "engine_sniffer.h"
@ -1008,11 +1008,11 @@ void setEngineType(int value, bool isWriteToFlash) {
resetConfigurationExt((engine_type_e)value);
engine->resetEngineSnifferIfInTestMode();
#if EFI_INTERNAL_FLASH
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
if (isWriteToFlash) {
writeToFlashNow();
}
#endif // EFI_INTERNAL_FLASH
#endif /* (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE) */
}
incrementGlobalConfigurationVersion("engineType");
#if ! EFI_UNIT_TEST

View File

@ -62,7 +62,7 @@
#include "map_averaging.h"
#endif
#if EFI_INTERNAL_FLASH
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
#include "flash_main.h"
#endif
@ -400,7 +400,7 @@ void initHardwareNoConfig() {
initRtc();
#endif // EFI_PROD_CODE && EFI_RTC
#if EFI_INTERNAL_FLASH
#if (EFI_STORAGE_INT_FLASH == TRUE) || (EFI_STORAGE_MFS == TRUE)
initFlash();
#endif

View File

@ -1,4 +1,5 @@
HW_AT32_PORT_DIR = $(PROJECT_DIR)/hw_layer/ports/at32
HW_LAYER_PORT_CPP += \
$(HW_AT32_PORT_DIR)/at32_common.cpp
$(HW_AT32_PORT_DIR)/at32_common.cpp \
$(HW_AT32_PORT_DIR)/at32f4/mpu_util.cpp

View File

@ -0,0 +1,33 @@
/**
* @file mpu_util.cpp
*
* @date Nov 3, 2023
* @author Andrey Gusakov, (c) 2023
*/
#include "pch.h"
#include "flash_int.h"
bool allowFlashWhileRunning() {
/* TODO: check for actual flash configuration? */
/* currently we support only AT32F43X with dual-bank flash, so allow flashing to second bank */
return true;
}
/* TODO: fix name! */
void stm32_standby() {
// Don't get bothered by interrupts
__disable_irq();
/* TODO: validate! */
#if 0
SysTick->CTRL = 0;
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
PWR->CR |= PWR_CR_PDDS; // PDDS = use standby mode (not stop mode)
PWR->CR |= PWR_CR_CSBF; // Clear standby flag
#endif
// Do anything the board wants to prepare for standby mode - enabling wakeup sources!
boardPrepareForStandby();
__WFI();
}

View File

@ -7,7 +7,7 @@
#include "pch.h"
#if EFI_INTERNAL_FLASH
#if EFI_STORAGE_INT_FLASH
#include "flash_int.h"
#include <string.h>
@ -132,4 +132,4 @@ int intFlashRead(flashaddr_t source, char* destination, size_t size) {
return FLASH_RETURN_SUCCESS;
}
#endif /* EFI_INTERNAL_FLASH */
#endif /* EFI_STORAGE_INT_FLASH */

View File

@ -7,7 +7,7 @@
#include "pch.h"
#if EFI_INTERNAL_FLASH
#if EFI_STORAGE_INT_FLASH
#include "flash_int.h"
#include "fsl_ftfx_flexnvm.h"
@ -202,4 +202,4 @@ int intFlashRead(flashaddr_t source, char* destination, size_t size) {
return FLASH_RETURN_SUCCESS;
}
#endif /* EFI_INTERNAL_FLASH */
#endif /* EFI_STORAGE_INT_FLASH */

View File

@ -11,6 +11,6 @@ HW_LAYER_PORT_CPP += $(PROJECT_DIR)/hw_layer/ports/kinetis/mpu_util.cpp \
$(PROJECT_DIR)/hw_layer/ports/kinetis/kinetis_common.cpp \
$(PROJECT_DIR)/hw_layer/trigger_input_comp.cpp \
$(PROJECT_DIR)/hw_layer/microsecond_timer/microsecond_timer_gpt.cpp \
$(PROJECT_DIR)/hw_layer/ports/kinetis/flash_int.c \
$(PROJECT_DIR)/hw_layer/ports/kinetis/flash_int.cpp
MCU = cortex-m4

View File

@ -9,7 +9,7 @@
#include "pch.h"
#if EFI_INTERNAL_FLASH
#if EFI_STORAGE_INT_FLASH
#include "flash_int.h"
#include <string.h>
@ -434,4 +434,4 @@ exit:
}
#endif
#endif /* EFI_INTERNAL_FLASH */
#endif /* EFI_STORAGE_INT_FLASH */

View File

@ -26,8 +26,7 @@ else ifeq ($(IS_AT32F435),yes)
DDEFS += -DAT32F4XX
HW_LAYER_PORT =
# TODO: Artery
HW_LAYER_PORT_CPP = $(PROJECT_DIR)/hw_layer/ports/stm32/stm32f4/mpu_util.cpp \
$(PROJECT_DIR)/hw_layer/ports/stm32/stm32_adc_v2.cpp
HW_LAYER_PORT_CPP = $(PROJECT_DIR)/hw_layer/ports/stm32/stm32_adc_v2.cpp
# TODO: Arterys
LDSCRIPT = $(PROJECT_DIR)/hw_layer/ports/at32/at32f4/AT32F435ZMxx.ld
else

View File

@ -143,7 +143,6 @@
#define FUEL_MATH_EXTREME_LOGGING FALSE
#define EFI_ANALOG_SENSORS TRUE
#define EFI_INTERNAL_FLASH TRUE
#define EFI_STORAGE_INT_FLASH TRUE
#define EFI_FLASH_WRITE_THREAD TRUE
#define EFI_STORAGE_MFS FALSE