cancel
Showing results for 
Search instead for 
Did you mean: 

STM32W Timer interrupt after x milliseconds [SOLVED] SimpleMAC 1.1.0 / 2.0.0 inside

fixmetal
Associate II
Posted on June 29, 2012 at 10:21

Hello everybody. I'm looking to find the proper way to achieve this: I need an interrupt to be invoked every x [ms] in my software.

I'm working with a Dizic MB851 Rev. A board. I found on the datasheet the NVIC description to activate the TIM1 (or TIM2) interrupt, but I can't understand how to make the GPTimers really work. How do I set their clock? How do I set their prescaler (and therefore their timing for the update event)?

Thanks in advance.

Simone

*UPDATE: I solved the problem. Have a look at my post below

#stm32w-timer-interrupt-event #stm32w-interrupt-handler-tim1
9 REPLIES 9
frankmeyer9
Associate II
Posted on June 29, 2012 at 10:45

I need an interrupt to be invoked every x [ms] in my software.

 

In this case, I would focus on the SysTick timer.

It is part of the core, thus available in all derivates, and had been especially designed for this purpose. If you do a search, there are dozens of examples around.

I would reserve peripheral timers for there special purposes. They have often other periphery attached, i.e. can trigger PWM, CCP, ADC, DAC, etc.

fixmetal
Associate II
Posted on June 29, 2012 at 12:52

Thanks a lot for your fast reply.

I can't seem to find any infos to use the systick and handling its interrupt correctly into the SimpleMAC library.

There's just a few timer handling functions, such as those included in the system_timer.h library, which are:

  (void)

  Initializes the system tick.

  (void)

  Returns the current system time in system ticks, as a 16-bit value.

  (void)

  Returns the current system time in system ticks, as a 32-bit value.

  (void)

  Returns the current system time in quarter second ticks, as a 16-bit value.

The simply initializes the Systick (kicking it for counting).

Plus, I actually need 2 different timings in my application:

1 interrupt once a minute (60seconds)

1 interrupt every 15 milliseconds

IN the STM32W108CBU6 datasheet I found thhis quote:

Event timer

The SysTick timer is an ARM® standard system timer in the NVIC. The SysTick timer can be clocked from either the FCLK (the clock going into the CPU) or the Sleep Timer clock. FCLK is either the SCLK or PCLK as selected by CPU_CLK_SEL (see Section 6.3.5: Clock switching on page 43).

No infos on how to set the Systick to be used on your desire though.

I found that it should be linked to the ST_CSR register. I found the defines of this register in the regs.h library, which are:

#define     *((volatile *)0xE000E010u)

#define     *((volatile *)0xE000E010u)

#define     (0xE000E010u)

#define     (0x00000000u)

#define     (0x00010000u)

#define     (0x00010000u)

#define     (16)

#define     (1)

#define     (0x00000004u)

#define     (0x00000004u)

#define     (2)

#define     (1)

#define     (0x00000002u)

#define     (0x00000002u)

#define     (1)

#define     (1)

#define     (0x00000001u)

#define     (0x00000001u)

#define     (0)

#define     (1)

That's all. I digged a while in the forum for examples, as you stated, but I just found STM32F related code, which is not useful for me, as I'm using STM32W SimpleMAC library. Documentation is pretty scarse, examples are even worse...

Could you help me?

Thanks.

Best,

Simone
frankmeyer9
Associate II
Posted on June 29, 2012 at 13:25

The magic keyword is CMSIS.

You may look for the SysTick_Config() function, which is located core_cm<n>.h, so core_cm0.h or core_cm3.h for Cortex M0 and M3, respectively.

In ST's Peripheral_Driver firmware, there is an explicit example for the SysTick use under

STM32<xxx>_FW_V<n.n>/Project/Peripheral_Examples/Systick.

I never messed with STM32W yet. There should be the CMSIS files, too.

fixmetal
Associate II
Posted on July 15, 2012 at 22:48

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6lI&d=%2Fa%2F0X0000000bun%2Fp9zeNX4gJUSqMR6gtTCbmYa6qraYVMEXGNlNVnKv1v0&asPdf=false
lucabe90
Associate II
Posted on September 19, 2012 at 13:02

hi

i'am a university student.i read your problem and i have a similirar case.

i have to configure a Sleep Timer.

Do you have an idea to configure a sleep timer?

thanks 

Luca

fixmetal
Associate II
Posted on November 25, 2012 at 15:06

I'm sorry for replying you this late. I don't lurk around the forum so much, just when I need it.

As I've seen, sleep timer INT functions are already overridden for deep sleep achievement. You can't use it for your own purpose. You can however add up your own code in the sleep timer INT function, if that's just what you're looking for.

p.s. anche io sono Italiano.

fixmetal
Associate II
Posted on December 06, 2012 at 09:49

Since the release of SimpleMAC 2.0.0 RC1, I've decided to update this post.

MB851 rev.A seems not to work correctly with this new firmware. They just don't reply to UART commands (no rx but they do tx).

Anyway, since this 2.0.0 included standard libraries templates for handling the hardware + the usual HAL thing for the wireless related modules, standard timebase TIM initialization goes like this:

  TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;

  NVIC_InitTypeDef Init;

  TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInitStruct.TIM_Prescaler = 5;

  TIM_TimeBaseInitStruct.TIM_Period = 375;

  TIM_TimeBaseInit(TIM1,&TIM_TimeBaseInitStruct);

  TIM_PrescalerConfig(TIM1, 5, TIM_PSCReloadMode_Immediate);

  TIM_ITConfig(TIM1_IT, TIM_IT_Update, ENABLE);

  TIM_UpdateRequestConfig(TIM1, TIM_UpdateSource_Global);

  TIM_UpdateDisableConfig(TIM1, DISABLE);

  TIM_Cmd(TIM1, ENABLE);

  Init.NVIC_IRQChannel = TIM1_IRQn;

  Init.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&Init);

This example sets TIM1 to standard priority, prescaler set @ 32 (2^5) and ARR (Period) @ 375. That means the TIM1 generates an update event every 1ms.

Best,

Simone
fixmetal
Associate II
Posted on December 12, 2012 at 19:41

Just to update this post a bit:

It seems that since SimpleMAC 1.1.0 they updated something in the TIM INT handling. In the previous version, enabling the TIM would have created an update event just for that.

In 2.0.0 this bug seems to be disappeared.

Anyway I'd like to highlight the fact that sometime these boards do just start up with HSI rather than HSE clock source. Seems a random issue.

To avoid the thing (since I was using TIM setup guessing PCLK=12MHz), I used this little code immediatly after halInit() call:

  //Check that HSE (Crystal) is being used

  if(CLK_GetClocksFreq() != 0x03)

  {

     //Forces crystal to be used in case it is not

     CLK_DeInit();

     CLK_Config(CLK_MODE3);

  }

CLK_MODE3 corresponds to HSE (XTAL) usage (24MHz main clock, PCLK= 12MHz therefore).

Best.

fixmetal
Associate II
Posted on January 17, 2013 at 14:24

I found another issue.

You have to set up all your interrupts and THEN call the INTERRUPTS_ON() macro.

Doint it the other way around will (surely) make TIMs do a trap. I don't have any experience about the same issue on other int handlers though.

Hope this will help some guys out there.