rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Enumerations | Functions
mpu_util.cpp File Reference

Detailed Description

Date
Jul 27, 2014
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file mpu_util.cpp.

Enumerations

enum class  DeviceType {
  DualBank1MB , DualBank2MB , SingleBank1MB , SingleBank2MB ,
  Unknown
}
 

Functions

static bool isDualBank ()
 
static uint16_t flashSize ()
 
static DeviceType determineDevice ()
 
bool mcuCanFlashWhileRunning ()
 
size_t flashSectorSize (flashsector_t sector)
 Get the size of sector.
 
uintptr_t getFlashAddrFirstCopy ()
 
uintptr_t getFlashAddrSecondCopy ()
 
void stm32_standby ()
 

Enumeration Type Documentation

◆ DeviceType

enum class DeviceType
strong
Enumerator
DualBank1MB 
DualBank2MB 
SingleBank1MB 
SingleBank2MB 
Unknown 

Definition at line 25 of file mpu_util.cpp.

Function Documentation

◆ determineDevice()

static DeviceType determineDevice ( )
static

Definition at line 33 of file mpu_util.cpp.

33 {
34 bool db = isDualBank();
35 uint16_t fs = flashSize();
36
37 if (db) {
38 if (fs == 1024) {
40 } else if (fs == 2048) {
42 }
43 } else {
44 if (fs == 1024) {
45 // Unsupported scenario! Not enough space for program plus two config copies
46 criticalError("1MB single bank MCU detected: please clear nDBANK option bit and reinstall FW.");
48 } else if (fs == 2048) {
50 }
51 }
52
53 criticalError("Unrecognized flash memory layout db=%d, size=%d", db, fs);
55}
static uint16_t flashSize()
Definition mpu_util.cpp:21
static bool isDualBank()
Definition mpu_util.cpp:12

Referenced by getFlashAddrFirstCopy(), getFlashAddrSecondCopy(), and mcuCanFlashWhileRunning().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flashSectorSize()

size_t flashSectorSize ( flashsector_t  sector)

Get the size of sector.

Returns
sector size in bytes.

Definition at line 63 of file mpu_util.cpp.

63 {
64 // 1MB devices have 8 sectors per bank
65 // 2MB devices have 12 sectors per bank
66 // However, the second bank always starts at index 12 (1MB devices have a 4 sector discontinuity between banks)
67
68 if (sector >= 12) {
69 // The second bank has the same structure as the first
70 return flashSectorSize(sector - 12);
71 }
72
73 // On 1MB devices, sectors 8-11 don't exist, therefore have zero size.
74 if (flashSize() == 1024) {
75 if (sector > 7 && sector < 12) {
76 return 0;
77 }
78 }
79
80 // Pages are twice the size when in single bank mode
81 size_t dbMul = isDualBank() ? 1 : 2;
82
83 if (sector <= 3)
84 return 16 * 1024 * dbMul;
85 else if (sector == 4)
86 return 64 * 1024 * dbMul;
87 else if (sector >= 5)
88 return 128 * 1024 * dbMul;
89 return 0;
90}
size_t flashSectorSize(flashsector_t sector)
Get the size of sector.
Definition mpu_util.cpp:237
Here is the call graph for this function:

◆ flashSize()

static uint16_t flashSize ( )
static

Definition at line 21 of file mpu_util.cpp.

21 {
22 return *reinterpret_cast<const volatile uint16_t*>(FLASHSIZE_BASE);
23}

Referenced by at32GetMcuType(), determineDevice(), flashSectorSize(), and sayHello().

Here is the caller graph for this function:

◆ getFlashAddrFirstCopy()

uintptr_t getFlashAddrFirstCopy ( void  )

Flex Non Volatile Memory is faster than flash It also has smaller pages so it takes less time to erase

There is no remote access to FlexNVM meaning that we cannot erase settings externally

Definition at line 92 of file mpu_util.cpp.

92 {
93 switch (determineDevice()) {
95 // Sector 18, second to last 128K sector
96 return 0x080C0000;
98 // Sector 7, last 256K sector
99 return 0x080C0000;
100 case DeviceType::DualBank2MB: /* falls thru */
102#ifdef EFI_FLASH_USE_1500_OF_2MB
103 // Right after the first 1.5 megabytes
104 // Sector 20 for dual bank
105 // Sector 10 for single bank
106 return 0x08180000;
107#else
108 // Start of the second megabyte
109 // Sector 12 for dual bank
110 // Sector 8 for single bank
111 return 0x08100000;
112#endif // EFI_FLASH_USE_1500_OF_2MB
113 default:
114 return 0;
115 }
116}
static DeviceType determineDevice()
Definition mpu_util.cpp:33
Here is the call graph for this function:

◆ getFlashAddrSecondCopy()

uintptr_t getFlashAddrSecondCopy ( void  )

Definition at line 118 of file mpu_util.cpp.

118 {
119 switch (determineDevice()) {
121 // Sector 19, last 128K sector, 128K after the first copy
122 return 0x080E0000;
124#ifdef EFI_FLASH_USE_1500_OF_2MB
125 // Sector 21, 128K after the first copy
126 return 0x081A0000;
127#else
128 // Sector 14, 32K after the first copy
129 return 0x08108000;
130#endif // EFI_FLASH_USE_1500_OF_2MB
132#ifdef EFI_FLASH_USE_1500_OF_2MB
133 // Sector 11, 256K after the first copy
134 return 0x081C0000;
135#else
136 // Sector 9, 256K after the first copy
137 return 0x08140000;
138#endif // EFI_FLASH_USE_1500_OF_2MB
140 // We can't fit a second copy in this config, fall thru to failure case
141 default:
142 return 0;
143 }
144}
Here is the call graph for this function:

◆ isDualBank()

static bool isDualBank ( void  )
static

Definition at line 12 of file mpu_util.cpp.

12 {
13#ifdef FLASH_OPTCR_nDBANK
14 // cleared bit indicates dual bank
15 return (FLASH->OPTCR & FLASH_OPTCR_nDBANK) == 0;
16#else
17 return 0;
18#endif
19}

Referenced by determineDevice(), and flashSectorSize().

Here is the caller graph for this function:

◆ mcuCanFlashWhileRunning()

bool mcuCanFlashWhileRunning ( )

Definition at line 57 of file mpu_util.cpp.

57 {
58 // Allow flash-while-running if dual bank mode is enabled, and we're a 2MB device (ie, no code located in second bank)
60}
Here is the call graph for this function:

◆ stm32_standby()

void stm32_standby ( )

Definition at line 177 of file mpu_util.cpp.

177 {
178 SysTick->CTRL = 0;
179 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
180 PWR->CR1 |= PWR_CR1_PDDS; // PDDS = use standby mode (not stop mode)
181 PWR->CR1 |= PWR_CR1_CSBF; // Clear standby flag
182
183 // Do anything the board wants to prepare for standby mode - enabling wakeup sources!
185
186 __disable_irq();
187 __WFI();
188}
void boardPrepareForStandby()
Here is the call graph for this function:

Go to the source code of this file.