Skip to content

Commit ff36ac0

Browse files
committed
Adding VCOM GPIO and USART pin exmple for the 32l476disco board
1 parent d66ac33 commit ff36ac0

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

examples/serial_vcom.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,24 @@ fn main() -> ! {
2929
let mut rcc = p.RCC.constrain();
3030
let mut gpioa = p.GPIOA.split(&mut rcc.ahb2);
3131
// let mut gpiob = p.GPIOB.split(&mut rcc.ahb2);
32+
// let mut gpiod = p.GPIOD.split(&mut rcc.ahb2);
3233

3334
// clock configuration using the default settings (all clocks run at 8 MHz)
3435
let clocks = rcc.cfgr.freeze(&mut flash.acr);
3536
// TRY this alternate clock configuration (clocks run at nearly the maximum frequency)
3637
// let clocks = rcc.cfgr.sysclk(64.mhz()).pclk1(32.mhz()).freeze(&mut flash.acr);
3738

3839
let tx = gpioa.pa2.into_af7(&mut gpioa.moder, &mut gpioa.afrl);
39-
// let tx = gpiob.pb6.into_af7(&mut gpiob.moder, &mut gpiob.afrl);
40+
// let tx = gpiob.pb6.into_af7(&mut gpiob.moder, &mut gpiob.afrl);
41+
// let tx = gpiod.pd5.into_af7(&mut gpiod.moder, &mut gpiod.afrl);
4042

4143
let rx = gpioa.pa3.into_af7(&mut gpioa.moder, &mut gpioa.afrl);
42-
// let rx = gpiob.pb7.into_af7(&mut gpiob.moder, &mut gpiob.afrl);
44+
// let rx = gpiob.pb7.into_af7(&mut gpiob.moder, &mut gpiob.afrl);
45+
// let rx = gpiod.pd6.into_af7(&mut gpiod.moder, &mut gpiod.afrl);
4346

4447
// TRY using a different USART peripheral here
45-
let serial = Serial::usart2(p.USART2, (tx, rx), 9_600.bps(), clocks, &mut rcc.apb1r1);
46-
let (mut tx, _) = serial.split();
48+
let serial = Serial::usart2(p.USART2, (tx, rx), 115_200.bps(), clocks, &mut rcc.apb1r1);
49+
let (mut tx, mut rx) = serial.split();
4750

4851
let sent = b'X';
4952

@@ -58,10 +61,11 @@ fn main() -> ! {
5861
block!(tx.write(sent)).ok();
5962
block!(tx.write(sent)).ok();
6063

61-
// when using virtual com port for recieve, causes a framing error
62-
// let received = block!(rx.read()).unwrap();
64+
// when using virtual com port for recieve can causes a framing error
65+
// On the stm32l476 discovery it is working fine at 115200 baud
66+
let received = block!(rx.read()).unwrap();
6367

64-
// assert_eq!(received, sent);
68+
assert_eq!(received, sent);
6569

6670
// if all goes well you should reach this breakpoint
6771
asm::bkpt();

src/gpio.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,17 @@ gpio!(GPIOB, gpiob, gpiob, gpioben, gpiobrst, PBx, [
589589
PB7: (pb7, 7, Input<Floating>, AFRL),
590590
]);
591591

592+
gpio!(GPIOD, gpiod, gpioc, gpioden, gpiodrst, PDx, [
593+
PD0: (pd0, 0, Input<Floating>, AFRL),
594+
PD1: (pd1, 1, Input<Floating>, AFRL),
595+
PD2: (pd2, 2, Input<Floating>, AFRL),
596+
PD3: (pd3, 3, Input<Floating>, AFRL),
597+
PD4: (pd4, 4, Input<Floating>, AFRL),
598+
PD5: (pd5, 5, Input<Floating>, AFRL),
599+
PD6: (pd6, 6, Input<Floating>, AFRL),
600+
PD7: (pd7, 7, Input<Floating>, AFRL),
601+
PD8: (pd8, 8, Input<Floating>, AFRH),
602+
]);
592603

593604
gpio!(GPIOE, gpioe, gpioc, gpioeen, gpioerst, PEx, [
594605
PE0: (pe0, 0, Input<Floating>, AFRL),
@@ -599,5 +610,5 @@ gpio!(GPIOE, gpioe, gpioc, gpioeen, gpioerst, PEx, [
599610
PE5: (pe5, 5, Input<Floating>, AFRL),
600611
PE6: (pe6, 6, Input<Floating>, AFRL),
601612
PE7: (pe7, 7, Input<Floating>, AFRL),
602-
PE8: (pe8, 8, Input<Floating>, AFRL),
613+
PE8: (pe8, 8, Input<Floating>, AFRH),
603614
]);

src/serial.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::stm32::{USART1, USART2};
1515
use void::Void;
1616

1717
use crate::gpio::gpioa::{PA10, PA2, PA3, PA9};
18+
use crate::gpio::gpiod::{PD5, PD6};
1819
use crate::gpio::gpiob::{PB6, PB7};
1920
use crate::gpio::{AF7, Alternate, Input, Floating};
2021
use crate::rcc::{APB1R1, APB2, Clocks};
@@ -34,6 +35,8 @@ pub enum Event {
3435
/// Serial error
3536
#[derive(Debug)]
3637
pub enum Error {
38+
// Read timeout
39+
ReadTimeOut,
3740
/// Framing error
3841
Framing,
3942
/// Noise error
@@ -62,9 +65,9 @@ impl Pins<USART2> for (PA2<Alternate<AF7, Input<Floating>>>, PA3<Alternate<AF7,
6265
const REMAP: u8 = 0;
6366
}
6467

65-
// impl Pins<USART2> for (PD5<Alternate<PushPull>>, PD6<Input<Floating>>) {
66-
// const REMAP: u8 = 0;
67-
// }
68+
impl Pins<USART2> for (PD5<Alternate<AF7, Input<Floating>>>, PD6<Alternate<AF7, Input<Floating>>>) {
69+
const REMAP: u8 = 0;
70+
}
6871

6972

7073
/// Serial abstraction
@@ -109,8 +112,8 @@ macro_rules! hal {
109112

110113
// disable hardware flow control
111114
// usart.cr3.write(|w| w.rtse().clear_bit().ctse().clear_bit());
112-
113115
usart.cr3.write(|w| w.dmat().set_bit().dmar().set_bit()); // enable DMA transfers
116+
//usart.cr3.write(|w| w.onebit().set_bit());
114117

115118
let brr = clocks.$pclkX().0 / baud_rate.0;
116119
assert!(brr >= 16, "impossible baud rate");
@@ -181,7 +184,9 @@ macro_rules! hal {
181184
// NOTE(unsafe) atomic read with no side effects
182185
let isr = unsafe { (*$USARTX::ptr()).isr.read() };
183186

184-
Err(if isr.pe().bit_is_set() {
187+
Err(if isr.rtof().bit_is_set() {
188+
nb::Error::Other(Error::ReadTimeOut)
189+
} else if isr.pe().bit_is_set() {
185190
nb::Error::Other(Error::Parity)
186191
} else if isr.fe().bit_is_set() {
187192
nb::Error::Other(Error::Framing)

0 commit comments

Comments
 (0)