Skip to content

Commit

Permalink
Use bare_metal::CriticalSection for GPIO configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
urdh committed Aug 22, 2024
1 parent b2e2e9d commit 3cccb82
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- Updated the `cast` dependency from 0.2 to 0.3
- Use `bare_metal::CriticalSection` for GPIO configuration (breaking change)

### Added

Expand Down
6 changes: 5 additions & 1 deletion examples/serial_spi_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ 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) = cortex_m::interrupt::free(move |_| {
// SAFETY: We are in a critical section, but the `cortex_m` critical section
// token is not compatible with the `bare_metal` token. Future version of the
// `cortex_m` crate will not supply *any* token to this callback!
let cs = unsafe { &bare_metal::CriticalSection::new() };
(
// SPI pins
gpioa.pa5.into_alternate_af0(cs),
Expand Down
6 changes: 5 additions & 1 deletion examples/spi_hal_apa102c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +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) = cortex_m::interrupt::free(move |_| {
// SAFETY: We are in a critical section, but the `cortex_m` critical section
// token is not compatible with the `bare_metal` token. Future version of the
// `cortex_m` crate will not supply *any* token to this callback!
let cs = unsafe { &bare_metal::CriticalSection::new() };
(
gpioa.pa5.into_alternate_af0(cs),
gpioa.pa6.into_alternate_af0(cs),
Expand Down
2 changes: 1 addition & 1 deletion src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ macro_rules! gpio {
pac::$GPIOX
};

use cortex_m::interrupt::CriticalSection;
use bare_metal::CriticalSection;

use super::{
Alternate, Analog, Floating, GpioExt, Input, OpenDrain, Output,
Expand Down

0 comments on commit 3cccb82

Please sign in to comment.