Quality RTOS & Embedded Software

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




Loading

freeRTOS xQueueReceive gives HardFault in LPC1769.

Posted by dmh3006 on June 16, 2015

Hi.

I have a queue between 2 tasks in which one writes certain commands to it and the other reads it (one is an application, the other is the task responsible for the display).

The tasks App sends a command to the task Display. Everything works well and it does as desired. After this the task Display waits for 5 seconds for a new command, if none is received it switches the display off and waits indefinitely for a new command on the queue.

This last part is where my program crashes as it "immediately" (I can't determine the exact time but as soon as I do a step over in debug it goes to the HardFault_Handler).

I check my main task App data structure and its values remain correct. I cast the xQueueHandle to xQUEUE * and its values are also correct (I'm only checking its length value and size of each item value).

The issue seems to be the xQueueReceived line after a command has been given.

However I've verified the code and I'm unable to find any fault whatsoever with it.

Both tasks are allocated 2KB of ram which do not even come close to fully using (the task App consumes the most ram and uses at most 640bytes) so I've ruled out stack overflow.

The task App has a priority of tskIDLEPRIORITY and the task Display has a priority of tskIDLEPRIORITY+2.

[CODE] void taskDisplay(xQueueHandle queue) { bool previousCommand = false; uint16t color; portTickType time = configTICKRATEHZ * TIMETODISPLAYOFF; DisplayCommand command; signed portBASETYPE queueResult; for (;;){ queueResult = xQueueReceive(queue,(void *)&command,previousCommand ? time : portMAXDELAY); if (queueResult == errQUEUEEMPTY){ DisplayBacklight(false); previousCommand = false; } else { switch (command.command){ case DISPLAYON: DisplayWriteStr(command.DisplayOnData.lineTemps,font6x8,DISPLAYONFIRSTLINE,FOREGROUNDCOLOR,BACKGROUNDCOLOR); DisplayWriteStr(command.DisplayOnData.lineDate,font6x8,DISPLAYONSECONDLINE,FOREGROUNDCOLOR,BACKGROUNDCOLOR); DisplayBacklight(true); previousCommand = true; break; case DISPLAYWRITELINE: DisplayClearLine(command.DisplayWriteLineData.line,font6x8); DisplayWriteStr(command.DisplayWriteLineData.lineText,font6x8,command.DisplayWriteLineData.line,FOREGROUNDCOLOR,BACKGROUNDCOLOR); DisplayBacklight(true); strncpy(internalBuffer[command.DisplayWriteLineData.line-1],command.DisplayWriteLineData.lineText,NUMCHARPERLINE); previousCommand = false; break; case DISPLAYHIGHLIGHTLINE: color = command.DisplayHighlightLineData.highlight ? HIGHLIGHTCOLOR : BACKGROUNDCOLOR; if (command.DisplayHighlightLineData.useInternalBuffer){ DisplayWriteStr(internalBuffer[command.DisplayHighlightLineData.line-1],font6x8,command.DisplayHighlightLineData.line,FOREGROUNDCOLOR,color); } else { DisplayWriteStr(command.DisplayHighlightLineData.lineText,font6x8,command.DisplayHighlightLineData.line,FOREGROUNDCOLOR,color); strncpy(internalBuffer[command.DisplayHighlightLineData.line-1],command.DisplayHighlightLineData.lineText,NUMCHARPERLINE); } previousCommand = false; break; case DISPLAYCLEAR: DisplayBacklight(command.DisplayClearData.turnOffDisplay); if (command.DisplayClearData.firstLineToClear == 1 && command.DisplayClearData.lastLineToClear == 16){ DisplayClear(BACKGROUNDCOLOR); } else { for (int i = command.DisplayClearData.firstLineToClear; i <= command.DisplayClearData.lastLineToClear; i++){ DisplayClearLine(i,font6x8); } } previousCommand = false; break; } } } } [/CODE]


freeRTOS xQueueReceive gives HardFault in LPC1769.

Posted by rtel on June 16, 2015

So the crash occurs after after the call to xQueueReceive() times out? When it times out the next function is executes is DisplayBacklight( false ); - did you put a break point on that and step into that function to see if it completes correctly? After that it should call xQueueReceive() again with portMAXDELAY, so you can continue stepping through the code and go into that function to see if everything is correct there too (check parameters, etc.).

Do you have configASSERT() defined?

The following page may also help: http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html

When you created the queue - did you get the parameters in the call to xQueueCreate() the right way around - so every space in the queue can hold sizeof( DisplayCommand ) bytes?


freeRTOS xQueueReceive gives HardFault in LPC1769.

Posted by dmh3006 on June 16, 2015
My apologies for my delay in answering.

No, the crash occurs after the xQueueReceive times out, it runs the DisplayBacklight(false) executes and when the xQueueReceive is called with the portMAX_DELAY time it crashes there.

The DisplayBacklight(false) executes and finishes correctly as the desired effect on the screen occurs and the function has been tested outside of the freeRTOS environment(it really just sends a command through the SPI interface and sets a GPIO pin to "0").

configASSERT() is not defined as I'm unsure how to define it since I see it in many freeRTOS functions.

I'm not allowed to write any kind of code proposed in the link until the teacher signs off on it (it's a crazy rule).

I've casted the xQueueHandle to a xQUEUE * and looked inside it and and the basic parameters seem to be right (the length of the queue and the size of each element). I've also made sure the queue is correct my verifying the heap space before and after the queue creation and the value of heap after the queue creation corresponds to the expected value (136 bytes for the queue structure and the 400 bytes for the actual buffer, 10 elements, each with a size of 40 bytes).

I've also checked that the following function, when it loads whats on the address given on the first assembly instruction, it's value is 0. (the ldr r0,[r0] instruction actually loads the 0 value to r0 which means the second time it runs that same instruction I have no idea what its actually putting in r0)

static void prvPortStartFirstTask( void ) { __asm volatile( " ldr r0, =0xE000ED08 n" /* Use the NVIC offset register to locate the stack. / / Loads 0 to the r0 register --> / " ldr r0, [r0] n" " ldr r0, [r0] n" " msr msp, r0 n" / Set the msp back to the start of the stack. / " cpsie i n" / Globally enable interrupts. / " svc 0 n" / System call to start first task. */ " nop n" ); }


freeRTOS xQueueReceive gives HardFault in LPC1769.

Posted by rtel on June 17, 2015

I would recommend defining configASSERT() before debugging any further, as it may catch the problem for you. It is best to start with the assert defined on any new project. In its simplest form you can just add:

#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }

into FreeRTOSConfig.h. That will stop the code on a line that fails an assert, so when you pause the debugger, you will see which line failed.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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