Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle debugger pins #79

Merged
merged 3 commits into from
Jul 10, 2019
Merged

Conversation

TeXitoi
Copy link
Contributor

@TeXitoi TeXitoi commented Jul 8, 2019

At startup, pins used by the debugger are in Debugger state, prohibiting their
use. disable_jtag allow to get PA15, PB3 and PB4 usable as GPIO or alternate
functions at the cost of disabling JTAG.

Discussed in #77

cc @MauroMombelli

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Jul 8, 2019

I've tested nojtag on a bluepill with success.

At startup, pins used by the debugger are in `Debugger` state, prohibiting their
use. `disable_jtag` allow to get PA15, PB3 and PB4 usable as GPIO or alternate
functions at the cost of disabling JTAG.
@TeXitoi TeXitoi force-pushed the handle-debugger-pins branch from b4072ad to 730678e Compare July 8, 2019 21:24
@TeXitoi
Copy link
Contributor Author

TeXitoi commented Jul 9, 2019

It doesn't work :-( This complies:

#![deny(unsafe_code)]
#![no_main]
#![no_std]

use panic_halt as _;

use stm32f1xx_hal::{
    prelude::*,
    pac,
};
use cortex_m_rt::entry;

#[entry]
fn main() -> ! {
    let p = pac::Peripherals::take().unwrap();

    let mut rcc = p.RCC.constrain();
    let mut gpioa = p.GPIOA.split(&mut rcc.apb2);
    let mut gpiob = p.GPIOB.split(&mut rcc.apb2);
    let mut afio = p.AFIO.constrain(&mut rcc.apb2);

    //let (pa15, pb3, pb4) = afio.mapr.disable_jtag(gpioa.pa15, gpiob.pb3, gpiob.pb4);

    let mut pa15 = gpioa.pa15.into_push_pull_output(&mut gpioa.crh);
    let mut pb3 = gpiob.pb3.into_push_pull_output(&mut gpiob.crl);
    let mut pb4 = gpiob.pb4.into_push_pull_output(&mut gpiob.crl);

    loop {
        pa15.toggle();
        pb3.toggle();
        pb4.toggle();
        cortex_m::asm::delay(8_000_000);
    }
}

@TeXitoi TeXitoi changed the title Handle debugger pins WiP: Handle debugger pins Jul 9, 2019
@thalesfragoso
Copy link
Member

thalesfragoso commented Jul 9, 2019

Maybe if you create a marker (empty) trait and implement it for Input<MODE>, Output<MODE>, Analog and Alternate<MODE>(maybe I'm missing another) but not for Debugger. And then you can add a bound to MODE on line 189.

Sorry for some lacking explanation, I'm on mobile right now.

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Jul 9, 2019

I see the idea, thanks, will try.

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Jul 9, 2019

@thalesfragoso Thanks it's working.

@TeXitoi TeXitoi changed the title WiP: Handle debugger pins Handle debugger pins Jul 9, 2019
@MauroMombelli
Copy link

MauroMombelli commented Jul 9, 2019

yay! Suggestion: those are not the only tricky pin, we could also completely disable debugging to get other 2 pin (PA13 and PA14).

PB2 could be used as GPIO or BOOT1 depending on the initial status (cant find how right now)

PD0 and PD1 are by default external clock, those could be reclaimed (not sure if they are already "fixed")

PC13 (tamper RTC), PC14(osc32_in) and PC15(osc32_out) also could be in a special state:

(GPIO is)Main function after the first backup domain power-up. Later on, it depends on the contents of the Backup registers even after reset (because these registers are not reset by the main reset). For details on how to manage these IOs, refer to theBattery backup domain and BKP register description sections in the STM32F10xxx reference manual, available from the STMicroelectronics website: www.st.com.

i took a look around and i saw a lot people banging their head against those pin used as debug by default; im sure the PR will help a lot of people to identify the problem

also i am wandering if this should be proposed to the other implementations too.

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Jul 9, 2019

I've blocked PA13 and PA14, freeing them would only be adding a disable_jtag_sw taking the 5 pins.

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Jul 9, 2019

also i am wandering if this should be proposed to the other implementations too.

I don't understand this sentence. Which other implementations?

@MauroMombelli
Copy link

I don't understand this sentence. Which other implementations?

other chip implementation like stm32f3xx-hal etc..

@therealprof
Copy link
Member

Hm, using MaybeUninit will bump the MSRV to 1.36, i.e. the latest and greatest. I personally don't have a problem with that but I can imagine people frowning upon that...

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Jul 10, 2019

@therealprof so you want I dont use it? I can, that's just using uninitialized instead.

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Jul 10, 2019

Or i thinks i can remove this uninitialized trick.

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Jul 10, 2019

@therealprof no more MaybeUninit

Copy link
Member

@therealprof therealprof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks!

@therealprof therealprof merged commit 5687091 into stm32-rs:master Jul 10, 2019
@TeXitoi TeXitoi deleted the handle-debugger-pins branch July 10, 2019 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants