-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
executable file
·143 lines (124 loc) · 4.49 KB
/
main.rs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#![no_main]
#![no_std]
#![allow(unused_imports)]
{% if rtt == "Yes" %}use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};{% else %}
use panic_halt as _;{% endif %}
{% if rtic == "Yes" %}use systick_monotonic::{fugit::Duration, Systick};{% else %}{% if board == "IskraJS" %}use cortex_m_rt::{entry, pre_init};{% else %}use cortex_m_rt::entry;{% endif %}{% endif %}
use stm32f4xx_hal::{
gpio::{Pin, Output, PushPull},
pac,
prelude::*,
};
{% if board == "IskraJS" %}// Example of using CCMRAM
#[link_section = ".ccmram"]
#[inline(never)]
fn example_function() -> u32 {
16 + 16
}
#[link_section = ".ccmram"]
static mut EXAMPLE_DATA: u32 = 0;{% endif %}
{% if rtic == "Yes" %}#[rtic::app(device = stm32f4xx_hal::pac, peripherals = true, dispatchers = [SPI3])]
mod app {
use super::*;
#[shared]
struct Shared {}
#[local]
struct Local {
{% if board == "IskraJS" %}led: Pin<'B', 6, Output<PushPull>>,{% else %}led: Pin<'B', 2, Output<PushPull>>,{% endif %}
}
#[monotonic(binds = SysTick, default = true)]
type MonoTimer = Systick<1000>;
#[init]
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
{% if rtt == "Yes" %}rtt_init_print!();{% endif %}
{% if board == "IskraJS" %}// CCMRAM initialization
unsafe {
extern "C" {
static mut _ccmram_start: u32;
static mut _ccmram_end: u32;
static mut _siccmram: u32;
}
r0::init_data(&mut _ccmram_start, &mut _ccmram_end, &_siccmram);
}{% endif %}
// Configuration clocks
let rcc = ctx.device.RCC.constrain();
{% if board == "IskraJS" %}let _clocks = rcc
.cfgr
.use_hse(8.MHz())
.sysclk(168.MHz())
.hclk(168.MHz())
.pclk1(42.MHz())
.pclk2(84.MHz())
.require_pll48clk()
.freeze();
{% else %}let _clocks = rcc
.cfgr
.use_hse(8.MHz())
.sysclk(96.MHz())
.hclk(96.MHz())
.pclk1(48.MHz())
.pclk2(96.MHz())
.require_pll48clk()
.freeze();{% endif %}
let mono = Systick::new(ctx.core.SYST, 96_000_000);
let gpiob = ctx.device.GPIOB.split();
{% if board == "IskraJS" %}let led = gpiob.pb6.into_push_pull_output();{% else %}let led = gpiob.pb2.into_push_pull_output();{% endif %}
{% if rtt == "Yes" %}rprintln!("It works 🎉");{% endif %}// Schedule the blinking task
blink::spawn_after(Duration::<u64, 1, 1000>::from_ticks(1000)).unwrap();
(Shared {}, Local { led }, init::Monotonics(mono))
}
#[task(local = [led])]
fn blink(ctx: blink::Context) {
ctx.local.led.toggle();
blink::spawn_after(Duration::<u64, 1, 1000>::from_ticks(1000)).unwrap();
}
}{% else %}{% if board == "IskraJS" %}// CCMRAM initialization
#[pre_init]
unsafe fn ccmram_init() {
extern "C" {
static mut _ccmram_start: u32;
static mut _ccmram_end: u32;
static mut _siccmram: u32;
}
r0::init_data(&mut _ccmram_start, &mut _ccmram_end, &_siccmram);
}{% endif %}
#[entry]
fn main() -> ! {
{% if rtt == "Yes" %}rtt_init_print!();{% endif %}if let (Some(device_periph), Some(core_periph)) =
(pac::Peripherals::take(), cortex_m::peripheral::Peripherals::take())
{
// Configuration clocks
let rcc = device_periph.RCC.constrain();
{% if board == "IskraJS" %}let clocks = rcc
.cfgr
.use_hse(8.MHz())
.sysclk(168.MHz())
.hclk(168.MHz())
.pclk1(42.MHz())
.pclk2(84.MHz())
.require_pll48clk()
.freeze();
{% else %}let clocks = rcc
.cfgr
.use_hse(8.MHz())
.sysclk(96.MHz())
.hclk(96.MHz())
.pclk1(48.MHz())
.pclk2(96.MHz())
.require_pll48clk()
.freeze();{% endif %}
let gpiob = device_periph.GPIOB.split();
{% if board == "IskraJS" %}let mut led = gpiob.pb6.into_push_pull_output();{% else %}let mut led = gpiob.pb2.into_push_pull_output();{% endif %}
let mut delay = core_periph.SYST.delay(&clocks);
{% if rtt == "Yes" %}rprintln!("It works 🎉");{% endif %}
loop {
led.set_high();
delay.delay_ms(1000_u32);
led.set_low();
delay.delay_ms(1000_u32);
}
}
loop {}
}
{% endif %}