/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Does Primer 2 lock TIMER 3 configuration registers?

Username:     
Password:     
             

Forum

# 1   2010-11-04 12:21:44 Does Primer 2 lock TIMER 3 configuration registers?

crowse
New member
Registered: 2010-07-11
Posts: 5

Does Primer 2 lock TIMER 3 configuration registers?

Hi
I am going mad trying to get my Primer2 to output a PWM signal on PB0 (TIM3 Ch3) - which seems otherwise to be unused. The code I use works great on TIM3 channels 1 and 2 on a Primer1, so I thought that the port would be simple.

When running in the debugger, the Timer3 registers are not updated in the init section as per the Primer1, In fact, nearly all peripheral registers show as zero on the primer2.

I must be missing something.

I would appreciate any suggestions

Here is the relevant code called from Application_Ini of a new Primer2 project

thanks in advance

Chris

#include "stm32f10x_lib.h"
// need the following define to switch off TYPES declared in circle_api.h
// the lib header is in $(RKitLib)/ARM/include
#define __STM32F10x_H
//#include "stm32f10x.h"
//#include "stm32f10x_gpio.h"
//#include "stm32f10x_tim.h"

#include "circle_api.h"

void InitT3CH3PWM(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  TIM_OCInitTypeDef  TIM_OCInitStructure;
  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  uint16_t PWM1_Width = 1500;

  TIM_Cmd(TIM3, DISABLE);

  RCC_AHBPeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  RCC_AHBPeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

  GPIO_StructInit (&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // PB0
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Prescaler = 71;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0; // 72M/(0+1)=72M
  TIM_TimeBaseStructure.TIM_Period = 20000; // generates 72M/(Prescaler+1)/(ClockDivision+1)/Period)
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
// stepping to here on PRimer1, the timer registers change, on primer 2 they do not

  /* PWM1 Mode configuration */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = PWM1_Width;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OC3Init(TIM3, &TIM_OCInitStructure);

  TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);
  TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);

  /* TIM enable counter */
  TIM_Cmd(TIM3, ENABLE);

}

Offline

 

# 2   2010-11-05 09:21:22 Does Primer 2 lock TIMER 3 configuration registers?

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Does Primer 2 lock TIMER 3 configuration registers?

Hi,

It seems that your clock configuration is false :
  RCC_AHBPeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  RCC_AHBPeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

must be replaced by :

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

Each peripheral clock must be configured depending on the peripheral bus connection (AHB, APB1 or APB2) according to the "Figure 1. STM32F103xC, STM32F103xD and STM32F103xE performance line block diagram" of the STM32F103x datasheet.

Yves

Offline

 

# 3   2010-11-08 09:52:59 Does Primer 2 lock TIMER 3 configuration registers?

crowse
New member
Registered: 2010-07-11
Posts: 5

Re: Does Primer 2 lock TIMER 3 configuration registers?

Hi Yves,
Many thanks for your response, your solution worked 'RIGHT FIRST TIME'. As is so often the case its the basics that cause the most headache when they are incorrect. The brain glosses over them, assuming correctness.

Apologies for not picking up the reply earlier,I have been moving offices.

I am a bit surprised that the compiler did not pick this error up, since the AHB does not have direst acccess to the peripherals concerned. Having a higher level interface for the clocks would add portability to code should a device be defined with different internal bussing.

I guess I've spent too much time in OO wonderland and have not yet grasped all the features and functionality of the Cortex.

As an aside does the bus speed of 4872 /2436MHz refer to an internal serial bus for APB1 and APB2?

Thanks again

Chris

Offline

 

# 4   2010-11-09 08:01:02 Does Primer 2 lock TIMER 3 configuration registers?

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Does Primer 2 lock TIMER 3 configuration registers?

Hi Chris,

The compiler cannot detect this error because the syntax is correct from a C point of view, but I agree, the STM32 peripheral clock configuration is not simple !
Peripherals are connected to CPU by three internal parallel bus through bridges. Its max speeds are 72, 48 or 36 MHz depending on the max CPU clock and depending on the bus.

Take a look at the Hitex website, where you will find a goog introduction to the STM32 http://www.hitex.com/index.php?id=downl … ers-guides

Yves

Offline

 

# 5   2010-11-22 15:19:31 Does Primer 2 lock TIMER 3 configuration registers?

crowse
New member
Registered: 2010-07-11
Posts: 5

Re: Does Primer 2 lock TIMER 3 configuration registers?

Hi Yves,
Thanks. I'll take a look again, I've been  using Java for some time, and one would usually have separate enumerations for AHB and APB clock commands.

     RCC_AHBPeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

      Would throw a compile time error due to RCC_APB1Periph_TIM3 not being defined in the enumeration for this parameter to RCC_AHBPeriphClockCmd.

I suppose macro expansion simply cant get there and I must unlearn some habits :-)

regards
Chris

Offline

 

# 6   2011-07-03 09:45:34 Does Primer 2 lock TIMER 3 configuration registers?

takikolo
New member
Registered: 2010-12-20
Posts: 1

Re: Does Primer 2 lock TIMER 3 configuration registers?

Hi, I`m new in STM32 Primer2 and trying to disable PWM Pulse after a specific time.
I there any simple way to give a delay in application? Is it true that Circle OS doesn`t have delay/wait funcion?
I`ve done  loop that take the procesor time, but this in not good way, because primer can`t do anything in that time.
... and the second problem is dynamic change value of Width PWM (I haven`t change Period and any other parameters). It is possible to change this value in 'if' loop? (for exemple: if a==0 PWM_Width = 11; if a>0 PWM_Width = 18; if a<0 PWM_Width = 5; )

My code is:

#include "stm32f10x_lib.h"
#define __STM32F10x_H

#include "circle_api.h"

void PWM_out(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  TIM_OCInitTypeDef  TIM_OCInitStructure;
  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  /* PWM Width <-- Can change value dinamic? */
  uint16_t PWM1_Width = 5;


  TIM_Cmd(TIM3, DISABLE);

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

  GPIO_StructInit (&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // PB0
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Prescaler = 4999;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0; // 72M/(0+1)=72M
  TIM_TimeBaseStructure.TIM_Period = 200; // generates 72M/(Prescaler+1)/(ClockDivision+1)/Period)
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
// stepping to here on PRimer1, the timer registers change, on primer 2 they do not

  /* PWM1 Mode configuration */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = PWM1_Width;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OC3Init(TIM3, &TIM_OCInitStructure);

  TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);
  /* TIM enable counter */
  TIM_Cmd(TIM3, ENABLE);
  /* wait for 1 sec HOW???*/
  int i;
  for (i=0; i<=(2000000-1);++i);
  /* TIM disable counter */
  TIM_Cmd(TIM3, DISABLE);
     
  }


Thank you in advance.

Last edited by takikolo (2011-07-03 09:48:49)

Offline

 

Board footer