FreeRTOS gets stuck at prvTaskExitError()

rohirto wrote on Monday, September 19, 2016:

Hello all,
I’m new to FreeRTOS. Im currently working with ST32F072RB Discovery board. I integrated the FreeRTOS with my test code. Im not using CubeMx, HAL library or Std Peripheral Lib. When running the code, it gets stuck at prvTaskExitError(). Here is my code

int main()
{
	//Set priority of SYSTick
	NVIC_EnableIRQ(SysTick_IRQn);
	NVIC_SetPriority(SysTick_IRQn, 3);
	/* Clock checkin code **********************************************************************/
	//Clock checking
  coreClock_1 = SystemCoreClock;                /* Store value of predefined SystemCoreClock */
  SystemCoreClockUpdate();                      /* Update SystemCoreClock according to register settings */
  coreClock_2 = SystemCoreClock;                /* Store value of calculated SystemCoreClock */
  if (coreClock_2 != coreClock_1) 
	{            
		/* Without changing the clock setting both core clock values should be the same */ 
    // Error Handling
  }
	//returnCode = SysTick_Config(SystemCoreClock / 1000);      /* Configure SysTick to generate an interrupt every millisecond */
	/********************************************************************************************/
	
	/* Initialization ***************************************************************************/
	GPIO_Init();
	UART1_Init();
	UART_HandleInit(&huart);
	ADC1_Init();
	
	/* Debug purpose  */
	if(DEBUG == 1)
	{
		printf("UART1 test string \r\n");
		printf("This is sample ADC code \r\n");
		printf("ADC1 used			 USART1 used		\r\n");
		
	}
	printf("INITILIZATION DONE \r\n");
	
	RTOS();
	while(1)
	{
		
	}
	
	
}


void RTOS()
{
	xTaskCreate(vTaskFunction1, "Task 1", 128, NULL, 2, NULL);
	
	vTaskStartScheduler();
	
	while(1)
	{
	}
}

/* Implementation of vTaskFunction----------------------------------------*/
void vTaskFunction1( void *pvParameters)
{
	//Start the ADC conversion
		ADC1_Start();
		
		printf("ADC Value: %d \r\n",ADC_Value);
		//Get the conversion value
		onTime = ADC_Value;
		
		//PWM code
		offTime = 4096 - onTime;
		GPIOC->BSRR |= 0x0040;      //Set Red LED
		
		for(i = 0; i < onTime; i++)
		{
		__ASM("nop");
		}
		GPIOC->BRR |= 0x0040;      //Reset Red LED
		for(i = 0; i < offTime; i++)
		{
		__ASM("nop");
		}
		
}

Here is my FreeRTOSConfig.h

/* Ensure stdint is only used by the compiler, and not the assembler. */
#ifdef __CC_ARM
	#include <stdint.h>
	extern uint32_t SystemCoreClock;
#endif

#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			( 5 )
#define configMINIMAL_STACK_SIZE		( ( unsigned short ) 60 )
#define configTOTAL_HEAP_SIZE			( ( size_t ) ( 6500 ) )
#define configMAX_TASK_NAME_LEN			( 5 )
#define configUSE_TRACE_FACILITY		1
#define configUSE_16_BIT_TICKS			0
#define configIDLE_SHOULD_YIELD			1
#define configUSE_MUTEXES				1
#define configQUEUE_REGISTRY_SIZE		8
//#define configCHECK_FOR_STACK_OVERFLOW	2
#define configUSE_RECURSIVE_MUTEXES		1
//#define configUSE_MALLOC_FAILED_HOOK	1
#define configUSE_APPLICATION_TASK_TAG	0
#define configUSE_COUNTING_SEMAPHORES	1
#define configGENERATE_RUN_TIME_STATS	0

/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 			0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )

/* Software timer definitions. */
//#define configUSE_TIMERS				1
//#define configTIMER_TASK_PRIORITY		( 2 )
//#define configTIMER_QUEUE_LENGTH		5
//#define configTIMER_TASK_STACK_DEPTH	( 80 )

/* 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	1
#define INCLUDE_vTaskSuspend			1
#define INCLUDE_vTaskDelayUntil			1
#define INCLUDE_vTaskDelay				1

/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names - or at least those used in the unmodified vector table. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler

The code gets stuck here, in port.c (indicated by >>)

static void prvTaskExitError( void )
{
	/* A function that implements a task must not exit or attempt to return to
	its caller as there is nothing to return to.  If a task wants to exit it
	should instead call vTaskDelete( NULL ).

	Artificially force an assert() to be triggered if configASSERT() is
	defined, then stop here so application writers can catch the error. */
	>>configASSERT( uxCriticalNesting == ~0UL );
	portDISABLE_INTERRUPTS();
	for( ;; );
}

Im also using ADC1 and USART1 Interrupts. Both have priority 0.

On Serial port im getting the output

UART1 test string
This is sample ADC code
ADC1 used USART1 used
INITILIZATION DONE
ADC Value: 0

The task is not running repeatedly.

rtel wrote on Monday, September 19, 2016:

Unfortunately there is a lot wrong with this code. The first place to start would probably be the following link, so you can see how to structure a task:
http://www.freertos.org/implementing-a-FreeRTOS-task.html

After that the following links might help:
http://www.freertos.org/FreeRTOS-quick-start-guide.html
http://www.freertos.org/Creating-a-new-FreeRTOS-project.html