UART1 TX DMA Transmission with LL Driver of CubeMX 6.9.1 not working
Dear Members,
I am using STM32L4P5VGT, STM32CubeMX 6.9.1, and STM32Cube_FW_L4_V1.18.0.
I am steaming data on UART using TX DMA. With the HAL driver, it works fine but do not like to use it due to processing and decided to use the LL driver and had a tough time making it work. It looks like the issue is in the header file supplied with CubeMX. I have to make the following change in the auto-generated file "usart.c" as below, where I have decremented the index.
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_USART1_TX - 1);
in functionMX_USART1_UART_Init, the first line. After the above change things worked.
To make it simple, I have added a limited code of init of DMA, Interrupt, and User code to transmit the data. For UART - GPIO and its configuration-related code were removed.
MX_GPIO_Init();
MX_DMA_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1);
LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_1, sizeof(buffer));
LL_DMA_SetMemoryAddress(DMA1, LL_DMA_CHANNEL_1, (uint32_t)&buffer);
LL_DMA_SetPeriphAddress(DMA1, LL_DMA_CHANNEL_1, (uint32_t)&(USART1->TDR));
// Enable transmit completion interrupt.
LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1);
LL_USART_ClearFlag_TC(USART1);
LL_USART_EnableDirectionTx(USART1);
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
LL_USART_EnableDMAReq_TX(USART1);
/* USER CODE END 2 */
void MX_USART1_UART_Init(void)
{
/* USART1 DMA Init */
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_USART1_TX-1);
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_MEDIUM);
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_NORMAL);
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT);
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT);
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_BYTE);
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_BYTE);
}
Question 1 - Does anyone have a similar experience of errors in the header file(stm32l4xx_ll_dmamux.h)?
Question 2 - Do I need to reload each time before transmission - size, src, and dst address, whereas all are fixed, peripheral address, buffer address, and size also?
Question 3 - Do I need to call LL_DMA_DisableChannel before loading of question 2 parameters and enable it after doing these?
Question 4 - Do I also need these two lines in every transmission as below code snips (Questions 2, 3, and 4 are related to making better and faster code, removing unwanted lines that are not needed)? LL_USART_ClearFlag_TC(USART1);
LL_USART_EnableDirectionTx(USART1);
Thanks in advance for the update.
Mahabir Prasad
