-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add dma fn read_available and uart-dma-rx example #116
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3b16129
Add dma fn read_available and uart-dma-rx example
usbalbin 5c2b27c
Remove debug code
usbalbin 28c842e
Enable circular buffer
usbalbin 9fbaab8
Rename uart-dma example
usbalbin 1ea1f4b
DMA: Add some useful methods for checking for trasfer errors
usbalbin 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
There are no files selected for viewing
This file contains 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,94 @@ | ||
#![deny(warnings)] | ||
#![deny(unsafe_code)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate cortex_m_rt as rt; | ||
|
||
use hal::dma::{config::DmaConfig, stream::DMAExt, TransferExt}; | ||
use hal::prelude::*; | ||
use hal::pwr::PwrExt; | ||
use hal::serial::*; | ||
use hal::{rcc, stm32}; | ||
use stm32g4xx_hal as hal; | ||
|
||
use cortex_m_rt::entry; | ||
use utils::logger::info; | ||
|
||
#[macro_use] | ||
mod utils; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
utils::logger::init(); | ||
|
||
info!("Initializing..."); | ||
|
||
let dp = stm32::Peripherals::take().expect("cannot take peripherals"); | ||
|
||
let rcc = dp.RCC.constrain(); | ||
let pwr = dp.PWR.constrain().freeze(); | ||
let mut rcc = rcc.freeze(rcc::Config::hsi(), pwr); | ||
|
||
let streams = dp.DMA1.split(&rcc); | ||
let config = DmaConfig::default() | ||
.transfer_complete_interrupt(false) | ||
.circular_buffer(true) | ||
.memory_increment(true); | ||
|
||
info!("Init UART"); | ||
//let gpioa = dp.GPIOA.split(&mut rcc); | ||
//let tx = gpioa.pa2.into_alternate(); | ||
//let rx = gpioa.pa3.into_alternate(); | ||
let gpioc = dp.GPIOC.split(&mut rcc); | ||
let tx = gpioc.pc10.into_alternate(); | ||
let rx = gpioc.pc11.into_alternate(); | ||
|
||
let usart = dp | ||
//.USART2 | ||
.USART3 | ||
.usart( | ||
tx, | ||
rx, | ||
FullConfig::default() | ||
.baudrate(115200.bps()) | ||
.receiver_timeout_us(1000), // Timeout after 1ms | ||
&mut rcc, | ||
) | ||
.unwrap(); | ||
|
||
//let mut led = gpioa.pa5.into_push_pull_output(); | ||
|
||
info!("Start reading"); | ||
|
||
let rx_buffer = cortex_m::singleton!(: [u8; 256] = [0; 256]).unwrap(); | ||
|
||
let (_tx, rx) = usart.split(); | ||
|
||
let mut transfer = streams.0.into_circ_peripheral_to_memory_transfer( | ||
rx.enable_dma(), | ||
&mut rx_buffer[..], | ||
config, | ||
); | ||
|
||
transfer.start(|_rx| {}); | ||
loop { | ||
while !transfer.timeout_lapsed() {} | ||
transfer.clear_timeout(); | ||
|
||
let mut data = [0; 256]; | ||
loop { | ||
let data = transfer.read_available(&mut data); | ||
if data.is_empty() { | ||
break; | ||
} | ||
if let Ok(data) = core::str::from_utf8(&*data) { | ||
info!("Received: '{}'", data); | ||
} else { | ||
info!("Received: {:?}", data); | ||
} | ||
info!("Sup"); | ||
} | ||
//led.toggle().unwrap(); | ||
} | ||
} |
File renamed without changes.
This file contains 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
This file contains 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
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyone have any preference for what pins to use? The commented out lines are same as
uart-dma
example