2024-07-31 11:26 PM - edited 2024-08-01 12:07 AM
I am trying to use DMA with PWM data on STM32 I need clarification on few parameters setting and facing few issues.
Q1.
While configuring DMA for PWM data in tha CUBE MX, there is a option for increment Address and selector for Peripheral or Memory.
What does it mean?
Q2. What does Use FIFO option means, if turned on
Q3. Data Width selector, there are options for byte, Half word and Word. Does that means it will transfer that amount of data at each DMA transfer?
NEXT TOPIC
It works fine when PWM is started manually with a single CCR1 value
TIM1->CCR1 = 10;
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
Q3.while using DMA to transfer an array of 16 bit data to the PWM register with the DMA configuration of data width selected to half word, as we will be sending 16 bit data to CCR register of PWM channels, when i am starting a DMA transfer of array of size 10 i see total garbage
/* USER CODE BEGIN 0 */
uint16_t pwmdata[10] = { 12, 15, 20, 30, 40, 50, 60, 70, 80, 90 };
/* USER CODE END 0 */
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t*) pwmdata, 10);
/* USER CODE END 2 */
DMA SETTING
OUTPUT DATA
it is in the normal mode, but I see some continuous garbage via logic analyzer
After that just changing the DMA setting to the circular mode, it works fine and when put it into normal mode it starts printing garbage.
Can you please suggest where i am missing some configuration or where i am doing something wrong.
2024-08-01 05:54 AM
> While configuring DMA for PWM data in tha CUBE MX, there is a option for increment Address and selector for Peripheral or Memory.
> What does it mean?
After a transfer, the DMA can increment the memory and/or peripheral address. If you are transferring from an array to a peripheral register, you should increment the memory address but not the peripheral address.
> Q2. What does Use FIFO option means, if turned on
The DMA has a FIFO, this option will enable it.
Generally, you should use the FIFO but for simple cases like this it doesn't really matter if you do or don't. The reference manual describes the FIFO and its behavior.
> Q3. Data Width selector, there are options for byte, Half word and Word. Does that means it will transfer that amount of data at each DMA transfer?
Yes. Since your array is uint16_t, you should select half-word.
> Next Q3:
Looks like a duty cycle of 90 to me, which is the last entry in your array. Why do you think this is garbage?