From 1cf3c85d8dd44eb6c589d0cd7a5b2b6d816fc1c9 Mon Sep 17 00:00:00 2001 From: Per <Per Lindgren> Date: Fri, 29 Dec 2017 13:02:44 +0100 Subject: [PATCH] Initial commit --- .vscode/tasks.json | 22 +++++++++++++++++++ Cargo.toml | 4 ++-- examples/blinky-blocking.rs | 2 +- examples/blinky.rs | 2 +- examples/capture4.rs | 2 +- examples/concurrency.rs | 2 +- examples/hello-world.rs | 2 +- examples/hello.rs | 2 +- examples/imu.rs | 4 ++-- examples/itm.rs | 2 +- examples/led.rs | 2 +- examples/loopback.rs | 2 +- examples/mco.rs | 4 ++-- examples/preemption.rs | 2 +- examples/pwm-control.rs | 2 +- examples/pwm1.rs | 2 +- examples/resource.rs | 2 +- examples/roulette.rs | 2 +- examples/spi1.rs | 8 +++---- examples/usart2-dma.rs | 2 +- examples/usart2-rx-dma.rs | 2 +- examples/usart2-tx-dma.rs | 2 +- examples/ws2812.rs | 2 +- src/capture.rs | 30 +++++++++++++------------- src/clock.rs | 2 +- src/dma.rs | 29 +++++++++++++++++++++++-- src/examples/_0_hello.rs | 2 +- src/examples/_1_itm.rs | 2 +- src/examples/_2_led.rs | 2 +- src/examples/_3_blinky.rs | 2 +- src/examples/_4_roulette.rs | 2 +- src/examples/_5_loopback.rs | 2 +- src/examples/_6_concurrency.rs | 2 +- src/examples/_7_resource.rs | 2 +- src/examples/_8_preemption.rs | 2 +- src/led.rs | 4 ++-- src/leds.rs | 2 +- src/lib.rs | 2 +- src/lsm9ds1.rs | 4 ++-- src/pwm.rs | 30 +++++++++++++------------- src/serial.rs | 39 ++++++++++++++++++++++++---------- src/spi.rs | 20 ++++++++--------- src/timer.rs | 2 +- 43 files changed, 162 insertions(+), 98 deletions(-) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..77d831f --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,22 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "label": "xargo build", + "command": "xargo", + "args": [ + "build" + ], + "problemMatcher": [ + "$rustc" + ], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index f4e5d76..fc1f404 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,10 +26,10 @@ rev = "7d904f515d15fd5fe7ea34e18820ea83e2651fa2" [dependencies.nb] git = "https://github.com/japaric/nb" -[dependencies.stm32f40x] +[dependencies.stm32f413] features = ["rt"] #version = "0.5.0" -git = "https://gitlab.henriktjader.com/pln/STM32F40x" +git = "https://gitlab.henriktjader.com/pln/stm32f413" [dev-dependencies] cortex-m = "0.3.0" diff --git a/examples/blinky-blocking.rs b/examples/blinky-blocking.rs index 1088983..e008567 100644 --- a/examples/blinky-blocking.rs +++ b/examples/blinky-blocking.rs @@ -23,7 +23,7 @@ use rtfm::{app, Threshold}; const FREQUENCY: Hertz = Hertz(1); app! { - device: f4::stm32f40x, + device: f4::stm32f413, idle: { resources: [TIM11], diff --git a/examples/blinky.rs b/examples/blinky.rs index fdf857e..b21fbd8 100644 --- a/examples/blinky.rs +++ b/examples/blinky.rs @@ -17,7 +17,7 @@ const FREQUENCY: u32 = 1; // Hz // TASKS & RESOURCES app! { - device: f4::stm32f40x, + device: f4::stm32f413, resources: { static ON: bool = false; diff --git a/examples/capture4.rs b/examples/capture4.rs index c382afc..48fe944 100644 --- a/examples/capture4.rs +++ b/examples/capture4.rs @@ -19,7 +19,7 @@ const RESOLUTION: Milliseconds = Milliseconds(1); const CHANNELS: [Channel; 2] = [Channel::_1, Channel::_2]; app! { - device: f4::stm32f40x, + device: f4::stm32f413, idle: { resources: [ITM, TIM2], diff --git a/examples/concurrency.rs b/examples/concurrency.rs index 44b6fbb..a7db377 100644 --- a/examples/concurrency.rs +++ b/examples/concurrency.rs @@ -24,7 +24,7 @@ const DIVISOR: u32 = 4; // TASKS & RESOURCES app! { - device: f4::stm32f40x, + device: f4::stm32f413, resources: { static ON: bool = false; diff --git a/examples/hello-world.rs b/examples/hello-world.rs index 23d4d26..3d46988 100644 --- a/examples/hello-world.rs +++ b/examples/hello-world.rs @@ -14,7 +14,7 @@ use rtfm::{app, Threshold}; use semihosting::hio::{self, HStdout}; app! { - device: f4::stm32f40x, + device: f4::stm32f413, resources: { static HSTDOUT: Option<HStdout> = None; diff --git a/examples/hello.rs b/examples/hello.rs index e636ecf..f4c8be5 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -11,7 +11,7 @@ extern crate f4; use rtfm::app; app! { - device: f4::stm32f40x, + device: f4::stm32f413, } fn init(_p: init::Peripherals) {} diff --git a/examples/imu.rs b/examples/imu.rs index 78bc15d..46cc0fb 100644 --- a/examples/imu.rs +++ b/examples/imu.rs @@ -19,7 +19,7 @@ extern crate cortex_m_rtfm as rtfm; #[macro_use] extern crate f4; extern crate heapless; -extern crate stm32f40x; +extern crate stm32f413; use cortex_m::peripheral::SystClkSource; use core::ops::Deref; @@ -36,7 +36,7 @@ const FREQUENCY: u32 = 10; const MAX_TX_LEN: usize = 256; app! { - device: f4::stm32f40x, + device: f4::stm32f413, resources: { static IMU_SETTINGS: ImuSettings = ImuSettings::new(); diff --git a/examples/itm.rs b/examples/itm.rs index 8c61208..8c0a217 100644 --- a/examples/itm.rs +++ b/examples/itm.rs @@ -31,7 +31,7 @@ extern crate f4; use rtfm::{app, Threshold}; app! { - device: f4::stm32f40x, + device: f4::stm32f413, idle: { resources: [ITM], diff --git a/examples/led.rs b/examples/led.rs index dfdc880..59f81fa 100644 --- a/examples/led.rs +++ b/examples/led.rs @@ -12,7 +12,7 @@ use rtfm::app; // TASKS & RESOURCES app! { - device: f4::stm32f40x, + device: f4::stm32f413, } // INITIALIZATION PHASE diff --git a/examples/loopback.rs b/examples/loopback.rs index df1d2f5..2f6e36e 100644 --- a/examples/loopback.rs +++ b/examples/loopback.rs @@ -18,7 +18,7 @@ const BAUD_RATE: Hertz = Hertz(115_200); // TASKS & RESOURCES app! { - device: f4::stm32f40x, + device: f4::stm32f413, tasks: { USART2: { diff --git a/examples/mco.rs b/examples/mco.rs index ccded2f..779ce0e 100644 --- a/examples/mco.rs +++ b/examples/mco.rs @@ -1,4 +1,4 @@ -//! Set the clock frequency on the Nucleo-64 stm32f40x +//! Set the clock frequency on the Nucleo-64 stm32f413 #![deny(warnings)] #![feature(proc_macro)] #![no_std] @@ -16,7 +16,7 @@ const FREQUENCY: u32 = 10; // Hz // TASKS & RESOURCES app! { - device: f4::stm32f40x, + device: f4::stm32f413, resources: { static ON: bool = false; diff --git a/examples/preemption.rs b/examples/preemption.rs index bf374ac..dcce6c0 100644 --- a/examples/preemption.rs +++ b/examples/preemption.rs @@ -34,7 +34,7 @@ const DIVISOR: u32 = 4; // TASK & RESOURCES app!{ - device: f4::stm32f40x, + device: f4::stm32f413, resources: { static BUFFER: Vec<u8, [u8; 16]> = Vec::new([0; 16]); diff --git a/examples/pwm-control.rs b/examples/pwm-control.rs index 702dead..bb38d0b 100644 --- a/examples/pwm-control.rs +++ b/examples/pwm-control.rs @@ -24,7 +24,7 @@ const BAUD_RATE: Hertz = Hertz(115_200); const FREQUENCY: Hertz = Hertz(1_000); app! { - device: f4::stm32f40x, + device: f4::stm32f413, tasks: { USART2: { diff --git a/examples/pwm1.rs b/examples/pwm1.rs index 329f89f..2c3fa91 100644 --- a/examples/pwm1.rs +++ b/examples/pwm1.rs @@ -14,7 +14,7 @@ use rtfm::app; const FREQUENCY: Hertz = Hertz(10_000); app! { - device: f4::stm32f40x, + device: f4::stm32f413, } fn init(p: init::Peripherals) { diff --git a/examples/resource.rs b/examples/resource.rs index 1e3356d..660f540 100644 --- a/examples/resource.rs +++ b/examples/resource.rs @@ -37,7 +37,7 @@ const DIVISOR: u32 = 4; // TASKS & RESOURCES app! { - device: f4::stm32f40x, + device: f4::stm32f413, resources: { // 16 byte buffer diff --git a/examples/roulette.rs b/examples/roulette.rs index d866334..83da6f9 100644 --- a/examples/roulette.rs +++ b/examples/roulette.rs @@ -19,7 +19,7 @@ const DIVISOR: u32 = 4; // TASKS & RESOURCES app! { - device: f4::stm32f40x, + device: f4::stm32f413, resources: { static STATE: u8 = 0; diff --git a/examples/spi1.rs b/examples/spi1.rs index db24b7b..fc8be0c 100644 --- a/examples/spi1.rs +++ b/examples/spi1.rs @@ -15,15 +15,15 @@ extern crate cortex_m; extern crate cortex_m_rtfm as rtfm; extern crate f4; -extern crate stm32f40x; +extern crate stm32f413; use f4::Spi; use f4::prelude::*; use rtfm::{app, Threshold}; -use stm32f40x::GPIOA; +use stm32f413::GPIOA; app! { - device: f4::stm32f40x, + device: f4::stm32f413, idle: { resources: [SPI3, GPIOA], @@ -79,7 +79,7 @@ fn disable_ag(gpioa: &mut GPIOA) { gpioa.odr.modify(|_, w| w.odr8().bit(true)); } -fn send_receive(spi: &f4::Spi<f4::stm32f40x::SPI3>, addr: u8) -> u8 { +fn send_receive(spi: &f4::Spi<f4::stm32f413::SPI3>, addr: u8) -> u8 { // Send and receive using the hal crate while spi.send(addr).is_err() {} while spi.read().is_err() {} diff --git a/examples/usart2-dma.rs b/examples/usart2-dma.rs index 305a595..8c9a81e 100644 --- a/examples/usart2-dma.rs +++ b/examples/usart2-dma.rs @@ -38,7 +38,7 @@ enum CmdType { } app! { - device: f4::stm32f40x, + device: f4::stm32f413, resources: { static CMD_BUFFER: Vec<u8, [u8; MAX_CMD_LEN]> = Vec::new([0; MAX_CMD_LEN]); diff --git a/examples/usart2-rx-dma.rs b/examples/usart2-rx-dma.rs index e704972..b741d51 100644 --- a/examples/usart2-rx-dma.rs +++ b/examples/usart2-rx-dma.rs @@ -16,7 +16,7 @@ use rtfm::{app, Threshold}; const BAUD_RATE: Hertz = Hertz(115_200); app! { - device: f4::stm32f40x, + device: f4::stm32f413, resources: { static BUFFER: Buffer<[u8; 8], Dma1Channel5> = Buffer::new([0; 8]); diff --git a/examples/usart2-tx-dma.rs b/examples/usart2-tx-dma.rs index 5d36f40..2d553cd 100644 --- a/examples/usart2-tx-dma.rs +++ b/examples/usart2-tx-dma.rs @@ -16,7 +16,7 @@ use rtfm::{app, Threshold}; const BAUD_RATE: Hertz = Hertz(115_200); app! { - device: f4::stm32f40x, + device: f4::stm32f413, resources: { static BUFFER: Buffer<[u8; 15], Dma1Channel6> = Buffer::new([0; 15]); diff --git a/examples/ws2812.rs b/examples/ws2812.rs index 7465d34..7e1f89d 100644 --- a/examples/ws2812.rs +++ b/examples/ws2812.rs @@ -24,7 +24,7 @@ const _0: u8 = 3; const _1: u8 = 5; app! { - device: f4::stm32f40x, + device: f4::stm32f413, resources: { static BUFFER: Buffer<[u8; 577], Dma1Channel2> = Buffer::new([_0; 577]); diff --git a/src/capture.rs b/src/capture.rs index 6f04cac..291a4a8 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -39,7 +39,7 @@ use core::u32; use cast::u32; use hal; use nb; -use stm32f40x::{TIM1, TIM2, TIM3, TIM4, GPIOA, GPIOB, GPIOC, RCC}; +use stm32f413::{TIM1, TIM2, TIM3, TIM4, GPIOA, GPIOB, GPIOC, RCC}; use timer::Channel; @@ -149,20 +149,20 @@ macro_rules! impl_Capture { // CH4 = PA11 = alternate push-pull match channel { Channel::_1 => { - gpioa.afrh.modify(|_, w| w.afrh8().bits(1)); - gpioa.moder.modify(|_, w| w.moder8().bits(2)); + gpioa.afrh.modify(|_, w| unsafe { w.afrh8().bits(1)}); + gpioa.moder.modify(|_, w| unsafe { w.moder8().bits(2)}); } Channel::_2 => { - gpioa.afrh.modify(|_, w| w.afrh9().bits(1)); - gpioa.moder.modify(|_, w| w.moder9().bits(2)); + gpioa.afrh.modify(|_, w| unsafe { w.afrh9().bits(1)}); + gpioa.moder.modify(|_, w| unsafe { w.moder9().bits(2)}); } Channel::_3 => { - gpioa.afrh.modify(|_, w| w.afrh10().bits(1)); - gpioa.moder.modify(|_, w| w.moder10().bits(2)); + gpioa.afrh.modify(|_, w| unsafe { w.afrh10().bits(1)}); + gpioa.moder.modify(|_, w| unsafe { w.moder10().bits(2)}); } Channel::_4 => { - gpioa.afrh.modify(|_, w| w.afrh11().bits(1)); - gpioa.moder.modify(|_, w| w.moder11().bits(2)); + gpioa.afrh.modify(|_, w| unsafe { w.afrh11().bits(1)}); + gpioa.moder.modify(|_, w| unsafe { w.moder11().bits(2)}); } } } else if tim.get_type_id() == TypeId::of::<TIM2>() { @@ -174,12 +174,12 @@ macro_rules! impl_Capture { // See datasheet DM00115249 Table 9. Alternate function mapping match channel { Channel::_1 => { - gpioa.afrl.modify(|_, w| w.afrl0().bits(1)); - gpioa.moder.modify(|_, w| w.moder0().bits(2)); + gpioa.afrl.modify(|_, w| unsafe { w.afrl0().bits(1)}); + gpioa.moder.modify(|_, w| unsafe { w.moder0().bits(2)}); } Channel::_2 => { - gpioa.afrl.modify(|_, w| w.afrl1().bits(1)); - gpioa.moder.modify(|_, w| w.moder1().bits(2)); + gpioa.afrl.modify(|_, w| unsafe { w.afrl1().bits(1)}); + gpioa.moder.modify(|_, w| unsafe { w.moder1().bits(2)}); } Channel::_3 => { gpiob.afrh.modify(|_, w| unsafe {w.afrh10().bits(1)}); @@ -196,8 +196,8 @@ macro_rules! impl_Capture { // CH4 = PB1 = alternate push-pull match channel { Channel::_1 => { - gpioa.afrl.modify(|_, w| w.afrl6().bits(2)); - gpioa.moder.modify(|_, w| w.moder6().bits(2)); + gpioa.afrl.modify(|_, w| unsafe { w.afrl6().bits(2)}); + gpioa.moder.modify(|_, w| unsafe { w.moder6().bits(2)}); } Channel::_2 => { gpioc.afrl.modify(|_, w| unsafe {w.afrl7().bits(2)}); diff --git a/src/clock.rs b/src/clock.rs index a74a079..907643a 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -1,6 +1,6 @@ //! System clocking -use stm32f40x::{FLASH, RCC}; +use stm32f413::{FLASH, RCC}; const HSI_FREQ: u32 = 16_000_000; diff --git a/src/dma.rs b/src/dma.rs index 47a03e9..f573995 100644 --- a/src/dma.rs +++ b/src/dma.rs @@ -5,7 +5,7 @@ use core::marker::PhantomData; use core::ops; use nb; -use stm32f40x::DMA1; +use stm32f413::DMA1; /// DMA error #[derive(Debug)] @@ -40,7 +40,32 @@ pub struct Dma1Channel5 { } /// Channel 6 of DMA1 -pub struct Dma1Channel6 { +pub struct Dma2Channel6 { + _0: (), +} + +/// Channel 1 of DMA2 +pub struct Dma2Channel1 { + _0: (), +} + +/// Channel 2 of DMA2 +pub struct Dma2Channel2 { + _0: (), +} + +/// Channel 4 of DMA2 +pub struct Dma2Channel4 { + _0: (), +} + +/// Channel 5 of DMA2 +pub struct Dma2Channel5 { + _0: (), +} + +/// Channel 6 of DMA2 +pub struct Dma2Channel6 { _0: (), } diff --git a/src/examples/_0_hello.rs b/src/examples/_0_hello.rs index b3fa8a7..9784efe 100644 --- a/src/examples/_0_hello.rs +++ b/src/examples/_0_hello.rs @@ -17,7 +17,7 @@ //! //! // TASKS & RESOURCES //! app! { -//! device: f4::stm32f40x, +//! device: f4::stm32f413, //! } //! //! // INITIALIZATION PHASE diff --git a/src/examples/_1_itm.rs b/src/examples/_1_itm.rs index 46f7bd8..e99db44 100644 --- a/src/examples/_1_itm.rs +++ b/src/examples/_1_itm.rs @@ -20,7 +20,7 @@ //! //! // TASK & RESOURCES //! app! { -//! device: f4::stm32f40x, +//! device: f4::stm32f413, //! //! idle: { //! resources: [ITM], diff --git a/src/examples/_2_led.rs b/src/examples/_2_led.rs index b058f61..8bc3371 100644 --- a/src/examples/_2_led.rs +++ b/src/examples/_2_led.rs @@ -14,7 +14,7 @@ //! //! // TASKS & RESOURCES //! app! { -//! device: f4::stm32f40x, +//! device: f4::stm32f413, //! } //! //! // INITIALIZATION PHASE diff --git a/src/examples/_3_blinky.rs b/src/examples/_3_blinky.rs index 4ecbfd4..0507c8d 100644 --- a/src/examples/_3_blinky.rs +++ b/src/examples/_3_blinky.rs @@ -19,7 +19,7 @@ //! //! // TASKS & RESOURCES //! app! { -//! device: f4::stm32f40x, +//! device: f4::stm32f413, //! //! resources: { //! static ON: bool = false; diff --git a/src/examples/_4_roulette.rs b/src/examples/_4_roulette.rs index 076b1e1..ffde32a 100644 --- a/src/examples/_4_roulette.rs +++ b/src/examples/_4_roulette.rs @@ -21,7 +21,7 @@ //! //! // TASKS & RESOURCES //! app! { -//! device: f4::stm32f40x, +//! device: f4::stm32f413, //! //! resources: { //! static STATE: u8 = 0; diff --git a/src/examples/_5_loopback.rs b/src/examples/_5_loopback.rs index aa111a3..b30b205 100644 --- a/src/examples/_5_loopback.rs +++ b/src/examples/_5_loopback.rs @@ -20,7 +20,7 @@ //! //! // TASKS & RESOURCES //! app! { -//! device: f4::stm32f40x, +//! device: f4::stm32f413, //! //! tasks: { //! USART2: { diff --git a/src/examples/_6_concurrency.rs b/src/examples/_6_concurrency.rs index bae72b2..b989569 100644 --- a/src/examples/_6_concurrency.rs +++ b/src/examples/_6_concurrency.rs @@ -27,7 +27,7 @@ //! //! // TASKS & RESOURCES //! app! { -//! device: f4::stm32f40x, +//! device: f4::stm32f413, //! //! resources: { //! static STATE: u8 = 0; diff --git a/src/examples/_7_resource.rs b/src/examples/_7_resource.rs index 19c674e..2afb0df 100644 --- a/src/examples/_7_resource.rs +++ b/src/examples/_7_resource.rs @@ -39,7 +39,7 @@ //! //! // TASKS & RESOURCES //! app! { -//! device: f4::stm32f40x, +//! device: f4::stm32f413, //! //! resources: { //! // 16 byte buffer diff --git a/src/examples/_8_preemption.rs b/src/examples/_8_preemption.rs index 549b86b..9064cb7 100644 --- a/src/examples/_8_preemption.rs +++ b/src/examples/_8_preemption.rs @@ -36,7 +36,7 @@ //! //! // TASK & RESOURCES //! app!{ -//! device: f4::stm32f40x, +//! device: f4::stm32f413, //! //! resources: { //! static BUFFER: Vec<u8, [u8; 16]> = Vec::new([0; 16]); diff --git a/src/led.rs b/src/led.rs index 71be9a5..6b039d1 100644 --- a/src/led.rs +++ b/src/led.rs @@ -1,6 +1,6 @@ //! User LED PA5 -use stm32f40x::{GPIOA, RCC}; +use stm32f413::{GPIOA, RCC}; /// LED connected to pin PA5 pub const LED: PA5 = PA5; @@ -14,7 +14,7 @@ pub fn init(gpioa: &GPIOA, rcc: &RCC) { rcc.ahb1enr.modify(|_, w| w.gpioaen().set_bit()); // configure PA5 as output - gpioa.moder.modify(|_, w| w.moder5().bits(1)); + gpioa.moder.modify(|_, w| unsafe { w.moder5().bits(1) }); } impl PA5 { diff --git a/src/leds.rs b/src/leds.rs index 1cf8a68..65e3f29 100644 --- a/src/leds.rs +++ b/src/leds.rs @@ -1,6 +1,6 @@ //! Eight LEDs connected to PORTB -use stm32f40x::{GPIOB, RCC}; +use stm32f413::{GPIOB, RCC}; /// All the LEDs pub static LEDS: [Led; 8] = [ diff --git a/src/lib.rs b/src/lib.rs index 8974f0a..5db97dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ extern crate embedded_hal as hal; extern crate nb; extern crate static_ref; -pub extern crate stm32f40x; +pub extern crate stm32f413; // For documentation only pub mod examples; diff --git a/src/lsm9ds1.rs b/src/lsm9ds1.rs index ae4aebe..6440ea1 100644 --- a/src/lsm9ds1.rs +++ b/src/lsm9ds1.rs @@ -1,8 +1,8 @@ //! Interfacing the LSM9DS1 3D accelerometer, gyroscope, and magnetometer //! using SPI. -extern crate stm32f40x; -use stm32f40x::{SPI1, SPI2, SPI3, GPIOA}; +extern crate stm32f413; +use stm32f413::{SPI1, SPI2, SPI3, GPIOA}; use spi::Spi; use prelude::*; diff --git a/src/pwm.rs b/src/pwm.rs index ace2368..11dd9aa 100644 --- a/src/pwm.rs +++ b/src/pwm.rs @@ -36,7 +36,7 @@ use core::marker::Unsize; use cast::{u16, u32}; use hal; use static_ref::Static; -use stm32f40x::{DMA1, TIM1, TIM2, TIM3, TIM4, GPIOA, GPIOB, GPIOC, RCC}; +use stm32f413::{DMA1, TIM1, TIM2, TIM3, TIM4, GPIOA, GPIOB, GPIOC, RCC}; use dma::{self, Buffer, Dma1Channel2}; use timer::Channel; @@ -125,20 +125,20 @@ macro_rules! impl_Pwm { // CH4 = PA11 = alternate push-pull match channel { Channel::_1 => { - gpioa.afrh.modify(|_, w| w.afrh8().bits(1)); - gpioa.moder.modify(|_, w| w.moder8().bits(2)); + gpioa.afrh.modify(|_, w| unsafe { w.afrh8().bits(1)} ); + gpioa.moder.modify(|_, w| unsafe { w.moder8().bits(2)}); } Channel::_2 => { - gpioa.afrh.modify(|_, w| w.afrh9().bits(1)); - gpioa.moder.modify(|_, w| w.moder9().bits(2)); + gpioa.afrh.modify(|_, w| unsafe { w.afrh9().bits(1)}); + gpioa.moder.modify(|_, w| unsafe { w.moder9().bits(2)}); } Channel::_3 => { - gpioa.afrh.modify(|_, w| w.afrh10().bits(1)); - gpioa.moder.modify(|_, w| w.moder10().bits(2)); + gpioa.afrh.modify(|_, w| unsafe { w.afrh10().bits(1)}); + gpioa.moder.modify(|_, w| unsafe { w.moder10().bits(2)}); } Channel::_4 => { - gpioa.afrh.modify(|_, w| w.afrh11().bits(1)); - gpioa.moder.modify(|_, w| w.moder11().bits(2)); + gpioa.afrh.modify(|_, w| unsafe { w.afrh11().bits(1)}); + gpioa.moder.modify(|_, w| unsafe { w.moder11().bits(2)}); } } } else if tim.get_type_id() == TypeId::of::<TIM2>() { @@ -150,12 +150,12 @@ macro_rules! impl_Pwm { // See datasheet DM00115249 Table 9. Alternate function mapping match channel { Channel::_1 => { - gpioa.afrl.modify(|_, w| w.afrl0().bits(1)); - gpioa.moder.modify(|_, w| w.moder0().bits(2)); + gpioa.afrl.modify(|_, w| unsafe { w.afrl0().bits(1)}); + gpioa.moder.modify(|_, w| unsafe { w.moder0().bits(2)}); } Channel::_2 => { - gpioa.afrl.modify(|_, w| w.afrl1().bits(1)); - gpioa.moder.modify(|_, w| w.moder1().bits(2)); + gpioa.afrl.modify(|_, w| unsafe { w.afrl1().bits(1)}); + gpioa.moder.modify(|_, w| unsafe { w.moder1().bits(2)}); } Channel::_3 => { gpiob.afrh.modify(|_, w| unsafe {w.afrh10().bits(1)}); @@ -172,8 +172,8 @@ macro_rules! impl_Pwm { // CH4 = PB1 = alternate push-pull match channel { Channel::_1 => { - gpioa.afrl.modify(|_, w| w.afrl6().bits(2)); - gpioa.moder.modify(|_, w| w.moder6().bits(2)); + gpioa.afrl.modify(|_, w| unsafe { w.afrl6().bits(2)} ); + gpioa.moder.modify(|_, w| unsafe { w.moder6().bits(2)} ); } Channel::_2 => { gpioc.afrl.modify(|_, w| unsafe {w.afrl7().bits(2)}); diff --git a/src/serial.rs b/src/serial.rs index d988cf7..61f3140 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -17,7 +17,7 @@ use cast::u16; use hal; use nb; use static_ref::Static; -use stm32f40x::{gpioa, DMA1, USART2, usart6, GPIOA, RCC}; +use stm32f413::{gpioa, DMA1, USART2, usart1, GPIOA, RCC}; use dma::{self, Buffer, Dma1Channel5, Dma1Channel6}; @@ -27,7 +27,7 @@ use core::fmt; pub type Result<T> = ::core::result::Result<T, nb::Error<Error>>; /// IMPLEMENTATION DETAIL -pub unsafe trait Usart: Deref<Target = usart6::RegisterBlock> { +pub unsafe trait Usart: Deref<Target = usart1::RegisterBlock> { /// IMPLEMENTATION DETAIL type GPIO: Deref<Target = gpioa::RegisterBlock>; /// IMPLEMENTATION DETAIL @@ -94,14 +94,25 @@ where /// /// The serial interface will be configured to use 8 bits of data, 1 stop /// bit, no hardware control and to omit parity checking - pub fn init<B>(&self, baud_rate: B, dma1: Option<&DMA1>, gpio: &U::GPIO, rcc: &RCC) - where + pub fn init<B>( + &self, + baud_rate: B, + dma1: Option<&DMA1>, + gpio: &U::GPIO, + rcc: &RCC, + ) where B: Into<U::Ticks>, { self._init(baud_rate.into(), dma1, gpio, rcc) } - fn _init(&self, baud_rate: U::Ticks, dma1: Option<&DMA1>, gpio: &U::GPIO, rcc: &RCC) { + fn _init( + &self, + baud_rate: U::Ticks, + dma1: Option<&DMA1>, + gpio: &U::GPIO, + rcc: &RCC, + ) { let usart = self.0; // power up peripherals @@ -124,13 +135,15 @@ where // DM00102166 // PA2 and PA3 is connected to USART2 TX and RX respectively // Alternate function AF7, Table 9 - gpio.afrl.modify(|_, w| w.afrl2().bits(7).afrl3().bits(7)); + gpio.afrl + .modify(|_, w| unsafe { w.afrl2().bits(7).afrl3().bits(7) }); // Highest output speed - gpio.ospeedr - .modify(|_, w| w.ospeedr2().bits(0b11).ospeedr3().bits(0b11)); + gpio.ospeedr.modify(|_, w| unsafe { + w.ospeedr2().bits(0b11).ospeedr3().bits(0b11) + }); // RM0368 8.3 Table 23 gpio.moder - .modify(|_, w| w.moder2().bits(2).moder3().bits(2)); + .modify(|_, w| unsafe { w.moder2().bits(2).moder3().bits(2) }); } if let Some(dma1) = dma1 { @@ -295,7 +308,9 @@ where } else if sr.rxne().bit_is_set() { // NOTE(read_volatile) the register is 9 bits big but we'll only // work with the first 8 bits - Ok(unsafe { ptr::read_volatile(&usart2.dr as *const _ as *const u8) }) + Ok(unsafe { + ptr::read_volatile(&usart2.dr as *const _ as *const u8) + }) } else { Err(nb::Error::WouldBlock) } @@ -320,7 +335,9 @@ where Err(nb::Error::Other(Error::Framing)) } else if sr.txe().bit_is_set() { // NOTE(write_volatile) see NOTE in the `read` method - unsafe { ptr::write_volatile(&usart2.dr as *const _ as *mut u8, byte) } + unsafe { + ptr::write_volatile(&usart2.dr as *const _ as *mut u8, byte) + } Ok(()) } else { Err(nb::Error::WouldBlock) diff --git a/src/spi.rs b/src/spi.rs index 76dda2f..af74a3f 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -28,7 +28,7 @@ use core::ptr; use hal; use nb; -use stm32f40x::{SPI1, SPI2, SPI3, GPIOA, GPIOB, RCC}; +use stm32f413::{SPI1, SPI2, SPI3, GPIOA, GPIOB, RCC}; /// SPI result pub type Result<T> = ::core::result::Result<T, nb::Error<Error>>; @@ -78,23 +78,23 @@ macro_rules! impl_Spi { // DM00102166 - Alternate function AF5, Table 9 gpioa.afrl.modify(|_, w| - w.afrl4().bits(5) + unsafe { w.afrl4().bits(5) .afrl5().bits(5) .afrl6().bits(5) - .afrl7().bits(5)); + .afrl7().bits(5)}); // RM0368 8.3 Table 23 // Highest output speed gpioa.ospeedr.modify(|_, w| - w.ospeedr4().bits(0b11) + unsafe { w.ospeedr4().bits(0b11) .ospeedr5().bits(0b11) .ospeedr6().bits(0b11) - .ospeedr7().bits(0b11)); + .ospeedr7().bits(0b11)}); // Alternate function mode gpioa.moder.modify(|_, w| - w.moder4().bits(2) + unsafe { w.moder4().bits(2) .moder5().bits(2) .moder6().bits(2) - .moder7().bits(2)); + .moder7().bits(2)}); // Push pull, MISO open drain gpioa.otyper.modify(|_, w| w.ot4().clear_bit() @@ -179,7 +179,7 @@ macro_rules! impl_Spi { // MOSI = PB5 = Alternate function push pull // DM00102166 - Alternate function AF6, Table 9 - gpioa.afrh.modify(|_, w| w.afrh15().bits(5)); + gpioa.afrh.modify(|_, w| unsafe { w.afrh15().bits(5)}); gpiob.afrl.modify(|_, w| unsafe { w.afrl3().bits(6) .afrl4().bits(6) @@ -187,14 +187,14 @@ macro_rules! impl_Spi { }); // RM0368 8.3 Table 23 // Highest output speed - gpioa.ospeedr.modify(|_, w| w.ospeedr15().bits(0b11)); + gpioa.ospeedr.modify(|_, w| unsafe { w.ospeedr15().bits(0b11)}); gpiob.ospeedr.modify(|_, w| unsafe { w.ospeedr3().bits(0b11) .ospeedr4().bits(0b11) .ospeedr5().bits(0b11) }); // Alternate function mode - gpioa.moder.modify(|_, w| w.moder15().bits(2)); + gpioa.moder.modify(|_, w| unsafe { w.moder15().bits(2)}); gpiob.moder.modify(|_, w| unsafe { w.moder3().bits(2) .moder4().bits(2) diff --git a/src/timer.rs b/src/timer.rs index d1f727e..2856152 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -5,7 +5,7 @@ use core::any::{Any, TypeId}; use cast::{u16, u32}; use hal; use nb::{self, Error}; -use stm32f40x::{TIM1, TIM10, TIM11, TIM2, TIM3, TIM4, TIM5, TIM9, RCC}; +use stm32f413::{TIM1, TIM10, TIM11, TIM2, TIM3, TIM4, TIM5, TIM9, RCC}; /// Channel associated to a timer #[derive(Clone, Copy, Debug)] -- GitLab