Bird
Raised Fist0
Embedded Cprogramming~20 mins

DMA with UART for bulk transfer in Embedded C - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
DMA UART Bulk Transfer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
DMA UART Bulk Transfer Initialization Output
What will be the output of this embedded C code snippet that initializes DMA for UART bulk transfer and starts the transfer?
Embedded C
#include <stdio.h>
#include <string.h>

// Simulated UART and DMA registers
volatile int UART_TX_READY = 1;
volatile int DMA_TRANSFER_COMPLETE = 0;

void DMA_StartTransfer(char *buffer, int length) {
    if (UART_TX_READY) {
        printf("DMA started for %d bytes\n", length);
        DMA_TRANSFER_COMPLETE = 1;
    } else {
        printf("UART not ready\n");
    }
}

int main() {
    char data[] = "Hello DMA UART!";
    DMA_StartTransfer(data, strlen(data));
    if (DMA_TRANSFER_COMPLETE) {
        printf("DMA transfer complete\n");
    } else {
        printf("DMA transfer not complete\n");
    }
    return 0;
}
A
DMA started for 15 bytes
DMA transfer complete
B
UART not ready
DMA transfer not complete
C
DMA started for 14 bytes
DMA transfer complete
D
DMA started for 15 bytes
DMA transfer not complete
Attempts:
2 left
💡 Hint
Check the length of the string passed to DMA_StartTransfer and the UART_TX_READY flag.
🧠 Conceptual
intermediate
1:30remaining
DMA and UART Bulk Transfer Buffer Size
In a DMA-based UART bulk transfer, why is it important to correctly configure the DMA buffer size?
ABecause the DMA buffer size controls the UART baud rate directly.
BBecause the DMA buffer size determines how many bytes are transferred in one operation, preventing data overflow or truncation.
CBecause the DMA buffer size sets the UART parity bits automatically.
DBecause the DMA buffer size decides the CPU clock speed during transfer.
Attempts:
2 left
💡 Hint
Think about how DMA moves data and what happens if the buffer is too small or too large.
🔧 Debug
advanced
2:00remaining
Identify the Bug in DMA UART Transfer Code
What error will this code cause when running a DMA UART bulk transfer?
Embedded C
char uart_buffer[10];
void start_dma_transfer() {
    // Intentionally incorrect length
    int length = 20;
    DMA_StartTransfer(uart_buffer, length);
}

void DMA_StartTransfer(char *buffer, int length) {
    // Simulated transfer
    printf("Transferring %d bytes\n", length);
}
ABuffer overflow because length exceeds buffer size
BSyntax error due to missing semicolon
CNo output because DMA_StartTransfer is never called
DRuntime error due to null pointer
Attempts:
2 left
💡 Hint
Check the buffer size and the length passed to DMA_StartTransfer.
📝 Syntax
advanced
1:30remaining
Syntax Error in DMA UART Transfer Setup
Which option contains the correct syntax to configure DMA for UART transmission in embedded C?
Embedded C
/* Assume DMA_Config is a struct with fields: source, destination, length */
DMA_Config dma_cfg;
dma_cfg.source = uart_tx_buffer;
dma_cfg.destination = UART_DATA_REGISTER;
dma_cfg.length = 64;
A
dma_cfg.source = uart_tx_buffer;
 dma_cfg.destination = UART_DATA_REGISTER
 dma_cfg.length = 64;
B
dma_cfg.source = uart_tx_buffer
 dma_cfg.destination = UART_DATA_REGISTER;
 dma_cfg.length = 64;
C
dma_cfg.source := uart_tx_buffer;
 dma_cfg.destination := UART_DATA_REGISTER;
 dma_cfg.length := 64;
D
dma_cfg.source = uart_tx_buffer;
 dma_cfg.destination = UART_DATA_REGISTER;
 dma_cfg.length = 64;
Attempts:
2 left
💡 Hint
Remember the correct statement terminator in C.
🚀 Application
expert
2:00remaining
Calculate Total Bytes Transferred in DMA UART Bulk Transfer
Given a DMA UART bulk transfer configured with a buffer size of 128 bytes and a transfer count of 10, what is the total number of bytes transferred?
A10 bytes
B138 bytes
C1280 bytes
D128 bytes
Attempts:
2 left
💡 Hint
Multiply buffer size by transfer count to get total bytes.

Practice

(1/5)
1. What is the main advantage of using DMA with UART for bulk data transfer?
easy
A. It reduces CPU load by handling data transfer automatically.
B. It increases the UART baud rate beyond hardware limits.
C. It encrypts data during transmission for security.
D. It allows UART to work without any clock signal.

Solution

  1. Step 1: Understand DMA role in UART transfer

    DMA transfers data directly between memory and UART without CPU intervention for each byte.
  2. Step 2: Identify the benefit of reduced CPU load

    This frees CPU to perform other tasks while data moves in background.
  3. Final Answer:

    It reduces CPU load by handling data transfer automatically. -> Option A
  4. Quick Check:

    DMA offloads CPU [OK]
