cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5 + PWM + DMA

nicolas
Senior

I'm able to generate a simple PWM signal but I wasn't able to generate arbitrary waveform with DMA (HAL_TIM_DMABurst_MultiWriteStart).

How should be configured the DMA ?

Is there an example that use PWM with DMA on STM32U5 ?

8 REPLIES 8
Saket_Om
ST Employee

Hello @nicolas 

Please refer to the application note AN4776 to generate arbitrary waveform with DMA.

Also see the article below:

Custom Signal generation using PWM and DMA - STMicroelectronics Community

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.
Saket_Om

Thanks for the reply. I have already looked at this document but it's old (2019) so it doesn't account of the new GPDMA found in STM32U5. It also directly access register instead of using the HAL (does ST recommend to not use HAL ?).

The article also don't use GPDMA.

I'm now able to use HAL_TIM_PWM_Start_DMA() with GPDMA configured with SrcDataWidth = DMA_SRC_DATAWIDTH_BYTE;

But it's only works with byte, so it's very limitative for a 16 bits timer.

I'm now able to use HAL_TIM_DMABurst_MultiWriteStart with full resolution.

For working with 32 bits data, GPDMA need to have DataAlignment = DMA_DATA_PACK;

DataLength of HAL_TIM_DMABurst_MultiWriteStart should be in byte length.

I still have a problem with ARR value that are shifted (first portion use 2nd ARR value ...)

NodeConfig.NodeType = DMA_GPDMA_LINEAR_NODE;
NodeConfig.Init.Request = GPDMA1_REQUEST_TIM1_UP;
NodeConfig.Init.BlkHWRequest = DMA_BREQ_SINGLE_BURST;
NodeConfig.Init.Direction = DMA_MEMORY_TO_PERIPH;
NodeConfig.Init.SrcInc = DMA_SINC_INCREMENTED;
NodeConfig.Init.DestInc = DMA_DINC_FIXED;
NodeConfig.Init.SrcDataWidth = DMA_SRC_DATAWIDTH_BYTE;
NodeConfig.Init.DestDataWidth = DMA_DEST_DATAWIDTH_WORD;
NodeConfig.Init.SrcBurstLength = 1;
NodeConfig.Init.DestBurstLength = 1;
NodeConfig.Init.TransferAllocatedPort = DMA_SRC_ALLOCATED_PORT0|DMA_DEST_ALLOCATED_PORT0;
NodeConfig.Init.TransferEventMode = DMA_TCEM_BLOCK_TRANSFER;
NodeConfig.Init.Mode = DMA_NORMAL;
NodeConfig.TriggerConfig.TriggerPolarity = DMA_TRIG_POLARITY_MASKED;
NodeConfig.DataHandlingConfig.DataExchange = DMA_EXCHANGE_NONE;
NodeConfig.DataHandlingConfig.DataAlignment = DMA_DATA_PACK;

Hello @nicolas 

Could you share your code please ?

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.
Saket_Om

Here is my project, ioc is not up to date.

It use PE9 on Nucleo U575.

Hello @nicolas 

Could you please check the status of the update event flag before starting the DMA brust. 

 

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.
Saket_Om

UIF is set after calling HAL_TIM_PWM_Start() and before HAL_TIM_DMABurst_MultiWriteStart()