How to use serial instructions to connect with a bluetooth device?

I'm trying to build a program so that i can connect my stm32 card with a bluetooth hc-06 in order to turn on and off a led by using letters. I've found the code i need but it's in arduino. Can anyone help me to translate it so that i can prove it?

This is the code i've found and the one i need to translate:

int led = 7;

int state = 0;

void setup() {

void loop() {
    if (Serial.available() > 0) {
        state =;
    if state == 'a' {
    if state == 'b' {

This is what i have done by far. I'm using the crate stm32f4xx-hal:


use panic_halt as _;

use cortex_m;
use cortex_m_rt::entry;
use stm32f4xx_hal as hal;

use crate::hal::{prelude::*, serial::config::Config, serial::Serial, stm32};

fn main() -> ! {
    let dp = stm32::Peripherals::take().unwrap();
    let cp = cortex_m::peripheral::Peripherals::take().unwrap();

    let gpioa = dp.GPIOA.split();

    let rcc = dp.RCC.constrain();

    let clocks = rcc.cfgr.use_hse(8.mhz()).freeze();

    let mut delay = hal::delay::Delay::new(cp.SYST, clocks);

    //define pins
    let tx_pin = gpioa.pa9.into_alternate_af7();
    let rx_pin = gpioa.pa10.into_alternate_af7();
    let mut led_pin = gpioa.pa7.into_push_pull_output();

    // configurar serial
    let serial = Serial::usart1(
        (tx_pin, rx_pin),

    let (mut _tx, mut rx) = serial.split();

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.