0
0
Embedded Cprogramming~20 mins

Memory-to-peripheral transfer in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Memory-to-peripheral Transfer Master
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 code?
Consider this embedded C code snippet that checks the status of a DMA transfer. What will be printed?
Embedded C
#include <stdio.h>
#include <stdint.h>

#define DMA_TRANSFER_COMPLETE 1

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 how the DMA_Status variable is checked using bitwise AND.
Predict Output
intermediate
2:00remaining
What is the value of buffer after this memory-to-peripheral transfer simulation?
This code simulates copying data from memory to a peripheral buffer. What is the final content of buffer?
Embedded C
#include <stdio.h>
#include <string.h>

int main() {
    char memory[] = "DATA";
    char buffer[5] = {0};
    memcpy(buffer, memory, 4);
    buffer[4] = '\0';
    printf("%s", buffer);
    return 0;
}
ADATA
BCompilation error
CDAT
DDATA\0
Attempts:
2 left
💡 Hint
Check how memcpy copies bytes and how the null terminator is added.
🔧 Debug
advanced
3:00remaining
Why does this DMA transfer code cause a runtime error?
Examine this code snippet for a DMA transfer setup. Why does it cause a runtime error?
Embedded C
void start_dma_transfer(uint32_t *src, uint32_t *dst, size_t size) {
    for (size_t i = 0; i < size; i++) {
        dst[i] = src[i];
    }
}

int main() {
    uint32_t source[3] = {1, 2, 3};
    uint32_t destination[3] = {0};
    start_dma_transfer(source, destination, 3);
    return 0;
}
ACompilation error due to missing header
BNull pointer dereference
CNo error, runs fine
DArray index out of bounds causing undefined behavior
Attempts:
2 left
💡 Hint
Check the loop condition and array sizes carefully.
📝 Syntax
advanced
2:00remaining
Which option fixes the syntax error in this DMA transfer initialization?
This code snippet has a syntax error. Which option fixes it?
Embedded C
typedef struct {
    uint32_t *source;
    uint32_t *destination;
    size_t length;
} DMA_Transfer;

void init_dma(DMA_Transfer *transfer) {
    transfer->source = (uint32_t *)0x20000000;
    transfer->destination = (uint32_t *)0x40000000;
    transfer->length = 256;
}
AChange '->' to '.' operator
BAdd a semicolon after the first assignment line
CRemove the cast to (uint32_t *)
DAdd braces around the struct initialization
Attempts:
2 left
💡 Hint
Look carefully at the end of each statement line.
🚀 Application
expert
3:00remaining
How many bytes are transferred in this memory-to-peripheral DMA setup?
Given this DMA transfer configuration, how many bytes will be transferred?
Embedded C
typedef struct {
    uint8_t *src;
    volatile uint8_t *peripheral;
    size_t count;
} DMA_Config;

int main() {
    DMA_Config config = {
        .src = (uint8_t *)0x20001000,
        .peripheral = (volatile uint8_t *)0x40002000,
        .count = 128
    };
    // DMA transfer code here
    return 0;
}
A128 bytes
BCannot determine from code
C64 bytes
D256 bytes
Attempts:
2 left
💡 Hint
Look at the count field and data type size.