cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB55 - how many concurrent timers may be provided by timer server?

Greg_
Associate II

As an example, the following code is provided, the timers are started and stopped in app_ble.c.

I can run two of the three leds using two different timers and they work properly, but when I add the third one than the leds start working in an unexpected way. I tried to find details about the concurrent work in AN5289 but I couldn't find any information. I also played a bit with periods, but this also didn't give me any clarity of the server behaviour. May I ask for some support?

OK, with some changes it works much better now :)

#include "leds_task.h"
//#include "main.h"
 
//#define PERIOD_S (1 * 1000 * 1000 / CFG_TS_TICK_VAL) //1s
//#define PERIOD_S (20 * 1000 * 1000 / CFG_TS_TICK_VAL)//20s
 
 
#define PERIOD_LED_BLUE (1 * 1000 * 1000 / CFG_TS_TICK_VAL)//1s
#define PERIOD_BLUE_LED_OFF (1 * 1000 / CFG_TS_TICK_VAL)//1ms
 
#define PERIOD_LED_GREEN (1 * 1270 * 1000 / CFG_TS_TICK_VAL)//1s
#define PERIOD_GREEN_LED_OFF (1 * 1000 / CFG_TS_TICK_VAL)//100ms
 
#define PERIOD_LED_RED (5 * 1000 * 1000 / CFG_TS_TICK_VAL)//1s
#define PERIOD_RED_LED_OFF (1 * 1000 / CFG_TS_TICK_VAL)//500ms
 
  uint8_t LEDSTimerId_BLUE_LED_R;
  uint8_t LEDSTimerId_BLUE_LED;
 
  uint8_t LEDSTimerId_GREEN_LED_R;
  uint8_t LEDSTimerId_GREEN_LED;
 
  uint8_t LEDSTimerId_RED_LED_R;
  uint8_t LEDSTimerId_RED_LED;
 
 
 
  void RegisterLED_BLUE(void)
  {
    HW_TS_Create(CFG_TIM_LED_BLUE, &LEDSTimerId_BLUE_LED_R, hw_ts_Repeated, TIM_SW_LED_BLUE);//creating repeated timer for blue led blinking period
    HW_TS_Start (LEDSTimerId_BLUE_LED_R, PERIOD_LED_BLUE);//starting the timer for blue led blinking period
  }
 
  void RegisterLED_GREEN(void)
  {
    HW_TS_Create(CFG_TIM_LED_GREEN, &LEDSTimerId_GREEN_LED_R, hw_ts_Repeated, TIM_SW_LED_GREEN);//creating repeated timer for green led blinking period
    HW_TS_Start (LEDSTimerId_GREEN_LED_R, PERIOD_LED_GREEN);//starting the timer for green led blinking period
  }
 
  void RegisterLED_RED(void)
  {
    HW_TS_Create(CFG_TIM_LED_RED, &LEDSTimerId_RED_LED_R, hw_ts_Repeated, TIM_SW_LED_RED);//creating repeated timer for red led blinking period
    HW_TS_Start (LEDSTimerId_RED_LED_R, PERIOD_LED_RED);//starting the timer for red led blinking period
  }
 
 
 
  void TIM_SW_LED_BLUE(void)
  {
	HW_TS_Create(CFG_TIM_LED_BLUE_OFF, &LEDSTimerId_BLUE_LED, hw_ts_SingleShot, BLUE_LED_OFF);//creating single shot timer for blue led blinking ratio
  	HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, SET);
  	HW_TS_Start (LEDSTimerId_BLUE_LED, PERIOD_BLUE_LED_OFF);//starting the timer
  }
 
  void TIM_SW_LED_GREEN(void)
  {
	HW_TS_Create(CFG_TIM_LED_GREEN_OFF, &LEDSTimerId_GREEN_LED, hw_ts_SingleShot, GREEN_LED_OFF);//creating single shot timer for green led blinking ratio
  	HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, SET);
  	HW_TS_Start (LEDSTimerId_GREEN_LED, PERIOD_GREEN_LED_OFF);//starting the timer
  }
 
  void TIM_SW_LED_RED(void)
  {
	HW_TS_Create(CFG_TIM_LED_RED_OFF, &LEDSTimerId_RED_LED, hw_ts_SingleShot, RED_LED_OFF);//creating single shot timer for red led blinking ratio
  	HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, SET);
  	HW_TS_Start (LEDSTimerId_RED_LED, PERIOD_RED_LED_OFF);//starting the timer
  }
 
 
 
  void BLUE_LED_OFF(void)
{
    HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, RESET);
    HW_TS_Delete(LEDSTimerId_BLUE_LED);
}
 
  void GREEN_LED_OFF(void)
{
    HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, RESET);
    HW_TS_Delete(LEDSTimerId_GREEN_LED);
}
 
  void RED_LED_OFF(void)
{
    HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, RESET);
    HW_TS_Delete(LEDSTimerId_RED_LED);
}
 
 
void LEDS_START(void)
{
	RegisterLED_BLUE();
	RegisterLED_GREEN();
	RegisterLED_RED();
}
 
void LEDS_STOP(void)
{
    HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, RESET);
	HW_TS_Delete(LEDSTimerId_BLUE_LED_R);
    HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, RESET);
	HW_TS_Delete(LEDSTimerId_GREEN_LED_R);
    HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, RESET);
	HW_TS_Delete(LEDSTimerId_RED_LED_R);
}
 
 
 
void LEDS_ON(void)
{
    HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, SET);
    HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, SET);
    HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, SET);
}
 
void LEDS_OFF(void)
{
    HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, RESET);
    HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, RESET);
    HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, RESET);
}

1 REPLY 1
Remi QUINTIN
ST Employee

Max numbers of timers is 255.