Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into openblt-can
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Aug 28, 2023
2 parents 2abe1a3 + d4bbd55 commit 2e114d1
Show file tree
Hide file tree
Showing 79 changed files with 498 additions and 290 deletions.
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@
"configFiles": ["interface/stlink.cfg", "target/stm32f4x.cfg"],
"rtos": "auto"
},
{
"name": "Debug Bootloader F42x",
"type": "cortex-debug",
"request": "launch",
"cwd": "${workspaceFolder}/firmware",
"executable": "${workspaceRoot}/firmware/bootloader/blbuild/fome_bl.elf",
"device": "STM32F429Z",
"v1": false,
"svdFile": "${workspaceRoot}/firmware/ext/cmsis-svd/STM32F427.svd",
"servertype": "openocd",
"configFiles": ["interface/stlink.cfg", "target/stm32f4x.cfg"],
"rtos": "auto"
},
{
"name": "Debug F7x6",
"type": "cortex-debug",
Expand All @@ -101,6 +114,19 @@
"servertype": "openocd",
"configFiles": ["interface/stlink.cfg", "target/stm32h7x.cfg"],
"rtos": "auto"
},
{
"name": "Debug Bootloader H743",
"type": "cortex-debug",
"request": "launch",
"cwd": "${workspaceFolder}/firmware",
"executable": "${workspaceRoot}/firmware/bootloader/blbuild/fome_bl.elf",
"device": "STM32H743V",
"v1": false,
"svdFile": "${workspaceRoot}/firmware/ext/cmsis-svd/STM32H743x.svd",
"servertype": "openocd",
"configFiles": ["interface/stlink.cfg", "target/stm32h7x.cfg"],
"rtos": "auto"
}
]
}
4 changes: 4 additions & 0 deletions firmware/bootloader/openblt_chibios/openblt_flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ blt_bool FlashVerifyChecksum() {
}

blt_addr FlashGetUserProgBaseAddress() {
#ifdef STM32H7XX
return 0x08020000;
#else // not STM32H7
return 0x08008000;
#endif
}

blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@
#define ts_show_vbatt true
#define ts_show_vr_threshold_2 true
#define ts_show_vr_threshold_all true
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.subaru_eg33_f7.2133657576"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.subaru_eg33_f7.2133657576"
#define TS_SINGLE_WRITE_COMMAND 'W'
#define TS_SINGLE_WRITE_COMMAND_char W
#define TS_TEST_COMMAND 't'
Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/generated/rusefi_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@
#define ts_show_vbatt true
#define ts_show_vr_threshold_2 true
#define ts_show_vr_threshold_all true
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.f407-discovery.2787437970"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.f407-discovery.2787437970"
#define TS_SINGLE_WRITE_COMMAND 'W'
#define TS_SINGLE_WRITE_COMMAND_char W
#define TS_TEST_COMMAND 't'
Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_48way.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 3202128349
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.48way.3202128349"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.48way.3202128349"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_alphax-2chan.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 3747157664
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.alphax-2chan.3747157664"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.alphax-2chan.3747157664"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_alphax-4chan.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 1435571393
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.alphax-4chan.1435571393"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.alphax-4chan.1435571393"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_alphax-8chan.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 757731896
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.alphax-8chan.757731896"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.alphax-8chan.757731896"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_atlas.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 3872187456
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.atlas.3872187456"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.atlas.3872187456"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_core8.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 3256949969
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.core8.3256949969"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.core8.3256949969"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_f407-discovery.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 2787437970
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.f407-discovery.2787437970"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.f407-discovery.2787437970"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_f429-discovery.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 4194701671
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.f429-discovery.4194701671"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.f429-discovery.4194701671"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_frankenso_na6.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 3629445549
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.frankenso_na6.3629445549"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.frankenso_na6.3629445549"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_harley81.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 1939024157
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.harley81.1939024157"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.harley81.1939024157"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_hellen-gm-e67.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 2473541556
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.hellen-gm-e67.2473541556"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.hellen-gm-e67.2473541556"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_hellen-honda-k.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 150925813
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.hellen-honda-k.150925813"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.hellen-honda-k.150925813"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_hellen-nb1.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 220266715
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.hellen-nb1.220266715"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.hellen-nb1.220266715"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_hellen121nissan.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 2113580177
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.hellen121nissan.2113580177"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.hellen121nissan.2113580177"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_hellen121vag.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 3522798402
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.hellen121vag.3522798402"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.hellen121vag.3522798402"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_hellen128.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 2056548544
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.hellen128.2056548544"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.hellen128.2056548544"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 3999485985
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.hellen154hyundai.3999485985"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.hellen154hyundai.3999485985"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_hellen72.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 196249808
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.hellen72.196249808"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.hellen72.196249808"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_hellen81.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 2805527122
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.hellen81.2805527122"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.hellen81.2805527122"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_hellen88bmw.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 2701190497
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.hellen88bmw.2701190497"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.hellen88bmw.2701190497"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_hellenNA6.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 3921039584
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.hellenNA6.3921039584"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.hellenNA6.3921039584"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_hellenNA8_96.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 1427253072
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.hellenNA8_96.1427253072"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.hellenNA8_96.1427253072"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_mre_f4.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 495482079
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.mre_f4.495482079"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.mre_f4.495482079"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_mre_f7.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 495482079
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.mre_f7.495482079"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.mre_f7.495482079"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_prometheus_405.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 3398622455
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.prometheus_405.3398622455"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.prometheus_405.3398622455"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_prometheus_469.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 3398622455
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.prometheus_469.3398622455"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.prometheus_469.3398622455"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_proteus_f4.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 1798886028
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.proteus_f4.1798886028"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.proteus_f4.1798886028"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_proteus_f7.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 1798886028
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.proteus_f7.1798886028"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.proteus_f7.1798886028"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_proteus_h7.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 1798886028
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.proteus_h7.1798886028"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.proteus_h7.1798886028"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_subaru_eg33_f7.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 2133657576
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.subaru_eg33_f7.2133657576"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.subaru_eg33_f7.2133657576"
2 changes: 1 addition & 1 deletion firmware/controllers/generated/signature_tdg-pdm8.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define SIGNATURE_HASH 1890073925
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.27.tdg-pdm8.1890073925"
#define TS_SIGNATURE "rusEFI (FOME) master.2023.08.28.tdg-pdm8.1890073925"
4 changes: 4 additions & 0 deletions firmware/hw_layer/drivers/can/can_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "pch.h"

#if HAL_USE_CAN

#if EFI_PROD_CODE

// Values below calculated with http://www.bittiming.can-wiki.info/
Expand Down Expand Up @@ -190,3 +192,5 @@ const CANConfig* findCanConfig(can_baudrate_e rate) {
return &canConfig500;
}
}

#endif // HAL_USE_CAN
4 changes: 4 additions & 0 deletions firmware/hw_layer/flash_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,7 @@ int intFlashRead(flashaddr_t source, char* destination, size_t size);
* @return FLASH_RETURN_NO_PERMISSION Access denied.
*/
int intFlashWrite(flashaddr_t address, const char* buffer, size_t size);

flashaddr_t intFlashSectorBegin(flashsector_t sector);
flashaddr_t intFlashSectorEnd(flashsector_t sector);
flashsector_t intFlashSectorAt(flashaddr_t address);
40 changes: 20 additions & 20 deletions firmware/hw_layer/main_hardfault.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ void HardFault_Handler_C(void* sp) {
memcpy(&ctx, sp, sizeof(struct port_extctx));

//Interrupt status register: Which interrupt have we encountered, e.g. HardFault?
FaultType faultType = (FaultType)__get_IPSR();
volatile FaultType faultType = (FaultType)__get_IPSR();
(void)faultType;
//For HardFault/BusFault this is the address that was accessed causing the error
uint32_t faultAddress = SCB->BFAR;
volatile uint32_t faultAddress = SCB->BFAR;

//Flags about hardfault / busfault
//See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/Cihdjcfc.html for reference
bool isFaultPrecise = ((SCB->CFSR >> SCB_CFSR_BUSFAULTSR_Pos) & (1 << 1) ? true : false);
bool isFaultImprecise = ((SCB->CFSR >> SCB_CFSR_BUSFAULTSR_Pos) & (1 << 2) ? true : false);
bool isFaultOnUnstacking = ((SCB->CFSR >> SCB_CFSR_BUSFAULTSR_Pos) & (1 << 3) ? true : false);
bool isFaultOnStacking = ((SCB->CFSR >> SCB_CFSR_BUSFAULTSR_Pos) & (1 << 4) ? true : false);
bool isFaultAddressValid = ((SCB->CFSR >> SCB_CFSR_BUSFAULTSR_Pos) & (1 << 7) ? true : false);
volatile bool isFaultPrecise = ((SCB->CFSR >> SCB_CFSR_BUSFAULTSR_Pos) & (1 << 1) ? true : false);
volatile bool isFaultImprecise = ((SCB->CFSR >> SCB_CFSR_BUSFAULTSR_Pos) & (1 << 2) ? true : false);
volatile bool isFaultOnUnstacking = ((SCB->CFSR >> SCB_CFSR_BUSFAULTSR_Pos) & (1 << 3) ? true : false);
volatile bool isFaultOnStacking = ((SCB->CFSR >> SCB_CFSR_BUSFAULTSR_Pos) & (1 << 4) ? true : false);
volatile bool isFaultAddressValid = ((SCB->CFSR >> SCB_CFSR_BUSFAULTSR_Pos) & (1 << 7) ? true : false);
(void)isFaultPrecise;
(void)isFaultImprecise;
(void)isFaultOnUnstacking;
Expand All @@ -71,16 +71,16 @@ void UsageFault_Handler_C(void* sp) {
memcpy(&ctx, sp, sizeof(struct port_extctx));

//Interrupt status register: Which interrupt have we encountered, e.g. HardFault?
FaultType faultType = (FaultType)__get_IPSR();
volatile FaultType faultType = (FaultType)__get_IPSR();
(void)faultType;
//Flags about hardfault / busfault
//See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/Cihdjcfc.html for reference
bool isUndefinedInstructionFault = ((SCB->CFSR >> SCB_CFSR_USGFAULTSR_Pos) & (1 << 0) ? true : false);
bool isEPSRUsageFault = ((SCB->CFSR >> SCB_CFSR_USGFAULTSR_Pos) & (1 << 1) ? true : false);
bool isInvalidPCFault = ((SCB->CFSR >> SCB_CFSR_USGFAULTSR_Pos) & (1 << 2) ? true : false);
bool isNoCoprocessorFault = ((SCB->CFSR >> SCB_CFSR_USGFAULTSR_Pos) & (1 << 3) ? true : false);
bool isUnalignedAccessFault = ((SCB->CFSR >> SCB_CFSR_USGFAULTSR_Pos) & (1 << 8) ? true : false);
bool isDivideByZeroFault = ((SCB->CFSR >> SCB_CFSR_USGFAULTSR_Pos) & (1 << 9) ? true : false);
volatile bool isUndefinedInstructionFault = ((SCB->CFSR >> SCB_CFSR_USGFAULTSR_Pos) & (1 << 0) ? true : false);
volatile bool isEPSRUsageFault = ((SCB->CFSR >> SCB_CFSR_USGFAULTSR_Pos) & (1 << 1) ? true : false);
volatile bool isInvalidPCFault = ((SCB->CFSR >> SCB_CFSR_USGFAULTSR_Pos) & (1 << 2) ? true : false);
volatile bool isNoCoprocessorFault = ((SCB->CFSR >> SCB_CFSR_USGFAULTSR_Pos) & (1 << 3) ? true : false);
volatile bool isUnalignedAccessFault = ((SCB->CFSR >> SCB_CFSR_USGFAULTSR_Pos) & (1 << 8) ? true : false);
volatile bool isDivideByZeroFault = ((SCB->CFSR >> SCB_CFSR_USGFAULTSR_Pos) & (1 << 9) ? true : false);
(void)isUndefinedInstructionFault;
(void)isEPSRUsageFault;
(void)isInvalidPCFault;
Expand All @@ -104,15 +104,15 @@ void MemManage_Handler_C(void* sp) {
FaultType faultType = (FaultType)__get_IPSR();
(void)faultType;
//For HardFault/BusFault this is the address that was accessed causing the error
uint32_t faultAddress = SCB->MMFAR;
volatile uint32_t faultAddress = SCB->MMFAR;

//Flags about hardfault / busfault
//See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/Cihdjcfc.html for reference
bool isInstructionAccessViolation = ((SCB->CFSR >> SCB_CFSR_MEMFAULTSR_Pos) & (1 << 0) ? true : false);
bool isDataAccessViolation = ((SCB->CFSR >> SCB_CFSR_MEMFAULTSR_Pos) & (1 << 1) ? true : false);
bool isExceptionUnstackingFault = ((SCB->CFSR >> SCB_CFSR_MEMFAULTSR_Pos) & (1 << 3) ? true : false);
bool isExceptionStackingFault = ((SCB->CFSR >> SCB_CFSR_MEMFAULTSR_Pos) & (1 << 4) ? true : false);
bool isFaultAddressValid = ((SCB->CFSR >> SCB_CFSR_MEMFAULTSR_Pos) & (1 << 7) ? true : false);
volatile bool isInstructionAccessViolation = ((SCB->CFSR >> SCB_CFSR_MEMFAULTSR_Pos) & (1 << 0) ? true : false);
volatile bool isDataAccessViolation = ((SCB->CFSR >> SCB_CFSR_MEMFAULTSR_Pos) & (1 << 1) ? true : false);
volatile bool isExceptionUnstackingFault = ((SCB->CFSR >> SCB_CFSR_MEMFAULTSR_Pos) & (1 << 3) ? true : false);
volatile bool isExceptionStackingFault = ((SCB->CFSR >> SCB_CFSR_MEMFAULTSR_Pos) & (1 << 4) ? true : false);
volatile bool isFaultAddressValid = ((SCB->CFSR >> SCB_CFSR_MEMFAULTSR_Pos) & (1 << 7) ? true : false);
(void)isInstructionAccessViolation;
(void)isDataAccessViolation;
(void)isExceptionUnstackingFault;
Expand Down
95 changes: 95 additions & 0 deletions firmware/hw_layer/ports/stm32/flash_int_common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Common logic for flash memory between F4/F7 and H7 implementations

#include "pch.h"

#if EFI_INTERNAL_FLASH

#include "flash_int.h"

flashaddr_t intFlashSectorEnd(flashsector_t sector) {
return intFlashSectorBegin(sector + 1);
}

flashsector_t intFlashSectorAt(flashaddr_t address) {
flashsector_t sector = 0;
while (address >= intFlashSectorEnd(sector))
++sector;
return sector;
}

int intFlashErase(flashaddr_t address, size_t size) {
while (size > 0) {
flashsector_t sector = intFlashSectorAt(address);
int err = intFlashSectorErase(sector);
if (err != FLASH_RETURN_SUCCESS)
return err;
address = intFlashSectorEnd(sector);
size_t sector_size = flashSectorSize(sector);
if (sector_size >= size)
break;
size -= sector_size;
}

return FLASH_RETURN_SUCCESS;
}

bool intFlashIsErased(flashaddr_t address, size_t size) {
#if CORTEX_MODEL == 7
// If we have a cache, invalidate the relevant cache lines.
// They may still contain old data, leading us to believe that the
// flash erase failed.
SCB_InvalidateDCache_by_Addr((uint32_t*)address, size);
#endif

/* Check for default set bits in the flash memory
* For efficiency, compare flashdata_t values as much as possible,
* then, fallback to byte per byte comparison. */
while (size >= sizeof(flashdata_t)) {
if (*(volatile flashdata_t*) address != (flashdata_t) (-1)) // flashdata_t being unsigned, -1 is 0xFF..FF
return false;
address += sizeof(flashdata_t);
size -= sizeof(flashdata_t);
}
while (size > 0) {
if (*(char*) address != 0xFF)
return false;
++address;
--size;
}

return TRUE;
}

bool intFlashCompare(flashaddr_t address, const char* buffer, size_t size) {
/* For efficiency, compare flashdata_t values as much as possible,
* then, fallback to byte per byte comparison. */
while (size >= sizeof(flashdata_t)) {
if (*(volatile flashdata_t*) address != *(flashdata_t*) buffer)
return FALSE;
address += sizeof(flashdata_t);
buffer += sizeof(flashdata_t);
size -= sizeof(flashdata_t);
}
while (size > 0) {
if (*(volatile char*) address != *buffer)
return FALSE;
++address;
++buffer;
--size;
}

return TRUE;
}

int intFlashRead(flashaddr_t source, char* destination, size_t size) {
#if CORTEX_MODEL == 7
// If we have a cache, invalidate the relevant cache lines.
// They may still contain old data, leading us to read invalid data.
SCB_InvalidateDCache_by_Addr((uint32_t*)source, size);
#endif

memcpy(destination, (char*) source, size);
return FLASH_RETURN_SUCCESS;
}

#endif // EFI_INTERNAL_FLASH
Loading

0 comments on commit 2e114d1

Please sign in to comment.