rusEFI
The most advanced open source ECU
mpu_util.cpp
Go to the documentation of this file.
1 /**
2  * @file mpu_util.cpp
3  *
4  * @date Jul 27, 2014
5  * @author Andrey Belomutskiy, (c) 2012-2020
6  */
7 #include "pch.h"
8 #include "flash_int.h"
9 
11  // Never allow flash while running on F4, dual bank not implemented.
12  return false;
13 }
14 
16  // sectors 0..11 are the 1st memory bank (1Mb), and 12..23 are the 2nd (the same structure).
17  if (sector <= 3 || (sector >= 12 && sector <= 15))
18  return 16 * 1024;
19  else if (sector == 4 || sector == 16)
20  return 64 * 1024;
21  else if ((sector >= 5 && sector <= 11) || (sector >= 17 && sector <= 23))
22  return 128 * 1024;
23  return 0;
24 }
25 
26 #define TM_ID_GetFlashSize() (*(__IO uint16_t *) (FLASHSIZE_BASE))
27 
28 uintptr_t getFlashAddrFirstCopy() {
29  /* last 128K sector on 512K devices */
30  if (TM_ID_GetFlashSize() <= 512)
31  return 0x08060000;
32  return 0x080E0000;
33 }
34 
36  /* no second copy on 512K devices */
37  if (TM_ID_GetFlashSize() <= 512)
38  return 0x000000000;
39  return 0x080C0000;
40 }
41 /*
42 STOP mode for F7 is needed for wakeup from multiple EXTI pins. For example PD0, which is CAN rx.
43 However, for F40X & F42X this may be useless. STOP in itself eats more current than standby.
44 With F4 only having PA0 available for wakeup, this negates its need.
45 */
46 /*
47 void stm32_stop() {
48  // Don't get bothered by interrupts
49  __disable_irq();
50 
51  SysTick->CTRL = 0;
52  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
53  enginePins.errorLedPin.setValue(0);
54  enginePins.runningLedPin.setValue(0);
55  enginePins.communicationLedPin.setValue(0);
56  enginePins.warningLedPin.setValue(0);
57 
58  PWR->CR &= ~PWR_CR_PDDS; // cleared PDDS means stop mode (not standby)
59  PWR->CR |= PWR_CR_FPDS; // turn off flash in stop mode
60  #ifdef STM32F429xx //F40X Does not have these regulators available.
61  PWR->CR |= PWR_CR_UDEN; // regulator underdrive in stop mode *
62  PWR->CR |= PWR_CR_LPUDS; // low power regulator in under drive mode
63  #endif
64  PWR->CR |= PWR_CR_LPDS; // regulator in low power mode
65 
66  // Do anything the board wants to prepare for stop mode - enabling wakeup sources!
67  boardPrepareForStop();
68 
69  // enable Deepsleep mode
70  __WFI();
71 
72  // Lastly, reboot
73  NVIC_SystemReset();
74 }
75 */
76 /*
77  * Standby for both F4 & F7 works perfectly, with very little current consumption.
78  * Downside is that there is a limited amount of pins that can wakeup F7, and only PA0 for F4XX.
79 */
80 void stm32_standby() {
81  // Don't get bothered by interrupts
82  __disable_irq();
83 
84  SysTick->CTRL = 0;
85  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
86  PWR->CR |= PWR_CR_PDDS; // PDDS = use standby mode (not stop mode)
87  PWR->CR |= PWR_CR_CSBF; // Clear standby flag
88 
89  // Do anything the board wants to prepare for standby mode - enabling wakeup sources!
91 
92  __WFI();
93 }
bool allowFlashWhileRunning()
Definition: mpu_util.cpp:10
void stm32_standby()
Definition: mpu_util.cpp:17
uintptr_t getFlashAddrSecondCopy()
Definition: mpu_util.cpp:234
uintptr_t getFlashAddrFirstCopy()
Definition: mpu_util.cpp:230
size_t flashSectorSize(flashsector_t sector)
Get the size of sector.
Definition: mpu_util.cpp:219
uint8_t flashsector_t
Index of a sector.
Definition: flash_int.h:89
void boardPrepareForStandby()