1+ #include < cstdint>
2+
3+ #include " stm32f469.hpp"
4+
5+ #include < klib/io/systick.hpp>
6+ #include < klib/io/core_clock.hpp>
7+ #include < io/system.hpp>
8+
9+ // disable the constructor does not take arguments error in vscode
10+ #ifdef __INTELLISENSE__
11+ #pragma diag_suppress 1094
12+ #endif
13+
14+ void __attribute__ ((__constructor__(101 ))) __target_startup() {
15+ namespace target = klib::stm32f469;
16+ using clock = target::io::system::clock;
17+
18+ // change the wait states for flash access to 5 (for 150-180Mhz)
19+ target::io::system::flash::setup<5 , true , true , true >();
20+
21+ // setup the clock to 180Mhz (in this example we are using an 8Mhz
22+ // oscillator)
23+ // ((8Mhz * 360) / 8 = 360Mhz) / 2 = 180Mhz
24+ target::io::system::clock::set_main<target::io::system::crystal::source::external, 8'000'000 , 360 , 8 , 2 >();
25+ // target::io::system::clock::set_main<target::io::system::crystal::source::internal, 16'000'000, 360, 16, 2>();
26+
27+ // setup the irq handler before main is called. This
28+ // moves the vector table to ram so it can be changed
29+ // at runtime. When no interrupts are used this
30+ // function call can be removed. By default interrupts
31+ // are mapped to a function that halts the whole cpu.
32+ // this call does nothing when a flash handler is
33+ // configured
34+ klib::irq::boot_helper::init<target::irq>();
35+
36+ // check if we can enable the systick. If we enable it
37+ // here when we have a flash irq handler we will cause
38+ // a hang in the default irq handler
39+ if constexpr (klib::irq::boot_helper::in_ram<target::irq>()) {
40+ // init the systick timer
41+ klib::io::systick<>::init<target::irq, true >();
42+
43+ // enable the systick timer
44+ klib::io::systick<>::enable ();
45+ }
46+
47+ // enable MPU, bus and usage faults in separate inpterrupts
48+ SCB->SHCSR = 0b111 << 16 ;
49+ }
0 commit comments