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

MAPR remaping with disable_jtag causes debugger to fail on stm32f103RGT6 #105

Closed
TheZoq2 opened this issue Aug 31, 2019 · 0 comments
Closed

Comments

@TheZoq2
Copy link
Member

TheZoq2 commented Aug 31, 2019

I recently got an XL density stm32f103 (stm32f103RGT6) and ran into a pretty strange issue.

When running the following code, the debugger stops responding and I have to reboot the microcontroller with BOOT0 pulled high in order to reflash it. The issue happens when configuring serial, when configuring SPI1 but not when configuring SPI2.

If mapr.mapr().modify(|_, w| w.spi1_remap().bit(PINS::REMAP)); is removed from spi.rs, things work fine which is a pretty clear indication that it is responsible.

Finally, removing disable_jtag also makes things work as normal

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

use panic_semihosting as _;

use stm32f1xx_hal::{
    prelude::*,
    pac,
    serial::{Config, Serial},
    spi::{Spi, Mode, Polarity, Phase}
};
use cortex_m_rt::entry;



#[entry]
fn main() -> ! {
    // Get access to the device specific peripherals from the peripheral access crate
    let p = pac::Peripherals::take().unwrap();

    let mut flash = p.FLASH.constrain();
    let mut rcc = p.RCC.constrain();

    let clocks=rcc.cfgr.freeze(&mut flash.acr);

    // Prepare the alternate function I/O registers
    let mut afio = p.AFIO.constrain(&mut rcc.apb2);

    // Prepare the GPIOB peripheral
    let mut gpioa = p.GPIOA.split(&mut rcc.apb2);
    let mut gpiob = p.GPIOB.split(&mut rcc.apb2);


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

    /*
    let right_usart = Serial::usart1(
        p.USART1,
        (
            gpioa.pa9.into_alternate_push_pull(&mut gpioa.crh),
            gpioa.pa10,
        ),
        &mut afio.mapr,
        Config::default().baudrate(921_600.bps()),
        clocks,
        &mut rcc.apb2,
    );
    */

    let mode = Mode{
        phase: Phase::CaptureOnFirstTransition,
        polarity: Polarity::IdleLow
    };
    let pins = (
        gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl),
        gpioa.pa6,
        gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl),
    );
    let mode = Mode{
        phase: Phase::CaptureOnFirstTransition,
        polarity: Polarity::IdleLow
    };

    let spi = Spi::spi1(p.SPI1, pins, &mut afio.mapr, mode, 1.khz(), clocks, &mut rcc.apb2);

    /*
    {
        let pins = (
            gpiob.pb13.into_alternate_push_pull(&mut gpiob.crh),
            gpiob.pb14,
            gpiob.pb15.into_alternate_push_pull(&mut gpiob.crh),
        );

        let spi = Spi::spi2(p.SPI2, pins, mode, 1.khz(), clocks, &mut rcc.apb1);
    }
    */
    loop {}
}

The same code works perfectly fine on the standard blue pill boards. This might also be a hardware issue, however as far as I know, the debug circuit on my custom PCB is the same as the blue pill.

therealprof added a commit that referenced this issue Aug 31, 2019
Rewrite SWJ config when modifying MAPR (fixes #105)
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

No branches or pull requests

1 participant