cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F207G-Nucleo TIM_DMA example sets the repeat count for a timer that doesn't have a repetition counter???

Mike Katz
Associate II
Posted on November 07, 2017 at 20:11

The following is a code snippet from the

STMCubeF2\Projects\STM32F207ZG-Nucleo\Examples\TIM\TIM_DMA\Src\main.c file:

  TimHandle.Instance               = TIMx;   TimHandle.Init.Period            = uwTimerPeriod;   TimHandle.Init.RepetitionCounter =

3

;   TimHandle.Init.Prescaler         =

0

;   TimHandle.Init.ClockDivision     =

0

;   TimHandle.Init.CounterMode       = TIM_COUNTERMODE_UP;   TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;  

if

(

HAL_TIM_PWM_Init

(&TimHandle) != HAL_OK)  

{

   

/* Initialization Error */

   

Error_Handler

();  

}

STMCubeF2\Projects\STM32F207ZG-Nucleo\Examples\TIM\TIM_DMA\Inc\main.h file contains:

/* Definition of TIM instance */

&sharpdefine

TIMx                             TIM3

This example is using timer 3.  However, according to RM0033 Refernce manual(STM32F205xx, STM32F207xx, STM32F215xx and STM32F217xx

advanced ARM-based 32-bit MCUs) the STM32F207 only has Repetition Counter for the advanced timers 1 and 8.

Am I missing something?

Also, this example does not do any setup of DMA prior to calling HAL_TIM_PWM_Start_DMA(). 

How does this function know which Timer 3 register to write to?

I ported this example to Timer 1 using STM32CubeMx and the duty cycle does not change as in the example.

#stm32f207-nucleo-repitition-count-timer-timers-pwm-duty
3 REPLIES 3
Posted on November 09, 2017 at 01:10

This example is using timer 3.  However, according to RM0033 Refernce manual(STM32F205xx, STM32F207xx, STM32F215xx and STM32F217xx

advanced ARM-based 32-bit MCUs) the STM32F207 only has Repetition Counter for the advanced timers 1 and 8.

I don't Cube but it's probably just some copy/paste code and that field gets ignored when the struct is used.

JW

Posted on November 09, 2017 at 18:08

The problem is that the repeat counter functionality is required for this example to work.  In other words this example will not work, as written, for this processor.

It just serves as an example of how frustrating it can be to try to use the tools provided by ST Micro to accomplish simple things.

Thanks for your feedback

Posted on November 10, 2017 at 00:20

The problem is that the repeat counter functionality is required for this example to work.

I looked at the same example for 'F446 Nucleo144 (as I don't intend to litter my PC with another half a gig of the 'F2 Cube, and I believe they just copy/paste/minimal-adjust the examples) and IMO no, repeat counter is not needed.

Contrary: as HAL_TIM_PWM_ConfigChannel() used to set up the compare sets the preload enable, in advanced timers with repetition - as it is set to the same 3 as the number of DMA items - given only every 3rd timer cycle sees the update event thus loads the 'live' compare register from the 'shadow', you'll never see change in the PWM duty cycle - and indeed, that's what you experience.

Also, this example does not do any setup of DMA prior to calling HAL_TIM_PWM_Start_DMA(). 

HAL_TIM_PWM_Init()   calls HAL_TIM_PWM_MspInit() which is in stm32f4xx_hal_msp.c and contains (part of) the DMA initialization. The rest of DMA initialization - including setting NDTR to 3 - happens in HAL_TIM_PWM_Start_DMA(), where also the target address (the CC register) is set.

JW