Hallo, hat jemand vielleicht ein Beispiel für DMA und USART am STM32F4. Ich steig durch die DMA_InitStructure noch nicht so richtig durch. Moritz
Gast
#2477958
Mit USART + DMA kann ich zwar nicht direkt dienen, aber ich hätte mal ein Beispiel für ADC + DMA ( daraus sollte man ja auch schon einiges lernen können ) mit einem 128-Messwerte-Ringpuffer.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | |
Du musst nur im DMA-Abschnitt im Reference Manual den richtigen DMA-Channel/Stream für deinen USART finden. Ansonsten müsstest du nur die Adressen und die DataSizes anpassen, schon sollte das bei der USART-Schnittstelle funktionieren.
Gast
#2478030
USART ueber DMA senden geht, aber hat das nachteil das du erst das anzahl bytes muss angeben, danach wird DMA gestart und genau diese anzahl von bytes wird dan ueber DMA an die USART gesendet.
Hallo also ich versuch über usart 3 und dma stream 3 channel 4
(richtig?) einen Text auszugeben:
#include "stm32f4xx.h"
void USART3_Init(void);
void DMAStream3_Channel4_Init();
unsigned char buffer[129] = "Hello World, this is a DMA test. If you can
read this the DMA is still working!\n";
int main(void)
{
USART3_Init();
DMAStream3_Channel4_Init();
USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE);
DMA_Cmd(DMA1_Stream3, ENABLE);
while(1);
}
void USART3_Init(void)
{
GPIO_InitTypeDef GPIOC_10_11_InitStructure;
USART_InitTypeDef USART3_InitStructure;
//GPIO C 10/11 Init
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);
GPIOC_10_11_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIOC_10_11_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIOC_10_11_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIOC_10_11_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIOC_10_11_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIOC_10_11_InitStructure);
//USART 3 Init
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
USART3_InitStructure.USART_BaudRate = 9600;
USART3_InitStructure.USART_WordLength = USART_WordLength_8b;
USART3_InitStructure.USART_StopBits = USART_StopBits_1;
USART3_InitStructure.USART_Parity = USART_Parity_No;
USART3_InitStructure.USART_HardwareFlowControl =
USART_HardwareFlowControl_None;
USART3_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART3_InitStructure);
USART_Cmd(USART3, ENABLE);
}
void DMAStream3_Channel4_Init(void)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
DMA_InitTypeDef DMA_InitStruct;
DMA_StructInit(&DMA_InitStruct);
DMA_InitStruct.DMA_Channel = DMA_Channel_4;
DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)&(USART3->DR);
DMA_InitStruct.DMA_Memory0BaseAddr = (uint32_t)&buffer;
DMA_InitStruct.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStruct.DMA_BufferSize = 129;
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_PeripheralDataSize =
DMA_PeripheralDataSize_HalfWord;
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
DMA_InitStruct.DMA_Priority = DMA_Priority_Medium;
DMA_InitStruct.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStruct.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStruct.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStruct.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream3, &DMA_InitStruct);
}
weiß vielleicht jemand was ich falsch mach?
Moritz
Gast
#2478197
Moritz M. schrieb: > über usart 3 und dma stream 3 channel 4 > (richtig?) DMA 1, Stream 3, Channel 4, korrekt. (Alternativ ginge auch DMA 1, Stream 4, Channel 7) Allerdings hast du wohl eine Stelle übersehen: Moritz M. schrieb: > DMA_Init(DMA2_Stream3, &DMA_InitStruct); In der Funktion DMAStream3_Channel4_Init. Da du Zeichen verschicken willst ( unsigned char ), beträgt deine DataSize ( sowohl Memory als auch Peripheral ) nur ein Byte und kein Half Word ( 2 Byte ). Ansonsten habe ich die DMA noch nie für USART TX benutzt, daher kann ich nicht mehr dazu sagen.
Hallo jetz funktioniert es wunderbar Dank an alle!
Antwort schreiben
Bitte melde dich an, um einen Beitrag zu schreiben.