# DMA: stream already enabled, cannot reconfigure while busy

- **ID:** `embedded/dma-configuration-busy-flag`
- **Domain:** embedded
- **Category:** resource_error
- **Error Code:** `HAL_DMA_ERROR_BUSY`
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

A DMA stream or channel is being reconfigured (e.g., changing source/destination address or transfer size) while the DMA peripheral is still active (EN bit set), causing a write to read-only registers or a bus error.

## Workarounds

1. **Disable the DMA stream before reconfiguration. Example: hdma->Instance->CCR &= ~DMA_CCR_EN; while (hdma->Instance->CCR & DMA_CCR_EN); // Wait for disable confirmation** (90% success)
   ```
   Disable the DMA stream before reconfiguration. Example: hdma->Instance->CCR &= ~DMA_CCR_EN; while (hdma->Instance->CCR & DMA_CCR_EN); // Wait for disable confirmation
   ```
2. **Use a state machine to ensure DMA is only reconfigured after transfer completion interrupt. Check the Transfer Complete flag before calling HAL_DMA_Start_IT again.** (85% success)
   ```
   Use a state machine to ensure DMA is only reconfigured after transfer completion interrupt. Check the Transfer Complete flag before calling HAL_DMA_Start_IT again.
   ```

## Dead Ends

- **** — Calling HAL_DMA_Abort() and then immediately reconfiguring without waiting for the abort completion flag results in the same busy state. (75% fail)
- **** — Resetting the DMA peripheral via RCC reset does clear the busy flag but also loses all configuration, requiring full re-initialization. (50% fail)
