Skip to content

Commit 3cccb82

Browse files
committed
Use bare_metal::CriticalSection for GPIO configuration
1 parent b2e2e9d commit 3cccb82

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Changed
1111

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

1415
### Added
1516

examples/serial_spi_bridge.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ fn main() -> ! {
3636

3737
let gpioa = p.GPIOA.split(&mut rcc);
3838

39-
let (sck, miso, mosi, tx, rx) = cortex_m::interrupt::free(move |cs| {
39+
let (sck, miso, mosi, tx, rx) = cortex_m::interrupt::free(move |_| {
40+
// SAFETY: We are in a critical section, but the `cortex_m` critical section
41+
// token is not compatible with the `bare_metal` token. Future version of the
42+
// `cortex_m` crate will not supply *any* token to this callback!
43+
let cs = unsafe { &bare_metal::CriticalSection::new() };
4044
(
4145
// SPI pins
4246
gpioa.pa5.into_alternate_af0(cs),

examples/spi_hal_apa102c.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ fn main() -> ! {
2828
let gpioa = p.GPIOA.split(&mut rcc);
2929

3030
// Configure pins for SPI
31-
let (sck, miso, mosi) = cortex_m::interrupt::free(move |cs| {
31+
let (sck, miso, mosi) = cortex_m::interrupt::free(move |_| {
32+
// SAFETY: We are in a critical section, but the `cortex_m` critical section
33+
// token is not compatible with the `bare_metal` token. Future version of the
34+
// `cortex_m` crate will not supply *any* token to this callback!
35+
let cs = unsafe { &bare_metal::CriticalSection::new() };
3236
(
3337
gpioa.pa5.into_alternate_af0(cs),
3438
gpioa.pa6.into_alternate_af0(cs),

src/gpio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ macro_rules! gpio {
190190
pac::$GPIOX
191191
};
192192

193-
use cortex_m::interrupt::CriticalSection;
193+
use bare_metal::CriticalSection;
194194

195195
use super::{
196196
Alternate, Analog, Floating, GpioExt, Input, OpenDrain, Output,

0 commit comments

Comments
 (0)