Forum: Mikrocontroller und Digitale Elektronik DMA zum laufen bringen STM32


von DAM (Gast)


Lesenswert?

Hallo,

ich möchte gerne den DMA von den STM32 Controllern zum laufen bringen.

Leider scheinen alle Beispiele mit einer veralteten Version des 
DMA_InitTypeDef her zu kommen.

Die Beispielprogramme haben allesamt diese Struktur:
1
  DMA_InitTypeDef DMA_InitStruct;
2
  DMA_StructInit(&DMA_InitStruct);
3
  DMA_InitStruct.DMA_Channel = DMA_Channel_4;
4
  DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)&(USART3->DR);
5
  DMA_InitStruct.DMA_Memory0BaseAddr = (uint32_t)&buffer;
6
  DMA_InitStruct.DMA_DIR = DMA_DIR_MemoryToPeripheral;
7
  DMA_InitStruct.DMA_BufferSize = 129;
8
  DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
9
  DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
10
  DMA_InitStruct.DMA_PeripheralDataSize = 
11
DMA_PeripheralDataSize_HalfWord;
12
  DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
13
  DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
14
  DMA_InitStruct.DMA_Priority = DMA_Priority_Medium;
15
  DMA_InitStruct.DMA_FIFOMode = DMA_FIFOMode_Disable;
16
  DMA_InitStruct.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
17
  DMA_InitStruct.DMA_MemoryBurst = DMA_MemoryBurst_Single;
18
  DMA_InitStruct.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
19
  DMA_Init(DMA2_Stream3, &DMA_InitStruct);

Das sind 15 Einträge.
Der eigentliche Datentyp besitz in der neuen Version irgendwie nur noch 
12 Einträge.

er sieht so aus:
1
typedef struct
2
{
3
  uint32_t Channel;              /*!< Specifies the channel used for the specified stream. 
4
                                      This parameter can be a value of @ref DMA_Channel_selection                    */
5
6
  uint32_t Direction;            /*!< Specifies if the data will be transferred from memory to peripheral, 
7
                                      from memory to memory or from peripheral to memory.
8
                                      This parameter can be a value of @ref DMA_Data_transfer_direction              */
9
10
  uint32_t PeriphInc;            /*!< Specifies whether the Peripheral address register should be incremented or not.
11
                                      This parameter can be a value of @ref DMA_Peripheral_incremented_mode          */
12
13
  uint32_t MemInc;               /*!< Specifies whether the memory address register should be incremented or not.
14
                                      This parameter can be a value of @ref DMA_Memory_incremented_mode              */
15
16
  uint32_t PeriphDataAlignment;  /*!< Specifies the Peripheral data width.
17
                                      This parameter can be a value of @ref DMA_Peripheral_data_size                 */
18
19
  uint32_t MemDataAlignment;     /*!< Specifies the Memory data width.
20
                                      This parameter can be a value of @ref DMA_Memory_data_size                     */
21
22
  uint32_t Mode;                 /*!< Specifies the operation mode of the DMAy Streamx.
23
                                      This parameter can be a value of @ref DMA_mode
24
                                      @note The circular buffer mode cannot be used if the memory-to-memory
25
                                            data transfer is configured on the selected Stream                        */
26
27
  uint32_t Priority;             /*!< Specifies the software priority for the DMAy Streamx.
28
                                      This parameter can be a value of @ref DMA_Priority_level                       */
29
30
  uint32_t FIFOMode;             /*!< Specifies if the FIFO mode or Direct mode will be used for the specified stream.
31
                                      This parameter can be a value of @ref DMA_FIFO_direct_mode
32
                                      @note The Direct mode (FIFO mode disabled) cannot be used if the 
33
                                            memory-to-memory data transfer is configured on the selected stream       */
34
35
  uint32_t FIFOThreshold;        /*!< Specifies the FIFO threshold level.
36
                                      This parameter can be a value of @ref DMA_FIFO_threshold_level                  */
37
38
  uint32_t MemBurst;             /*!< Specifies the Burst transfer configuration for the memory transfers. 
39
                                      It specifies the amount of data to be transferred in a single non interruptible
40
                                      transaction.
41
                                      This parameter can be a value of @ref DMA_Memory_burst 
42
                                      @note The burst mode is possible only if the address Increment mode is enabled. */
43
44
  uint32_t PeriphBurst;          /*!< Specifies the Burst transfer configuration for the peripheral transfers. 
45
                                      It specifies the amount of data to be transferred in a single non interruptible 
46
                                      transaction. 
47
                                      This parameter can be a value of @ref DMA_Peripheral_burst
48
                                      @note The burst mode is possible only if the address Increment mode is enabled. */
49
}DMA_InitTypeDef;


