Quality RTOS & Embedded Software

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


Loading

vTaskDelay doesn't return and Timers not running

Posted by tobisf on June 6, 2018

Hi,

I'm trying to set up my first project with FreeRTOS. I want to run it on a STM32L0, for the first tests a NUCLEO-L031K6 using Keil ┬ÁVision 5.

I included the FreeRTOS by adding FreeRTOS/source, FreeRTOS/soruce/include and FreeRTOS/source/portable/RVDS/ARM_CM0 directorys to the include path and the files to the project. I took the FreeTROSConfig.h from an generated project.

To get into FreeRTOS, the first thing I wanted to implement is just one task what does some periodic UART printouts. For creating a delay between the printouts, first I used a simple Loop and it worked. Second I wanted to use vTaskDelay, but it seems that it never returns. After that I wanted to create a Timer to achive a delay between printouts, but the Timer Callback is never called.

Since I don't took my task to sleep, I thought maybe it's a priority problem. But the TimerTask is running at priority 6 and my task at priority 2.

Another strange thing was, when I switched from a STM32L011 to a STM32L031 (because of memory issues), I did not got the error that the SysTick_Handler is defined multiple times. So is this maybe a problem that some SysTick in FreeRTOS is not running correctly?

How can I check if everything is running correctly?

Here is my code:

main.c ~~~ [Auto Generated Config Code] UartTask_init();

/* Start the scheduler so the demo tasks start to execute. */
vTaskStartScheduler();

/* USER CODE END 2 */

/* Infinite loop / / USER CODE BEGIN WHILE */ while (1) [Empty Loop] ~~~

UartTask.c ~~~

include "UartTask.h"

// STM Includes

include "stm32l0xx_hal.h"
include "usart.h"

/* Scheduler include files. */

include "FreeRTOS.h"
include "task.h"
include "queue.h"
include "semphr.h"
include "event_groups.h"
include "timers.h"
include "assert.h"

/* ---------- Timers ---------- */ static TimerHandlet timerHandle = NULL; static StaticTimert timer;

static volatile bool timerFlag = false;

/* ---------- Task Variables ---------- */

/* The priority at which the task that performs the tests is created. */

define UARTTASKPRIORITY (tskIDLE_PRIORITY + 2)

/* The size of the stack used by the task that runs the tests. */

define UARTTASKSTACK_SIZE (256)

/* StaticTaskt is a publicly accessible structure that has the same size and alignment requirements as the real TCB structure. It is provided as a mechanism for applications to know the size of the TCB (which is dependent on the architecture and configuration file settings) without breaking the strict data hiding policy by exposing the real TCB. This StaticTaskt variable is passed into the xTaskCreateStatic() function that creates the prvStaticallyAllocatedCreator() task, and will hold the TCB of the created tasks. / static StaticTask_t uartTaskTCBBuffer; / This is the stack that will be used by the prvStaticallyAllocatedCreator() task, which is itself created using statically allocated buffers (so without any dynamic memory allocation). */ static StackTypet uartTaskStackBuffer[UARTTASKSTACKSIZE];

/* ---------- Private Function Declarations ----------- */

static void task_function(void *pvParameters);

/* ---------- Callback Declarations ---------- */

static void timerCallback(TimerHandle_t xTimer);

/* ---------- Public Function ---------- */

void UartTask_init(void) { timerHandle = NULL; timerFlag = false;

timerHandle = xTimerCreateStatic(
							/* Just a text name. Not used by the RTOS kernel. */
            "UartTimer",
							/* The timer period, in ticks. Must be greater than 0. */
							pdMS_TO_TICKS(2000),
            /* The timers will auto-reload themselves when they expire. */
            pdTRUE,
            /* The ID*/
            (void*)0,
            /* Each timer calls the same callback when it expires. */
            timerCallback,
            /* Pass in the address of a StaticTimer_t variable, which will hold the data associated with the timer being created. */
            &timer);

if(timerHandle == NULL)
	_Error_Handler(__FILE__, __LINE__);

/* Create a single task, which then repeatedly creates and deletes the other
	 RTOS objects using both statically and dynamically allocated RAM. */
xTaskCreateStatic(task_function,								/* The function that implements the task being created. */
									"UartTask",										/* Text name for the task - not used by the RTOS, its just to assist debugging. */
									UART_TASK_STACK_SIZE,					/* Size of the buffer passed in as the stack - in words, not bytes! */
									NULL,													/* Parameter passed into the task - not used in this case. */
									UART_TASK_PRIORITY,						/* Priority of the task. */
									&(uartTaskStackBuffer[0]),		/* The buffer to use as the task's stack. */
									&uartTaskTCBBuffer );					/* The variable that will hold the task's TCB. */

}

