Embedded Rust on a Blue Pill Using the Embassy RTOS to Create a Simple LED Blink Program

Hello,

I am new to Rust and I program embedded C. I would like to deepen my knowledge of Rust. I created a simple example using the LED blink program available at this link: embassy/examples/stm32f1/src/bin/blinky.rs at main · embassy-rs/embassy · GitHub.

My Cargo.toml file is as follows:

[package]
name = "testeLed"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
# Dependencies for Embassy and other libraries
embassy-stm32 = { version = "0.1.0", features = ["stm32f103c8", "defmt", "unstable-pac", "memory-x", "time-driver-any"] }
embassy-sync = { version = "0.6.0", features = ["defmt"] }
embassy-executor = { version = "0.6.0", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
embassy-time = { version = "0.3.2", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
embassy-usb = { version = "0.3.0", features = ["defmt"] }
embassy-futures = "0.1.1"

defmt = "0.3"
defmt-rtt = "0.4"

cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.3"
embedded-hal = "1.0.0"
panic-probe = { version = "0.3.2", features = ["print-defmt"] }
heapless = { version = "0.8.0", default-features = false }
nb = "1.1.0"
panic-halt = "0.2.0"

[build]
target = "thumbv7m-none-eabi"

[target.thumbv7m-none-eabi]
runner = "probe-run --chip STM32F103C8T6"
rustflags = [
    "-C", "link-arg=-Tlink.x"
]

[profile.dev]
![duvida|679x500](upload://6grLnoN5UgRwwBffg1DBXRvWcls.png)

opt-level = "s"

[profile.release]
![duvida|679x500](upload://6grLnoN5UgRwwBffg1DBXRvWcls.png)

debug = 2

I adapted it for the new versions of crates available. In Windows PowerShell, when I run the command cargo run --release, the following error from the image appears. Please help me! I'm making a project in college using embedded rust. Thank you!

i have the following declaration (with features enabled) for the cortex-m crate:

cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }

these are cargo configurations, which should be in .cargo/config.toml file, not the Cargo.toml file, which is the package's manifest.

2 Likes

You are right. I forgot about that. Thank you. But I am still having trouble trying to put the program on the Blue Pill. I tried to use probe-rs and OpenOCD, but they don't work. Do you know where I can find information about it or how to use them? I found the information at these links, but it didn't work. It seems so easy, I'm afraid I'm missing something. I'm really worried I really need to do this work to college.

These are the links with the information:
Hardware - The Embedded Rust Book

https://docs.rust-embedded.org/book/start/hardware.html

Thank you!

you need a st-link v2 for programming the board:

I have a template-like repo for the blue-pill with embassy also:

1 Like

Thank you for your answer. I have an ST-Link V2, but I cannot flash the code onto the Blue Pill. I tried using cargo embed among others (like probe-rs, for example), but it doesn't work. Do you know where or how I can perform the flashing process? It's important, and I really appreciate your help. Thank you so much!

What fails when you're flashing? We need to see what's going wrong to be able to help

1 Like

I changed the board. I was using bluepill but now I'm using STM32G070RBT6 instead. But they both are returning the same error. The image explains that. I don't know what could be wrong and I don't know what else I could do. Please helpe me!


.

There are still [build] and [target.thumbv7m-none-eabi] section in your Cargo.toml

Thank you for your help. I solved the problem. The error was in the memory.x file.

1 Like