diff --git a/CHANGELOG.md b/CHANGELOG.md index 61aa417..08a3dbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Updated the `cast` dependency from 0.2 to 0.3 - Updated `stm32f0` peripheral access crate from 0.14 to 0.15 +- Use `critical_section::CriticalSection` for GPIO configuration (breaking change) ### Added diff --git a/Cargo.toml b/Cargo.toml index dd0b982..08642a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ targets = ["thumbv6m-none-eabi"] bare-metal = { version = "1.0.0" } cast = "0.3" cortex-m = "0.7" +critical-section = "1.0" embedded-hal = { version = "0.2", features = ["unproven"] } stm32f0 = "0.15" nb = "1" diff --git a/examples/adc_values.rs b/examples/adc_values.rs index bd7cd8d..351d13f 100644 --- a/examples/adc_values.rs +++ b/examples/adc_values.rs @@ -7,8 +7,9 @@ use stm32f0xx_hal as hal; use crate::hal::{pac, prelude::*}; -use cortex_m::{interrupt::Mutex, peripheral::syst::SystClkSource::Core}; +use cortex_m::peripheral::syst::SystClkSource::Core; use cortex_m_rt::{entry, exception}; +use critical_section::Mutex; use core::{cell::RefCell, fmt::Write}; @@ -25,7 +26,7 @@ fn main() -> ! { hal::pac::Peripherals::take(), cortex_m::peripheral::Peripherals::take(), ) { - cortex_m::interrupt::free(move |cs| { + critical_section::with(move |cs| { let mut flash = p.FLASH; let mut rcc = p.RCC.configure().sysclk(8.mhz()).freeze(&mut flash); @@ -46,8 +47,8 @@ fn main() -> ! { syst.enable_interrupt(); // USART1 at PA9 (TX) and PA10(RX) - let tx = gpioa.pa9.into_alternate_af1(cs); - let rx = gpioa.pa10.into_alternate_af1(cs); + let tx = gpioa.pa9.into_alternate_af1(&cs); + let rx = gpioa.pa10.into_alternate_af1(&cs); // Initialiase UART let (mut tx, _) = @@ -74,7 +75,7 @@ fn SysTick() { use core::ops::DerefMut; // Enter critical section - cortex_m::interrupt::free(|cs| { + critical_section::with(|cs| { // Get access to the Mutex protected shared data if let Some(ref mut shared) = SHARED.borrow(cs).borrow_mut().deref_mut() { // Read temperature data from internal sensor using ADC diff --git a/examples/blinky.rs b/examples/blinky.rs index df1c90c..6c1178c 100644 --- a/examples/blinky.rs +++ b/examples/blinky.rs @@ -17,7 +17,7 @@ fn main() -> ! { let gpioa = p.GPIOA.split(&mut rcc); // (Re-)configure PA1 as output - let mut led = cortex_m::interrupt::free(|cs| gpioa.pa1.into_push_pull_output(cs)); + let mut led = critical_section::with(|cs| gpioa.pa1.into_push_pull_output(&cs)); loop { // Turn PA1 on a million times in a row diff --git a/examples/blinky_adc.rs b/examples/blinky_adc.rs index c74c2c3..aec4bdc 100644 --- a/examples/blinky_adc.rs +++ b/examples/blinky_adc.rs @@ -17,12 +17,12 @@ fn main() -> ! { let gpioa = p.GPIOA.split(&mut rcc); - let (mut led, mut an_in) = cortex_m::interrupt::free(move |cs| { + let (mut led, mut an_in) = critical_section::with(move |cs| { ( // (Re-)configure PA1 as output - gpioa.pa1.into_push_pull_output(cs), + gpioa.pa1.into_push_pull_output(&cs), // (Re-)configure PA0 as analog input - gpioa.pa0.into_analog(cs), + gpioa.pa0.into_analog(&cs), ) }); diff --git a/examples/blinky_delay.rs b/examples/blinky_delay.rs index 22fdd52..4b7c2b5 100644 --- a/examples/blinky_delay.rs +++ b/examples/blinky_delay.rs @@ -18,7 +18,7 @@ fn main() -> ! { let gpioa = p.GPIOA.split(&mut rcc); // (Re-)configure PA1 as output - let mut led = cortex_m::interrupt::free(move |cs| gpioa.pa1.into_push_pull_output(cs)); + let mut led = critical_section::with(move |cs| gpioa.pa1.into_push_pull_output(&cs)); // Get delay provider let mut delay = Delay::new(cp.SYST, &rcc); diff --git a/examples/blinky_multiple.rs b/examples/blinky_multiple.rs index a4939ea..bb94558 100644 --- a/examples/blinky_multiple.rs +++ b/examples/blinky_multiple.rs @@ -18,12 +18,12 @@ fn main() -> ! { let gpioa = p.GPIOA.split(&mut rcc); let gpiob = p.GPIOB.split(&mut rcc); - let (led1, led2) = cortex_m::interrupt::free(move |cs| { + let (led1, led2) = critical_section::with(move |cs| { ( // (Re-)configure PA1 as output - gpioa.pa1.into_push_pull_output(cs), + gpioa.pa1.into_push_pull_output(&cs), // (Re-)configure PB1 as output - gpiob.pb1.into_push_pull_output(cs), + gpiob.pb1.into_push_pull_output(&cs), ) }); diff --git a/examples/blinky_timer.rs b/examples/blinky_timer.rs index 994dcc0..50f74c3 100644 --- a/examples/blinky_timer.rs +++ b/examples/blinky_timer.rs @@ -17,7 +17,7 @@ fn main() -> ! { let gpioa = p.GPIOA.split(&mut rcc); // (Re-)configure PA1 as output - let mut led = cortex_m::interrupt::free(move |cs| gpioa.pa1.into_push_pull_output(cs)); + let mut led = critical_section::with(move |cs| gpioa.pa1.into_push_pull_output(&cs)); // Set up a timer expiring after 1s let mut timer = Timer::tim1(p.TIM1, Hertz(1), &mut rcc); diff --git a/examples/blinky_timer_irq.rs b/examples/blinky_timer_irq.rs index 9504638..5ef9c0e 100644 --- a/examples/blinky_timer_irq.rs +++ b/examples/blinky_timer_irq.rs @@ -16,7 +16,8 @@ use crate::hal::{ use cortex_m_rt::entry; use core::cell::RefCell; -use cortex_m::{interrupt::Mutex, peripheral::Peripherals as c_m_Peripherals}; +use cortex_m::peripheral::Peripherals as c_m_Peripherals; +use critical_section::Mutex; // A type definition for the GPIO pin to be used for our LED type LEDPIN = gpioa::PA5>; @@ -35,14 +36,14 @@ fn TIM7() { static mut INT: Option> = None; let led = LED.get_or_insert_with(|| { - cortex_m::interrupt::free(|cs| { + critical_section::with(|cs| { // Move LED pin here, leaving a None in its place GLED.borrow(cs).replace(None).unwrap() }) }); let int = INT.get_or_insert_with(|| { - cortex_m::interrupt::free(|cs| { + critical_section::with(|cs| { // Move LED pin here, leaving a None in its place GINT.borrow(cs).replace(None).unwrap() }) @@ -55,7 +56,7 @@ fn TIM7() { #[entry] fn main() -> ! { if let (Some(mut p), Some(cp)) = (Peripherals::take(), c_m_Peripherals::take()) { - cortex_m::interrupt::free(move |cs| { + critical_section::with(move |cs| { let mut rcc = p .RCC .configure() @@ -68,7 +69,7 @@ fn main() -> ! { let gpioa = p.GPIOA.split(&mut rcc); // (Re-)configure PA5 as output - let led = gpioa.pa5.into_push_pull_output(cs); + let led = gpioa.pa5.into_push_pull_output(&cs); // Move the pin into our global storage *GLED.borrow(cs).borrow_mut() = Some(led); diff --git a/examples/dac.rs b/examples/dac.rs index 6ba0d23..f20676d 100644 --- a/examples/dac.rs +++ b/examples/dac.rs @@ -24,7 +24,7 @@ fn main() -> ! { let mut rcc = dp.RCC.configure().sysclk(8.mhz()).freeze(&mut dp.FLASH); let gpioa = dp.GPIOA.split(&mut rcc); - let pa4 = cortex_m::interrupt::free(move |cs| gpioa.pa4.into_analog(cs)); + let pa4 = critical_section::with(move |cs| gpioa.pa4.into_analog(&cs)); let mut dac = dac(dp.DAC, pa4, &mut rcc); diff --git a/examples/flash_systick.rs b/examples/flash_systick.rs index 05589de..fb0e37d 100644 --- a/examples/flash_systick.rs +++ b/examples/flash_systick.rs @@ -7,8 +7,9 @@ use stm32f0xx_hal as hal; use crate::hal::{gpio::*, pac, prelude::*}; -use cortex_m::{interrupt::Mutex, peripheral::syst::SystClkSource::Core, Peripherals}; +use cortex_m::{peripheral::syst::SystClkSource::Core, Peripherals}; use cortex_m_rt::{entry, exception}; +use critical_section::Mutex; use core::cell::RefCell; use core::ops::DerefMut; @@ -19,13 +20,13 @@ static GPIO: Mutex>>>> = Mutex::new(R #[entry] fn main() -> ! { if let (Some(mut p), Some(cp)) = (pac::Peripherals::take(), Peripherals::take()) { - cortex_m::interrupt::free(move |cs| { + critical_section::with(move |cs| { let mut rcc = p.RCC.configure().sysclk(48.mhz()).freeze(&mut p.FLASH); let gpioa = p.GPIOA.split(&mut rcc); // (Re-)configure PA1 as output - let led = gpioa.pa1.into_push_pull_output(cs); + let led = gpioa.pa1.into_push_pull_output(&cs); // Transfer GPIO into a shared structure *GPIO.borrow(cs).borrow_mut() = Some(led); @@ -62,7 +63,7 @@ fn SysTick() { static mut STATE: u8 = 1; // Enter critical section - cortex_m::interrupt::free(|cs| { + critical_section::with(|cs| { // Borrow access to our GPIO pin from the shared structure if let Some(ref mut led) = *GPIO.borrow(cs).borrow_mut().deref_mut() { // Check state variable, keep LED off most of the time and turn it on every 10th tick diff --git a/examples/flash_systick_fancier.rs b/examples/flash_systick_fancier.rs index de4ca2e..f79962e 100644 --- a/examples/flash_systick_fancier.rs +++ b/examples/flash_systick_fancier.rs @@ -7,8 +7,9 @@ use stm32f0xx_hal as hal; use crate::hal::{gpio::*, pac, prelude::*}; -use cortex_m::{interrupt::Mutex, peripheral::syst::SystClkSource::Core, Peripherals}; +use cortex_m::{peripheral::syst::SystClkSource::Core, Peripherals}; use cortex_m_rt::{entry, exception}; +use critical_section::Mutex; use core::cell::RefCell; use core::mem::swap; @@ -22,14 +23,14 @@ static GPIO: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { if let (Some(mut p), Some(cp)) = (pac::Peripherals::take(), Peripherals::take()) { - cortex_m::interrupt::free(move |cs| { + critical_section::with(move |cs| { let mut rcc = p.RCC.configure().sysclk(48.mhz()).freeze(&mut p.FLASH); // Get access to individual pins in the GPIO port let gpioa = p.GPIOB.split(&mut rcc); // (Re-)configure the pin connected to our LED as output - let led = gpioa.pb3.into_push_pull_output(cs); + let led = gpioa.pb3.into_push_pull_output(&cs); // Transfer GPIO into a shared structure swap(&mut Some(led), &mut GPIO.borrow(cs).borrow_mut()); @@ -88,7 +89,7 @@ fn SysTick() { // Otherwise move it out of the Mutex protected shared region into our exception handler else { // Enter critical section - cortex_m::interrupt::free(|cs| { + critical_section::with(|cs| { // Swap globally stored data with SysTick private data swap(LED, &mut GPIO.borrow(cs).borrow_mut()); }); diff --git a/examples/i2c_find_address.rs b/examples/i2c_find_address.rs index 4ca8454..3a5b779 100644 --- a/examples/i2c_find_address.rs +++ b/examples/i2c_find_address.rs @@ -14,15 +14,15 @@ use cortex_m_rt::entry; #[entry] fn main() -> ! { if let Some(p) = pac::Peripherals::take() { - cortex_m::interrupt::free(move |cs| { + critical_section::with(move |cs| { let mut flash = p.FLASH; let mut rcc = p.RCC.configure().freeze(&mut flash); let gpiob = p.GPIOB.split(&mut rcc); // Configure pins for I2C - let sda = gpiob.pb7.into_alternate_af1(cs); - let scl = gpiob.pb8.into_alternate_af1(cs); + let sda = gpiob.pb7.into_alternate_af1(&cs); + let scl = gpiob.pb8.into_alternate_af1(&cs); // Configure I2C with 100kHz rate let mut i2c = I2c::i2c1(p.I2C1, (scl, sda), 100.khz(), &mut rcc); diff --git a/examples/led_hal_button_irq.rs b/examples/led_hal_button_irq.rs index a635809..7ed70ef 100644 --- a/examples/led_hal_button_irq.rs +++ b/examples/led_hal_button_irq.rs @@ -12,8 +12,9 @@ use crate::hal::{ prelude::*, }; -use cortex_m::{interrupt::Mutex, peripheral::Peripherals as c_m_Peripherals}; +use cortex_m::peripheral::Peripherals as c_m_Peripherals; use cortex_m_rt::entry; +use critical_section::Mutex; use core::{cell::RefCell, ops::DerefMut}; @@ -29,7 +30,7 @@ static INT: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { if let (Some(p), Some(cp)) = (Peripherals::take(), c_m_Peripherals::take()) { - cortex_m::interrupt::free(move |cs| { + critical_section::with(move |cs| { // Enable clock for SYSCFG let rcc = p.RCC; rcc.apb2enr.modify(|_, w| w.syscfgen().set_bit()); @@ -43,10 +44,10 @@ fn main() -> ! { let exti = p.EXTI; // Configure PB1 as input (button) - let _ = gpiob.pb1.into_pull_down_input(cs); + let _ = gpiob.pb1.into_pull_down_input(&cs); // Configure PA1 as output (LED) - let mut led = gpioa.pa1.into_push_pull_output(cs); + let mut led = gpioa.pa1.into_push_pull_output(&cs); // Turn off LED led.set_low().ok(); @@ -88,7 +89,7 @@ fn main() -> ! { #[interrupt] fn EXTI0_1() { // Enter critical section - cortex_m::interrupt::free(|cs| { + critical_section::with(|cs| { // Obtain all Mutex protected resources if let (&mut Some(ref mut led), &mut Some(ref mut delay), &mut Some(ref mut exti)) = ( LED.borrow(cs).borrow_mut().deref_mut(), diff --git a/examples/pwm.rs b/examples/pwm.rs index 8990f2f..08a777f 100644 --- a/examples/pwm.rs +++ b/examples/pwm.rs @@ -18,10 +18,10 @@ fn main() -> ! { let mut rcc = dp.RCC.configure().sysclk(8.mhz()).freeze(&mut dp.FLASH); let gpioa = dp.GPIOA.split(&mut rcc); - let channels = cortex_m::interrupt::free(move |cs| { + let channels = critical_section::with(move |cs| { ( - gpioa.pa8.into_alternate_af2(cs), - gpioa.pa9.into_alternate_af2(cs), + gpioa.pa8.into_alternate_af2(&cs), + gpioa.pa9.into_alternate_af2(&cs), ) }); diff --git a/examples/pwm_complementary.rs b/examples/pwm_complementary.rs index f190c20..1280d77 100644 --- a/examples/pwm_complementary.rs +++ b/examples/pwm_complementary.rs @@ -18,10 +18,10 @@ fn main() -> ! { let mut rcc = dp.RCC.configure().sysclk(8.mhz()).freeze(&mut dp.FLASH); let gpioa = dp.GPIOA.split(&mut rcc); - let channels = cortex_m::interrupt::free(move |cs| { + let channels = critical_section::with(move |cs| { ( - gpioa.pa8.into_alternate_af2(cs), // on TIM1_CH1 - gpioa.pa7.into_alternate_af2(cs), // on TIM1_CH1N + gpioa.pa8.into_alternate_af2(&cs), // on TIM1_CH1 + gpioa.pa7.into_alternate_af2(&cs), // on TIM1_CH1N ) }); diff --git a/examples/serial_echo.rs b/examples/serial_echo.rs index d0c70d3..94a4220 100644 --- a/examples/serial_echo.rs +++ b/examples/serial_echo.rs @@ -17,10 +17,10 @@ fn main() -> ! { let gpioa = p.GPIOA.split(&mut rcc); - let (tx, rx) = cortex_m::interrupt::free(move |cs| { + let (tx, rx) = critical_section::with(move |cs| { ( - gpioa.pa9.into_alternate_af1(cs), - gpioa.pa10.into_alternate_af1(cs), + gpioa.pa9.into_alternate_af1(&cs), + gpioa.pa10.into_alternate_af1(&cs), ) }); diff --git a/examples/serial_spi_bridge.rs b/examples/serial_spi_bridge.rs index b3bacd5..d8a7ee7 100644 --- a/examples/serial_spi_bridge.rs +++ b/examples/serial_spi_bridge.rs @@ -36,15 +36,15 @@ fn main() -> ! { let gpioa = p.GPIOA.split(&mut rcc); - let (sck, miso, mosi, tx, rx) = cortex_m::interrupt::free(move |cs| { + let (sck, miso, mosi, tx, rx) = critical_section::with(move |cs| { ( // SPI pins - gpioa.pa5.into_alternate_af0(cs), - gpioa.pa6.into_alternate_af0(cs), - gpioa.pa7.into_alternate_af0(cs), + gpioa.pa5.into_alternate_af0(&cs), + gpioa.pa6.into_alternate_af0(&cs), + gpioa.pa7.into_alternate_af0(&cs), // USART pins - gpioa.pa9.into_alternate_af1(cs), - gpioa.pa10.into_alternate_af1(cs), + gpioa.pa9.into_alternate_af1(&cs), + gpioa.pa10.into_alternate_af1(&cs), ) }); diff --git a/examples/serial_stopwatch.rs b/examples/serial_stopwatch.rs index 37c5127..19697f4 100644 --- a/examples/serial_stopwatch.rs +++ b/examples/serial_stopwatch.rs @@ -15,8 +15,9 @@ use core::cell::RefCell; use core::fmt::Write as _; use core::ops::DerefMut; -use cortex_m::{interrupt::Mutex, peripheral::Peripherals as c_m_Peripherals}; +use cortex_m::peripheral::Peripherals as c_m_Peripherals; use cortex_m_rt::entry; +use critical_section::Mutex; // Make timer interrupt registers globally available static GINT: Mutex>>> = Mutex::new(RefCell::new(None)); @@ -36,7 +37,7 @@ static TIME: Mutex> = Mutex::new(RefCell::new(Time { // interrupt trips when the timer timed out #[interrupt] fn TIM7() { - cortex_m::interrupt::free(|cs| { + critical_section::with(|cs| { // Move LED pin here, leaving a None in its place GINT.borrow(cs) .borrow_mut() @@ -57,14 +58,14 @@ fn TIM7() { #[entry] fn main() -> ! { if let (Some(p), Some(cp)) = (Peripherals::take(), c_m_Peripherals::take()) { - let mut serial = cortex_m::interrupt::free(move |cs| { + let mut serial = critical_section::with(move |cs| { let mut flash = p.FLASH; let mut rcc = p.RCC.configure().sysclk(48.mhz()).freeze(&mut flash); // Use USART2 with PA2 and PA3 as serial port let gpioa = p.GPIOA.split(&mut rcc); - let tx = gpioa.pa2.into_alternate_af1(cs); - let rx = gpioa.pa3.into_alternate_af1(cs); + let tx = gpioa.pa2.into_alternate_af1(&cs); + let rx = gpioa.pa3.into_alternate_af1(&cs); // Set up a timer expiring every millisecond let mut timer = Timer::tim7(p.TIM7, 1000.hz(), &mut rcc); @@ -98,7 +99,7 @@ fn main() -> ! { // Wait for reception of a single byte let received = nb::block!(serial.read()).unwrap(); - let time = cortex_m::interrupt::free(|cs| { + let time = critical_section::with(|cs| { let mut time = TIME.borrow(cs).borrow_mut(); // If we received a 0, reset the time diff --git a/examples/spi_hal_apa102c.rs b/examples/spi_hal_apa102c.rs index f3c2007..99b9c28 100644 --- a/examples/spi_hal_apa102c.rs +++ b/examples/spi_hal_apa102c.rs @@ -28,11 +28,11 @@ fn main() -> ! { let gpioa = p.GPIOA.split(&mut rcc); // Configure pins for SPI - let (sck, miso, mosi) = cortex_m::interrupt::free(move |cs| { + let (sck, miso, mosi) = critical_section::with(move |cs| { ( - gpioa.pa5.into_alternate_af0(cs), - gpioa.pa6.into_alternate_af0(cs), - gpioa.pa7.into_alternate_af0(cs), + gpioa.pa5.into_alternate_af0(&cs), + gpioa.pa6.into_alternate_af0(&cs), + gpioa.pa7.into_alternate_af0(&cs), ) }); diff --git a/examples/usb_serial.rs b/examples/usb_serial.rs index 49afe55..e9a86a5 100644 --- a/examples/usb_serial.rs +++ b/examples/usb_serial.rs @@ -35,7 +35,7 @@ fn main() -> ! { // Configure the on-board LED (LD3, green) let gpiob = dp.GPIOB.split(&mut rcc); - let mut led = cortex_m::interrupt::free(|cs| gpiob.pb3.into_push_pull_output(cs)); + let mut led = critical_section::with(|cs| gpiob.pb3.into_push_pull_output(&cs)); led.set_low().ok(); // Turn off let gpioa = dp.GPIOA.split(&mut rcc); diff --git a/examples/watchdog.rs b/examples/watchdog.rs index bcd265e..5e94fea 100644 --- a/examples/watchdog.rs +++ b/examples/watchdog.rs @@ -30,7 +30,7 @@ fn main() -> ! { let mut delay = Delay::new(cp.SYST, &rcc); // Configure serial TX pin - let tx = cortex_m::interrupt::free(move |cs| gpioa.pa9.into_alternate_af1(cs)); + let tx = critical_section::with(move |cs| gpioa.pa9.into_alternate_af1(&cs)); // Obtain a serial peripheral with for unidirectional communication let mut serial = Serial::usart1tx(p.USART1, tx, 115_200.bps(), &mut rcc); diff --git a/src/adc.rs b/src/adc.rs index edf97a2..f5473a5 100644 --- a/src/adc.rs +++ b/src/adc.rs @@ -12,14 +12,14 @@ //! use crate::hal::prelude::*; //! use crate::hal::adc::Adc; //! -//! cortex_m::interrupt::free(|cs| { +//! critical_section::with(|cs| { //! let mut p = pac::Peripherals::take().unwrap(); //! let mut rcc = p.RCC.configure().freeze(&mut p.FLASH); //! //! let gpioa = p.GPIOA.split(&mut rcc); //! -//! let mut led = gpioa.pa1.into_push_pull_pull_output(cs); -//! let mut an_in = gpioa.pa0.into_analog(cs); +//! let mut led = gpioa.pa1.into_push_pull_pull_output(&cs); +//! let mut an_in = gpioa.pa0.into_analog(&cs); //! //! let mut delay = Delay::new(cp.SYST, &rcc); //! diff --git a/src/dac.rs b/src/dac.rs index 4587276..328f0be 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -29,11 +29,11 @@ //!#[entry] //!fn main() -> ! { //! if let (Some(mut dp), Some(_cp)) = (pac::Peripherals::take(), cortex_m::Peripherals::take()) { -//! cortex_m::interrupt::free(move |cs| { +//! critical_section::with(move |cs| { //! let mut rcc = dp.RCC.configure().sysclk(8.mhz()).freeze(&mut dp.FLASH); //! //! let gpioa = dp.GPIOA.split(&mut rcc); -//! let mut dac = dac(dp.DAC, gpioa.pa4.into_analog(cs), &mut rcc); +//! let mut dac = dac(dp.DAC, gpioa.pa4.into_analog(&cs), &mut rcc); //! //! dac.enable(); //! diff --git a/src/gpio.rs b/src/gpio.rs index dd2757e..072085a 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -190,7 +190,7 @@ macro_rules! gpio { pac::$GPIOX }; - use cortex_m::interrupt::CriticalSection; + use critical_section::CriticalSection; use super::{ Alternate, Analog, Floating, GpioExt, Input, OpenDrain, Output, diff --git a/src/serial.rs b/src/serial.rs index ea8bed9..f157491 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -16,13 +16,13 @@ //! //! use nb::block; //! -//! cortex_m::interrupt::free(|cs| { +//! critical_section::with(|cs| { //! let rcc = p.RCC.configure().sysclk(48.mhz()).freeze(); //! //! let gpioa = p.GPIOA.split(&mut rcc); //! -//! let tx = gpioa.pa9.into_alternate_af1(cs); -//! let rx = gpioa.pa10.into_alternate_af1(cs); +//! let tx = gpioa.pa9.into_alternate_af1(&cs); +//! let rx = gpioa.pa10.into_alternate_af1(&cs); //! //! let mut serial = Serial::usart1(p.USART1, (tx, rx), 115_200.bps(), &mut rcc); //! @@ -43,12 +43,12 @@ //! //! use nb::block; //! -//! cortex_m::interrupt::free(|cs| { +//! critical_section::with(|cs| { //! let rcc = p.RCC.configure().sysclk(48.mhz()).freeze(); //! //! let gpioa = p.GPIOA.split(&mut rcc); //! -//! let tx = gpioa.pa9.into_alternate_af1(cs); +//! let tx = gpioa.pa9.into_alternate_af1(&cs); //! //! let mut serial = Serial::usart1tx(p.USART1, tx, 115_200.bps(), &mut rcc); //! diff --git a/src/spi.rs b/src/spi.rs index 17eeef7..4b75c7a 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -13,16 +13,16 @@ //! use crate::hal::prelude::*; //! use crate::hal::spi::{Spi, Mode, Phase, Polarity}; //! -//! cortex_m::interrupt::free(|cs| { +//! critical_section::with(|cs| { //! let mut p = pac::Peripherals::take().unwrap(); //! let mut rcc = p.RCC.constrain().freeze(&mut p.FLASH); //! //! let gpioa = p.GPIOA.split(&mut rcc); //! //! // Configure pins for SPI -//! let sck = gpioa.pa5.into_alternate_af0(cs); -//! let miso = gpioa.pa6.into_alternate_af0(cs); -//! let mosi = gpioa.pa7.into_alternate_af0(cs); +//! let sck = gpioa.pa5.into_alternate_af0(&cs); +//! let miso = gpioa.pa6.into_alternate_af0(&cs); +//! let mosi = gpioa.pa7.into_alternate_af0(&cs); //! //! // Configure SPI with 1MHz rate //! let mut spi = Spi::spi1(p.SPI1, (sck, miso, mosi), Mode { diff --git a/src/timers.rs b/src/timers.rs index 136bc93..ff64e20 100644 --- a/src/timers.rs +++ b/src/timers.rs @@ -13,13 +13,13 @@ //! use crate::hal::timers::*; //! use nb::block; //! -//! cortex_m::interrupt::free(|cs| { +//! critical_section::with(|cs| { //! let mut p = pac::Peripherals::take().unwrap(); //! let mut rcc = p.RCC.configure().freeze(&mut p.FLASH); //! //! let gpioa = p.GPIOA.split(&mut rcc); //! -//! let mut led = gpioa.pa1.into_push_pull_pull_output(cs); +//! let mut led = gpioa.pa1.into_push_pull_pull_output(&cs); //! //! let mut timer = Timer::tim1(p.TIM1, Hertz(1), &mut rcc); //! loop { diff --git a/src/usb.rs b/src/usb.rs index ba5e792..828b900 100644 --- a/src/usb.rs +++ b/src/usb.rs @@ -30,7 +30,7 @@ unsafe impl UsbPeripheral for Peripheral { fn enable() { let rcc = unsafe { &*RCC::ptr() }; - cortex_m::interrupt::free(|_| { + critical_section::with(|_| { // Enable USB peripheral rcc.apb1enr.modify(|_, w| w.usben().set_bit());