[SOLVED] FreeRTOS Problem -> "Assert failed"

Firmware/software/electronics/mechanics
Post Reply
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

[SOLVED] FreeRTOS Problem -> "Assert failed"

Post by Che. »

Hi everyone,

I've been trying to change my driver for a ranging system, as I was updating to the newest firmware, where the LPS is used.

In my old driver version I used to take the ressources of CPPM-Driver as my range driver.
Everything worked so far, see my previous thread.

Now I needed to change the ressources, as the old ones are now used by CPPM-system.

Indeed I changed my used Timer and GPIO-Pin, to TIM2 and PA5 as I want to capture PWM-Signals.

I changed everything according to the following graphic from the STM32-Datasheet:
Image

When firing up my firmware, I get

Code: Select all

SYS: The system resumed after watchdog timeout [WARNING]
SYS: Assert failed at src/lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c:736
from my console, though.

My code for initialising the timer and gpio follows:

Code: Select all

void pwmInit(void)		// PWM-Funktion einrichten auf PIN MOSI (PA6, Funktion in neuer Firmware für LPS auf Konflikt checken)
{
#define PWM_TIMER					TIM2
#define PWM_TIMER_RCC				RCC_APB1Periph_TIM2		
#define PWM_TIMER_CH_Init			TIM_OC1Init				
#define PWM_TIMER_CH_PreloadConfig	TIM_OC1PreloadConfig	
#define PWM_TIMER_CH_SetCompare		TIM_SetCompare1			
#define PWM_GPIO_RCC				RCC_AHB1Periph_GPIOA	
#define PWM_GPIO_PORT				GPIOA
#define PWM_GPIO_PIN				GPIO_Pin_5
#define PWM_GPIO_SOURCE				GPIO_PinSource5
#define PWM_GPIO_AF					GPIO_AF_TIM2

#define PWM_TIM_PRESCALER			(84 - 1) 

#define PWM_MIN_PPM_USEC			1150
#define PWM_MAX_PPM_USEC			1900


	// Deklarieren von Init Structures
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;	// Time Base Init structure definition
	TIM_ICInitTypeDef TIM_ICInitStructure;			// Input Capture Init structure definition
	GPIO_InitTypeDef GPIO_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;

	/*Enable clock for GPIOB*/
	RCC_AHB1PeriphClockCmd(PWM_GPIO_RCC, ENABLE);	// GPIOClock einschalten (1)
	RCC_APB1PeriphClockCmd(PWM_TIMER_RCC, ENABLE);	// TimerClock einschalten

	// Configure the GPIO to be the timer (TIM14) input [MOSI-Pin]
	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_InitStructure.GPIO_Pin = PWM_GPIO_PIN;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
	GPIO_InitStructure.GPIO_Speed = GPIO_Medium_Speed;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
	GPIO_Init(PWM_GPIO_PORT, &GPIO_InitStructure);

	GPIO_PinAFConfig(PWM_GPIO_PORT, PWM_GPIO_SOURCE, PWM_GPIO_AF);

	// Time base configuration. 1us tick.
	TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
	TIM_TimeBaseStructure.TIM_Prescaler = PWM_TIM_PRESCALER*10; //1 µS
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInit(PWM_TIMER, &TIM_TimeBaseStructure);

	// Setup input capture
	TIM_ICStructInit(&TIM_ICInitStructure);
	TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;
	TIM_ICInit(PWM_TIMER, &TIM_ICInitStructure);

	NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	captureQueue = xQueueCreate(64, sizeof(uint32_t));

	// Enables or disables the specified TIM interrupts
	TIM_ITConfig(PWM_TIMER, TIM_IT_Update | TIM_IT_CC1, ENABLE);
	// Enables or disables the specified TIM peripheral
	TIM_Cmd(PWM_TIMER, ENABLE);
}

Any thoughts on this would be very useful.

Thanks in advance!

Greets,
Che.
Last edited by Che. on Thu Apr 28, 2016 9:34 am, edited 2 times in total.
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: FreeRTOS Problem -> "Assert failed"

Post by Che. »

I think its a problem of FreeRTOS. Either the priority is set wrong, or the stack is overused by my timer.

No one has a hint?
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: FreeRTOS Problem -> "Assert failed"

Post by tobias »

