cancel
Showing results for 
Search instead for 
Did you mean: 

Important question about advanced timer complementary pwm and strange things in HAL

VGold
Associate II

Hi everyone!

After AVR mcus STM32 with Cube and HAL is like an oasis in the desert! But after many experiments, researches and sleepless nights I know the situation isn't so great as I thought.

I have few boards with 100, 103, 407 and other series.

I'm generating new project using cube for STM32F103C8T6 mcu. Selected options are: 72MHz freq, TIM1 in PWM+PWMN mode on first channel, DMA transmits pulse durations from array to channel, empty main loop. Working in KEIL uVision 5, HAL drivers.

So here we have some miracles:

  1. Why do we need to create an uint32_t word array of future PWM pulse values if our register is only uint16_t HALF WORD? HAL_TIM_PWM_START_DMA accepts 32-bit pointer to pData buffer but ST wrote this way in Cube examples using whole word array of values. Why? Is this correct?
  2. Sometimes I need to make a zero-filled pulse, I mean empty pulse. So if i'm using DMA with counting UP timer, it's working, but if i'm switching it to center-aligned mode it's working ONLY if there are no zero values in buffer. This is very strange.

PWM and DMA STOPS AT ALL if pulse was written zero value.

BUT it's working fine without DMA!

uint16_t Values[3] = {0, 1000, 2000}; //works only with UP counting timer
uint16_t Values2[3] = {1, 1000, 2000}; //also works on center-aligned UP-DOWN counting timer
 
//... Initialization code ARR = 4999
 
HAL_TIM_PWM_START_DMA(&htim1, TIM_CHANNEL_1, (uint32_t*)&Values, sizeof(Values) );
//working
 
HAL_TIMEx_PWMN_START_DMA(&htim1, TIM_CHANNEL_1, (uint32_t*)&Values, sizeof(Values) );
//doesn't working

I dug all documentatin and forums i found and have found no answer. Somebody answered that we need to use WORD size variables, while somebody discovered that DMA copies first (lower) part of word WITH value and by second transaction copies ZEROES (second, higher part). Where is the truth?

Maybe somebody have some appnotes describing HOW TO work with this HAL step by step (NOT the cube help document that desribes only function itself) i.e. how to START timers, conversions, transmissions PROPERLY. Yes, i'm talking about HAL, not about datasheets with tonns of registers only.

Thanks a lot!

0 REPLIES 0