cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H750 DMA cannot generate PWM

Ray G
Associate

I am trying to use the DMA of the STM32H750 to generate a specific PWM, but it does not output any waves.

HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_4);
__HAL_TIM_SET_COMPARE(&htim2,TIM_CHANNEL_4,50);

This is the code that usually generates pwm, it works, I can see pwm on the logic analyzer.

0690X00000AAEG0QAP.png

But if I use DMA, it will not output anything.

uint16_t buffer[10]={0};
buffer[0]=50;
buffer[1]=50;
buffer[2]=50;
 
HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_4, (uint32_t *)buffer, 10);
while(HAL_TIM_PWM_GetState(&htim2) != HAL_TIM_STATE_READY);
// HAL_TIM_PWM_GetState will get HAL_TIM_STATE_READY

It will get...

0690X00000AAEG5QAP.png

I passed the debugger and found that it fell into TIM_DMAError.

0690X00000AAEGAQA5.png

I observed that the value of ErrorCode for HDMA becomes 1, which is defined in stm32h7xx_hal_dma.h as

...
#define HAL_DMA_ERROR_TE              (0x00000001U)    /*!< Transfer error */
...

How can I solve this problem? I used the same code in STM32F042 and it works.

My cubemx configuration

Clock

0690X00000AAEGFQA5.png

TIM

0690X00000AAEGKQA5.png

DMA

0690X00000AAEGPQA5.png

Linker Strrings(default value)0690X00000AAEGUQA5.png

3 REPLIES 3

Pretty sure TIM2 is 32-bit wide, should use array of 32-bit ints, DMA to TIM is likely at 32-bit already, but then your CCRx > ARR, ie 0x00320032

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thank you for your reply.

I changed the buffer array to uint32_t. Then set the DMA data width to 32-bit(Word).

Try again.DMA still doesn't work, ErrorCode is still 1.TIM seems to work fine, I can see that CNT is changing.

0690X00000AAEHwQAP.png

Isn't the memory where buffer variable lies, unaccessible to the DMA you've chosen?

JW