Stm32g4xx-hal blinky example

Hello

I am trying to run the examples in stm32g4xx-hal to learn how embedded rust works. But when I try to build the example I get the following error:

PS C:\Users\source\repos\stm32g4xx-hal\examples> cargo build --example blinky --features stm32g474
Updating crates.io index
error: failed to select a version for bare-metal.
... required by package stm32g4xx-hal v0.0.1 (C:\Users\source\repos\stm32g4xx-hal)
versions that meet the requirements ^1.0.0 are: 1.0.0

the package stm32g4xx-hal depends on bare-metal, with features: const-fn but bare-metal does not have these features.

failed to select a version for bare-metal which could resolve this conflict

How do I resolve it? Appreciate any leads!

apparently, there's no const-fn feature in bare-metal crate, in fact the bare-metal crate has no configurable features at all.the crate's Cargo.toml manifest:

you might fix the issue by simply remove the const-fn feature requirement in Cargo.toml, assuming the example code doesn't contain other errors:

 [dependencies.bare-metal]
-features = ["const-fn"]
+features = []
 version = "0.2.5"

side note: at a quick look, the latest released version number of stm32g4xx-hal crate is 0.0.1, this seems to indicate the crate is not very mature in development stage. if you have other hardware, I'd suggest you start learning the basic concept of embedded rust ecosystem using a crate with more active development and support, like the stm32f series, the nrf52 series, and the rp2040 (a.k.a. the raspberry pi pico).

as an example for comparison: the crate stm32f4xx-hal has 34 versions published on crates.io with over 170k downloads, while the stm32g4xx-hal has only 2 versions published with only 1k downloads.

also, there's alternative HAL crates for stm32. one example is stm32-hal2, which uses the same auto generated PAC crates. you can give it a try. another example is the embassy project, which integrate async/await into embedded runtimes.

2 Likes

This was super helpful. Thank you very much @nerditation :slight_smile:

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.