rtic/examples/stm32f411_adc_and_mpsc_channel
Milton Eduardo Sosa 624f643a97
Add example for STM32F411 with HW & SW tasks communicating via MPSC channel (#953)
* Add example with HW & SW tasks communicating via MPSC channel

* example: f411-adc-mpcsc: nit: typos

* example: f411-adc-mpsc: prefer text over picture

---------

Co-authored-by: Milton Eduardo Sosa <milton@Miltons-MacBook-Pro.local>
Co-authored-by: Henrik Tjäder <henrik@tjaders.com>
2024-06-26 17:35:48 +00:00
..
.cargo Add example for STM32F411 with HW & SW tasks communicating via MPSC channel (#953) 2024-06-26 17:35:48 +00:00
src Add example for STM32F411 with HW & SW tasks communicating via MPSC channel (#953) 2024-06-26 17:35:48 +00:00
build.rs Add example for STM32F411 with HW & SW tasks communicating via MPSC channel (#953) 2024-06-26 17:35:48 +00:00
Cargo.lock Add example for STM32F411 with HW & SW tasks communicating via MPSC channel (#953) 2024-06-26 17:35:48 +00:00
Cargo.toml Add example for STM32F411 with HW & SW tasks communicating via MPSC channel (#953) 2024-06-26 17:35:48 +00:00
memory.x Add example for STM32F411 with HW & SW tasks communicating via MPSC channel (#953) 2024-06-26 17:35:48 +00:00
README.md Add example for STM32F411 with HW & SW tasks communicating via MPSC channel (#953) 2024-06-26 17:35:48 +00:00

STM32F411CEU6 ADC example

This example is a continuation of the stm32f411_adc. In this variant, there are 3 tasks (1 HW & 2 SW) involved and communication between them by means of an MPSC channel.

In the #[init] before spawning any task, an MPSC channel is created and split in its two parts.
Immediately after separating the Receiver and Sender the software task printer_actor is spawned and receives the Receiver end of the channel and starts listening.

Then two clones of the Sender type are created. The first one is stored as Local resource for the HW task and the second, is passed as an argument when the pinger software task is spawned.

Hardware task bound to EXTI0: gpio_interrupt_handler

This task,

  • Decreases the value of delayval by 200
  • Takes a new sample from the ADC input connected on pin PA1
  • Sends a message of type Message::PotentiometerValue to the printer task
  • Clears the interrupt_pending_bit

Software task: printer_actor

This task makes use of the unused interrupt SPI1 as a dispatcher. Since it is an async fn, it ia constantly awaiting for incoming messages from other actors. Depending on the type of message received, it prints something different.

Software task: pinger

This is just a simple task that sends ping every 25000 millis and uses SPI2 as a dispatcher.

How-to

Build

Run cargo build --release to compile the code. If you run it for the first time, it will take some time to download and compile dependencies.

Run

Install probe-rs and configure it using the debugging extension for VScode.

The output should look like this:

INFO Printer actor received a PING from software task
INFO Current delay value 1900
INFO Printer actor received a new PotentiometerValue: 607 from hardware task.

INFO Current delay value 1800
INFO Printer actor received a new PotentiometerValue: 1011 from hardware task.

INFO Current delay value 1700
INFO Printer actor received a new PotentiometerValue: 819 from hardware task.

INFO Printer actor received a PING from software task