All Projects → stm32-rs → Stm32f1xx Hal

stm32-rs / Stm32f1xx Hal

Licence: other
A Rust embedded-hal HAL impl for the STM32F1 family based on japarics stm32f103xx-hal

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Stm32f1xx Hal

Easy Build
Collection of Dockerfiles for building embedded software distributions
Stars: ✭ 130 (-46.94%)
Mutual labels:  hacktoberfest, embedded
Flutter Pi
A light-weight Flutter Engine Embedder for Raspberry Pi that runs without X.
Stars: ✭ 492 (+100.82%)
Mutual labels:  hacktoberfest, embedded
Rusefi
rusefi - GPL internal combustion engine control unit
Stars: ✭ 277 (+13.06%)
Mutual labels:  hacktoberfest, embedded
Azure Sdk For C
This repository is for active development of the Azure SDK for Embedded C. For consumers of the SDK we recommend visiting our versioned developer docs at https://azure.github.io/azure-sdk-for-c.
Stars: ✭ 77 (-68.57%)
Mutual labels:  hacktoberfest, embedded
U Root
A fully Go userland with Linux bootloaders! u-root can create a one-binary root file system (initramfs) containing a busybox-like set of tools written in Go.
Stars: ✭ 1,816 (+641.22%)
Mutual labels:  hacktoberfest, embedded
Libreelec.tv
Just enough OS for KODI
Stars: ✭ 1,358 (+454.29%)
Mutual labels:  hacktoberfest, embedded
Openswiftui
WIP — OpenSwiftUI is an OpenSource implementation of Apple's SwiftUI DSL.
Stars: ✭ 967 (+294.69%)
Mutual labels:  hacktoberfest, embedded
Labgrid
embedded systems control library for development, testing and installation
Stars: ✭ 124 (-49.39%)
Mutual labels:  hacktoberfest, embedded
Openthread
OpenThread released by Google is an open-source implementation of the Thread networking protocol
Stars: ✭ 2,643 (+978.78%)
Mutual labels:  hacktoberfest, embedded
Sponge
The SpongeAPI implementation targeting vanilla Minecraft and 3rd party platforms.
Stars: ✭ 241 (-1.63%)
Mutual labels:  hacktoberfest
Design Patterns
💼 Design patterns written in different programming languages 📐
Stars: ✭ 244 (-0.41%)
Mutual labels:  hacktoberfest
Sysadmin Reading List
A reading/viewing list for larval stage sysadmins and SREs
Stars: ✭ 240 (-2.04%)
Mutual labels:  hacktoberfest
Dotfiles
😈 Vim, git, zsh, tmux, and other goodies.
Stars: ✭ 240 (-2.04%)
Mutual labels:  hacktoberfest
Spandex
A platform agnostic tracing library
Stars: ✭ 244 (-0.41%)
Mutual labels:  hacktoberfest
Switcher
Gnome Shell extension to switch windows quickly by typing
Stars: ✭ 239 (-2.45%)
Mutual labels:  hacktoberfest
Action cable client
A ruby client for interacting with Rails' ActionCable. -- Maintainers Wanted.
Stars: ✭ 245 (+0%)
Mutual labels:  hacktoberfest
Eir
Erlang ecosystem common IR
Stars: ✭ 242 (-1.22%)
Mutual labels:  hacktoberfest
Web3swift
Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions.
Stars: ✭ 237 (-3.27%)
Mutual labels:  hacktoberfest
Instantwm
The window manager for instantOS
Stars: ✭ 244 (-0.41%)
Mutual labels:  hacktoberfest
Alsatian
TypeScript testing framework with test cases
Stars: ✭ 244 (-0.41%)
Mutual labels:  hacktoberfest

stm32f1xx-hal

HAL for the STM32F1 family of microcontrollers

Continuous integration crates.io Released API docs

Quick start guide

Embedded Rust development requires a bit more setup than ordinary development. For this guide, we'll assume you're using a stm32 blue pill board (shown below), but if you have another f1 microcontroller, you should be able to adapt it.

blue pill pinout

You will also need a debug probe, for example an stlink v3 mini for programming and debugging. (There are many different STLink probes out there, all of them should work fine with the instructions given here, other JTAG or SWD debug probes will work as well but will need different software or configuration).

Installing software

To program your microcontroller, you need to install:

  • openocd
  • gdb-multiarch (on some platforms you may need to use gdb-arm-none-eabi instead, make sure to update .cargo/config to reflect this change)

