cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure DMA to change PWM frequency (led strip controlling through one-wire protocol)?

JonConesa
Associate II

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:

JonConesa_0-1705403303314.png

This is my PWM configuration:

JonConesa_1-1705403332317.png

This is my Clock configuration:

JonConesa_2-1705403353197.png

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();

 

 

 

5 REPLIES 5

Try to walk before running.

Generate a simple PWM with the TIM on given pin, first.

JW

JonConesa
Associate II

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?

JonConesa_0-1705415309308.png

 

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,

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

Hello @JonConesa 

Try using TIM1_CH3N on PB1

SarraS_0-1705931956510.png

 

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.

JonConesa
Associate II

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?

 

JonConesa_0-1706084370957.png