This repository is a xmas holiday side project on the development board STM32-NUCELO-F767ZI. This git repository documents the exploration of the Rust embedded world with the asynchronous framework Embassy.
Table of Contents
The used hardware is shown in the picture below. On the right you see a A STM32-NUCELO-F767ZI it is connected to a PC via micro USB. The bread board on the left side has a power control, although it is powered by the NUCLEO in this picture. Continuing from bottom to top, the red wires connect to a 4.7k resistance each to act as starting line for SCL and SDA of the I2C bus (white and black wires). The small IC connected to the bus is a BH1750FVI light sensor. The next sensor is a DS18B20 temperature sensor that uses the 1-Wire Bus protocol...
The main project shall is a sensor platform powered by Embassy. It supports the following features so far and has an open roadmap:
- Module for simple LED controls (on/toggle/off)
- Remote LED control via UART
- Support of BH1750FVI light sensor via I2C (single and continious reading)
- Remote Light Sensor control via UART
- Status Report via UART
- Support of DS18B20 temperature sensor
- Implement 1-wire driver
- Add a display showing temperature
- Control display light by Lux measured by DS18B20
- Build small HTTP server for status reports over ETH module of NUCLEO
Besides the main project, this repository consists of the following sub-projects, mainly used as starters and proof of concepts to ensure things work the way intended:
- LED Counter based upon embedded Rust Book, uses PAC-level abstraction.
- LED Blinker based upon embassy starting example, uses async and embassy to implement a binary LED based counting.
- UART Echoing based upon embassy ensure there are debug messages accessible and use UART for both sending and receiving.
We start with the sub-projects for testing from simple to complex to finally arrive at the sensor platform project.
- LED Counter
- LED Blinker
- UART Echoing
- Sensor Plattform
Assumptions:
- Hardware sanity check with the official STM tools done successfully. That means the STM Cube Programmer software can be used to connect over STLink.
- Installation as described in Rust Embedded Book - Hardware which is based on the Cortex Quickstart Template.
The LED Counter project acts as a
- If not running, start OpenOCD
openocd -f interface/stlink.cfg -f target/stm32f7x.cfg
- Switch to folder
cd led_counter
- Execute
cargo run --release
You should see Breakpoint 4, 0x08000254 in main ()
in gdb. Type continue
and the counting started.
Observe the binary counting using GREEN LED for 1 bit, BLUE for 2nd bit and RED for 3rd bit. It's to fast isn't it? - we use busy loop here so you can redo it without release:
- Execute
cargo run
to reduce the counter frequency. You can see the code here
LED Blinker acted as a starter for getting in touch with the Embassy Framework.
- If not running, start OpenOCD
openocd -f interface/stlink.cfg -f target/stm32f7x.cfg
- Switch to folder
cd embassy
- Execute
cargo run --bin example_led_blinking --release
Use gdb to continue from main.
You should witness the blue LED blinking and you can use the blue user button to raise the frequency of the blinking. You can see the code here
Uart Echoing was a small project to get UART running within embassy. As this is very helpful for debug messages and to control the embedded device via a simple command language.
- If not running, start OpenOCD
openocd -f interface/stlink.cfg -f target/stm32f7x.cfg
- Switch to folder
cd embassy
- Execute
cargo run --bin example_uart_echoing --release
Use gdb to continue from main.
Next we have to setup a remote program that is used to connect over the UART protocol using the USB connection to the PC of the NUCLEO. I used putty on Windows for that with the following settings:
You should also check that a return is needed to sent the message in the settings.
The buffer is eight bytes long so if you write 12345678
and ensure it is send (e.g. pressing return) you should see the first echo. You can see the code here
This is the main project - Besides the previous projects it does consist of several files and is currently mainly controled with UART.
It supports the following commands:
- LED Control
led <color-code> <function>
color-code = r|g|b - for red, green and blue user LEDs respectively
function = on|off|<number in ms> - turns the led on or off, or if a number is given toggles the LED every given ms
- Light Sensor Control
light <state>
state = off|single|continious - s or c may be used as short form. Turns on the light sensor for measurment or shuts it down.
- Uart Report Interval
status <number in ms>
number in ms = the ms between each UART based status report, default is 10000ms
Here you see an example output over the UART console:
- If not running, start OpenOCD
openocd -f interface/stlink.cfg -f target/stm32f7x.cfg
- Switch to folder
cd embassy
- Execute
cargo run --bin example_sensors --release
Use gdb to continue from main.
You can see the main code file here
A list of data sheets, references and manuals for the hardware setup used in this Repository.
- DS18B20 - Programmable Resolution 1-Wire Digital Thermometer
- BH1750FVI - Digital 16bit Serial Output Type Ambient Light Sensor IC
- STM32 NUCLEO-144 - User Manual
- STM32 - Shared Reference
- STM32F76xxx - RM0410 Reference manual
- I2C-bus - Specification and User Manual Rev. 7
All code in this repository is dual-licensed under either:
MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT) Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) at your option. This means you can select the license you prefer! This dual-licensing approach is the de-facto standard in the Rust ecosystem and there are very good reasons to include both.