diff options
Diffstat (limited to 'embassy-nrf/src/uarte.rs')
| -rw-r--r-- | embassy-nrf/src/uarte.rs | 174 |
1 files changed, 105 insertions, 69 deletions
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 66fb3b3f2..049830aed 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -15,7 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | use core::future::poll_fn; | 16 | use core::future::poll_fn; |
| 17 | use core::marker::PhantomData; | 17 | use core::marker::PhantomData; |
| 18 | use core::sync::atomic::{compiler_fence, AtomicU8, Ordering}; | 18 | use core::sync::atomic::{AtomicU8, Ordering, compiler_fence}; |
| 19 | use core::task::Poll; | 19 | use core::task::Poll; |
| 20 | 20 | ||
| 21 | use embassy_hal_internal::drop::OnDrop; | 21 | use embassy_hal_internal::drop::OnDrop; |
| @@ -25,7 +25,7 @@ use embassy_sync::waitqueue::AtomicWaker; | |||
| 25 | pub use pac::uarte::vals::{Baudrate, ConfigParity as Parity}; | 25 | pub use pac::uarte::vals::{Baudrate, ConfigParity as Parity}; |
| 26 | 26 | ||
| 27 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; | 27 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; |
| 28 | use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits, SealedPin as _, DISCONNECTED}; | 28 | use crate::gpio::{self, AnyPin, DISCONNECTED, Pin as GpioPin, PselBits, SealedPin as _}; |
| 29 | use crate::interrupt::typelevel::Interrupt; | 29 | use crate::interrupt::typelevel::Interrupt; |
| 30 | use crate::pac::gpio::vals as gpiovals; | 30 | use crate::pac::gpio::vals as gpiovals; |
| 31 | use crate::pac::uarte::vals; | 31 | use crate::pac::uarte::vals; |
| @@ -113,20 +113,20 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 113 | let r = T::regs(); | 113 | let r = T::regs(); |
| 114 | let s = T::state(); | 114 | let s = T::state(); |
| 115 | 115 | ||
| 116 | let endrx = r.events_endrx().read(); | 116 | let endrx = r.events_dma().rx().end().read(); |
| 117 | let error = r.events_error().read(); | 117 | let error = r.events_error().read(); |
| 118 | if endrx != 0 || error != 0 { | 118 | if endrx != 0 || error != 0 { |
| 119 | s.rx_waker.wake(); | 119 | s.rx_waker.wake(); |
| 120 | if endrx != 0 { | 120 | if endrx != 0 { |
| 121 | r.intenclr().write(|w| w.set_endrx(true)); | 121 | r.intenclr().write(|w| w.set_dmarxend(true)); |
| 122 | } | 122 | } |
| 123 | if error != 0 { | 123 | if error != 0 { |
| 124 | r.intenclr().write(|w| w.set_error(true)); | 124 | r.intenclr().write(|w| w.set_error(true)); |
| 125 | } | 125 | } |
| 126 | } | 126 | } |
| 127 | if r.events_endtx().read() != 0 { | 127 | if r.events_dma().tx().end().read() != 0 { |
| 128 | s.tx_waker.wake(); | 128 | s.tx_waker.wake(); |
| 129 | r.intenclr().write(|w| w.set_endtx(true)); | 129 | r.intenclr().write(|w| w.set_dmatxend(true)); |
| 130 | } | 130 | } |
| 131 | } | 131 | } |
| 132 | } | 132 | } |
| @@ -257,7 +257,7 @@ impl<'d> Uarte<'d> { | |||
| 257 | /// Return the endtx event for use with PPI | 257 | /// Return the endtx event for use with PPI |
| 258 | pub fn event_endtx(&self) -> Event<'_> { | 258 | pub fn event_endtx(&self) -> Event<'_> { |
| 259 | let r = self.tx.r; | 259 | let r = self.tx.r; |
| 260 | Event::from_reg(r.events_endtx()) | 260 | Event::from_reg(r.events_dma().tx().end()) |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | /// Read bytes until the buffer is filled. | 263 | /// Read bytes until the buffer is filled. |
| @@ -296,7 +296,13 @@ pub(crate) fn configure_tx_pins(r: pac::uarte::Uarte, txd: Peri<'_, AnyPin>, cts | |||
| 296 | txd.conf().write(|w| { | 296 | txd.conf().write(|w| { |
| 297 | w.set_dir(gpiovals::Dir::OUTPUT); | 297 | w.set_dir(gpiovals::Dir::OUTPUT); |
| 298 | w.set_input(gpiovals::Input::DISCONNECT); | 298 | w.set_input(gpiovals::Input::DISCONNECT); |
| 299 | #[cfg(not(feature = "_nrf54l"))] | ||
| 299 | w.set_drive(gpiovals::Drive::H0H1); | 300 | w.set_drive(gpiovals::Drive::H0H1); |
| 301 | #[cfg(feature = "_nrf54l")] | ||
| 302 | { | ||
| 303 | w.set_drive0(gpiovals::Drive::H); | ||
| 304 | w.set_drive1(gpiovals::Drive::H); | ||
| 305 | } | ||
| 300 | }); | 306 | }); |
| 301 | r.psel().txd().write_value(txd.psel_bits()); | 307 | r.psel().txd().write_value(txd.psel_bits()); |
| 302 | 308 | ||
| @@ -304,7 +310,13 @@ pub(crate) fn configure_tx_pins(r: pac::uarte::Uarte, txd: Peri<'_, AnyPin>, cts | |||
| 304 | pin.conf().write(|w| { | 310 | pin.conf().write(|w| { |
| 305 | w.set_dir(gpiovals::Dir::INPUT); | 311 | w.set_dir(gpiovals::Dir::INPUT); |
| 306 | w.set_input(gpiovals::Input::CONNECT); | 312 | w.set_input(gpiovals::Input::CONNECT); |
| 313 | #[cfg(not(feature = "_nrf54l"))] | ||
| 307 | w.set_drive(gpiovals::Drive::H0H1); | 314 | w.set_drive(gpiovals::Drive::H0H1); |
| 315 | #[cfg(feature = "_nrf54l")] | ||
| 316 | { | ||
| 317 | w.set_drive0(gpiovals::Drive::H); | ||
| 318 | w.set_drive1(gpiovals::Drive::H); | ||
| 319 | } | ||
| 308 | }); | 320 | }); |
| 309 | } | 321 | } |
| 310 | r.psel().cts().write_value(cts.psel_bits()); | 322 | r.psel().cts().write_value(cts.psel_bits()); |
| @@ -314,7 +326,13 @@ pub(crate) fn configure_rx_pins(r: pac::uarte::Uarte, rxd: Peri<'_, AnyPin>, rts | |||
| 314 | rxd.conf().write(|w| { | 326 | rxd.conf().write(|w| { |
| 315 | w.set_dir(gpiovals::Dir::INPUT); | 327 | w.set_dir(gpiovals::Dir::INPUT); |
| 316 | w.set_input(gpiovals::Input::CONNECT); | 328 | w.set_input(gpiovals::Input::CONNECT); |
| 329 | #[cfg(not(feature = "_nrf54l"))] | ||
| 317 | w.set_drive(gpiovals::Drive::H0H1); | 330 | w.set_drive(gpiovals::Drive::H0H1); |
| 331 | #[cfg(feature = "_nrf54l")] | ||
| 332 | { | ||
| 333 | w.set_drive0(gpiovals::Drive::H); | ||
| 334 | w.set_drive1(gpiovals::Drive::H); | ||
| 335 | } | ||
| 318 | }); | 336 | }); |
| 319 | r.psel().rxd().write_value(rxd.psel_bits()); | 337 | r.psel().rxd().write_value(rxd.psel_bits()); |
| 320 | 338 | ||
| @@ -323,7 +341,13 @@ pub(crate) fn configure_rx_pins(r: pac::uarte::Uarte, rxd: Peri<'_, AnyPin>, rts | |||
| 323 | pin.conf().write(|w| { | 341 | pin.conf().write(|w| { |
| 324 | w.set_dir(gpiovals::Dir::OUTPUT); | 342 | w.set_dir(gpiovals::Dir::OUTPUT); |
| 325 | w.set_input(gpiovals::Input::DISCONNECT); | 343 | w.set_input(gpiovals::Input::DISCONNECT); |
| 344 | #[cfg(not(feature = "_nrf54l"))] | ||
| 326 | w.set_drive(gpiovals::Drive::H0H1); | 345 | w.set_drive(gpiovals::Drive::H0H1); |
| 346 | #[cfg(feature = "_nrf54l")] | ||
| 347 | { | ||
| 348 | w.set_drive0(gpiovals::Drive::H); | ||
| 349 | w.set_drive1(gpiovals::Drive::H); | ||
| 350 | } | ||
| 327 | }); | 351 | }); |
| 328 | } | 352 | } |
| 329 | r.psel().rts().write_value(rts.psel_bits()); | 353 | r.psel().rts().write_value(rts.psel_bits()); |
| @@ -333,6 +357,10 @@ pub(crate) fn configure(r: pac::uarte::Uarte, config: Config, hardware_flow_cont | |||
| 333 | r.config().write(|w| { | 357 | r.config().write(|w| { |
| 334 | w.set_hwfc(hardware_flow_control); | 358 | w.set_hwfc(hardware_flow_control); |
| 335 | w.set_parity(config.parity); | 359 | w.set_parity(config.parity); |
| 360 | #[cfg(feature = "_nrf54l")] | ||
| 361 | w.set_framesize(vals::Framesize::_8BIT); | ||
| 362 | #[cfg(feature = "_nrf54l")] | ||
| 363 | w.set_frametimeout(true); | ||
| 336 | }); | 364 | }); |
| 337 | r.baudrate().write(|w| w.set_baudrate(config.baudrate)); | 365 | r.baudrate().write(|w| w.set_baudrate(config.baudrate)); |
| 338 | 366 | ||
| @@ -341,8 +369,8 @@ pub(crate) fn configure(r: pac::uarte::Uarte, config: Config, hardware_flow_cont | |||
| 341 | 369 | ||
| 342 | // Reset rxstarted, txstarted. These are used by drop to know whether a transfer was | 370 | // Reset rxstarted, txstarted. These are used by drop to know whether a transfer was |
| 343 | // stopped midway or not. | 371 | // stopped midway or not. |
| 344 | r.events_rxstarted().write_value(0); | 372 | r.events_dma().rx().ready().write_value(0); |
| 345 | r.events_txstarted().write_value(0); | 373 | r.events_dma().tx().ready().write_value(0); |
| 346 | 374 | ||
| 347 | // reset all pins | 375 | // reset all pins |
| 348 | r.psel().txd().write_value(DISCONNECTED); | 376 | r.psel().txd().write_value(DISCONNECTED); |
| @@ -434,29 +462,29 @@ impl<'d> UarteTx<'d> { | |||
| 434 | let drop = OnDrop::new(move || { | 462 | let drop = OnDrop::new(move || { |
| 435 | trace!("write drop: stopping"); | 463 | trace!("write drop: stopping"); |
| 436 | 464 | ||
| 437 | r.intenclr().write(|w| w.set_endtx(true)); | 465 | r.intenclr().write(|w| w.set_dmatxend(true)); |
| 438 | r.events_txstopped().write_value(0); | 466 | r.events_txstopped().write_value(0); |
| 439 | r.tasks_stoptx().write_value(1); | 467 | r.tasks_dma().tx().stop().write_value(1); |
| 440 | 468 | ||
| 441 | // TX is stopped almost instantly, spinning is fine. | 469 | // TX is stopped almost instantly, spinning is fine. |
| 442 | while r.events_endtx().read() == 0 {} | 470 | while r.events_dma().tx().end().read() == 0 {} |
| 443 | trace!("write drop: stopped"); | 471 | trace!("write drop: stopped"); |
| 444 | }); | 472 | }); |
| 445 | 473 | ||
| 446 | r.txd().ptr().write_value(ptr as u32); | 474 | r.dma().tx().ptr().write_value(ptr as u32); |
| 447 | r.txd().maxcnt().write(|w| w.set_maxcnt(len as _)); | 475 | r.dma().tx().maxcnt().write(|w| w.set_maxcnt(len as _)); |
| 448 | 476 | ||
| 449 | r.events_endtx().write_value(0); | 477 | r.events_dma().tx().end().write_value(0); |
| 450 | r.intenset().write(|w| w.set_endtx(true)); | 478 | r.intenset().write(|w| w.set_dmatxend(true)); |
| 451 | 479 | ||
| 452 | compiler_fence(Ordering::SeqCst); | 480 | compiler_fence(Ordering::SeqCst); |
| 453 | 481 | ||
| 454 | trace!("starttx"); | 482 | trace!("starttx"); |
| 455 | r.tasks_starttx().write_value(1); | 483 | r.tasks_dma().tx().start().write_value(1); |
| 456 | 484 | ||
| 457 | poll_fn(|cx| { | 485 | poll_fn(|cx| { |
| 458 | s.tx_waker.register(cx.waker()); | 486 | s.tx_waker.register(cx.waker()); |
| 459 | if r.events_endtx().read() != 0 { | 487 | if r.events_dma().tx().end().read() != 0 { |
| 460 | return Poll::Ready(()); | 488 | return Poll::Ready(()); |
| 461 | } | 489 | } |
| 462 | Poll::Pending | 490 | Poll::Pending |
| @@ -464,7 +492,7 @@ impl<'d> UarteTx<'d> { | |||
| 464 | .await; | 492 | .await; |
| 465 | 493 | ||
| 466 | compiler_fence(Ordering::SeqCst); | 494 | compiler_fence(Ordering::SeqCst); |
| 467 | r.events_txstarted().write_value(0); | 495 | r.events_dma().tx().ready().write_value(0); |
| 468 | drop.defuse(); | 496 | drop.defuse(); |
| 469 | 497 | ||
| 470 | Ok(()) | 498 | Ok(()) |
| @@ -500,21 +528,21 @@ impl<'d> UarteTx<'d> { | |||
| 500 | 528 | ||
| 501 | let r = self.r; | 529 | let r = self.r; |
| 502 | 530 | ||
| 503 | r.txd().ptr().write_value(ptr as u32); | 531 | r.dma().tx().ptr().write_value(ptr as u32); |
| 504 | r.txd().maxcnt().write(|w| w.set_maxcnt(len as _)); | 532 | r.dma().tx().maxcnt().write(|w| w.set_maxcnt(len as _)); |
| 505 | 533 | ||
| 506 | r.events_endtx().write_value(0); | 534 | r.events_dma().tx().end().write_value(0); |
| 507 | r.intenclr().write(|w| w.set_endtx(true)); | 535 | r.intenclr().write(|w| w.set_dmatxend(true)); |
| 508 | 536 | ||
| 509 | compiler_fence(Ordering::SeqCst); | 537 | compiler_fence(Ordering::SeqCst); |
| 510 | 538 | ||
| 511 | trace!("starttx"); | 539 | trace!("starttx"); |
| 512 | r.tasks_starttx().write_value(1); | 540 | r.tasks_dma().tx().start().write_value(1); |
| 513 | 541 | ||
| 514 | while r.events_endtx().read() == 0 {} | 542 | while r.events_dma().tx().end().read() == 0 {} |
| 515 | 543 | ||
| 516 | compiler_fence(Ordering::SeqCst); | 544 | compiler_fence(Ordering::SeqCst); |
| 517 | r.events_txstarted().write_value(0); | 545 | r.events_dma().tx().ready().write_value(0); |
| 518 | 546 | ||
| 519 | Ok(()) | 547 | Ok(()) |
| 520 | } | 548 | } |
| @@ -526,7 +554,7 @@ impl<'a> Drop for UarteTx<'a> { | |||
| 526 | 554 | ||
| 527 | let r = self.r; | 555 | let r = self.r; |
| 528 | 556 | ||
| 529 | let did_stoptx = r.events_txstarted().read() != 0; | 557 | let did_stoptx = r.events_dma().tx().ready().read() != 0; |
| 530 | trace!("did_stoptx {}", did_stoptx); | 558 | trace!("did_stoptx {}", did_stoptx); |
| 531 | 559 | ||
| 532 | // Wait for txstopped, if needed. | 560 | // Wait for txstopped, if needed. |
| @@ -629,7 +657,7 @@ impl<'d> UarteRx<'d> { | |||
| 629 | let mut ppi_ch2 = Ppi::new_one_to_one( | 657 | let mut ppi_ch2 = Ppi::new_one_to_one( |
| 630 | ppi_ch2.into(), | 658 | ppi_ch2.into(), |
| 631 | timer.cc(0).event_compare(), | 659 | timer.cc(0).event_compare(), |
| 632 | Task::from_reg(r.tasks_stoprx()), | 660 | Task::from_reg(r.tasks_dma().rx().stop()), |
| 633 | ); | 661 | ); |
| 634 | ppi_ch2.enable(); | 662 | ppi_ch2.enable(); |
| 635 | 663 | ||
| @@ -664,41 +692,41 @@ impl<'d> UarteRx<'d> { | |||
| 664 | trace!("read drop: stopping"); | 692 | trace!("read drop: stopping"); |
| 665 | 693 | ||
| 666 | r.intenclr().write(|w| { | 694 | r.intenclr().write(|w| { |
| 667 | w.set_endrx(true); | 695 | w.set_dmarxend(true); |
| 668 | w.set_error(true); | 696 | w.set_error(true); |
| 669 | }); | 697 | }); |
| 670 | r.events_rxto().write_value(0); | 698 | r.events_rxto().write_value(0); |
| 671 | r.events_error().write_value(0); | 699 | r.events_error().write_value(0); |
| 672 | r.tasks_stoprx().write_value(1); | 700 | r.tasks_dma().rx().stop().write_value(1); |
| 673 | 701 | ||
| 674 | while r.events_endrx().read() == 0 {} | 702 | while r.events_dma().rx().end().read() == 0 {} |
| 675 | 703 | ||
| 676 | trace!("read drop: stopped"); | 704 | trace!("read drop: stopped"); |
| 677 | }); | 705 | }); |
| 678 | 706 | ||
| 679 | r.rxd().ptr().write_value(ptr as u32); | 707 | r.dma().rx().ptr().write_value(ptr as u32); |
| 680 | r.rxd().maxcnt().write(|w| w.set_maxcnt(len as _)); | 708 | r.dma().rx().maxcnt().write(|w| w.set_maxcnt(len as _)); |
| 681 | 709 | ||
| 682 | r.events_endrx().write_value(0); | 710 | r.events_dma().rx().end().write_value(0); |
| 683 | r.events_error().write_value(0); | 711 | r.events_error().write_value(0); |
| 684 | r.intenset().write(|w| { | 712 | r.intenset().write(|w| { |
| 685 | w.set_endrx(true); | 713 | w.set_dmarxend(true); |
| 686 | w.set_error(true); | 714 | w.set_error(true); |
| 687 | }); | 715 | }); |
| 688 | 716 | ||
| 689 | compiler_fence(Ordering::SeqCst); | 717 | compiler_fence(Ordering::SeqCst); |
| 690 | 718 | ||
| 691 | trace!("startrx"); | 719 | trace!("startrx"); |
| 692 | r.tasks_startrx().write_value(1); | 720 | r.tasks_dma().rx().start().write_value(1); |
| 693 | 721 | ||
| 694 | let result = poll_fn(|cx| { | 722 | let result = poll_fn(|cx| { |
| 695 | s.rx_waker.register(cx.waker()); | 723 | s.rx_waker.register(cx.waker()); |
| 696 | 724 | ||
| 697 | if let Err(e) = self.check_and_clear_errors() { | 725 | if let Err(e) = self.check_and_clear_errors() { |
| 698 | r.tasks_stoprx().write_value(1); | 726 | r.tasks_dma().rx().stop().write_value(1); |
| 699 | return Poll::Ready(Err(e)); | 727 | return Poll::Ready(Err(e)); |
| 700 | } | 728 | } |
| 701 | if r.events_endrx().read() != 0 { | 729 | if r.events_dma().rx().end().read() != 0 { |
| 702 | return Poll::Ready(Ok(())); | 730 | return Poll::Ready(Ok(())); |
| 703 | } | 731 | } |
| 704 | Poll::Pending | 732 | Poll::Pending |
| @@ -706,7 +734,7 @@ impl<'d> UarteRx<'d> { | |||
| 706 | .await; | 734 | .await; |
| 707 | 735 | ||
| 708 | compiler_fence(Ordering::SeqCst); | 736 | compiler_fence(Ordering::SeqCst); |
| 709 | r.events_rxstarted().write_value(0); | 737 | r.events_dma().rx().ready().write_value(0); |
| 710 | drop.defuse(); | 738 | drop.defuse(); |
| 711 | 739 | ||
| 712 | result | 740 | result |
| @@ -726,25 +754,25 @@ impl<'d> UarteRx<'d> { | |||
| 726 | 754 | ||
| 727 | let r = self.r; | 755 | let r = self.r; |
| 728 | 756 | ||
| 729 | r.rxd().ptr().write_value(ptr as u32); | 757 | r.dma().rx().ptr().write_value(ptr as u32); |
| 730 | r.rxd().maxcnt().write(|w| w.set_maxcnt(len as _)); | 758 | r.dma().rx().maxcnt().write(|w| w.set_maxcnt(len as _)); |
| 731 | 759 | ||
| 732 | r.events_endrx().write_value(0); | 760 | r.events_dma().rx().end().write_value(0); |
| 733 | r.events_error().write_value(0); | 761 | r.events_error().write_value(0); |
| 734 | r.intenclr().write(|w| { | 762 | r.intenclr().write(|w| { |
| 735 | w.set_endrx(true); | 763 | w.set_dmarxend(true); |
| 736 | w.set_error(true); | 764 | w.set_error(true); |
| 737 | }); | 765 | }); |
| 738 | 766 | ||
| 739 | compiler_fence(Ordering::SeqCst); | 767 | compiler_fence(Ordering::SeqCst); |
| 740 | 768 | ||
| 741 | trace!("startrx"); | 769 | trace!("startrx"); |
| 742 | r.tasks_startrx().write_value(1); | 770 | r.tasks_dma().rx().start().write_value(1); |
| 743 | 771 | ||
| 744 | while r.events_endrx().read() == 0 && r.events_error().read() == 0 {} | 772 | while r.events_dma().rx().end().read() == 0 && r.events_error().read() == 0 {} |
| 745 | 773 | ||
| 746 | compiler_fence(Ordering::SeqCst); | 774 | compiler_fence(Ordering::SeqCst); |
| 747 | r.events_rxstarted().write_value(0); | 775 | r.events_dma().rx().ready().write_value(0); |
| 748 | 776 | ||
| 749 | self.check_and_clear_errors() | 777 | self.check_and_clear_errors() |
| 750 | } | 778 | } |
| @@ -756,7 +784,7 @@ impl<'a> Drop for UarteRx<'a> { | |||
| 756 | 784 | ||
| 757 | let r = self.r; | 785 | let r = self.r; |
| 758 | 786 | ||
| 759 | let did_stoprx = r.events_rxstarted().read() != 0; | 787 | let did_stoprx = r.events_dma().rx().ready().read() != 0; |
| 760 | trace!("did_stoprx {}", did_stoprx); | 788 | trace!("did_stoprx {}", did_stoprx); |
| 761 | 789 | ||
| 762 | // Wait for rxto, if needed. | 790 | // Wait for rxto, if needed. |
| @@ -816,38 +844,38 @@ impl<'d> UarteRxWithIdle<'d> { | |||
| 816 | self.timer.stop(); | 844 | self.timer.stop(); |
| 817 | 845 | ||
| 818 | r.intenclr().write(|w| { | 846 | r.intenclr().write(|w| { |
| 819 | w.set_endrx(true); | 847 | w.set_dmarxend(true); |
| 820 | w.set_error(true); | 848 | w.set_error(true); |
| 821 | }); | 849 | }); |
| 822 | r.events_rxto().write_value(0); | 850 | r.events_rxto().write_value(0); |
| 823 | r.events_error().write_value(0); | 851 | r.events_error().write_value(0); |
| 824 | r.tasks_stoprx().write_value(1); | 852 | r.tasks_dma().rx().stop().write_value(1); |
| 825 | 853 | ||
| 826 | while r.events_endrx().read() == 0 {} | 854 | while r.events_dma().rx().end().read() == 0 {} |
| 827 | }); | 855 | }); |
| 828 | 856 | ||
| 829 | r.rxd().ptr().write_value(ptr as u32); | 857 | r.dma().rx().ptr().write_value(ptr as u32); |
| 830 | r.rxd().maxcnt().write(|w| w.set_maxcnt(len as _)); | 858 | r.dma().rx().maxcnt().write(|w| w.set_maxcnt(len as _)); |
| 831 | 859 | ||
| 832 | r.events_endrx().write_value(0); | 860 | r.events_dma().rx().end().write_value(0); |
| 833 | r.events_error().write_value(0); | 861 | r.events_error().write_value(0); |
| 834 | r.intenset().write(|w| { | 862 | r.intenset().write(|w| { |
| 835 | w.set_endrx(true); | 863 | w.set_dmarxend(true); |
| 836 | w.set_error(true); | 864 | w.set_error(true); |
| 837 | }); | 865 | }); |
| 838 | 866 | ||
| 839 | compiler_fence(Ordering::SeqCst); | 867 | compiler_fence(Ordering::SeqCst); |
| 840 | 868 | ||
| 841 | r.tasks_startrx().write_value(1); | 869 | r.tasks_dma().rx().start().write_value(1); |
| 842 | 870 | ||
| 843 | let result = poll_fn(|cx| { | 871 | let result = poll_fn(|cx| { |
| 844 | s.rx_waker.register(cx.waker()); | 872 | s.rx_waker.register(cx.waker()); |
| 845 | 873 | ||
| 846 | if let Err(e) = self.rx.check_and_clear_errors() { | 874 | if let Err(e) = self.rx.check_and_clear_errors() { |
| 847 | r.tasks_stoprx().write_value(1); | 875 | r.tasks_dma().rx().stop().write_value(1); |
| 848 | return Poll::Ready(Err(e)); | 876 | return Poll::Ready(Err(e)); |
| 849 | } | 877 | } |
| 850 | if r.events_endrx().read() != 0 { | 878 | if r.events_dma().rx().end().read() != 0 { |
| 851 | return Poll::Ready(Ok(())); | 879 | return Poll::Ready(Ok(())); |
| 852 | } | 880 | } |
| 853 | 881 | ||
| @@ -856,10 +884,10 @@ impl<'d> UarteRxWithIdle<'d> { | |||
| 856 | .await; | 884 | .await; |
| 857 | 885 | ||
| 858 | compiler_fence(Ordering::SeqCst); | 886 | compiler_fence(Ordering::SeqCst); |
| 859 | let n = r.rxd().amount().read().0 as usize; | 887 | let n = r.dma().rx().amount().read().0 as usize; |
| 860 | 888 | ||
| 861 | self.timer.stop(); | 889 | self.timer.stop(); |
| 862 | r.events_rxstarted().write_value(0); | 890 | r.events_dma().rx().ready().write_value(0); |
| 863 | 891 | ||
| 864 | drop.defuse(); | 892 | drop.defuse(); |
| 865 | 893 | ||
| @@ -884,27 +912,27 @@ impl<'d> UarteRxWithIdle<'d> { | |||
| 884 | 912 | ||
| 885 | self.ppi_ch1.enable(); | 913 | self.ppi_ch1.enable(); |
| 886 | 914 | ||
| 887 | r.rxd().ptr().write_value(ptr as u32); | 915 | r.dma().rx().ptr().write_value(ptr as u32); |
| 888 | r.rxd().maxcnt().write(|w| w.set_maxcnt(len as _)); | 916 | r.dma().rx().maxcnt().write(|w| w.set_maxcnt(len as _)); |
| 889 | 917 | ||
| 890 | r.events_endrx().write_value(0); | 918 | r.events_dma().rx().end().write_value(0); |
| 891 | r.events_error().write_value(0); | 919 | r.events_error().write_value(0); |
| 892 | r.intenclr().write(|w| { | 920 | r.intenclr().write(|w| { |
| 893 | w.set_endrx(true); | 921 | w.set_dmarxend(true); |
| 894 | w.set_error(true); | 922 | w.set_error(true); |
| 895 | }); | 923 | }); |
| 896 | 924 | ||
| 897 | compiler_fence(Ordering::SeqCst); | 925 | compiler_fence(Ordering::SeqCst); |
| 898 | 926 | ||
| 899 | r.tasks_startrx().write_value(1); | 927 | r.tasks_dma().rx().start().write_value(1); |
| 900 | 928 | ||
| 901 | while r.events_endrx().read() == 0 && r.events_error().read() == 0 {} | 929 | while r.events_dma().rx().end().read() == 0 && r.events_error().read() == 0 {} |
| 902 | 930 | ||
| 903 | compiler_fence(Ordering::SeqCst); | 931 | compiler_fence(Ordering::SeqCst); |
| 904 | let n = r.rxd().amount().read().0 as usize; | 932 | let n = r.dma().rx().amount().read().0 as usize; |
| 905 | 933 | ||
| 906 | self.timer.stop(); | 934 | self.timer.stop(); |
| 907 | r.events_rxstarted().write_value(0); | 935 | r.events_dma().rx().ready().write_value(0); |
| 908 | 936 | ||
| 909 | self.rx.check_and_clear_errors().map(|_| n) | 937 | self.rx.check_and_clear_errors().map(|_| n) |
| 910 | } | 938 | } |
| @@ -927,14 +955,14 @@ pub(crate) fn apply_workaround_for_enable_anomaly(r: pac::uarte::Uarte) { | |||
| 927 | // NB Safety: This is taken from Nordic's driver - | 955 | // NB Safety: This is taken from Nordic's driver - |
| 928 | // https://github.com/NordicSemiconductor/nrfx/blob/master/drivers/src/nrfx_uarte.c#L197 | 956 | // https://github.com/NordicSemiconductor/nrfx/blob/master/drivers/src/nrfx_uarte.c#L197 |
| 929 | if unsafe { core::ptr::read_volatile(txenable_reg) } == 1 { | 957 | if unsafe { core::ptr::read_volatile(txenable_reg) } == 1 { |
| 930 | r.tasks_stoptx().write_value(1); | 958 | r.tasks_dma().tx().stop().write_value(1); |
| 931 | } | 959 | } |
| 932 | 960 | ||
| 933 | // NB Safety: This is taken from Nordic's driver - | 961 | // NB Safety: This is taken from Nordic's driver - |
| 934 | // https://github.com/NordicSemiconductor/nrfx/blob/master/drivers/src/nrfx_uarte.c#L197 | 962 | // https://github.com/NordicSemiconductor/nrfx/blob/master/drivers/src/nrfx_uarte.c#L197 |
| 935 | if unsafe { core::ptr::read_volatile(rxenable_reg) } == 1 { | 963 | if unsafe { core::ptr::read_volatile(rxenable_reg) } == 1 { |
| 936 | r.enable().write(|w| w.set_enable(vals::Enable::ENABLED)); | 964 | r.enable().write(|w| w.set_enable(vals::Enable::ENABLED)); |
| 937 | r.tasks_stoprx().write_value(1); | 965 | r.tasks_dma().rx().stop().write_value(1); |
| 938 | 966 | ||
| 939 | let mut workaround_succeded = false; | 967 | let mut workaround_succeded = false; |
| 940 | // The UARTE is able to receive up to four bytes after the STOPRX task has been triggered. | 968 | // The UARTE is able to receive up to four bytes after the STOPRX task has been triggered. |
| @@ -948,6 +976,14 @@ pub(crate) fn apply_workaround_for_enable_anomaly(r: pac::uarte::Uarte) { | |||
| 948 | break; | 976 | break; |
| 949 | } else { | 977 | } else { |
| 950 | // Need to sleep for 1us here | 978 | // Need to sleep for 1us here |
| 979 | |||
| 980 | // Get the worst case clock speed | ||
| 981 | #[cfg(feature = "_nrf9160")] | ||
| 982 | const CLOCK_SPEED: u32 = 64_000_000; | ||
| 983 | #[cfg(feature = "_nrf5340")] | ||
| 984 | const CLOCK_SPEED: u32 = 128_000_000; | ||
| 985 | |||
| 986 | cortex_m::asm::delay(CLOCK_SPEED / 1_000_000); | ||
| 951 | } | 987 | } |
| 952 | } | 988 | } |
| 953 | 989 | ||
