serial dma TX
This commit is contained in:
parent
0225e6d074
commit
fc94b6186a
1 changed files with 31 additions and 2 deletions
33
src/main.rs
33
src/main.rs
|
@ -9,12 +9,13 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use cortex_m::singleton;
|
||||
use panic_halt as _;
|
||||
|
||||
use nb::block;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use stm32f1xx_hal::{pac, prelude::*, rcc::Config, timer::Timer};
|
||||
use stm32f1xx_hal::{pac, prelude::*, rcc, serial, timer::Timer};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
|
@ -31,7 +32,7 @@ fn main() -> ! {
|
|||
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
|
||||
// `clocks`
|
||||
let clocks = rcc.cfgr.freeze_with_config(
|
||||
Config {
|
||||
rcc::Config {
|
||||
// HSE frequency
|
||||
hse: Some(8_000_000),
|
||||
// PLLMUL represented by an integer -2
|
||||
|
@ -46,8 +47,36 @@ fn main() -> ! {
|
|||
);
|
||||
|
||||
// Acquire the GPIOC peripheral
|
||||
let mut gpioa = dp.GPIOA.split();
|
||||
let mut gpioc = dp.GPIOC.split();
|
||||
|
||||
let mut afio = dp.AFIO.constrain();
|
||||
let dma1 = dp.DMA1.split();
|
||||
|
||||
// USART1
|
||||
let tx = gpioa.pa9.into_alternate_push_pull(&mut gpioa.crh);
|
||||
let rx = gpioa.pa10; //.into_pull_up_input(&mut gpioa.crh);
|
||||
|
||||
let serial = serial::Serial::new(
|
||||
dp.USART1,
|
||||
(tx, rx),
|
||||
&mut afio.mapr,
|
||||
serial::Config {
|
||||
baudrate: 9_600.bps(),
|
||||
..Default::default()
|
||||
},
|
||||
&clocks,
|
||||
);
|
||||
|
||||
let tx = serial.tx.with_dma(dma1.4);
|
||||
let buf = singleton!(: [u8; 255] = [0b01010101; 255]).unwrap();
|
||||
|
||||
let xfer = tx.write(buf);
|
||||
while !xfer.is_done() {}
|
||||
|
||||
// while circ_buffer.readable_half().unwrap() != dma::Half::First {}
|
||||
// let _first_half = circ_buffer.peek(|half, _| *half).unwrap();
|
||||
|
||||
// Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function
|
||||
// in order to configure the port. For pins 0-7, crl should be passed instead.
|
||||
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
|
||||
|
|
Loading…
Reference in a new issue