aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f411_adc_and_mpsc_channel/README.md
blob: d7dc6f3f93edde395727ff4e2a7f2a2b9ef0cc62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
```