2022-08-31 02:01 PM
I have a timer + dma which outputs a signal for addressable LEDS. The code calls the PWM Start function on a crude timer loop for testing purposes.
The first time the DMS starts, its perfect, and the output is correct and as expected. However the second, and subsequent times it executes, the first few cycles are incorrect.
Ive removed the boilerplate comments etc for brevity.
int timer = 0;
while (1)
{
if (timer >= 9000000) {
timer = 0;
HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t *)pwmData, sizeof(pwmData));
while (!datasentflag){};
datasentflag = 0;
}
timer++;
}
The first output of the signal is correct as shown in the scope screenshot here...
The second output of the signal is not correct.
There is no change to the pwmData array during the execution, so i would not expect the output to change.
Any ideas on why this could be happening?
2022-09-01 11:08 AM
I think, that start /stopping DMA is a bad idea in general. Likely jam / congestion of the data flow happens due to very complex processes involved, init FIFO, triggers, data busses schedulers etc. The better option would be to start DMA with timer only ones, than inside dma_transfer _complete stop a Master clock - another timer, that generates clock for your PWM engine. All it takes is to link two timers. Since master would not be directly interact with DMA, it can be initialised, reset, re-started whenever you like.
2022-09-01 03:41 PM
Register-based implementation here. Needs the augmented header from here.
It's for 'L4 as I don't have a 'F3 at hand at the moment - probably the largest difference is, that the 'L4 has a CSELR register selecting the trigger to given DMA channel and 'F3 - quite surprisingly, honestly, given it's contemporary to 'F0 which does have it - does not, it has the older and simpler plain fixed OR. So just remove that line and change the DMA channel to the one which is connected to TIM1_UP (it appears to be Channel 5 from reading RM0316).
JW
2022-09-04 08:36 AM
As Tesla already said, datasentflag variable must be volatile.
2022-11-25 04:31 AM
@samsamm777 , any progress/findings on this?
JW