Giter Site home page Giter Site logo

eboskma / stm32f1xx-hal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stm32-rs/stm32f1xx-hal

0.0 1.0 0.0 135 KB

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

License: Apache License 2.0

GDB 0.33% Logos 0.09% Rust 99.58%

stm32f1xx-hal's Introduction

stm32f1xx-hal

HAL for the STM32F1 family of microcontrollers

crates.io Released API docs

Usage

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.

Supported Microcontrollers

  • stm32f100
  • stm32f101
  • stm32f103

Trying out the examples

$ 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.2.0"
features = ["stm32f100", "rt"]

Blinky example

The following example blinks an LED connected to pin PC13. For instructions on how set up a project and run the example, see the documentation. For more examples, see the examples directory.

#![no_std]
#![no_main]

extern crate panic_halt;

use nb::block;

use stm32f1xx_hal::{
    prelude::*,
    pac,
    timer::Timer,
};
use cortex_m_rt::entry;

#[entry]
fn main() -> ! {
    // Get access to the core peripherals from the cortex-m crate
    let cp = cortex_m::Peripherals::take().unwrap();
    // Get access to the device specific peripherals from the peripheral access crate
    let dp = pac::Peripherals::take().unwrap();

    // Take ownership over the raw flash and rcc devices and convert them into the corresponding
    // HAL structs
    let mut flash = dp.FLASH.constrain();
    let mut rcc = dp.RCC.constrain();

    // Freeze the configuration of all the clocks in the system and store
    // the frozen frequencies in `clocks`
    let clocks = rcc.cfgr.freeze(&mut flash.acr);

    // Acquire the GPIOC peripheral
    let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);

    // Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function
    // in order to configure the port. For pins 0-7, crl should be passed instead.
    let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
    // Configure the syst timer to trigger an update every second
    let mut timer = Timer::syst(cp.SYST, 1.hz(), clocks);

    // Wait for the timer to trigger an update and change the state of the LED
    loop {
        block!(timer.wait()).unwrap();
        led.set_high();
        block!(timer.wait()).unwrap();
        led.set_low();
    }
}

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.

stm32f1xx-hal's People

Contributors

alexandermorozov avatar astro avatar burrbull avatar fmckeogh avatar gbip avatar geomatsi avatar harnesser avatar jounathaen avatar kellerkindt avatar skammer avatar thalesfragoso avatar therealprof avatar thezoq2 avatar wgh- avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.