From 624f643a976fc0676750de9c22d789115cba21c1 Mon Sep 17 00:00:00 2001 From: Milton Eduardo Sosa <31409391+snorkman88@users.noreply.github.com> Date: Wed, 26 Jun 2024 19:35:48 +0200 Subject: Add example for STM32F411 with HW & SW tasks communicating via MPSC channel (#953) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 Co-authored-by: Henrik Tjäder --- examples/stm32f411_adc_and_mpsc_channel/README.md | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 examples/stm32f411_adc_and_mpsc_channel/README.md (limited to 'examples/stm32f411_adc_and_mpsc_channel/README.md') diff --git a/examples/stm32f411_adc_and_mpsc_channel/README.md b/examples/stm32f411_adc_and_mpsc_channel/README.md new file mode 100644 index 0000000..d7dc6f3 --- /dev/null +++ b/examples/stm32f411_adc_and_mpsc_channel/README.md @@ -0,0 +1,46 @@ +# 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](https://probe.rs/docs/tools/debugger/). + +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 +``` -- cgit v1.2.3