diff options
| -rw-r--r-- | embassy-stm32/src/can/bxcan.rs | 31 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/can.rs | 16 |
2 files changed, 27 insertions, 20 deletions
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 4afbb5687..260f567b4 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs | |||
| @@ -1,9 +1,8 @@ | |||
| 1 | use core::cell::{RefCell, RefMut}; | ||
| 1 | use core::future::poll_fn; | 2 | use core::future::poll_fn; |
| 2 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 3 | use core::ops::{Deref, DerefMut}; | 4 | use core::ops::{Deref, DerefMut}; |
| 4 | use core::task::Poll; | 5 | use core::task::Poll; |
| 5 | use core::cell::RefMut; | ||
| 6 | use core::cell::RefCell; | ||
| 7 | 6 | ||
| 8 | pub use bxcan; | 7 | pub use bxcan; |
| 9 | use bxcan::{Data, ExtendedId, Frame, Id, StandardId}; | 8 | use bxcan::{Data, ExtendedId, Frame, Id, StandardId}; |
| @@ -155,7 +154,11 @@ impl<'d, T: Instance> Can<'d, T> { | |||
| 155 | 154 | ||
| 156 | pub fn set_bitrate(&mut self, bitrate: u32) { | 155 | pub fn set_bitrate(&mut self, bitrate: u32) { |
| 157 | let bit_timing = Self::calc_bxcan_timings(T::frequency(), bitrate).unwrap(); | 156 | let bit_timing = Self::calc_bxcan_timings(T::frequency(), bitrate).unwrap(); |
| 158 | self.can.borrow_mut().modify_config().set_bit_timing(bit_timing).leave_disabled(); | 157 | self.can |
| 158 | .borrow_mut() | ||
| 159 | .modify_config() | ||
| 160 | .set_bit_timing(bit_timing) | ||
| 161 | .leave_disabled(); | ||
| 159 | } | 162 | } |
| 160 | 163 | ||
| 161 | /// Queues the message to be sent but exerts backpressure | 164 | /// Queues the message to be sent but exerts backpressure |
| @@ -432,19 +435,19 @@ impl<'d, T: Instance> Drop for Can<'d, T> { | |||
| 432 | } | 435 | } |
| 433 | } | 436 | } |
| 434 | 437 | ||
| 435 | // impl<'d, T: Instance> Deref for Can<'d, T> { | 438 | impl<'d, T: Instance> Deref for Can<'d, T> { |
| 436 | // type Target = bxcan::Can<BxcanInstance<'d, T>>; | 439 | type Target = RefCell<bxcan::Can<BxcanInstance<'d, T>>>; |
| 437 | 440 | ||
| 438 | // fn deref(&self) -> &Self::Target { | 441 | fn deref(&self) -> &Self::Target { |
| 439 | // self.can.borrow() | 442 | &self.can |
| 440 | // } | 443 | } |
| 441 | // } | 444 | } |
| 442 | 445 | ||
| 443 | // impl<'d, T: Instance> DerefMut for Can<'d, T> { | 446 | impl<'d, T: Instance> DerefMut for Can<'d, T> { |
| 444 | // fn deref_mut(&mut self) -> &mut Self::Target { | 447 | fn deref_mut(&mut self) -> &mut Self::Target { |
| 445 | // self.can.borrow_mut() | 448 | &mut self.can |
| 446 | // } | 449 | } |
| 447 | // } | 450 | } |
| 448 | 451 | ||
| 449 | pub(crate) mod sealed { | 452 | pub(crate) mod sealed { |
| 450 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 453 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
diff --git a/examples/stm32f7/src/bin/can.rs b/examples/stm32f7/src/bin/can.rs index d821039c2..65af9845e 100644 --- a/examples/stm32f7/src/bin/can.rs +++ b/examples/stm32f7/src/bin/can.rs | |||
| @@ -2,15 +2,17 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | use core::borrow::BorrowMut; | 5 | use core::borrow::{Borrow, BorrowMut}; |
| 6 | use core::borrow::Borrow; | 6 | |
| 7 | use cortex_m_rt::entry; | 7 | use cortex_m_rt::entry; |
| 8 | use defmt::*; | 8 | use defmt::*; |
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::bind_interrupts; | 10 | use embassy_stm32::bind_interrupts; |
| 11 | use embassy_stm32::can::bxcan::filter::Mask32; | 11 | use embassy_stm32::can::bxcan::filter::Mask32; |
| 12 | use embassy_stm32::can::bxcan::{Fifo, Frame, StandardId, Data}; | 12 | use embassy_stm32::can::bxcan::{Data, Fifo, Frame, StandardId}; |
| 13 | use embassy_stm32::can::{Can,CanTx,CanRx, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler}; | 13 | use embassy_stm32::can::{ |
| 14 | Can, CanRx, CanTx, Rx0InterruptHandler, Rx1InterruptHandler, SceInterruptHandler, TxInterruptHandler, | ||
| 15 | }; | ||
| 14 | use embassy_stm32::gpio::{Input, Pull}; | 16 | use embassy_stm32::gpio::{Input, Pull}; |
| 15 | use embassy_stm32::peripherals::CAN3; | 17 | use embassy_stm32::peripherals::CAN3; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | 18 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -44,8 +46,10 @@ async fn main(spawner: Spawner) { | |||
| 44 | let rx_pin = Input::new(&mut p.PA15, Pull::Up); | 46 | let rx_pin = Input::new(&mut p.PA15, Pull::Up); |
| 45 | core::mem::forget(rx_pin); | 47 | core::mem::forget(rx_pin); |
| 46 | 48 | ||
| 47 | let CAN: &'static mut Can<'static,CAN3> = static_cell::make_static!(Can::new(p.CAN3, p.PA8, p.PA15, Irqs)); | 49 | let CAN: &'static mut Can<'static, CAN3> = static_cell::make_static!(Can::new(p.CAN3, p.PA8, p.PA15, Irqs)); |
| 48 | CAN.as_mut().modify_filters().enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); | 50 | CAN.as_mut() |
| 51 | .modify_filters() | ||
| 52 | .enable_bank(0, Fifo::Fifo0, Mask32::accept_all()); | ||
| 49 | 53 | ||
| 50 | CAN.as_mut() | 54 | CAN.as_mut() |
| 51 | .modify_config() | 55 | .modify_config() |
