3
3
4
4
use panic_rtt_target as _;
5
5
6
+ // This example application prints all characters it receives via Serial and sends them back.
7
+ //
8
+ // NOTES:
9
+ // - Depending on the board you're using, `Serial` might need different Tx and Rx pins instead of
10
+ // pa9 and pa10 (for example, the STM32f3DISCOVERY board uses pc4 and pc5).
11
+ // Check your boards' schematic and adjust the code accordingly.
12
+ // - https://docs.rust-embedded.org/discovery/10-serial-communication/nix-tooling.html?highlight=*nix#nix-tooling
13
+ // has instructions on how to connect to your Serial device (make sure to adjust the baud rate)
6
14
#[ rtic:: app( device = stm32f3xx_hal:: pac, dispatchers = [ TIM20_BRK , TIM20_UP , TIM20_TRG_COM ] ) ]
7
15
mod app {
8
16
use dwt_systick_monotonic:: DwtSystick ;
@@ -19,6 +27,7 @@ mod app {
19
27
type DwtMono = DwtSystick < 48_000_000 > ;
20
28
21
29
type SerialType = Serial < pac:: USART1 , ( gpio:: PA9 < AF7 < PushPull > > , gpio:: PA10 < AF7 < PushPull > > ) > ;
30
+ // The LED that will light up when data is received via serial
22
31
type DirType = gpio:: PE13 < Output < PushPull > > ;
23
32
24
33
#[ shared]
@@ -46,7 +55,7 @@ mod app {
46
55
let mono = DwtSystick :: new ( & mut dcb, dwt, systick, clocks. sysclk ( ) . 0 ) ;
47
56
48
57
// Initialize the peripherals
49
- // DIR
58
+ // DIR (the LED that lights up during serial rx)
50
59
let mut gpioe = cx. device . GPIOE . split ( & mut rcc. ahb ) ;
51
60
let mut dir: DirType = gpioe
52
61
. pe13
@@ -57,10 +66,18 @@ mod app {
57
66
let mut gpioa = cx. device . GPIOA . split ( & mut rcc. ahb ) ;
58
67
let mut pins = (
59
68
gpioa
69
+ // Tx pin
60
70
. pa9
71
+ // configure this pin to make use of its `USART1_TX` alternative function
72
+ // (AF mapping taken from table 14 "Alternate functions for port A" of the datasheet at
73
+ // https://www.st.com/en/microcontrollers-microprocessors/stm32f303vc.html)
61
74
. into_af7_push_pull ( & mut gpioa. moder , & mut gpioa. otyper , & mut gpioa. afrh ) ,
62
75
gpioa
76
+ // Rx pin
63
77
. pa10
78
+ // configure this pin to make use of its `USART1_RX` alternative function
79
+ // (AF mapping taken from table 14 "Alternate functions for port A" of the datasheet at
80
+ // https://www.st.com/en/microcontrollers-microprocessors/stm32f303vc.html)
64
81
. into_af7_push_pull ( & mut gpioa. moder , & mut gpioa. otyper , & mut gpioa. afrh ) ,
65
82
) ;
66
83
pins. 1 . internal_pull_up ( & mut gpioa. pupdr , true ) ;
0 commit comments