Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

FreeRTOS software timer not working

Posted by anupshamanur on June 29, 2017

Hey guys I am Anup and i am a student. I am new to freeRTOS concepts. I am using STM32F407VGTx board and i want to implement Software Timers to blink the LEDs using Keil software. I am creating the software timer and then I am starting the timer. As per the concepts the software timer should call the callback function as soon as the timer has expired but this is not happening with my code. I have pasted my main.c and the software timer configurations in freeRTOSconfig.h below. Do see that and tell me what I am doing wrong soon. Thanks in advance.

#include "stm32f4xx_hal.h"
#include "cmsis_os.h"
osThreadId defaultTaskHandle;
osTimerId mytimerHandle;
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
void StartDefaultTask(void const * argument);
void myfn(TimerHandle_t mytimer);
TimerHandle_t mytimer = NULL;
int main(void)
{
	printf("dsfsdfsdfsd");
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
  osKernelStart();
  while (1)
  {
  }
}
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
}
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct;
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
  GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}




void StartDefaultTask(void const * argument)
{
**     vTaskStartScheduler();
	 mytimer = xTimerCreate( "Timer" , pdMS_TO_TICKS( 500 ) ,pdTRUE, "123" , myfn);
	 xTimerStart( mytimer, 0);**
}

**/* myfn Callaback function */
void myfn(TimerHandle_t mytimer)
{
	HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12|GPIO_PIN_14|GPIO_PIN_15);
}**




void Error_Handler(void)
{
  while(1) 
  {
  }
}

void assert_failed(uint8_t* file, uint32_t line)
{
}





/* Software timer definitions. */
**#define configUSE_TIMERS  **                               1
**#define configTIMER_TASK_PRIORITY**                ( configMAX_PRIORITIES - 1 )
**#define configTIMER_QUEUE_LENGTH  **              10
**#define configTIMER_TASK_STACK_DEPTH**         256


FreeRTOS software timer not working

Posted by rtel on June 29, 2017

This is very hard to answer as you are not using the native FreeRTOS API. I don't know what osThreadDef() is doing, but a quick Google search would seem to indicate it is defined as:

#define osThreadDef	(	 	name,
  	priority,
  	instances,
  	stacksz
)		

You are calling:

osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);

so it seems you are setting the priority to StartDefaultTask.

These are not FreeRTOS APIs though, so falls outside of FreeRTOS support.

I cannot see defaultTask being defined anywhere. Is it just a name? Is StartDefaultTask support to be the actual task? If so then it needs to be implemented as described here: http://www.freertos.org/implementing-a-FreeRTOS-task.html


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS