#stm32 #embedded-hal #nucleo #stm32l0x1 #stm32l031k6

no-std bin+lib nucleo-l031k6-bsp

Board support crate for the ST L031K6-NUCLEO

3 releases (breaking)

0.3.0 Nov 16, 2022
0.2.0 Aug 8, 2020
0.1.1 Nov 4, 2018

#700 in Embedded development

0BSD license

15KB
215 lines

NUCLEO-L031K6-BSP

This crate implements a BSP for the ST NUCLEO-L031K6 development board. It is intended to ease development while relieving the programmer of tracking peripheral and pin combinations, as well as providing helper methods for instantiating peripherals.

An example of crate usage can be found in src/main.rs

Requirements

Building this (and the dependent crates) requires Rust v1.30 or later.

Setup

We need to we need to get OpenOCD on our machine. If you already have it, feel free to skip this step.

  • Install or build from source the latest version of OpenOCD.

To launch OpenOCD and target your ST NUCLEO-L031K6

  • Launch OpenOCD and target your STM32 by executing the following command. openocd -f interface/stlink-v2-1.cfg -f target/stm32l0.cfg
  • NOTE: In OpenOCD's current tip of master, stlink-v2-1.cfg (the config file needed when running OpenOCD from latest stable release, 0.10.0) has been deprecated, and is now replaced by stlink.cfg.

Now, the fun part, getting Rust up and going!

  • Install or build from source Rust v1.30 or greater. NOTE: If you already have rust installed, feel free to run rustup update to get the latest stable version.
  • We need to add the thumbv6m-none-eabi target
    • rustup target add thumbv6m-none-eabi
  • Next, let's clone the repo and get it running!
    • git clone https://github.com/thenewwazoo/nucleo-l031k6-bsp.git
    • cd nucleo-l031k6-bsp
    • cargo run

Example Code

The current example code initializes the board:

let mut p = cortex_m::Peripherals::take().unwrap();
let d = hal::stm32l0x1::Peripherals::take().unwrap();

let mut board = bsp::init::<hal::power::VCoreRange1>(d.PWR, d.FLASH, d.RCC);

Starts a system clock:

let ticks = board.rcc.cfgr.context().unwrap().sysclk().0;
board.systick_start(&mut p.SYST, SystClkSource::Core, ticks / 1000);

And initializes the D12 and D13 pins:

let pins = board.pins(d.GPIOA, d.GPIOB, d.GPIOC);

let mut user_led = board.user_led(pins.d13);
let input_line = pins.d12.into_input::<PullDown>();

It then enters a loop with a few simple conditional check. If the D12 pin is set to HIGH, then the D13 (LED) pin state toggles at a frequency of 5hz. If D12 is set to LOW, then nothing will happen.

To test the example code, flash a board using the setup instructions above, and short the D12 and 3.3v pins on your ST NUCLEO-L031K6.

Dependencies

~13MB
~379K SLoC