Hat jemand ev. ein neueres Beispiel, in dem man die Einträge direkt 
übernehmen kann?

Danke!

von Dr. Sommer (Gast)


Lesenswert?

Es könnte damit zusammenhängen, dass die verschiedenen STM32 komplett 
unterschiedliche DMA Hardware haben. Du musst also Beispiele fur exakt 
deinen Controller suchen. Und dann gibt es noch die Alternative, im 
Reference Manual das Kapitel über DMA durchzulesen. Dann weißt du auch 
wie es ohne Library geht.

von aSma>> (Gast)


Lesenswert?

DAM schrieb:
> DMA_InitStruct.DMA_PeripheralDataSize =
> DMA_PeripheralDataSize_HalfWord;
>   DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

Das kann schon mal nicht stimmen.

von Franz (Gast)


Lesenswert?

DAM schrieb:
> Hat jemand ev. ein neueres Beispiel, in dem man die Einträge direkt
> übernehmen kann?
Selber bauen, steht ja alles in dem struct (und darüber):
1
DMA_HandleTypeDef DMA_Handle;
2
3
__DMAx_CLK_ENABLE();
4
5
DMA_Handle.Instance = DMAx_Streamy;
6
DMA_Handle.Init.Channel = DMA_CHANNEL_x;
7
DMA_Handle.Init.Direction = DMA_MEMORY_TO_PERIPH;
8
DMA_Handle.Init.PeriphInc = DMA_PINC_DISABLE;
9
DMA_Handle.Init.MemInc    = DMA_MINC_ENABLE;
10
DMA_Handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
11
DMA_Handle.Init.MemDataAlignment    = DMA_MDATAALIGN_HALFWORD;
12
DMA_Handle.Init.Mode      = DMA_NORMAL;
13
DMA_Handle.Init.Priority  = DMA_PRIORITY_LOW;
14
DMA_Handle.Init.FIFOMode  = DMA_FIFOMODE_DISABLE;
15
DMA_Handle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
16
DMA_Handle.Init.MemBurst  = DMA_MBURST_INC4;
17
DMA_Handle.Init.PeriphBurst   = DMA_PBURST_SINGLE;
18
19
HAL_DMA_Init( &DMA_Handle);
20
__HAL_LINKDMA( ..., ..., DMA_Handle);

Im Zweifelsfall muss man mit der lokalen Suchmachine durch den 
Cube-Ordner grasen, da finden sich einige Beispiele:
1
$ ls -1 .ac6/SW4STM32/firmwares/STM32Cube_FW_F4_V1.13.1/Projects/
2
STM32446E-Nucleo
3
STM32446E_EVAL
4
STM32469I-Discovery
5
STM32469I_EVAL
6
STM324x9I_EVAL
7
STM324xG_EVAL
8
STM32CubeProjectsList.html
9
STM32F4-Discovery
10
STM32F401-Discovery
11
STM32F401RE-Nucleo
12
STM32F410xx-Nucleo
13
STM32F411E-Discovery
14
STM32F411RE-Nucleo
15
STM32F412G-Discovery
16
STM32F412ZG-Nucleo
17
STM32F429I-Discovery
18
STM32F429ZI-Nucleo
19
STM32F446ZE-Nucleo
20
WIN32

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.