This repository was archived by the owner on Feb 13, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ //! Disables the JTAG ports to give access to pb3, pb4 and PA15
2
+
3
+ #![ deny( unsafe_code) ]
4
+ #![ deny( warnings) ]
5
+ #![ no_main]
6
+ #![ no_std]
7
+
8
+ extern crate cortex_m_rt as rt;
9
+ extern crate panic_semihosting;
10
+ extern crate stm32f103xx_hal as hal;
11
+
12
+ use hal:: prelude:: * ;
13
+ use hal:: stm32f103xx;
14
+ use rt:: { entry, exception, ExceptionFrame } ;
15
+
16
+ #[ entry]
17
+ fn main ( ) -> ! {
18
+ let p = stm32f103xx:: Peripherals :: take ( ) . unwrap ( ) ;
19
+
20
+ let mut rcc = p. RCC . constrain ( ) ;
21
+ let mut gpiob = p. GPIOB . split ( & mut rcc. apb2 ) ;
22
+ let mut afio = p. AFIO . constrain ( & mut rcc. apb2 ) ;
23
+
24
+ afio. mapr . disable_jtag ( ) ;
25
+
26
+ gpiob. pb4 . into_push_pull_output ( & mut gpiob. crl ) . set_low ( ) ;
27
+
28
+ loop { }
29
+ }
30
+
31
+ #[ exception]
32
+ fn HardFault ( ef : & ExceptionFrame ) -> ! {
33
+ panic ! ( "{:#?}" , ef) ;
34
+ }
35
+
36
+ #[ exception]
37
+ fn DefaultHandler ( irqn : i16 ) {
38
+ panic ! ( "Unhandled exception (IRQn = {})" , irqn) ;
39
+ }
Original file line number Diff line number Diff line change @@ -52,6 +52,11 @@ impl MAPR {
52
52
pub fn mapr ( & mut self ) -> & afio:: MAPR {
53
53
unsafe { & ( * AFIO :: ptr ( ) ) . mapr }
54
54
}
55
+
56
+ /// Disables the JTAG to free up pb3, pb4 and pa15 for normal use
57
+ pub fn disable_jtag ( & mut self ) {
58
+ self . mapr ( ) . modify ( |_, w| unsafe { w. swj_cfg ( ) . bits ( 0b010 ) } )
59
+ }
55
60
}
56
61
57
62
pub struct EXTICR1 {
You can’t perform that action at this time.
0 commit comments