Challenge - 5 Problems
DMA Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this DMA transfer status check?
Consider this embedded C code snippet that checks the status of a DMA peripheral-to-memory transfer. What will be printed?
Embedded C
#include <stdio.h> #include <stdint.h> #define DMA_TRANSFER_COMPLETE 1 volatile uint8_t DMA_Status = DMA_TRANSFER_COMPLETE; int main() { if (DMA_Status == DMA_TRANSFER_COMPLETE) { printf("Transfer Complete\n"); } else { printf("Transfer Incomplete\n"); } return 0; }
Attempts:
2 left
💡 Hint
Look at the value of DMA_Status and the condition in the if statement.
✗ Incorrect
DMA_Status is set to DMA_TRANSFER_COMPLETE which equals 1. The if condition checks if DMA_Status equals DMA_TRANSFER_COMPLETE, so it prints 'Transfer Complete'.
🧠 Conceptual
intermediate1:30remaining
Which statement best describes peripheral-to-memory DMA transfer?
In embedded systems, what does a peripheral-to-memory DMA transfer do?
Attempts:
2 left
💡 Hint
Think about what DMA stands for and its purpose.
✗ Incorrect
DMA (Direct Memory Access) allows peripherals to transfer data directly to memory without CPU involvement, improving efficiency.
🔧 Debug
advanced2:30remaining
What error does this DMA transfer code cause?
Examine the following code snippet for a peripheral-to-memory DMA transfer. What error will occur when compiling or running this code?
Embedded C
void start_dma_transfer(uint32_t *peripheral_reg, uint32_t *memory_buffer, uint32_t length) {
for (int i = 0; i < length; i++) {
memory_buffer[i] = *peripheral_reg;
}
}
int main() {
uint32_t peripheral_data = 0x12345678;
uint32_t buffer[5] = {0};
start_dma_transfer(&peripheral_data, buffer, 5);
return 0;
}Attempts:
2 left
💡 Hint
Check the loop boundary condition carefully.
✗ Incorrect
The loop runs from i = 0 to i <= length, which means it accesses memory_buffer[length], causing buffer overflow since valid indices are 0 to length-1.
📝 Syntax
advanced2:00remaining
Which option correctly initializes a DMA peripheral-to-memory transfer in C?
Given the following incomplete code to configure a DMA transfer, which option correctly completes the initialization without syntax errors?
Embedded C
typedef struct {
uint32_t CCR;
uint32_t CNDTR;
uint32_t CPAR;
uint32_t CMAR;
} DMA_Channel_TypeDef;
void dma_init(DMA_Channel_TypeDef *dma_channel, uint32_t peripheral_addr, uint32_t memory_addr, uint32_t length) {
dma_channel->CPAR = peripheral_addr;
dma_channel->CMAR = memory_addr;
dma_channel->CNDTR = length;
// Configure control register
dma_channel->CCR = Attempts:
2 left
💡 Hint
Remember to end statements with a semicolon in C.
✗ Incorrect
Option D correctly assigns the value with a semicolon. Option D misses the semicolon, C has an extra semicolon, and D uses invalid assignment syntax.
🚀 Application
expert3:00remaining
How many bytes are transferred in this peripheral-to-memory DMA example?
Consider this embedded C code configuring a DMA transfer from a peripheral to memory. How many bytes will be transferred?
Embedded C
#define DMA_BUFFER_SIZE 8 uint16_t dma_buffer[DMA_BUFFER_SIZE]; void configure_dma() { DMA_Channel_TypeDef dma_channel; dma_channel.CPAR = (uint32_t)&PERIPHERAL_DATA_REGISTER; dma_channel.CMAR = (uint32_t)dma_buffer; dma_channel.CNDTR = DMA_BUFFER_SIZE; dma_channel.CCR = 0x00000001; // Enable DMA channel } int main() { configure_dma(); return 0; }
Attempts:
2 left
💡 Hint
Consider the data type size and the number of elements transferred.
✗ Incorrect
dma_buffer is an array of 8 elements of type uint16_t (2 bytes each). Total bytes = 8 * 2 = 16 bytes.