-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmain.cc
75 lines (58 loc) · 1.68 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "boot_media_loader.hh"
#include "clocks.hh"
#include "ddr/ram_tests.hh"
#include "ddr/stm32mp1_ram.h"
#include "delay.h"
#include "drivers/leds.hh"
#include "drivers/uart.hh"
#include "pmic.hh"
#include "print.hh"
#include "stm32mp157cxx_ca7.h"
#include "systeminit.h"
#include "osd32brk_conf.hh"
#include "stm32disco_conf.hh"
// Uncomment one of these to select your board:
namespace Board = OSD32BRK;
// namespace Board = STM32MP1Disco;
void main()
{
Board::OrangeLED led;
auto clockspeed = SystemClocks::init_core_clocks(Board::HSE_Clock_Hz, Board::MPU_MHz);
security_init();
Uart<Board::ConsoleUART> console(Board::UartRX, Board::UartTX, 115200);
print("\n\nMP1-Boot\n\n");
print("MPU clock: ", clockspeed, " Hz\n");
if constexpr (Board::PMIC::HasSTPMIC) {
STPMIC1 pmic{Board::PMIC::I2C_config};
if (!pmic.setup_vddcore_pwr())
panic("Could not setup PMIC VDDCORE\n");
if (!pmic.setup_ddr3_pwr())
panic("Could not setup PMIC DDR voltages\n");
}
print("Initializing RAM\n");
stm32mp1_ddr_setup();
print("Testing RAM.\n");
RamTests::run_all(DRAM_MEM_BASE, stm32mp1_ddr_get_size());
auto boot_method = BootDetect::read_boot_method();
print("Booted from ", BootDetect::bootmethod_string(boot_method).data(), "\n");
print("Loading app image...\n");
BootMediaLoader loader{boot_method};
bool image_ok = loader.load_image();
if (image_ok) {
print("Jumping to app\n");
loader.boot_image();
}
// Should not reach here, but in case we do, blink LED rapidly
print("FAILED!\n");
constexpr uint32_t dlytime = 50000;
while (1) {
led.on();
udelay(dlytime);
led.off();
udelay(dlytime);
}
}
void putchar_s(const char c)
{
Uart<Board::ConsoleUART>::putchar(c);
}