microHAL
An abstraction layer for your future F4xx projects
Loading...
Searching...
No Matches
dma.h File Reference

Function prototypes for the DMA driver. More...

#include <stdint.h>
#include "stm32f4xx.h"
#include "defines.h"

Go to the source code of this file.

Data Structures

struct  DMAStreamRegs
 Contains DMA stream registers. More...
 
struct  DMARegs
 Contains DMA registers. More...
 
struct  DMAStreamConfig
 Contains DMA stream options. More...
 
struct  DMAStreamISR
 Contains DMA stream interrupt configuration. More...
 

Macros

#define DMA(x)
 

Typedefs

typedef enum dma_peripheral dma_peripheral_t
 Available DMA peripherals.
 
typedef enum dma_dir dma_dir_t
 Available DMA directions.
 
typedef enum dma_datasize dma_datasize_t
 Available DMA data sizes.
 
typedef enum dma_priority dma_priority_t
 Available DMA priorities.
 

Enumerations

enum  dma_peripheral { DMA_PERIPH_1 = 0x00 , DMA_PERIPH_2 = 0x01 }
 Available DMA peripherals.
 
enum  dma_dir { DMA_DIR_PER2MEM = 0x00 , DMA_DIR_MEM2PER = 0x01 , DMA_DIR_MEM2MEM = 0x02 }
 Available DMA directions.
 
enum  dma_datasize { DMA_DATASIZE_BYTE = 0x00 , DMA_DATASIZE_HWRD = 0x01 , DMA_DATASIZE_WORD = 0x02 }
 Available DMA data sizes.
 
enum  dma_priority { DMA_PRIORITY_LOW = 0x00 , DMA_PRIORITY_MED = 0x01 , DMA_PRIORITY_HIG = 0x02 , DMA_PRIORITY_VHI = 0x03 }
 Available DMA priorities.
 

Functions

void dma_set_addresses (const dma_peripheral_t dma, const uint8_t stream, const uint32_t PA, const uint32_t M0A, const uint32_t M1A)
 Set the DMA source and destination addresses.
 
void dma_configure_data (const dma_peripheral_t dma, const uint8_t stream, const uint16_t count, const dma_datasize_t msize, const dma_datasize_t psize)
 Set DMA transfers to specified configuration.
 
void dma_set_direction (const dma_peripheral_t dma, const uint8_t stream, const dma_dir_t direction)
 Set DMA transfers to the desired direction.
 
void dma_configure_stream (const dma_peripheral_t dma, const uint8_t stream, const struct DMAStreamConfig config)
 Set DMA stream to the specified configuration.
 
void dma_set_channel (const dma_peripheral_t dma, const uint8_t stream, const uint8_t channel, const dma_priority_t priority)
 Set the DMA stream channel and priority.
 
void dma_set_interrupts (const dma_peripheral_t dma, const uint8_t stream, const struct DMAStreamISR config)
 Enabled the specified DMA stream interrupts.
 
void dma_enable (const dma_peripheral_t dma, const uint8_t stream)
 Enables DMA stream transfers.
 
void dma_disable (const dma_peripheral_t dma, const uint8_t stream)
 Disables DMA stream transfers.
 

Detailed Description

Function prototypes for the DMA driver.

This file contains all of the enums, macros, and function prototypes required for a functional DMA driver.

DISCLAIMER: No burst or FIFO for the time being!

Author
Vasileios Ch. (BillisC)
Bug
There is a case where DMA1 clears EN SxCR bit when the peripheral address is USART2 DR. There is no workaround at the moment (is it errata?).

Macro Definition Documentation

◆ DMA

#define DMA ( x)
Value:
(struct DMARegs *)(DMA1_BASE + (x * 0x400UL))
Contains DMA registers.
Definition dma.h:43

Function Documentation

◆ dma_configure_data()

void dma_configure_data ( const dma_peripheral_t dma,
const uint8_t stream,
const uint16_t count,
const dma_datasize_t msize,
const dma_datasize_t psize )

Set DMA transfers to specified configuration.

The DMA datasizes are specified in the dma_datasize_t enum. Any other value will be ignored.

Parameters
dmaThe selected DMA
streamThe selected stream (0..7)
countThe total number of data items
msizeThe size of data stored in memory
psizeThe size of data stored in the peripheral
Returns
None

◆ dma_configure_stream()

void dma_configure_stream ( const dma_peripheral_t dma,
const uint8_t stream,
const struct DMAStreamConfig config )

Set DMA stream to the specified configuration.

The DMA stream options are specified in the DMAStreamConfig struct.

Parameters
dmaThe selected DMA
streamThe selected stream (0..7)
configThe stream configuration
Returns
None

◆ dma_disable()

void dma_disable ( const dma_peripheral_t dma,
const uint8_t stream )

Disables DMA stream transfers.

Parameters
dmaThe selected DMA
streamThe selected stream (0..7)
Returns
None

◆ dma_enable()

void dma_enable ( const dma_peripheral_t dma,
const uint8_t stream )

Enables DMA stream transfers.

Parameters
dmaThe selected DMA
streamThe selected stream (0..7)
Returns
None

◆ dma_set_addresses()

void dma_set_addresses ( const dma_peripheral_t dma,
const uint8_t stream,
const uint32_t PA,
const uint32_t M0A,
const uint32_t M1A )

Set the DMA source and destination addresses.

Usually only the peripheral and M0 addresses are needed. In that case you shall set M1A to zero.

Parameters
dmaThe selected DMA
streamThe selected stream (0..7)
PAThe peripheral address
M0AThe memory 0 address
M1AThe memory 1 address
Returns
None

◆ dma_set_channel()

void dma_set_channel ( const dma_peripheral_t dma,
const uint8_t stream,
const uint8_t channel,
const dma_priority_t priority )

Set the DMA stream channel and priority.

The DMA priority levels are specified in the dma_priority_t enum. Any other value will be ignored. Refer to the chip's manual for the channel function matrix.

Parameters
dmaThe selected DMA
streamThe selected stream (0..7)
channelThe selected channel (0..7)
priorityThe stream priority level
Returns
None

◆ dma_set_direction()

void dma_set_direction ( const dma_peripheral_t dma,
const uint8_t stream,
const dma_dir_t direction )

Set DMA transfers to the desired direction.

The DMA directions are specified in the dma_dir_t enum. Any other value will be ignored. After that set the addresses according to the chip's manual.

Parameters
dmaThe selected DMA
streamThe selected stream (0..7)
directionThe transfer direction
Returns
None

◆ dma_set_interrupts()

void dma_set_interrupts ( const dma_peripheral_t dma,
const uint8_t stream,
const struct DMAStreamISR config )

Enabled the specified DMA stream interrupts.

The available DMA interrupts are located in the DMAStreamISR struct.

Parameters
dmaThe selected DMA
streamThe selected stream (0..7)
configThe interrupt configuration
Returns
None