-
Notifications
You must be signed in to change notification settings - Fork 37
Add support for RX DMA always enabled UART #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jerrysxie
merged 28 commits into
OpenDevicePartnership:main
from
Neil-alter:personal/v-neilxu/portGen3ReadLogic
Jan 20, 2026
Merged
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4d094e8
Port Gen3 Read Logic
e7413d1
Add new_with_rtscts_buffer
b168b71
Remove potential panic and change error type
c667ec1
Add time feature for new_with_rtscts_buffer
54fb33e
Merge branch main into personal/v-neilxu/portGen3ReadLogic
5a7481c
Update to avoid complie fail
f7a079f
Update commit for review
f2ad65c
Merge branch 'main' into personal/v-neilxu/portGen3ReadLogic
a6b66cd
Add time feature check back
c32df29
Add transfer import
ed62121
Use BBBuffer to implement circular buffer and add example
96c88d1
Merge branch main into personal/v-neilxu/portGen3ReadLogic
b1ce341
Update to avoid compiling fail
3f05448
Remove unused code
1b99e13
Remove redundant code in channel.rs and enlarge BBQueue size the add …
729215e
Merge branch 'main' into personal/v-neilxu/portGen3ReadLogic
a226078
Use ping pong buffer to implement continuous DMA transfer
5dcd4b5
Update to avoid building fail
d091d2f
Update Cargo.toml
Neil-alter 95bb668
Remove unuse dependency
bf9e8c5
Remove unuse dependency
23e82c2
Update src/uart.rs to avoid panic
Neil-alter c2d3041
Update based on suggestion
Neil-alter 2c5b37c
Update rename, overrun record and xfercount count for index
717c77c
Remove unnecessary import
4e5a9dd
Update based on copilot suggestion
d97ff2c
Fix UART async read error handling
jerrysxie fad5483
Merge branch 'main' into personal/v-neilxu/portGen3ReadLogic
jerrysxie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #![no_std] | ||
| #![no_main] | ||
|
|
||
| use defmt::info; | ||
| use embassy_executor::Spawner; | ||
| use embassy_imxrt::uart::{Async, Uart, UartRx}; | ||
| use embassy_imxrt::{bind_interrupts, peripherals, uart}; | ||
| use embassy_time::Timer; | ||
| use {defmt_rtt as _, embassy_imxrt_examples as _, panic_probe as _}; | ||
|
|
||
| const BUFLEN: usize = 2048; | ||
| const POLLING_RATE_US: u64 = 1000; | ||
|
|
||
| bind_interrupts!(struct Irqs { | ||
| FLEXCOMM4 => uart::InterruptHandler<peripherals::FLEXCOMM4>; | ||
| }); | ||
|
|
||
| #[embassy_executor::task] | ||
| async fn reader(mut rx: UartRx<'static, Async>) { | ||
| info!("Reading..."); | ||
| let mut expected_counter = 0; | ||
| loop { | ||
| let mut buf = [0; BUFLEN / 2]; | ||
| rx.read(&mut buf).await.unwrap(); | ||
| info!("RX {:?}", buf); | ||
|
|
||
| for &b in buf.iter() { | ||
| assert_eq!(b, expected_counter); | ||
| } | ||
| expected_counter = expected_counter.wrapping_add(1); | ||
|
|
||
| Timer::after_millis(1).await; | ||
| } | ||
| } | ||
|
|
||
| #[embassy_executor::main] | ||
| async fn main(spawner: Spawner) { | ||
| let p = embassy_imxrt::init(Default::default()); | ||
|
|
||
| info!("UART test start"); | ||
|
|
||
| static mut RX_BUF: [u8; BUFLEN] = [0; BUFLEN]; | ||
| let uart = Uart::new_async_with_buffer( | ||
| p.FLEXCOMM4, | ||
| p.PIO0_29, | ||
| p.PIO0_30, | ||
| Irqs, | ||
| p.DMA0_CH9, | ||
| p.DMA0_CH8, | ||
| Default::default(), | ||
| unsafe { &mut *core::ptr::addr_of_mut!(RX_BUF) }, | ||
| POLLING_RATE_US, | ||
| ) | ||
| .unwrap(); | ||
| let (mut tx, rx) = uart.split(); | ||
| spawner.must_spawn(reader(rx)); | ||
|
|
||
| info!("Writing..."); | ||
|
|
||
| let mut counter = 1; | ||
| loop { | ||
| let mut data: [u8; BUFLEN / 2] = [0; BUFLEN / 2]; | ||
| for b in data.iter_mut() { | ||
| *b = counter; | ||
| } | ||
| tx.write(&data).await.unwrap(); | ||
|
|
||
| counter = counter.wrapping_add(1); | ||
| } | ||
| } | ||
92 changes: 92 additions & 0 deletions
92
examples/rt685s-evk/src/bin/uart-async_with_rtscts_buffer.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| #![no_std] | ||
| #![no_main] | ||
|
|
||
| use defmt::info; | ||
| use embassy_executor::Spawner; | ||
| use embassy_imxrt::uart::{Async, Uart}; | ||
| use embassy_imxrt::{bind_interrupts, peripherals, uart}; | ||
| use embassy_time::Timer; | ||
| use {defmt_rtt as _, embassy_imxrt_examples as _, panic_probe as _}; | ||
|
|
||
| bind_interrupts!(struct Irqs { | ||
| FLEXCOMM2 => uart::InterruptHandler<peripherals::FLEXCOMM2>; | ||
| FLEXCOMM4 => uart::InterruptHandler<peripherals::FLEXCOMM4>; | ||
| }); | ||
|
|
||
| const BUFLEN: usize = 2048; | ||
| const POLLING_RATE_US: u64 = 1000; | ||
|
|
||
| #[embassy_executor::task] | ||
| async fn usart4_task(mut uart: Uart<'static, Async>) { | ||
| loop { | ||
| let mut rx_buf = [0; BUFLEN / 2]; | ||
| uart.read(&mut rx_buf).await.unwrap(); | ||
| assert!(rx_buf.iter().all(|b| *b == 0x55)); | ||
| info!("usart4_task read"); | ||
|
|
||
| Timer::after_millis(10).await; | ||
|
|
||
| let tx_buf = [0xaa; BUFLEN / 2]; | ||
| uart.write(&tx_buf).await.unwrap(); | ||
| info!("usart4_task write"); | ||
| } | ||
| } | ||
|
|
||
| #[embassy_executor::task] | ||
| async fn usart2_task(mut uart: Uart<'static, Async>) { | ||
| loop { | ||
| let tx_buf = [0x55; BUFLEN / 2]; | ||
| uart.write(&tx_buf).await.unwrap(); | ||
| info!("usart2_task write"); | ||
|
|
||
| Timer::after_millis(10).await; | ||
|
|
||
| let mut rx_buf = [0x00; BUFLEN / 2]; | ||
| uart.read(&mut rx_buf).await.unwrap(); | ||
| assert!(rx_buf.iter().all(|b| *b == 0xaa)); | ||
| info!("usart2_task read"); | ||
| } | ||
| } | ||
|
|
||
| /* WARNING: to enable HW flow control, a 0 ohm resistor on the EVK needs to moved to the neighboring pad. | ||
| */ | ||
| #[embassy_executor::main] | ||
| async fn main(spawner: Spawner) { | ||
| let p = embassy_imxrt::init(Default::default()); | ||
|
|
||
| info!("UART test start"); | ||
|
|
||
| static mut RX_BUF4: [u8; BUFLEN] = [0; BUFLEN]; | ||
| let usart4: Uart<'_, Async> = Uart::new_async_with_rtscts_buffer( | ||
| p.FLEXCOMM4, | ||
| p.PIO0_29, | ||
| p.PIO0_30, | ||
| p.PIO1_0, | ||
| p.PIO0_31, | ||
| Irqs, | ||
| p.DMA0_CH9, | ||
| p.DMA0_CH8, | ||
| Default::default(), | ||
| unsafe { &mut *core::ptr::addr_of_mut!(RX_BUF4) }, | ||
| POLLING_RATE_US, | ||
| ) | ||
| .unwrap(); | ||
| spawner.must_spawn(usart4_task(usart4)); | ||
|
|
||
| static mut RX_BUF2: [u8; BUFLEN] = [0; BUFLEN]; | ||
| let usart2 = Uart::new_async_with_rtscts_buffer( | ||
| p.FLEXCOMM2, | ||
| p.PIO0_15, | ||
| p.PIO0_16, | ||
| p.PIO0_18, | ||
| p.PIO0_17, | ||
| Irqs, | ||
| p.DMA0_CH5, | ||
| p.DMA0_CH4, | ||
| Default::default(), | ||
| unsafe { &mut *core::ptr::addr_of_mut!(RX_BUF2) }, | ||
| POLLING_RATE_US, | ||
| ) | ||
| .unwrap(); | ||
| spawner.must_spawn(usart2_task(usart2)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.