Skip to content

Commit 5165381

Browse files
committed
Added startup, clocks and system
1 parent 01344fa commit 5165381

4 files changed

Lines changed: 73 additions & 4 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef KLIB_STM32F429_CLOCKS_HPP
2+
#define KLIB_STM32F429_CLOCKS_HPP
3+
4+
#include <targets/core/stm/stm32f4xx/clocks.hpp>
5+
6+
namespace klib::stm32f429::io {
7+
using clocks = klib::core::stm32f4xx::io::clocks;
8+
}
9+
10+
#endif
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef KLIB_STM32F429_SYSTEM_HPP
2+
#define KLIB_STM32F429_SYSTEM_HPP
3+
4+
#include <targets/core/stm/stm32f4xx/system.hpp>
5+
6+
namespace klib::stm32f429::io::system {
7+
using namespace klib::core::stm32f4xx::io::system;
8+
}
9+
10+
#endif

targets/chip/stm32f429/startup.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <cstdint>
2+
3+
#include "stm32f429.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::stm32f429;
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+
}

targets/chip/stm32f429/stm32f429.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#ifndef KLIB_STM32F469_HPP
2-
#define KLIB_STM32F469_HPP
1+
#ifndef KLIB_STM32F429_HPP
2+
#define KLIB_STM32F429_HPP
33

44
#include <klib/irq.hpp>
55

66
#include "stm32f429.h"
77

8-
namespace klib::stm32f469 {
9-
// irq for the stm32f469
8+
namespace klib::stm32f429 {
9+
// irq for the stm32f429
1010
using irq = klib::irq::KLIB_IRQ<0, 16 + 91>;
1111

1212
/**

0 commit comments

Comments
 (0)