@@ -311,6 +311,70 @@ the `read` is a method on the `rx`,
...
@@ -311,6 +311,70 @@ the `read` is a method on the `rx`,
---
---
### RTFM Blinky
No example suit is complete without the mandatory `blinky` demo, so here we go! The exampe `rtfm_blinky.rs` showcase the simplicity of using the RTFM framework.
An application using RTFM is defined using the `app` attribute, specifying the target PAC.
- The `static mut` section defines the shared resources. In this example we need to access the `GPIOA` in the `SysTick` exception handler. Initially all resources are delegated to the `init` task (running before the system goes live).
- In `init` we:
- configure the `SysTick` exception/task to be triggered periodically (each second),- configure the `RCC` (enabling the `GPIOA` peripheral),
- configure the `PA5` pin (connected to the Green LED on the Nucleo) as an output, and finally
- delegate access to `GPIO` as a "late" resource.
- The `#[exception (resources = [GPIOA])]` attribute enables access to the `GPIOA` peripheral for the `SysTick` exception/task. (Resource access goes through `resources.<RESOURCE>`.)
- In `SysTick` we define a task local resource `TOGGLE` to hold the current state, and we set/clear the `PA5` pin correspondingly. (The `bs5` field sets the `PA5` high, while `br5` clears the corresponding bit controlling the led.) Finnally the `TOGGLE` state is inverted.
Notice here, under the hood the RTFM framework analyses the `app` and concludes that `TOGGLE` and `GPIOA` are accessible (in scope) for `SysTick` exclusively, so we safely (without running any risk of race conditions) access the resources directly.
Side note: Accessing a resource shared with a higher priority task, requires the user to lock the resource in order to guarantee race-free access. For further information, see the RTFM API documentation and book, cf. `cortex-m-rtfm`.
``` rust
usertfm::app;
#[app(device=stm32f4::stm32f413)]
constAPP:()={
// late resorce binding
staticmutGPIOA:GPIOA=();
// init runs in an interrupt free section
#[init]
fninit(){
// configures the system timer to trigger a SysTick exception every second