0
0
Embedded Cprogramming~20 mins

Peripheral-to-memory transfer in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DMA Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
ACompilation error
BTransfer Incomplete
CTransfer Complete
DNo output
Attempts:
2 left
💡 Hint
Look at the value of DMA_Status and the condition in the if statement.
🧠 Conceptual
intermediate
1:30remaining
Which statement best describes peripheral-to-memory DMA transfer?
In embedded systems, what does a peripheral-to-memory DMA transfer do?
AIt moves data from a peripheral device directly into system memory without CPU intervention.
BIt moves data from system memory to a peripheral device using CPU instructions.
CIt copies data between two peripheral devices using CPU interrupts.
DIt requires the CPU to manually read and write each data byte between peripheral and memory.
Attempts:
2 left
💡 Hint
Think about what DMA stands for and its purpose.
🔧 Debug
advanced
2: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;
}
ABuffer overflow due to accessing memory_buffer[length] index
BCompilation error because of missing semicolon
CRuntime segmentation fault due to null pointer dereference
DNo error, code runs correctly
Attempts:
2 left
💡 Hint
Check the loop boundary condition carefully.
📝 Syntax
advanced
2: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 = 
A0x00000001;; // Double semicolon causes syntax error
B0x00000001 // Enable DMA channel (missing semicolon)
C0x00000001 = dma_channel->CCR; // Invalid assignment
D0x00000001; // Enable DMA channel
Attempts:
2 left
💡 Hint
Remember to end statements with a semicolon in C.
🚀 Application
expert
3: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;
}
A32 bytes
B16 bytes
C8 bytes
D64 bytes
Attempts:
2 left
💡 Hint
Consider the data type size and the number of elements transferred.