/* ----------- Private Functions ---------- */

static void task_function(void pvParameters) { / Avoid compiler warnings. */ (void)pvParameters; volatile int foo = 0;

if (xTimerStart(timerHandle, 0) == pdFAIL)
	foo++; // Code does not reach here, so xTimerStart does NOT return pdFAIL

while (true)
{
	/* ------ With Timer ------ */
	if (timerFlag)
	{
		timerFlag = false;
		HAL_UART_Transmit(&huart2, (uint8_t*)"Timer\n", 6, 1000);
	}

	/* ----- With Delay ------ */

// HALUARTTransmit(&huart2, (uint8t*)"Delayn", 6, 1000); // vTaskDelay(pdMSTO_TICKS(1000));

	/* ----- With DelayLoop ----- */

// HALStatusTypeDef status = HALUARTTransmit(&huart2, (uint8t*)"Loopn", 5, 1000); // while (foo < 1000000) // foo++; // foo = 0; } }

/* ---------- Callbacks ---------- */

static void timerCallback(TimerHandle_t xTimer) { timerFlag = true; } ~~~

FreeRTOSConfig.h ~~~ /* FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. All rights reserved

VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.

This file is part of the FreeRTOS distribution.

FreeRTOS is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License (version 2) as published by the
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.

***************************************************************************
>>!   NOTE: The modification to the GPL is included to allow you to     !<<
>>!   distribute a combined work that includes FreeRTOS without being   !<<
>>!   obliged to provide the source code for proprietary components     !<<
>>!   outside of the FreeRTOS kernel.                                   !<<
***************************************************************************

FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  Full license text is available on the following
link: http://www.freertos.org/a00114.html

***************************************************************************
 *                                                                       *
 *    FreeRTOS provides completely free yet professionally developed,    *
 *    robust, strictly quality controlled, supported, and cross          *
 *    platform software that is more than just the market leader, it     *
 *    is the industry's de facto standard.                               *
 *                                                                       *
 *    Help yourself get started quickly while simultaneously helping     *
 *    to support the FreeRTOS project by purchasing a FreeRTOS           *
 *    tutorial book, reference manual, or both:                          *
 *    http://www.FreeRTOS.org/Documentation                              *
 *                                                                       *
***************************************************************************

http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
the FAQ page "My application does not run, what could be wrong?".  Have you
defined configASSERT()?

http://www.FreeRTOS.org/support - In return for receiving this top quality
embedded software for free we request you assist our global community by
participating in the support forum.

http://www.FreeRTOS.org/training - Investing in training allows your team to
be as productive as possible as early as possible.  Now you can receive
FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
Ltd, and the world's leading authority on the world's leading RTOS.

http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
compatible FAT file system, and our tiny thread aware UDP/IP stack.

http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.

http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
licenses offer ticketed support, indemnification and commercial middleware.

http://www.SafeRTOS.com - High Integrity Systems also provide a safety
engineered and independently SIL3 certified version for use in safety and
mission critical applications that require provable dependability.

1 tab == 4 spaces!

*/

ifndef FREERTOSCONFIGH
define FREERTOSCONFIGH

/----------------------------------------------------------- * Application specific definitions. * * These definitions should be adjusted for your particular hardware and * application requirements. * * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. * * See http://www.freertos.org/a00110.html. *----------------------------------------------------------/

/* USER CODE BEGIN Includes /
/ Section where include file can be added / / USER CODE END Includes */

/* Ensure stdint is only used by the compiler, and not the assembler. */

if defined(ICCARM) || defined(CC_ARM) || defined(GNUC__)
#include <stdint.h>
#include "main.h" 
extern uint32_t SystemCoreClock;
endif
define configUSE_PREEMPTION 1
define configSUPPORTSTATICALLOCATION 1
define configSUPPORTDYNAMICALLOCATION 0
define configUSEIDLEHOOK 0
define configUSETICKHOOK 0
define configCPUCLOCKHZ ( SystemCoreClock )
define configTICKRATEHZ ((TickType_t)1000)
define configMAX_PRIORITIES ( 7 )
define configMINIMALSTACKSIZE ((uint16_t)64)
define configMAXTASKNAME_LEN ( 16 )
define configUSE16BIT_TICKS 0
define configUSE_MUTEXES 1
define configQUEUEREGISTRYSIZE 8

/* Co-routine definitions. */

define configUSECOROUTINES 0
define configMAXCOROUTINE_PRIORITIES ( 2 )

/* Software timer definitions. */

define configUSE_TIMERS 1

//#define configTIMERTASKPRIORITY ( 2 )

define configTIMERTASKPRIORITY ( configMAX_PRIORITIES - 1 )
define configTIMERQUEUELENGTH 16
define configTIMERTASKSTACK_DEPTH 128

/* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */

define INCLUDE_vTaskPrioritySet 1
define INCLUDE_uxTaskPriorityGet 1
define INCLUDE_vTaskDelete 1
define INCLUDE_vTaskCleanUpResources 0
define INCLUDE_vTaskSuspend 1
define INCLUDE_vTaskDelayUntil 0
define INCLUDE_vTaskDelay 1
define INCLUDE_xTaskGetSchedulerState 1

/* Cortex-M specific definitions. */

ifdef _NVICPRIO_BITS

/* _BVICPRIOBITS will be specified when CMSIS is being used. */ #define configPRIOBITS _NVICPRIO_BITS

else

#define configPRIO_BITS 2

endif

/* The lowest interrupt priority that can be used in a call to a "set priority" function. */

define configLIBRARYLOWESTINTERRUPT_PRIORITY 3

/* The highest interrupt priority that can be used by any interrupt service routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER PRIORITY THAN THIS! (higher priorities are lower numeric values. */

define configLIBRARYMAXSYSCALLINTERRUPTPRIORITY 3

/* Interrupt priorities used by the kernel port layer itself. These are generic to all Cortex-M ports, and do not rely on any particular library functions. */

define configKERNELINTERRUPTPRIORITY ( configLIBRARYLOWESTINTERRUPTPRIORITY << (8 - configPRIOBITS) )

/* !!!! configMAXSYSCALLINTERRUPT_PRIORITY must not be set to zero !!!! See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */

define configMAXSYSCALLINTERRUPTPRIORITY ( configLIBRARYMAXSYSCALLINTERRUPTPRIORITY << (8 - configPRIOBITS) )

/* Normal assert() semantics without relying on the provision of an assert.h header file. / / USER CODE BEGIN 1 */

define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}

/* USER CODE END 1 */

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS standard names. */

define vPortSVCHandler SVC_Handler
define xPortPendSVHandler PendSV_Handler

/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware, to prevent overwriting SysTickHandler defined within STM32Cube HAL / / #define xPortSysTickHandler SysTickHandler */

/* USER CODE BEGIN Defines /
/ Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) / / USER CODE END Defines */

endif /* FREERTOSCONFIGH */

~~~


vTaskDelay doesn't return and Timers not running

Posted by rtel on June 6, 2018

In the first case it sounds like the tick interrupt is not executing - which probably just means its not installed. if the tick count is not incrementing then as far as the kernel is concerned time is standing still and no timeouts will even expire. See the 'special note for ARM Cortex-M users' in the first Q on this page of the FAQ: https://www.freertos.org/FAQHelp.html


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


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

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo & Nuvoton Cortex-M23 demo.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Mediatek

Renesas

RISC-V

SiFIve RISC-V

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

Xilinx Microblaze and Zynq partner