Challenge - 5 Problems
DMA UART Bulk Transfer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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; }
Attempts:
2 left
💡 Hint
Check the length of the string passed to DMA_StartTransfer and the UART_TX_READY flag.
✗ Incorrect
The string "Hello DMA UART!" has 15 characters including spaces and punctuation. UART_TX_READY is 1, so DMA starts and sets DMA_TRANSFER_COMPLETE to 1. The output matches option A.
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
Think about how DMA moves data and what happens if the buffer is too small or too large.
✗ Incorrect
The DMA buffer size defines how many bytes the DMA controller transfers in one go. If it's too small, data may be lost or require multiple transfers. If too large, it may cause memory issues. It does not affect UART baud rate, parity, or CPU clock.
🔧 Debug
advanced2: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); }
Attempts:
2 left
💡 Hint
Check the buffer size and the length passed to DMA_StartTransfer.
✗ Incorrect
The buffer uart_buffer is only 10 bytes, but the code tries to transfer 20 bytes, causing a buffer overflow risk. This can lead to memory corruption or crashes.
📝 Syntax
advanced1: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;
Attempts:
2 left
💡 Hint
Remember the correct statement terminator in C.
✗ Incorrect
In C, each statement must end with a semicolon. Option D correctly uses semicolons on all lines. Option D and D miss semicolons on some lines. Option D uses := which is invalid in C.
🚀 Application
expert2: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?
Attempts:
2 left
💡 Hint
Multiply buffer size by transfer count to get total bytes.
✗ Incorrect
Total bytes transferred equals buffer size multiplied by the number of transfers: 128 * 10 = 1280 bytes.