FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [January 2009 Threads] gcc optimisation freertos and all thatPosted by kurator on January 15, 2009 Hi, I got hit by a very strange GCC/FreeRTOS problem. In a task I check the return value of a function like this:
int ret;
if( xQueueReceive(QueueMain, &Event, portMAX_DELAY) == pdTRUE ) switch(Event.id) { case EV_KEY_MENU_OK: ret = menu_descend(); if( ret != 0 ) {............
Using this code the system hangs after returning from menu_descend()! The program gets stuck in xQueueReceive() in an endless loop of xTaskResumeAll(). There is a while loop: while( ( pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xPendingReadyList ) ) ) != NULL )
As there is an portENTER_CRITICAL() in the beginning of that routine there interrupts are disabled, the os tick is no longer called.
But, when I declare ret as volatile volatile int ret; the program runs as expected!
Looking at the assembler code shows: Without volatile:
blmenu_descend cmpr0, #0 beq.L123
With volatile:
blmenu_descend strr0, [sp, #84] ldrr3, [sp, #84] cmpr3, #0 beq.L123
So it looks like that storing the return value on the stack and using r3 for comparison against zero saves my program from getting stuck.
From here I only can guess. Maybe gcc tricks itself by the assumption that there lies a return value of the function on stack, but optimisation uses r0 for handover directly instead, and from there on the stack pointer is one position to low?
Or has it to do with register treatment of freertos, especially register r0?
I use freertos version 3.2 ( because thats what the project started with and I'm not allowed to upgrade ;-) It's a port for the STR7 ARM7 from ST. gcc is arm-elf-gcc 4.2.2 optimization level is 2
All that really frightens me! I must use optimization, at least for size, as the code got to big.
What goes wrong here?
RE: gcc optimisation freertos and all thatPosted by Dave on January 15, 2009 Wow, that is an old version.
Could you post more of the function? The snippet you posted has brackets missing, I'm guessing this is just a typo on your part.
Getting stuck in loops like that is normally a sign of memory corruption occurring somewhere. The most likely cause of which is a stack overflow. Unfortunately the version you are using does not have the stack traps in it.
RE: gcc optimisation freertos and all thatPosted by kurator on January 15, 2009 the missing bracket is just a typo I sampled the code together, there is much more between the queuereceive and the switch I forgot that spaces and tabs got eaten up here the stack looks good to me everything works fine when I change to volatile, so....
RE: gcc optimisation freertos and all thatPosted by kurator on January 19, 2009 juhuu,
no ideas around? I know its an old FreeRTOS version but maybe someone stumbled over something similar?
RE: gcc optimisation freertos and all thatPosted by Rainer Bittendorf on January 13, 2012 Hi kurator,
I have a problem similar to yours. I am using gcc 4.3.3 and FreeRTOS 6.0.4 on Atmel AT91SAM7S. Everythins seems to work fine but from time to time the return value of 'cComReceiveChar ()' is lost and 'vReadLine ()' receives '\0' instead. The functions are located in different modules. The problem is dependent on optimization level: With -O3 and -O2 it occurs, with -O1 or without optimization it doesn't. I checked stack sizes and found that there's space left on every stack I use. With better optimizations I found that variables are placed in registers - so memory location overwrites are improbable. The return value is returned in r0 (as in your code).
portCHAR cComReceiveChar (portBASE_TYPE xComIndex) { portCHAR cReceived;
switch (xComIndex) { case 0: xQueueReceive (xCom0Receive, & cReceived, portMAX_DELAY); break; case 1: xQueueReceive (xCom1Receive, & cReceived, portMAX_DELAY); break; default: cReceived = '\0'; break; } return (cReceived); } /* cComReceiveChar () */
static void vReadLine (portCHAR *pcLine, portBASE_TYPE xMaxChars, portBASE_TYPE xComIndex, portCHAR cTerm) { portBASE_TYPE xIndex = 0; portCHAR cCom;
do { cCom = cComReceiveChar (xComIndex); pcLine [xIndex++] = cCom; } while ((pcLine [xIndex - 1] != cTerm) && (xIndex < xMaxChars));
...
} /* vReadLine () */
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|