Skip to content

Commit fab9315

Browse files
authored
UART pins & RS485 (#109)
* UART pins & RS485 * format code * rename examples
1 parent e91feef commit fab9315

File tree

7 files changed

+203
-68
lines changed

7 files changed

+203
-68
lines changed

examples/adc_ext_trig_double_dma_serial.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ fn main() -> ! {
9494
let usart1 = dp
9595
.USART1
9696
.usart(
97-
gpioa.pa9, // TX: pa9, => CN3 Pin-D5
98-
gpioa.pa10, // RX: pa10, => CN3 Pin-D4
97+
// TX: pa9, => CN3 Pin-D5
98+
// RX: pa10, => CN3 Pin-D4
99+
(gpioa.pa9, gpioa.pa10),
99100
FullConfig::default().baudrate(460800.bps()).fifo_enable(), // enable fifo, so that dma can fill it fast, otherwise it may not finish before ch1 is requested again
100101
&mut rcc,
101102
)

examples/sdcard.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ fn main() -> ! {
3535
let mut uart = dp
3636
.USART2
3737
.usart(
38-
gpioa.pa2,
39-
gpioa.pa3,
38+
(gpioa.pa2, gpioa.pa3),
4039
serial::FullConfig::default(),
4140
&mut rcc,
4241
)

examples/uart.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() -> ! {
2323
let gpioa = dp.GPIOA.split(&mut rcc);
2424
let mut usart = dp
2525
.USART2
26-
.usart(gpioa.pa2, gpioa.pa3, FullConfig::default(), &mut rcc)
26+
.usart((gpioa.pa2, gpioa.pa3), FullConfig::default(), &mut rcc)
2727
.unwrap();
2828

2929
writeln!(usart, "Hello\r").unwrap();

examples/uart-dma.rs renamed to examples/uart_dma.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ fn main() -> ! {
2525
let mut usart1 = dp
2626
.USART1
2727
.usart(
28-
gpioa.pa9,
29-
gpioa.pa10,
28+
(gpioa.pa9, gpioa.pa10),
3029
FullConfig::default().baudrate(115200.bps()),
3130
&mut rcc,
3231
)

examples/uart-fifo.rs renamed to examples/uart_fifo.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ fn main() -> ! {
2323
let mut usart1 = dp
2424
.USART1
2525
.usart(
26-
gpioa.pa9,
27-
gpioa.pa10,
26+
(gpioa.pa9, gpioa.pa10),
2827
FullConfig::default()
2928
.baudrate(115200.bps())
3029
.fifo_enable()

examples/uart_rs485.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![deny(warnings)]
2+
#![deny(unsafe_code)]
3+
#![no_main]
4+
#![no_std]
5+
6+
extern crate cortex_m;
7+
extern crate cortex_m_rt as rt;
8+
extern crate panic_halt;
9+
extern crate stm32g0xx_hal as hal;
10+
11+
use core::fmt::Write;
12+
13+
use hal::prelude::*;
14+
use hal::serial::FullConfig;
15+
use hal::stm32;
16+
use nb::block;
17+
use rt::entry;
18+
19+
#[entry]
20+
fn main() -> ! {
21+
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
22+
let mut rcc = dp.RCC.constrain();
23+
let gpioa = dp.GPIOA.split(&mut rcc);
24+
let mut usart = dp
25+
.USART2
26+
.usart(
27+
(gpioa.pa2, gpioa.pa3, gpioa.pa1),
28+
FullConfig::default(),
29+
&mut rcc,
30+
)
31+
.unwrap();
32+
33+
writeln!(usart, "Hello RS485\r").unwrap();
34+
35+
let mut cnt = 0;
36+
loop {
37+
let byte = block!(usart.read()).unwrap();
38+
writeln!(usart, "{}: {}\r", cnt, byte).unwrap();
39+
cnt += 1;
40+
}
41+
}

0 commit comments

Comments
 (0)