File tree 6 files changed +681
-215
lines changed
6 files changed +681
-215
lines changed Original file line number Diff line number Diff line change
1
+ #![ no_main]
2
+ #![ no_std]
3
+
4
+ extern crate cortex_m_rt as rt;
5
+ extern crate panic_halt;
6
+ extern crate stm32g0xx_hal as hal;
7
+
8
+ use core:: fmt:: Write ;
9
+
10
+ use hal:: prelude:: * ;
11
+ use hal:: serial:: * ;
12
+ use hal:: stm32;
13
+ use hal:: dma:: { self , Channel , Target } ;
14
+
15
+ use rt:: entry;
16
+
17
+ #[ entry]
18
+ fn main ( ) -> ! {
19
+ let dp = stm32:: Peripherals :: take ( ) . expect ( "cannot take peripherals" ) ;
20
+ let mut rcc = dp. RCC . constrain ( ) ;
21
+ let gpioa = dp. GPIOA . split ( & mut rcc) ;
22
+
23
+ let mut usart1 = dp. USART1 . usart (
24
+ gpioa. pa9 ,
25
+ gpioa. pa10 ,
26
+ FullConfig :: default ( ) . baudrate ( 115200 . bps ( ) ) , & mut rcc) . unwrap ( ) ;
27
+
28
+ writeln ! ( usart1, "Hello without DMA\r \n " ) . unwrap ( ) ;
29
+
30
+ let tx_buffer: [ u8 ; 16 ] = * b"Hello with DMA!\n " ;
31
+
32
+ let ( mut tx, _rx) = usart1. split ( ) ;
33
+
34
+ let mut dma = dp. DMA . split ( & mut rcc, dp. DMAMUX ) ;
35
+
36
+ let usart = unsafe { & ( * stm32:: USART1 :: ptr ( ) ) } ;
37
+ let tx_data_register_addr = & usart. tdr as * const _ as u32 ;
38
+ let tx_dma_buf_addr : u32 = tx_buffer. as_ptr ( ) as u32 ;
39
+
40
+ dma. ch1 . set_direction ( dma:: Direction :: FromMemory ) ;
41
+ dma. ch1 . set_memory_address ( tx_dma_buf_addr, true ) ;
42
+ dma. ch1 . set_peripheral_address ( tx_data_register_addr, false ) ;
43
+ dma. ch1 . set_transfer_length ( tx_buffer. len ( ) as u16 ) ;
44
+
45
+ dma. ch1 . select_peripheral ( tx. dmamux ( ) ) ;
46
+
47
+ tx. enable_dma ( ) ;
48
+ dma. ch1 . enable ( ) ;
49
+
50
+ loop {
51
+ continue ;
52
+ }
53
+ }
You can’t perform that action at this time.
0 commit comments