0
0
Embedded Cprogramming~20 mins

Circular buffer DMA mode in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DMA Circular Buffer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of DMA circular buffer index update

Consider a DMA circular buffer of size 8. The DMA current index is updated after each transfer. What is the value of current_index after 10 transfers?

Embedded C
int buffer_size = 8;
int current_index = 0;
for (int i = 0; i < 10; i++) {
    current_index = (current_index + 1) % buffer_size;
}
printf("%d", current_index);
A10
B8
C0
D2
Attempts:
2 left
💡 Hint

Think about how modulo (%) operator wraps the index around the buffer size.

🧠 Conceptual
intermediate
1:30remaining
Purpose of circular buffer in DMA mode

What is the main advantage of using a circular buffer in DMA mode for data reception?

AIt allows continuous data reception without CPU intervention by wrapping the buffer index automatically.
BIt stores data in a linked list to manage variable sizes.
CIt prevents data loss by disabling interrupts during transfer.
DIt increases the data transfer speed by doubling the buffer size.
Attempts:
2 left
💡 Hint

Think about how circular buffers help with continuous streaming data.

🔧 Debug
advanced
2:30remaining
Identify the error in DMA circular buffer setup

What error will occur when running this DMA circular buffer initialization code?

Embedded C
uint8_t dma_buffer[16];
DMA_InitTypeDef dma_init;
dma_init.Mode = DMA_NORMAL;
dma_init.BufferSize = 16;
dma_init.MemInc = ENABLE;
DMA_Init(&dma_init);
// Start DMA transfer
DMA_Start(dma_buffer, 16);
ABuffer overflow error due to wrong buffer size.
BDMA will stop after filling buffer once, no circular mode enabled.
CCompilation error: DMA_InitTypeDef has no member 'Mode'.
DRuntime crash due to uninitialized dma_buffer.
Attempts:
2 left
💡 Hint

Check the DMA mode setting for continuous circular operation.

📝 Syntax
advanced
1:30remaining
Correct syntax for enabling DMA circular mode

Which option correctly enables circular mode in DMA configuration?

Embedded C
DMA_InitTypeDef dma_init;
dma_init.Mode = ???;
// rest of initialization
ADMA_CIRCULAR_MODE
BDMA_MODE_CIRCULAR
CDMA_CIRCULAR
DCIRCULAR_DMA_MODE
Attempts:
2 left
💡 Hint

Look for the standard DMA mode constant for circular mode.

🚀 Application
expert
3:00remaining
Calculate remaining data in DMA circular buffer

You have a DMA circular buffer of size 32 bytes. The DMA current data counter shows 10 bytes remaining to transfer. How many bytes have been transferred so far?

A22 bytes
B10 bytes
C42 bytes
D32 bytes
Attempts:
2 left
💡 Hint

Subtract the remaining bytes from the total buffer size.