Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 323 of 9364. Peripheral Interfacing and ControlFree lesson

Configuring DMA Channels and Priority Levels

Learn to assign specific peripheral requests to dedicated DMA channels while managing hardware priority levels for simultaneous bus access.

In this lesson, you will learn how to map specific peripheral hardware requests to dedicated DMA channels and how to resolve bus contention using hardware priority levels.

Channel Mapping

A Direct Memory Access (DMA) controller acts as a traffic cop for data. Because your microcontroller has many peripherals (like ADCs, UARTs, or SPI modules) that might need to move data simultaneously, the DMA controller uses channels. Think of a channel as a dedicated "pipe" connecting a specific peripheral to memory.

When you configure a DMA channel, you are essentially telling the controller: "Whenever the ADC signals it has new data, move that data through Channel 1." By assigning one peripheral per channel, you ensure that the data stream remains orderly and consistent.

Managing Priority Levels

What happens if your ADC and your high-speed UART both trigger a DMA request at the exact same time? Since they cannot both occupy the system bus simultaneously, the DMA controller must decide which request gets serviced first. This is where Priority Levels come in.

Hardware priority levels act as a hierarchy (e.g., Very High, High, Medium, Low). If two channels request access at once, the DMA controller grants the bus to the channel with the higher priority.

// Conceptual configuration of DMA channels and priority
DMA_ChannelConfig(CHANNEL_1, ADC_SOURCE, HIGH_PRIORITY);
DMA_ChannelConfig(CHANNEL_2, UART_SOURCE, LOW_PRIORITY);

In the example above, if the ADC and UART request a transfer simultaneously, the DMA controller handles the ADC data first. The UART request will wait in a pending state until the ADC transfer is complete.

Avoiding Bus Contention

By assigning your most time-critical tasks (like real-time audio sampling or high-speed sensor streams) to higher priority levels, you prevent data loss due to latency. However, be careful: if you set too many channels to "Very High," you may starve lower-priority peripherals, potentially causing buffer overflows in slower tasks. Balancing these priorities is the key to a responsive embedded system.

Key Takeaway: Dedicated DMA channels act as specific data paths for your peripherals, while priority levels determine the order of operations when multiple data transfers compete for the system bus.