串口使用usart2* E+ b( x) m9 N* `3 x6 [
dma使用dma1-stream6-channel49 B) D& O& O1 y0 M* f2 U9 g1 Q4 ~. w
使用hal库函数
- `7 F" B% q3 W- DMA_Init(DMA1_Stream6,DMA_CHANNEL_4);0 B' c. ~0 |$ A t3 x, h
- HAL_UART_Transmit_DMA(&UART2_Handler,page,num);/ @5 g2 M: k2 \# {2 |3 s
- while(1)
1 O- Y' U/ C' x- y r8 J - {5 f# Z0 P/ z- W; W5 l0 d
- if(__HAL_DMA_GET_FLAG(&UART2TxDMA_Handler,DMA_FLAG_TCIF2_6))//判断传输完成+ ]5 v( x6 A2 U) S+ L
- {
9 O' V( W, O: z8 S+ K! z, C( P - __HAL_DMA_CLEAR_FLAG(&UART2TxDMA_Handler,DMA_FLAG_TCIF2_6);//清除标志位8 ]; B+ n8 C% y3 _2 N' }
- HAL_UART_DMAStop(&UART2_Handler); //关闭dma" y7 o% s0 n8 q: `: `
- break;
9 B* b6 o7 V2 z5 i; y6 w- J - }
( H2 U! O5 g H2 q7 S# e - pos=__HAL_DMA_GET_COUNTER(&UART1TxDMA_Handler);//传输进度
- M% y+ U' b; b/ `. u - printf("pos:%d\n",pos);
, S8 Y$ u5 v7 ^# c - } V% z: P1 H; i! h% ?4 j
% T" ^: L, p! N- d) A3 W4 ~
. S: Z# ~3 R- ?2 [- + e7 |! u: |, T2 x
- void DMA_Init(DMA_Stream_TypeDef *DMA_Streamx,u32 chx)" z8 I2 t. d" ?1 a3 o$ A v
- {
4 x8 u6 a9 O5 F% `8 ?. f/ j -
/ d9 k8 k5 ]: u Z5 j - __HAL_RCC_DMA1_CLK_ENABLE(); + a0 f! C$ A1 g6 |* U% ?1 Z3 }
- __HAL_LINKDMA(&UART2_Handler,hdmatx,UART2TxDMA_Handler); 0 Z; h# j6 G$ i [8 B, u
( U# H$ x: C% [- UART2TxDMA_Handler.Instance=DMA_Streamx;
, f9 u& q/ W( f* Y- N# K% b* A - UART2TxDMA_Handler.Init.Channel=chx;
+ Z9 T" Z$ c' z3 E2 q - UART2TxDMA_Handler.Init.Direction=DMA_MEMORY_TO_PERIPH; % ?6 V7 E5 t% ~8 q& q& E' l
- UART2TxDMA_Handler.Init.PeriphInc=DMA_PINC_DISABLE;
3 C! S# Z; w' z9 W9 A7 {: C$ \' q - UART2TxDMA_Handler.Init.MemInc=DMA_MINC_ENABLE;
2 [+ f/ d1 i# ] - UART2TxDMA_Handler.Init.PeriphDataAlignment=DMA_PDATAALIGN_BYTE;
& Q7 |' e) K7 |* ^" V1 a* p5 I - UART2TxDMA_Handler.Init.MemDataAlignment=DMA_MDATAALIGN_BYTE;
( n) d8 ^8 B9 p- y% B - UART2TxDMA_Handler.Init.Mode=DMA_NORMAL;
' p- B! F; d+ @, s5 h5 a6 `: U - UART2TxDMA_Handler.Init.Priority=DMA_PRIORITY_MEDIUM;
; T( g% W' q9 f' l - UART2TxDMA_Handler.Init.FIFOMode=DMA_FIFOMODE_DISABLE; 5 M- l ~' _ V, u& ?
- UART2TxDMA_Handler.Init.FIFOThreshold=DMA_FIFO_THRESHOLD_FULL;
* T7 g$ \, v$ h - UART2TxDMA_Handler.Init.MemBurst=DMA_MBURST_SINGLE; 1 w/ c" b& l+ C" n( r [) V
- UART2TxDMA_Handler.Init.PeriphBurst=DMA_PBURST_SINGLE;
4 y7 u v$ e1 p$ J/ ]2 B5 J% c
! t% C6 }8 q9 A* s/ z- HAL_DMA_DeInit(&UART2TxDMA_Handler); " l" B4 P7 N0 M. I) [6 c K
- HAL_DMA_Init(&UART2TxDMA_Handler);
" ^/ L3 T" O: p. K - }
4 ]& S4 V. a* M% G: Y* f" O - % w8 d& o- E5 p1 X% l! a0 O
复制代码
$ u/ j1 d" N$ b4 ?
+ s& C/ g- f2 Q% _' ^0 T |