Program Hang in xEventGroupSetBits (STM32F407 using Cube)

ab-infodev wrote on Tuesday, 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;
   HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_14);  //For testing purposes
   xHigherPriorityTaskWoken = pdFALSE;
   ucTest = xEventGroupSetBitsFromISR(eghtasktrig,( const EventBits_t)0x4,&xHigherPriorityTaskWoken);
   if(ucTest != pdFAIL)

Here is my Task:

void tPingScanningTask(void *pvParameters)
 char i;
 BaseType_t ucScanOn = 0;
  int  iTestFlag;
 eghtasktrig = xEventGroupCreate(); 
  if(ucScanOn == 0)
    ucScanOn = xEventGroupWaitBits(eghtasktrig,(const EventBits_t)FLAG_TICKER,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 & eventEVENT_BITS_CONTROL_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;

#define configUSE_PREEMPTION                     1
#define configUSE_IDLE_HOOK                      0
#define configUSE_TICK_HOOK                      0
#define configCPU_CLOCK_HZ                       ( SystemCoreClock )
#define configTICK_RATE_HZ                       ((TickType_t)1000)
#define configMAX_PRIORITIES                     ( 7 )
#define configMINIMAL_STACK_SIZE                 ((uint16_t)128)
#define configTOTAL_HEAP_SIZE                    ((size_t)15360)
#define configMAX_TASK_NAME_LEN                  ( 16 )
#define configUSE_TRACE_FACILITY                 1
#define configUSE_16_BIT_TICKS                   0
#define configUSE_MUTEXES                        1
#define configQUEUE_REGISTRY_SIZE                8

#define configUSE_QUEUE_SETS                     0
#define configUSE_TIME_SLICING                   0 
#define configUSE_TIMERS                         1
#define configTIMER_TASK_PRIORITY                6 
#define configTIMER_QUEUE_LENGTH                 10
#define configTIMER_TASK_STACK_DEPTH             7
#define configIDLE_SHOULD_YIELD                  0

/* Co-routine definitions. */
#define configUSE_CO_ROUTINES                    0
#define configMAX_CO_ROUTINE_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. */
 /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
 #define configPRIO_BITS         __NVIC_PRIO_BITS
 #define configPRIO_BITS         4

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

/* 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
PRIORITY THAN THIS! (higher priorities are lower numeric values. */

/* 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. */
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See */

/* 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( ;; );} 

/* 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 SysTick_Handler defined within STM32Cube HAL */
/* #define xPortSysTickHandler SysTick_Handler */

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

Help would be very much apreciated


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

rtel wrote on Tuesday, February 28, 2017:

configTIMER_TASK_STACK_DEPTH is set incorrectly. It needs to be set to
at least configMINIMAL_STACK_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

ab-infodev wrote on Tuesday, February 28, 2017:

Thank you that solved my problem !