Jump to content

ufgx + freertos + ufgx


Waylander

Recommended Posts

can someone suggest a proper way to use mutex in freertos to share an lcd bus between display and touch driver?

This variant of aquire_bus function does not work properly (calibration screen only fills with color, but no text is drawn).

while (xSemaphoreTake(lcdBusMutex, MUTEX_DELAY) != pdTRUE) {
	gfxYield();
}

Without mutex and empty touch driver calibration screen is drawn fully. Seems like inside ugfx something goes wrong because of tasks being paused by freertos (because of failed mutex take) or something like this.

Link to comment
Share on other sites

nothing is working neither with freertos mutex nor with ugfx's one.

currently i've tested completely empty touch driver (even no mutex usage) and a display driver that uses mutexes. and calibration screen is drawn without text. if i remove mutex usage from display driver (touch driver still empty), calibreation screen is drawn fully. this is insane! two function calls just break everything!

and most interesting thing that gui works fine (at least it draws fine), buttons and labels.

Link to comment
Share on other sites

i tried debugging the code and now i know what is the cause. when ugfx comes to a moment to draw the text on calibration screen, display driver calls aquire_bus as 4 times before this moment but after calling gfxMutexTake MCU goes into infinite loop.

it actually fails in queue.c in this code block:

line 1444/* Check to see if other tasks are blocked waiting to give the
semaphore, and if so, unblock the highest priority such task. */
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
{
  if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) // this is the last line executed
  {
    queueYIELD_IF_USING_PREEMPTION();
  }
  else
  {
    mtCOVERAGE_TEST_MARKER();
  }

wtf is going on? i'm too newbie to understand..

this function above calls this block of code in tasks.c

line 3000 /*This function assumes that a check has already been made to ensure that
pxEventList is not empty. */
pxUnblockedTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );
configASSERT( pxUnblockedTCB );
( void ) uxListRemove( &( pxUnblockedTCB->xEventListItem ) ); // fails here

why it removes something, while it is supposed just to take mutex?

and this last line goes into list.c and calls this line of code:

List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer;

and just after this it goes into infinite loop. i think it is some sort of exception, but i don't know which. where can i look for a type? but freertos's hooks for malloc_failed and stackoverlow do not get called, but they should be called if this occurs, right?

i've looked at this pxItemToRemove in the debugger and all the fields of this struct are zeroes, so it means this pointer is pointing into wrong memory area? but why???

Edited by Waylander
Link to comment
Share on other sites

1. This sort of thing is deep in the FreeRTOS code so really has nothing to do with uGFX. If #2 below fails you will need to seek help from the FreeRTOS forums.

2. Where you might be coming unstuck is if your main thread stack is too small. Again this is a FreeRTOS setting. What gives this indication is your comment on something pointing to the wrong memory area.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...