diff options
| author | datdenkikniet <jcdra1@gmail.com> | 2023-04-22 18:28:40 +0200 |
|---|---|---|
| committer | datdenkikniet <jcdra1@gmail.com> | 2023-05-11 19:20:58 +0200 |
| commit | 6c91ff2d7f83bbba81d8fc24ad9760b5cf6b394e (patch) | |
| tree | 18737c31c872eb100c19c5653905966d03bb4e38 /book/en/src | |
| parent | d90fa95266bc9864d2dec0248fa4bae5c7e5b6ec (diff) | |
Include the examples
Diffstat (limited to 'book/en/src')
| -rw-r--r-- | book/en/src/migration/migration_v2/complete_example.md | 82 |
1 files changed, 3 insertions, 79 deletions
diff --git a/book/en/src/migration/migration_v2/complete_example.md b/book/en/src/migration/migration_v2/complete_example.md index fec475d..b68f1ef 100644 --- a/book/en/src/migration/migration_v2/complete_example.md +++ b/book/en/src/migration/migration_v2/complete_example.md @@ -87,89 +87,13 @@ mod app { # V2.0.0 ``` rust -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] -#![feature(type_alias_impl_trait)] - -use panic_rtt_target as _; -use rtic::app; -use rtt_target::{rprintln, rtt_init_print}; -use stm32f3xx_hal::gpio::{Output, PushPull, PA5}; -use stm32f3xx_hal::prelude::*; -use rtic_monotonics::Systick; - -#[app(device = stm32f3xx_hal::pac, peripherals = true, dispatchers = [SPI1])] -mod app { - use super::*; - - #[shared] - struct Shared {} - - #[local] - struct Local { - led: PA5<Output<PushPull>>, - state: bool, - } - - #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { - // Setup clocks - let mut flash = cx.device.FLASH.constrain(); - let mut rcc = cx.device.RCC.constrain(); - - let mono_token = rtic_monotonics::create_systick_token!(); - let mono = Systick::new(cx.core.SYST, 36_000_000, mono_token); - - rtt_init_print!(); - rprintln!("init"); - - let _clocks = rcc - .cfgr - .use_hse(8.MHz()) - .sysclk(36.MHz()) - .pclk1(36.MHz()) - .freeze(&mut flash.acr); - - // Setup LED - let mut gpioa = cx.device.GPIOA.split(&mut rcc.ahb); - let mut led = gpioa - .pa5 - .into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper); - led.set_high().unwrap(); - - // Schedule the blinking task - blink::spawn().unwrap(); - - ( - Shared {}, - Local { led, state: false }, - init::Monotonics(mono), - ) - } - - #[task(local = [led, state])] - async fn blink(cx: blink::Context) { - loop { - // A task is now allowed to run forever, provided that - // there is an `await` somewhere in the loop. - SysTick::delay(1000.millis()).await; - rprintln!("blink"); - if *cx.local.state { - cx.local.led.set_high().unwrap(); - *cx.local.state = false; - } else { - cx.local.led.set_low().unwrap(); - *cx.local.state = true; - } - } - } -} +{{ #include ../../../../../examples/stm32f3_blinky/src/main.rs }} ``` ## A diff between the two projects +_Note_: This diff may not be 100% accurate, but it displays the important changes. + ``` diff #![no_main] #![no_std] |
