diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000000000000000000000000000000000000..77d831fea6e2a5f479291b03d81253453994e6c2 --- /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 f4e5d76d71595427f3095b5c04405da0256f5d21..fc1f404e2b5992c5109ac674d4df6ef91823315e 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 1088983c04d086aa6dba04e8b39b3f774e2f20cf..e0085671ddb753ecbec8924bf9bd6277202a0429 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 fdf857e26f99a8079d61c1e8cf344065086a80bb..b21fbd8bccaaf41ed80cc79a55c777796fbf37bb 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 c382afc2a73c781558a76295f07879e7c22bfdc0..48fe94405d892d47d37f1be86453a7c512ae7982 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 44b6fbbec221edbd837ed166c95f52e8aa136151..a7db37764a61a1e78add06a703cc41fab735cf26 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 23d4d26bf5326af106d925eb7a50b9a3bf119213..3d469885502786c4e9fc397d230b212e0a29c07c 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 e636ecf092cb27262e88d4ed256433d111b26051..f4c8be51ed88a06289b87465d587694afbd3de70 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 78bc15d99144918ae2aa02b45ab1af5b44f0a8a3..46cc0fba17f21f9948303a4f58298be87ca7fc0b 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 8c61208d492e0d9fbdbee48b7053228c3a325cce..8c0a217a87057cac678b00c1cbf03752f7d2d4b2 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 dfdc88067a2dbd979ac701a7a4823e0f22ab97e0..59f81fa28319ec0626eeae2bfe8598e4d5698b33 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 df1d2f50276d4c98e18850d4b0caad018fd59049..2f6e36eae06e39452a4639da3cd27118e3da2d46 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 ccded2f728642ab019b7de09f1acf838b6c535fe..779ce0e32205dfe6a2dac7c81c966bca5c35fcb8 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 bf374acdb057d7fa3a2272f02888960f2cf71447..dcce6c065ad7b69d6dbae85a24f1c8ae9ce9a0fb 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 702dead04d2314db4d114d5387ea40e4643021e3..bb38d0bad97b68ad7a07fa27513e587ae550cd50 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 329f89f78c9d6d18a3a93951262085432646fdd8..2c3fa912c51170867ff8d1b33fc74e1b0d4a0528 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 1e3356d3ed4a6f0a7893d135c59fe225fb939426..660f5408e9b6d2311b467a7dbe1e9d47e3cbd573 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 d866334a00ffd33c95c0d85eee102bf30de3c3ef..83da6f942c4285424ae12777699ca838633996ef 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 db24b7b50f9155b2e0e65696ff0c71991b3de8ac..fc8be0c621d52239784dbf7c5ec1e859ee238e4b 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 305a595809220d31af1cc8bb350658a3f1c035bf..8c9a81e3221abc906e51160d6936866e53d37269 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 e704972a234ca5bcc64933459a4d870bf403d4d4..b741d518bfdfddb2c27b3f4e547a53be9a1b9c03 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 5d36f40f8fe3a4e0c0be328ec59f284918540437..2d553cdcc6d50054cde6308308ba9a60f7f33f77 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 7465d34b9805f1409ffbefa50be826fcc91b54a0..7e1f89d718c72b35a14a83e37f3b79ca8b0f6929 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 6f04cac67739e79d9f77540131bc8427ceaca786..291a4a862c06d039c7d9e60abd25a6ee4ff54348 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 a74a0790856725f4e0d320041cacc01a7598a695..907643a6943085b7fba39c0115d0e7e56bf8db1a 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 47a03e9ee5337818dff40c345b2aaada6f90ecee..f57399574c87b0f531c7432b7f10b66282352f25 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 b3fa8a7c83c777cbc4855ea010f71defdcf5177b..9784efe303c8af313a598cbce12e2f62b5623a67 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 46f7bd8a5481f3c97935a535d435a8a760eb4199..e99db44764bea4c1039f6ed4413752e303f4dfed 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 b058f6173f477d2da15ee4eb3be5bd15408d3c38..8bc3371a6b5e4f757025607f4ed72e60f1bfadb7 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 4ecbfd489838c52ed5da263c1926b76ed367e9b4..0507c8deb782a8e3d2cd6370f237bb4256cce26d 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 076b1e11642dd4ce382462332e1ac36d60e9ba00..ffde32aeb8ec5ac0a15c27b27be622c5cfca5578 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 aa111a334da1484c3d7ab54a782ad3b7efa3ce4d..b30b205eb1a95446a1cf039abcdd378b9931abed 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 bae72b26ec3cf791350318862ef7a6575914e011..b98956979afa5fcdbec2c9fe642e86cd2c903769 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 19c674e391ff8c7e9a49528d543004c13098ac9b..2afb0df463d8360c3b37021f61e149b6140a53f0 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 549b86b6f0562318f210f79f6f152d572b4dcae1..9064cb79a2d94665abc0cdf3ac1cc0aea38afcf3 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 71be9a56ab9dd2e6f049e31319a43e5723ac56dd..6b039d10e6bdb276db3a040d7bd3c580f51aab3d 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 1cf8a68d1c59fb3fc6da40ad0982293883b374df..65e3f29dd7df0a25d99381cf5fb00d396c8d83c5 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 8974f0aef41ae62c2243c86cd5cfa715f8cf945d..5db97ddc42764501e846e12f1310cf8857b8729d 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 ae4aebe7bdcbd9d8fe7d8e69ebf440a54719df04..6440ea1759de6c3e4c38b69c571d912ef213b3fd 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 ace23688536451b8fe9e873d91acdc6fd3f05cff..11dd9aaab493cd0ea6318286e658430d7ba46852 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 d988cf789cba92828747a1a720b2889ffa7b3552..61f31408f8d536cc0eb254c70cd91e18e583ff6f 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 76dda2f192b2fd8baaf598bd26becab375af538b..af74a3f512b5eb246dee0df78a8780b4c687c50b 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 d1f727e9bf3b6a6accd33d365d863d8019bf064a..28561528985df108d137dc6ac7e373f6d916e8c5 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)]