rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
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
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/*
43 * Standby for both F4 & F7 works perfectly, with very little current consumption.
44 * Downside is that there is a limited amount of pins that can wakeup F7, and only PA0 for F4XX.
45*/
47 // Don't get bothered by interrupts
48 __disable_irq();
49
50 SysTick->CTRL = 0;
51 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
52 PWR->CR |= PWR_CR_PDDS; // PDDS = use standby mode (not stop mode)
53 PWR->CR |= PWR_CR_CSBF; // Clear standby flag
54
55 // Do anything the board wants to prepare for standby mode - enabling wakeup sources!
57
58 __WFI();
59}
bool mcuCanFlashWhileRunning()
Definition mpu_util.cpp:10
void stm32_standby()
Definition mpu_util.cpp:18
uintptr_t getFlashAddrSecondCopy()
Definition mpu_util.cpp:252
uintptr_t getFlashAddrFirstCopy()
Definition mpu_util.cpp:248
size_t flashSectorSize(flashsector_t sector)
Get the size of sector.
Definition mpu_util.cpp:237
uint8_t flashsector_t
Index of a sector.
Definition flash_int.h:89
void boardPrepareForStandby()