cancel
Showing results for 
Search instead for 
Did you mean: 

UART1 TX DMA Transmission with LL Driver of CubeMX 6.9.1 not working

mahapusha
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions

> I am using STM32L4P5VGT

Is it really a 'L4P5?

Post a photo of the chip. Post screenshot of CubeProgrammer when connected to it. Read out and post content of DBGMCU_IDCODE (Address: 0xE004 2000).

JW

 

View solution in original post

7 REPLIES 7
Foued_KH
ST Employee

Hello @mahapusha ,

You can check this : stm32-usart-uart-dma-rx-tx/projects/usart_rx_idle_line_irq_L4 at main · MaJerle/stm32-usart-uart-dma-rx-tx (github.com)

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

The MCU L4P5 is different compared to other low series due to DMAMUX which is not available in others.

Please check the attached file.

Hope it helps ,
Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

mahapusha
Associate III

It did not work. It behaved similarly to earlier CubeMX generated. Same time, it looks that you have generated code for a higher-end processor, AHB3 is not available in L4P5. Please select processor - L4P5VGT, series, UART1, DMA1, and CH1 so I do not need to make changes while testing.

Did you find the reason - why is not working as the reported problem.

> I am using STM32L4P5VGT

Is it really a 'L4P5?

Post a photo of the chip. Post screenshot of CubeProgrammer when connected to it. Read out and post content of DBGMCU_IDCODE (Address: 0xE004 2000).

JW

 

After your query about the MCU Part Number, I checked the real part soldered on board and schematic circuit. Both are not the same. I do not know, where is it changed due to inventory or something else.
The soldered part is STM32L4R5VGT6, Once I corrected it in Cubex and Regenerated the project again it worked fine without having an interrupt vector problem with DMA.
Thanks for pointing out the mistake and sorry for wasting time of everyone.
Regards