Skip to content

Commit 01b08b2

Browse files
committed
Disable UART2 DMA when using DSHOT to avoid DMA conflict
CF21BL uses DSHOT for brushless motors, which requires DMA1_Stream6. UART2 TX also needs DMA1_Stream6, creating a conflict during ESP32 flashing. Changes: - Guard uart2DmaInit() with #ifndef CONFIG_MOTORS_ESC_PROTOCOL_DSHOT - Guard initialDMACount variable (only used with DMA) - Add fallback in uart2SendDataDmaBlocking() to use interrupt-based uart2SendData() instead when DSHOT is enabled This allows UART2 (and thus ESP32 flashing) to work on CF21BL by avoiding the DMA conflict entirely - UART2 uses interrupts instead of DMA when motors need the stream.
1 parent a18e216 commit 01b08b2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/drivers/src/uart2.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,19 @@ static StaticSemaphore_t waitUntilSendDoneBuffer;
5252

5353
static bool isInit = false;
5454

55+
#ifndef CONFIG_MOTORS_ESC_PROTOCOL_DSHOT
5556
static DMA_InitTypeDef DMA_InitStructureShare;
5657
static uint8_t dmaBuffer[UART2_DMA_BUFFER_SIZE];
5758
static bool isUartDmaInitialized;
5859
static uint32_t initialDMACount;
60+
#endif
5961

6062
static StreamBufferHandle_t rxStream;
6163
static EventGroupHandle_t isrEvents;
6264

6365
static bool hasOverrun = false;
6466

67+
#ifndef CONFIG_MOTORS_ESC_PROTOCOL_DSHOT
6568
/**
6669
* Configures the UART DMA. Mainly used for FreeRTOS trace
6770
* data transfer.
@@ -97,6 +100,7 @@ static void uart2DmaInit(void)
97100

98101
isUartDmaInitialized = true;
99102
}
103+
#endif
100104

101105
void uart2Init(const uint32_t baudrate)
102106
{
@@ -139,7 +143,10 @@ void uart2Init(const uint32_t baudrate)
139143
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
140144
USART_Init(UART2_TYPE, &USART_InitStructure);
141145

146+
// Only initialize DMA when NOT using DSHOT (DSHOT motors conflict with UART2 DMA)
147+
#ifndef CONFIG_MOTORS_ESC_PROTOCOL_DSHOT
142148
uart2DmaInit();
149+
#endif
143150

144151
// Configure Rx buffer not empty interrupt
145152
NVIC_InitStructure.NVIC_IRQChannel = UART2_IRQ;
@@ -195,6 +202,10 @@ void uart2SendData(uint32_t size, uint8_t* data)
195202

196203
void uart2SendDataDmaBlocking(uint32_t size, uint8_t* data)
197204
{
205+
#ifdef CONFIG_MOTORS_ESC_PROTOCOL_DSHOT
206+
// DMA disabled due to conflict with brushless motors, fall back to regular send
207+
uart2SendData(size, data);
208+
#else
198209
if (isUartDmaInitialized)
199210
{
200211
xSemaphoreTake(uartBusy, portMAX_DELAY);
@@ -217,6 +228,7 @@ void uart2SendDataDmaBlocking(uint32_t size, uint8_t* data)
217228
xSemaphoreTake(waitUntilSendDone, portMAX_DELAY);
218229
xSemaphoreGive(uartBusy);
219230
}
231+
#endif
220232
}
221233

222234
int uart2Putchar(int ch)

0 commit comments

Comments
 (0)