File tree 5 files changed +64
-0
lines changed 5 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
8
8
## [ Unreleased]
9
9
10
+ ### Added
11
+
12
+ - Initialize the FPU before main
13
+
10
14
## [ v0.1.0] - 2016-10-04
11
15
12
16
### Added
Original file line number Diff line number Diff line change
1
+ //! You can do fast, single precision, floating point math as well
2
+
3
+ #![ feature( asm) ]
4
+ #![ no_main]
5
+ #![ no_std]
6
+
7
+ #[ macro_use]
8
+ extern crate f3;
9
+
10
+ #[ export_name = "main" ]
11
+ pub extern "C" fn main ( ) -> ! {
12
+ let x = black_box ( 2_f32 ) ;
13
+ let y = black_box ( 3_f32 ) ;
14
+ let z = black_box ( x * y) ;
15
+
16
+ iprintln ! ( "{} * {} = {}" , x, y, z) ;
17
+
18
+ loop { }
19
+ }
20
+
21
+ // Magic to prevent optimizations like "constant folding" which is when LLVM
22
+ // performs arithmetic at compile time. This is a copy of `test::black_box`.
23
+ fn black_box < T > ( x : T ) -> T {
24
+ unsafe {
25
+ asm ! ( "" :: "r" ( & x) ) ;
26
+ }
27
+
28
+ x
29
+ }
Original file line number Diff line number Diff line change
1
+ //! Floating Point Unit (FPU)
2
+
3
+ use cortex_m;
4
+
5
+ /// Initializes the FPU
6
+ ///
7
+ /// # Safety
8
+ ///
9
+ /// - Must be called once
10
+ /// - Must be called in an interrupt-free environment
11
+ pub unsafe fn init ( ) {
12
+ let scb = cortex_m:: peripheral:: scb_mut ( ) ;
13
+
14
+ // Enable the FPU co-processor
15
+ let cpacr = scb. cpacr . read ( ) ;
16
+ scb. cpacr . write ( {
17
+ // Enable privileged access to the co-processor 10
18
+ const CP10 : u32 = 0b01 << 20 ;
19
+ // Enable privileged access to the co-processor 11
20
+ const CP11 : u32 = 0b01 << 22 ;
21
+
22
+ cpacr | CP10 | CP11
23
+ } ) ;
24
+ }
Original file line number Diff line number Diff line change @@ -23,6 +23,11 @@ impl Write for Port {
23
23
}
24
24
25
25
/// Initializes the ITM port
26
+ ///
27
+ /// # Safety
28
+ ///
29
+ /// - Must be called once
30
+ /// - Must be called in an interrupt-free environment
26
31
pub unsafe fn init ( ) {
27
32
let dbgmcu = peripheral:: dbgmcu_mut ( ) ;
28
33
let dcb = cortex_m:: peripheral:: dcb_mut ( ) ;
Original file line number Diff line number Diff line change @@ -142,6 +142,7 @@ mod lang_items;
142
142
pub mod delay;
143
143
pub mod examples;
144
144
pub mod exception;
145
+ pub mod fpu;
145
146
pub mod itm;
146
147
pub mod led;
147
148
pub mod peripheral;
@@ -152,6 +153,7 @@ pub mod peripheral;
152
153
#[ linkage = "weak" ]
153
154
pub unsafe extern "C" fn init ( ) {
154
155
delay:: init ( ) ;
156
+ fpu:: init ( ) ;
155
157
itm:: init ( ) ;
156
158
led:: init ( ) ;
157
159
}
You can’t perform that action at this time.
0 commit comments