Finally, you need to install arm target support for the Rust compiler. To do so, run

rustup target install thumbv7m-none-eabi

Setting up your project

Create a new Rust project as you usually do with cargo init. The hello world of embedded development is usually to blink an LED and code to do so is available in examples/blinky.rs. Copy that file to the main.rs of your project.

You also need to add some dependencies to your Cargo.toml:

[dependencies]
embedded-hal = "0.2.3"
nb = "0.1.2"
cortex-m = "0.6.2"
cortex-m-rt = "0.6.11"
# Panic behaviour, see https://crates.io/keywords/panic-impl for alternatives
panic-halt = "0.2.0"

[dependencies.stm32f1xx-hal]
version = "0.6.1"
features = ["rt", "stm32f103", "medium"]

If you build your project now, you should get a single error: error: language item required, but not found: eh_personality. This unhelpful error message is fixed by compiling for the right target.

We also need to tell Rust how to link our executable, and how to lay out the result in memory. To accomplish all this, copy .cargo/config and memory.x from the stm32f1xx-hal repo to your project.

cargo build

If everything went well, your project should have built without errors.

Programming the microcontroller

It is now time to actually run the code on the hardware. To do so plug your debug probe into the blue pill and start openocd using

openocd -f interface/stlink-v3.cfg -f target/stm32f1x.cfg

If you are not using an stlink V3, change the interface accordingly. For more information, see the embeddonomicon.

If all went well, it should detect your microcontroller and say Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints. Keep it running in the background.

We will use gdb for uploading the compiled binary to the microcontroller and for debugging. Cargo will automatically start gdb thanks to the .cargo/config you added earlier. gdb also needs to be told to connect to openocd which is done by copying .gdbinit to the root of your project.

You may also need to tell gdb that it is safe to load .gdbinit from the working directory.

  • Linux
    echo "set auto-load safe-path $(pwd)" >> ~/.gdbinit
    
  • Windows
    echo set auto-load safe-path %CD% >> %USERPROFILE%\.gdbinit
    

If everything was successful, cargo should compile your project, start gdb, load your program and give you a prompt. If you type continue in the gdb prompt, your program should start and the green led on the blue pill should start blinking.

Going further

From here on, you can start adding more code to your project to make it do something more interesting. For crate documentation, see docs.rs/stm32f1xx-hal. There are also a lot more examples available. If something is unclear in the docs or examples, please, open an issue and we will try to improve it.

Selecting a microcontroller

This crate supports multiple microcontrollers in the stm32f1 family. Which specific microcontroller you want to build for has to be specified with a feature, for example stm32f103.

If no microcontroller is specified, the crate will not compile.

You may also need to specify the density of the device with medium, high or xl to enable certain peripherals. Generally the density can be determined by the 2nd character after the number in the device name (i.e. For STM32F103C6U, the 6 indicates a low-density device) but check the datasheet or CubeMX to be sure.

  • 4, 6 => low density, no feature required
  • 8, B => medium feature
  • C, D, E => high feature
  • F, G => xl feature

For microcontrollers of the connectivity line (stm32f105 and stm32f107) no density feature must be specified.

Supported Microcontrollers

  • stm32f100
  • stm32f101
  • stm32f103
  • stm32f105
  • stm32f107

Trying out the examples

You may need to give cargo permission to call gdb from the working directory.

  • Linux
    echo "set auto-load safe-path $(pwd)" >> ~/.gdbinit
    
  • Windows
    echo set auto-load safe-path %CD% >> %USERPROFILE%\.gdbinit
    

Compile, load, and launch the hardware debugger.

$ rustup target add thumbv7m-none-eabi

# on another terminal
$ openocd -f interface/$INTERFACE.cfg -f target/stm32f1x.cfg

# flash and debug the "Hello, world" example. Change stm32f103 to match your hardware
$ cargo run --features stm32f103 --example hello

$INTERFACE should be set based on your debugging hardware. If you are using an stlink V2, use stlink-v2.cfg. For more information, see the embeddonomicon.

Using as a Dependency

When using this crate as a dependency in your project, the microcontroller can be specified as part of the Cargo.toml definition.

[dependencies.stm32f1xx-hal]
version = "0.6.1"
features = ["stm32f100", "rt"]

Documentation

The documentation can be found at docs.rs.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].