Hint: DMA moves data without CPU, so CPU load drops [OK]
Common Mistakes:
  • Thinking DMA increases UART speed beyond hardware limits
  • Confusing DMA with encryption or clock control
  • Assuming UART can work without clock signal
2. Which of the following code snippets correctly enables UART DMA transmission in embedded C?
easy
A. UART->CR3 |= USART_CR3_DMAT;
B. UART->CR1 |= USART_CR1_DMAT;
C. DMA->CR |= DMA_CR_EN;
D. UART->BRR = USART_BRR_DMAT;

Solution

  1. Step 1: Identify UART register for DMA transmit enable

    UART control register 3 (CR3) contains the DMAT bit to enable DMA for transmission.
  2. Step 2: Check correct bit and register usage

    Setting USART_CR3_DMAT in UART->CR3 enables DMA transmit requests.
  3. Final Answer:

    UART->CR3 |= USART_CR3_DMAT; -> Option A
  4. Quick Check:

    DMA transmit enable bit is in CR3 [OK]
Hint: DMA transmit enable is in UART CR3 register [OK]
Common Mistakes:
  • Using CR1 instead of CR3 for DMA transmit enable
  • Confusing DMA channel enable with UART DMA request enable
  • Setting baud rate register instead of control bits
3. Given this DMA setup code for UART RX bulk transfer, what will be the value of DMA->NDTR after starting the transfer?
DMA->CCR = DMA_CCR_MINC | DMA_CCR_TCIE;
DMA->CNDTR = 100;
DMA->CPAR = (uint32_t)&UART->RDR;
DMA->CMAR = (uint32_t)rx_buffer;
DMA->CCR |= DMA_CCR_EN;
medium
A. 0
B. 99
C. 100
D. Undefined

Solution

  1. Step 1: Understand DMA CNDTR register role

    CNDTR holds the number of data items to transfer; initially set to 100.
  2. Step 2: Check when CNDTR changes

    CNDTR decrements only after each data transfer, so right after enabling DMA, it remains 100.
  3. Final Answer:

    100 -> Option C
  4. Quick Check:

    DMA transfer count starts at set value = 100 [OK]
Hint: DMA count decrements after transfer, not immediately [OK]
Common Mistakes:
  • Assuming CNDTR decrements immediately on enable
  • Confusing CNDTR with current data register
  • Thinking CNDTR resets to zero on start
4. Identify the error in this DMA UART transmit setup code snippet:
DMA->CCR = DMA_CCR_MINC | DMA_CCR_DIR;
DMA->CNDTR = 50;
DMA->CPAR = (uint32_t)&UART->TDR;
DMA->CMAR = (uint32_t)tx_buffer;
DMA->CCR |= DMA_CCR_EN;
UART->CR3 &= ~USART_CR3_DMAT;
medium
A. DMA direction bit is set incorrectly for UART transmit.
B. UART DMA transmit request is disabled after enabling DMA.
C. Memory increment mode is not enabled.
D. Peripheral address points to wrong UART register.

Solution

  1. Step 1: Check UART DMA transmit enable bit

    UART->CR3 must have DMAT bit set to enable DMA requests for transmit.
  2. Step 2: Identify disabling of DMAT bit

    Code clears DMAT bit after DMA enable, disabling UART DMA transmit requests, so transfer won't start.
  3. Final Answer:

    UART DMA transmit request is disabled after enabling DMA. -> Option B
  4. Quick Check:

    DMAT bit must be set for DMA transmit [OK]
Hint: Keep UART DMAT bit set to allow DMA transmit [OK]
Common Mistakes:
  • Disabling UART DMA transmit request after DMA enable
  • Confusing DMA direction bit meaning
  • Forgetting to enable memory increment mode
5. You want to transfer 256 bytes from a memory buffer to UART using DMA. Which sequence correctly sets up the DMA and UART for this bulk transfer?
hard
A. Set DMA source to UART RDR, destination to buffer, length 256; enable UART DMAR bit; enable DMA channel.
B. Set DMA source to UART TDR, destination to buffer, length 256; enable UART DMAR bit; enable DMA channel.
C. Set DMA source to buffer, destination to UART RDR, length 256; enable UART DMAT bit; enable DMA channel.
D. Set DMA source to buffer, destination to UART TDR, length 256; enable UART DMAT bit; enable DMA channel.

Solution

  1. Step 1: Identify direction for UART transmit DMA

    For UART transmit, DMA source is memory buffer, destination is UART TDR register.
  2. Step 2: Enable UART DMA transmit request and DMA channel

    Set UART DMAT bit to enable DMA requests on transmit, then enable DMA channel to start transfer.
  3. Final Answer:

    Set DMA source to buffer, destination to UART TDR, length 256; enable UART DMAT bit; enable DMA channel. -> Option D
  4. Quick Check:

    Memory to UART TDR + DMAT enabled [OK]
Hint: For UART TX DMA: memory source, UART TDR destination, enable DMAT [OK]
Common Mistakes:
  • Confusing UART TDR and RDR registers for source/destination
  • Using DMAR bit for transmit instead of DMAT
  • Setting DMA direction opposite to data flow
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard