Skip to content
This repository was archived by the owner on Feb 13, 2019. It is now read-only.

Commit 45ff868

Browse files
authored
Merge pull request #117 from TheZoq2/disable_jtag
Add function for disabling JTAG
2 parents 3bca91d + 4d9c292 commit 45ff868

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

examples/nojtag.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}

src/afio.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ impl MAPR {
5252
pub fn mapr(&mut self) -> &afio::MAPR {
5353
unsafe { &(*AFIO::ptr()).mapr }
5454
}
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+
}
5560
}
5661

5762
pub struct EXTICR1 {

0 commit comments

Comments
 (0)