vTaskDelay() Leading into hardfault

Hi,

I’m working on a STM32 based board and got: main tasks and TouchGFX task running. I’m using a queue to communicate between both tasks and it works just fine most of the time but when I put one specific command into the queue and call vTasksDelay() right after it falls into a HardFault.

I’ve tracked down a little more in detail and the fault happens when in prvAddCurrentTaskToDelayedList() the values inside pxCurrentTCB->xStateListItem aren’t correct, so when it goes into uxListRemove() just crashes.

This is my call to put data in the queue, it works with all the other commands, there’s nothing different that I can spot.

	ScrHandler_Typedef dataX = {
			.OpCode = Refresh,
			.d 		= 0,
			.f 		= 0,
			.s 		= {0},
			.posX  = 0
	};

	xQueueSend(DSPmessageQ, &dataX, 0);

I’m trying to understand why the values of xStateListItem are pointing out of the ram address. Where are these meant to be set?

Regards,
Diego B

It seems like a memory corruption. Have you defined configASSERT and enabled stack overflow checking? This page has helpful information - FreeRTOS - Open Source RTOS Kernel for small embedded systems

I’m using the stack overflow checking and asserts but none are kicking out.

Using CHECK_FOR_STACK_OVERFLOW option2 and also checking the usage with uxTaskGetStackHighWaterMark(NULL) on each task.

I’ve tried though increasing the stack of all the tasks, and still have the same issue.

Is there any other way to check what’s corrupting the memory?

Regards,
Diego B

Apparently there is. I was using variable arguments as an input of the function and when those arguments were NULL vsprintf() would corrupt the memory.

It works fine now, thanks for the help!

void DSP_Alert(uint8_t action, const char *fmt, ...){

	ScrHandler_Typedef dataX = {
			.OpCode = Alert,
			.d 		= action,
			.f 		= 0,
			.s 		= {0},
			.posX	= 0
	};

	if(fmt != NULL){
		va_list arg;

		va_start (arg, fmt);
		vsprintf(dataX.s, fmt, arg);
		va_end (arg);
	}

	if( xQueueSend(DSPmessageQ, &dataX,  0) != pdPASS ){
		/* Handle Error */
	}

	if(!action){
		DSP_RefreshScreen();
	}
}

Thank you taking time to report back.