Skip to content

GPIO output toggling does not work on Alternate pins #102

Closed
@dbrgn

Description

@dbrgn

I'm using the blue pill board, which has an LED connected to PC13.

With the following code, the LED lights up as soon as the pin is configured as push/pull output, but it cannot be turned off (set_low does not turn off the LED, and for sanity checking set_high does not either).

#![deny(unsafe_code)]
#![no_main]
#![cfg_attr(not(test), no_std)]

// Panicking behavior
extern crate panic_semihosting; // logs messages to the host stderr; requires a debugger

#[macro_use]
extern crate cortex_m_rt;

use cortex_m_semihosting::hprintln;
use embedded_hal::digital::v2::OutputPin;
use stm32f1xx_hal::{prelude::*, pac};

#[entry]
fn main() -> ! {
    hprintln!("init").unwrap();

    let device: pac::Peripherals = pac::Peripherals::take().unwrap();

    let mut rcc = device.RCC.constrain();
    let mut gpioc = device.GPIOC.split(&mut rcc.apb2);

    let mut led = gpioc.pc13.into_alternate_push_pull(&mut gpioc.crh);
    led.set_low().unwrap();

    hprintln!("loop").unwrap();
    loop {
    }
}

This code uses stm32f1 0.8 and stm32f1xx-hal 0.4. I also tried stm32f1 0.6 and stm32f1xx-hal 0.2, which showed the same behavior.

Any idea what the problem could be?

The full code can be found here (branch led-bug).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions