How to configure DMA to change PWM frequency (led strip controlling through one-wire protocol)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-16 3:22 AM
Hi! I am configuring DMA to generate a PWM signal to control addressable LEDs with an STM32563VGTx MCU.
My issue arises when generating the PWM signal using DMA. When calling the "HAL_TIM_PWM_Start_DMA" function, it executes without any errors, and the finished callback is triggered, indicating the completion of the data transmission. However, i am not able to see the data displayed on the logical analyzer.
I have verified the signal generated with a logic analyzer, and at all times, the signal remains at 0. I believe the error is not so much in the code but in the configuration of DMA and PWM.
Thanks for your help.
This is my GPDMA configuration:
This is my PWM configuration:
This is my Clock configuration:
Main code:
void HMILed_create(uint8_t numLEDs,TIM_HandleTypeDef *htim,uint32_t channel_timer, DMA_HandleTypeDef *hdma)
{
CEXCEPTION_T e;
Try
{
if (numLEDs == 0 || htim == NULL || hdma == NULL || (channel_timer != TIM_CHANNEL_1 && channel_timer != TIM_CHANNEL_2 && channel_timer != TIM_CHANNEL_3 && channel_timer != TIM_CHANNEL_4))
{
Throw(EMBL_WRONGPARAMS);
}
theHMILed.numLEDs = numLEDs;
theHMILed.htim = htim;
theHMILed.hdma = hdma;
theHMILed.channel_timer = channel_timer;
}
Catch(e)
{
Throw(e);
}
}
void Send_LEDs (void)
{
HAL_TIM_PWM_Start_DMA(theHMILed.htim, theHMILed.channel_timer, (uint32_t *)pwmData, 434);
while (!theHMILed.datasentflag){};
theHMILed.datasentflag = 0;
}
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
{
HAL_TIM_PWM_Stop_DMA(theHMILed.htim, theHMILed.channel_timer);
theHMILed.datasentflag=1;
}
Setup:
HMILed_create(16,&htim3,TIM_CHANNEL_4, &handle_GPDMA2_Channel1);
Set_LEDs(RED);
Send_LEDs();
- Labels:
-
DMA
-
STM32H5 Series
-
TIM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-16 5:31 AM
Try to walk before running.
Generate a simple PWM with the TIM on given pin, first.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-16 6:28 AM
hello,
I have tried to test PWM on pin PB1 (TIM3 CHANNEL4) and PWM is not generated. With the same configuration, PWM works on pin PD15 (TIM4 CHANNEL4). The ST configuration allows me to set it up, but could it be that this pin does not support PWM?
With pin PD15, where I have been able to configure PWM successfully, DMA still does not work. What could be the cause of this?
ty,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-16 8:03 AM
What hardware is this, a "known good" board like Nucleo, or your own?
Try setting PB1 to GPIO Out and toggle "manually".
If that works and PWM does not, read out and check/post content of TIM and relevant GPIO registers.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-22 6:07 AM
Hello @JonConesa
Try using TIM1_CH3N on PB1
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-24 12:23 AM
I'm sorry for taking so long to respond.
I have a custom board with the STM32F563VGTx MCU. That's why I chose Timer 3 CHANNEL4, as it turned out to be the most suitable option for routing. Furthermore, when testing Timer 5, it worked correctly in generating PWM through DMA. Is it possible that I can only generate DMA with Timers 2 and 5?
