cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX generates incorrect code for the STM32U575 MDF peripheral for multiple filters using DMA

LVan .31
Associate III

I am working with the MDF peripheral and find this to be a great peripheral. However the CubeMX generated code for multiple DMA based filters is not correct.


I am using two filters with DMA and CubeMX generates the following descriptors:

  1. MDF_HandleTypeDef MdfHandle0;
  2. MDF_FilterConfigTypeDef MdfFilterConfig0;
  3. MDF_HandleTypeDef MdfHandle1;
  4. MDF_FilterConfigTypeDef MdfFilterConfig1;
  5. DMA_NodeTypeDef Node_GPDMA1_Channel1;
  6. DMA_QListTypeDef List_GPDMA1_Channel1;
  7. DMA_HandleTypeDef handle_GPDMA1_Channel1;
  8. DMA_NodeTypeDef Node_GPDMA1_Channel0;
  9. DMA_QListTypeDef List_GPDMA1_Channel0;
  10. DMA_HandleTypeDef handle_GPDMA1_Channel0;

 

When starting the application I found that both MdfHandle0 and MdfHandle1 refer the same DMA handle,  handle_GPDMA1_Channel1. Likewise both handle_GPDMA1_Channel0.Parent and handle_GPDMA1_Channel1.Parent refer the same filter handle,  MdfHandle0.

This is caused by generated function HAL_MDF_MspInit which is called when starting a filter using HAL_MDF_AcqStart_DMA. This generated function is executed twice since I use two filters but inside this function the exact same code is executed and no distinction is made whether it is called for filter 0 (MdfHandle0) or filter 1 (MdfHandle1).

In other generated ....MspInit functions a distinction is made based on the peripheral instance the function is called for. For instance for UART's in my code, HAL_UART_MspInit looks like:

...

if(huart->Instance==LPUART1)
{

...;

}

else if(huart->Instance==USART1)

{

...;

}

In order to differentiate between the different UART instances.

 

This however is not done in HAL_MDF_MspInit. Instead of the above use is made of:

if(IS_MDF_INSTANCE(hmdf->Instance)) which is typically used inside the HAL but not in the generated code and using this no different code is generated for the different filter instances.

The same issue applies to HAL_MDF_MspDeInit.

 

I have set the wrong descriptors correct manually after the CubeMX initialization code and everything works as expected.

I am using version 6.10.0 of CubeMX and version 1.4.0 of the STM32U5xx HAL library.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Souhaib MAZHOUD
ST Employee

Hello @LVan .31 

Thank you for bringing this issue to our attention, I will check it internally and get back to you as soon as possible.

Thx

Souhaib

 

View solution in original post

2 REPLIES 2
Souhaib MAZHOUD
ST Employee

Hello @LVan .31 

Thank you for bringing this issue to our attention, I will check it internally and get back to you as soon as possible.

Thx

Souhaib

 

I really love the software ST provides nowadays. I remember the time (not that long ago) that chip manufacturers did offer very limited software support. Their business was selling chips and the programming was left to the customer. Most manufacturers have come a long way since then......... but.........

When customers report bugs in the software and since the time of reporting two new versions of the software (CubeMX in this case) have emerged I think it is quite annoying that the issues are not solved. The issue reported in the original post still exists and I have not heard or seen any reaction since the end of 2023 when this issue was reported.

The issue is a serious bug in the CubeMX generated code for the MDF peripheral. I use two filters each having its own DMA channel. Not only is the complete initialization code for the MDF filters executed twice in this case (or even more often when using more filters) but, and this is the bug, all filters are set to the same DMA channel leading to an error when running the code since the same channel is started more than once. My workaround is that in the user code at the end of the generated function I have added:

 

 

 

/* USER CODE BEGIN MDF1_MspInit 1 */
if (hmdf->Instance == MDF1_Filter0)
{
    __HAL_LINKDMA(hmdf, hdma, handle_GPDMA1_Channel0);
}
else
{
    __HAL_LINKDMA(hmdf, hdma, handle_GPDMA1_Channel1);
}

/* USER CODE END MDF1_MspInit 1 */

 

 

to set the desired DMA channel to the correct filter but for sure this is not what you want. The call to __HAL_LINKDMA is already present in the generated code and my workaround just overwrites this.

 

Please ST, is it possible to be more responsive...............