Are you maybe using a queue that has not been initialized?
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: FreeRTOS Problem -> "Assert failed"

Post by Che. »

tobias wrote:Are you maybe using a queue that has not been initialized?
Hi, I initialised the queue just like in the CPPM-driver with

Code: Select all

static xQueueHandle captureQueue;
and later with

Code: Select all

captureQueue = xQueueCreate(64, sizeof(uint16_t));
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: FreeRTOS Problem -> "Assert failed"

Post by tobias »

Took a look in port.c line 736 as from the print.

Code: Select all

			
			/* The following assertion will fail if a service routine (ISR) for
			an interrupt that has been assigned a priority above
			configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API
			function.  ISR safe FreeRTOS API functions must *only* be called
			from interrupts that have been assigned a priority at or below
			configMAX_SYSCALL_INTERRUPT_PRIORITY.

			Numerically low interrupt priority numbers represent logically high
			interrupt priorities, therefore the priority of the interrupt must
			be set to a value equal to or numerically *higher* than
			configMAX_SYSCALL_INTERRUPT_PRIORITY.

			Interrupts that	use the FreeRTOS API must not be left at their
			default priority of	zero as that is the highest possible priority,
			which is guaranteed to be above configMAX_SYSCALL_INTERRUPT_PRIORITY,
			and	therefore also guaranteed to be invalid.

			FreeRTOS maintains separate thread and ISR API functions to ensure
			interrupt entry is as fast and simple as possible.

			The following links provide detailed information:
			http://www.freertos.org/RTOS-Cortex-M3-M4.html
			http://www.freertos.org/FAQHelp.html */
			configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );
Are you maybe calling a FreeRTOS function from an ISR that does not have ...FromISR or using a too high priority?
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: FreeRTOS Problem -> "Assert failed"

Post by Che. »

Hi, I found that greentext too and checked it.
The only ISR is my Timer9-IRQ-Handler. In this function I call xQueueSendFromISR() as only FreeRTOS function.

Here, in port.c it says
Numerically low interrupt priority numbers represent logically high interrupt priorities, therefore the priority of the interrupt must be set to a value equal to or numerically *higher* than configMAX_SYSCALL_INTERRUPT_PRIORITY.
Code in FreeRTOSConfig.h in line 110 says:

Code: Select all

//#define configMAX_SYSCALL_INTERRUPT_PRIORITY 1
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 0x5F /* equivalent to 0x05, or priority 5. */
Hence my Interrupt Priority should be equal or higher than 5.

Where can I configure this interrupt priority?

In the further code, I create a FreeRTOS-Task, which receives the xQueue to save it to a variable distance, which I am Logging with the LOGGING-Interface.

Code: Select all

void rangeTask(void)
{
	//uint32_t lastWakeTime;

	vTaskSetApplicationTaskTag(0, (void*)TASK_RANGE_ID_NBR);

	//lastWakeTime = xTaskGetTickCount();

	while(1){
		//vTaskDelayUntil(&lastWakeTime, F2T(2));
		xQueueReceive(captureQueue, &distance, 100);	//Lies aus dem Queue, immer wenn dort ein Wert auftritt, warte x(10) Ticks
	}
}
That whole code worked on the old firmware, however with little overflow-something-problems, but the rough distance-measurement worked.

When commenting out my xTaskCreate

Code: Select all

xTaskCreate(rangeTask, RANGE_TASK_NAME, RANGE_TASK_STACKSIZE, NULL, RANGE_TASK_PRI, NULL);
the code works.

RANGE_TASK_STACKSIZE I varied from configMINIMAL_STACK_SIZE to (3*configMINIMAL_STACK_SIZE) to no avail.

RANGE_TASK_PRI is set to 0 as the code in config.h line 72 says
// Task priorities. Higher number higher priority
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: FreeRTOS Problem -> "Assert failed"

Post by Che. »

Hi, I had a little bug in my code, as I did not switch the GPIO_Pinsource correctly when switching my input pin.
Second bug was indeed the priority here:

Code: Select all

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
Switching it to above 5, which means lower priority, as I understand it, did the trick.

Thanks for your help.
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: [SOLVED] FreeRTOS Problem -> "Assert failed"

Post by tobias »

I'm glad I could be of some help!
Post Reply