Quality RTOS & Embedded Software

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




Loading

Program Hang in xEventGroupSetBits (STM32F407 using Cube)

Posted by ab-infodev on February 28, 2017

Hi I am a beginner with Free RTOS

I am using the STM32F407 which is configured with the cube. Free RTOS version is v8.2.3. I am using IAR version 7.70.1

I have a simple program as my first experiment on Free RTOS.

Basically I have a hardware timer that acts as a ticker.Around every 15ms the timer overruns and trigs an interrupt. Said interrupt enables a flag in a group event .(Of course since I enable this flag in a ISR I am using xEventGroupSetBitsFromISR())Then my only task ,which is blocked on the same flag that the ticker enables, gets unblocked and clears the flag in the event group.

Here is my timer interrupt callback: ~~~ if (htim->Instance == TIM2) { ucTest = 0;

HALGPIOTogglePin(GPIOB,GPIOPIN14); //For testing purposes

xHigherPriorityTaskWoken = pdFALSE; ucTest = xEventGroupSetBitsFromISR(eghtasktrig,( const EventBits_t)0x4,&xHigherPriorityTaskWoken);

if(ucTest != pdFAIL) { portYIELDFROMISR(xHigherPriorityTaskWoken); } } ~~~ Here is my Task: ~~~ void tPingScanningTask(void *pvParameters) { char i; BaseType_t ucScanOn = 0; int iTestFlag;

eghtasktrig = xEventGroupCreate();

for(;;) { if(ucScanOn == 0) { ucScanOn = xEventGroupWaitBits(eghtasktrig,(const EventBitst)FLAGTICKER,pdTRUE,pdTRUE,portMAX_DELAY);

ucScanOn &= 0x04; } if(ucScanOn != 0) { //Planning to do an action each time the ticker trigs this task here ucScanOn = 0; } } vTaskDelete( NULL ); }

~~~ My problem is that ,when running the debugger, the program hangs in xEventGroupSetBits() More precisly it hangs on: configASSERT(( uxBitsToSet & eventEVENTBITSCONTROL_BYTES ) == 0); At first i thought I simply had input a wrong variable as uxBitsToSet but on closer inspection it seems that the program runs 3 times past this ASSERT without any issues but on its 4th try it doesnt pass the ASSERT.

What I know is that the programs hangs when it exits the interrupt and when the Daemon task preempts the os to execute the EventGroupSetBits (resquested in the ISR).On the three first tries uxBitsToSet keeps the value that I had set to in the timer callback,which in this case is 0x04, and succesfully unblocks the task, but when i look at its value on the 4th try ,in the debugger, its now at 0xAC8. The the program hangs on the ASSERT mentionned before.

The Daemon task does have the highest priority amongst all my tasks.

Can the Daemon task change uxBitsToSet value ? Is it possible that another interrupt overwrites data and accidentally writes to the adress of uxBitsToSet ? Thus changing its value.

I have tried to enable the flag using the none-ISR fonction xEventGroupSetBits() and I've had no issues. Which tells me I probably have an ISR conflict. The only other interrupt that I have is for Timer 14 which is enabled and used by the HAL as a timebase but that is all configured by the cube. I have looked at the Event group demo and compared to my code and haven't found major differences. I have checked my configuration file multiples times and havent found any issues.(Considering I am a beginner there is a good chance that I overlooked something)

Here is my Free RTOS config : ~~~ * Ensure stdint is only used by the compiler, and not the assembler. */

if defined(ICCARM) || defined(CC_ARM) || defined(GNUC__)
#include <stdint.h>
#include "mxconstants.h" 
extern uint32_t SystemCoreClock;
endif
define configUSE_PREEMPTION 1
define configUSEIDLEHOOK 0
define configUSETICKHOOK 0
define configCPUCLOCKHZ ( SystemCoreClock )
define configTICKRATEHZ ((TickType_t)1000)
define configMAX_PRIORITIES ( 7 )
define configMINIMALSTACKSIZE ((uint16_t)128)
define configTOTALHEAPSIZE ((size_t)15360)
define configMAXTASKNAME_LEN ( 16 )
define configUSETRACEFACILITY 1
define configUSE16BIT_TICKS 0
define configUSE_MUTEXES 1
define configQUEUEREGISTRYSIZE 8
define configUSEQUEUESETS 0
define configUSETIMESLICING 0
define configUSE_TIMERS 1
define configTIMERTASKPRIORITY 6
define configTIMERQUEUELENGTH 10
define configTIMERTASKSTACK_DEPTH 7
define configIDLESHOULDYIELD 0

/* Co-routine definitions. */

define configUSECOROUTINES 0
define configMAXCOROUTINE_PRIORITIES ( 2 )

/* 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
define INCLUDE_xTimerPendFunctionCall 1
define INCLUDE_xEventGroupSetBitFromISR 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 4

endif

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

define configLIBRARYLOWESTINTERRUPT_PRIORITY 15

/* 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 5

/* 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 */

~~~

Help would be very much apreciated

-Andy

ps:My appologies if there are any english mistakes this is my 2nd language :)


Program Hang in xEventGroupSetBits (STM32F407 using Cube)

Posted by rtel on February 28, 2017

configTIMERTASKSTACKDEPTH is set incorrectly. It needs to be set to at least configMINIMALSTACK_SIZE. With a value of 7 it will overflow the task stack immediately - and it was just luck that you got three execution cycles without any problems.

I would recommend turning stack overflow detection on. See http://www.freertos.org/Stacks-and-stack-overflow-checking.html


Program Hang in xEventGroupSetBits (STM32F407 using Cube)

Posted by ab-infodev on February 28, 2017

Thank you that solved my problem !

-Andy


[ 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