Quality RTOS & Embedded Software

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


Loading

DelayUntil causes hardware fault on arm cortex m4 when task function is moved into a separate c file

Posted by neicdech on February 11, 2019

Hello All, I am working on a FreeRTOS project on mcuxpresso , ksdk 2.5 and cortex m4 and at the moment, I simply want to get a task to blink an LED. The project runned without problems when the task function was defined in the main.c file. For clarity, I moved the LED task into its its own "Usertaskfunction.c" and included the "Usertaskfunction.h" in the main. Afterwards, the program will raise a hardware fault in the LED task when it calls DelayUntil(). I have tried for several days. I will appreciate help in resolving this issue. I have attached the project.

                `
                #ifdef __cplusplus

extern "C" { #endif

#include "MK22F51212.h"
#include "fsl_clock.h"
#include "clock_config.h"
#include "Defs.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "timers.h"
#include "queue.h"
#include "fsl_port.h"
#include "fsl_gpio.h"
#include "global_variable.h"
#include "user_task_functions.h"
#include "pins.h"
#include "pin_mux.h"

#ifdef cplusplus } #endif

int main () { BOARDBootClockHSRUN(); BOARDInitBootPins();

if (xTaskCreate(air_blinky, "air_blinky_A", 200, &Board_A_blinky, blinkyPriority,
	&BlinkyAhandle) == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY)
	exit(-1);


vTaskStartScheduler();

while(true);

return 0;

} `

// Below is the Header for the task function.

#ifndef USER_TASK_FUNCTIONS_H_ #define USERTASKFUNCTIONSH #include "Defs.h" #include "FreeRTOS.h" #include "task.h" #include "globalvariable.h" #include "fslgpio.h"`

void airblinky(void* blinkyparameters); void vApplicationIdleHook( void );

#endif /* USER_TASK_FUNCTIONS_H_ */`

// Below is the task functions definition

`#include "usertaskfunctions.h"

void airblinky(void* blinkyparameters) {

volatile BLINKY_param_t* 	LED 						= (BLINKY_param_t*) blinky_parameters;
char* 						Mytaskname 			 		= pcTaskGetName(NULL);
TickType_t 				 	xBlinkyLastwakeuptime 		= xTaskGetTickCount();
const TickType_t			Flash_Time 					= 100;
const TickType_t			Flash_Return_Time 			= 2000;


GPIO_PortClear(LED->GPIO, mask(LED->Pin_name)); // on

for (;;)
{

	if( isTasksuspended & (!(strcmp(Mytaskname,"air_blinky_A")) ? 0b10000000 : 0b00010000) )     // area to publish a paper on
	{
		portTICK_TYPE_ENTER_CRITICAL();

		xBlinkyLastwakeuptime = xTaskGetTickCount();
		isTasksuspended &= ( (!(strcmp(Mytaskname,"air_blinky_A"))) ? 0b01111111 : 0b11101111 ) ;

		portTICK_TYPE_EXIT_CRITICAL();
	}

	{
		GPIO_PortClear	(LED->GPIO, mask(LED->Pin_name));

		GPIO_PortToggle	(LED->GPIO, mask(LED->Pin_name));

		vTaskDelayUntil	(&xBlinkyLastwakeuptime,Flash_Time);

		GPIO_PortToggle	(LED->GPIO, mask(LED->Pin_name));

		vTaskDelayUntil	(&xBlinkyLastwakeuptime,Flash_Time);

		GPIO_PortToggle	(LED->GPIO, mask(LED->Pin_name));

		vTaskDelayUntil	(&xBlinkyLastwakeuptime,Flash_Time);

		GPIO_PortToggle	(LED->GPIO, mask(LED->Pin_name));

		vTaskDelayUntil	(&xBlinkyLastwakeuptime, Flash_Return_Time);
	}



}

`

` // Below is the header for the global variables ~~~

ifndef GLOBALVARIABLEH_
define GLOBALVARIABLEH_
include "stdint.h"
include "stddef.h"
include "FreeRTOS.h"
include "task.h"
include "semphr.h"
include "Defs.h"
include "pins.h"
include "arm_math.h"

~~~

extern uint8t isTasksuspended ; extern BLINKYparamt BoardAblinky ; extern BLINKYparamt BoardBblinky ; extern TaskHandlet BlinkyAhandle ; extern TaskHandlet BlinkyBhandle ; extern TaskHandlet MasterTaskhandle ; extern SemaphoreHandlet INTERRUPTsemphr ; extern bool ActuatorOneDetectState ; extern bool ActuatorTwoDetectState ; extern armbiquadcasddf1instf32 NoiseFilter ; extern float32t corruptdataA[Blocksize]; extern float32t corruptdataB[Blocksize]; extern float32t outputA[Blocksize] ; extern float32_t outputB[Blocksize] ;

#endif /* GLOBAL_VARIABLE_H_ */ `

// Below is my global variables

`#include "global_variable.h"

	uint8_t 							isTasksuspended 					= 	0;
	BLINKY_param_t 						Board_A_blinky 						= 	{ GPIOE, PTE1 } ;
	BLINKY_param_t 						Board_B_blinky 						= 	{ GPIOB, PTB22} ;
	TaskHandle_t 						BlinkyAhandle    					= 	NULL			;
	TaskHandle_t 						BlinkyBhandle     					= 	NULL			;
	TaskHandle_t 						MasterTaskhandle 					= 	NULL			;
	SemaphoreHandle_t 					INTERRUPT_semphr 					= 	NULL			;
	bool 								ActuatorOneDetectState 				= 	false			;
	bool 								ActuatorTwoDetectState 				= 	false			;
	arm_biquad_casd_df1_inst_f32 		NoiseFilter												;
	float32_t 							corrupt_dataA[Blocksize] 			= 	{0}				;
	float32_t 							corrupt_dataB[Blocksize] 			= 	{0}				;
	float32_t 							outputA[Blocksize] 					= 	{0}				;
	float32_t 							outputB[Blocksize] 					= 	{0}				;

`


DelayUntil causes hardware fault on arm cortex m4 when task function is moved into a separate c file

Posted by rtel on February 11, 2019

There does not seem to be anything wrong with the call to vTaskDelayUntil(). Can you try taking out the calls to GPIOPortToggle() to see if there is anything wrong with the way the parameter is being passed into the task. If you take out the GPIOPortToggle() calls then obviously the LED won't blink, but you will at least be able to see that you don't end up in the hard fault handler.

Additionally, did you try stepping into the code to see where the hard fault occurs? It might be that the vTaskDelay() is causing a context switch, and the fault actually occurs somewhere else. Inspecting the pxCurrentTCB variable (which you may have to cast to a (tskTCB*) in the debugger) will show you the name of the running task. You can also follow the instructions here: https://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html to see what that tells you. If it doesn't tell you much at first then also note the "Handling Imprecise Faults" section at the bottom of that page.


DelayUntil causes hardware fault on arm cortex m4 when task function is moved into a separate c file

Posted by neicdech on February 13, 2019

Hi Richard, thanks for the help, I have been able to find what was causing the error. I had configured the idlehooktask to call a function for which had not properly set up and that was causing the hardware fault immediately after the context switch. thanks once again


[ 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 & STM32H745 dual core (AMP) 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