crc.rs 898 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //! CRC
  2. use crate::pac::CRC;
  3. use crate::rcc::{Enable, AHB};
  4. /// Extension trait to constrain the CRC peripheral
  5. pub trait CrcExt {
  6. /// Constrains the CRC peripheral to play nicely with the other abstractions
  7. fn new(self, ahb: &mut AHB) -> Crc;
  8. }
  9. impl CrcExt for CRC {
  10. fn new(self, ahb: &mut AHB) -> Crc {
  11. CRC::enable(ahb);
  12. Crc { crc: self }
  13. }
  14. }
  15. /// Constrained CRC peripheral
  16. pub struct Crc {
  17. crc: CRC,
  18. }
  19. impl Crc {
  20. pub fn read(&self) -> u32 {
  21. self.crc.dr.read().bits()
  22. }
  23. pub fn write(&mut self, val: u32) {
  24. self.crc.dr.write(|w| w.dr().bits(val))
  25. }
  26. pub fn reset(&self) {
  27. self.crc.cr.write(|w| w.reset().set_bit());
  28. // calling CRC::dr::write() just after CRC::cr::reset() will not work as expected, and
  29. // inserting single nop() seems to solve the problem.
  30. cortex_m::asm::nop();
  31. }
  32. }