cancel
Showing results for 
Search instead for 
Did you mean: 

Suspending TouchGFX_Task thread when using two or more different FreeRTOS threads

EmiM
Associate

I'm trying to run two threads when using TouchGFX. One is TouchGFX_Task and another is custom. Problem is that custom task requires about 30ms uninterrupted run.

Problem is that running two tasks - one is interrupted which causes issues. If TouchGFX_Task is higher priority - screen works ok, but communication with external device is interrupted in another task. If TouchGFX_Task is lower priority - screen freezes and becomes unresponsive.

Tried suspending and resuming TouchGFX_Task with osThreadSuspend() and osThreadResume() but it just stops updating screen (just like with changing priority, tried with commented/uncommented versions)

Changed Preemptive mode to Cooperative in FreeRTOS configuration but did not help.

Considering trying to use semaphores and/or mutexes however I'm unsure how to proceed with TouchGFX_Task to stop it so no issues arise when suspending and resuming task.

Or maybe there is a better way to achieve something like this when using TouchGFX ?

Below is sample code of main.c, StartTask02 is my task where time-sensitive code resides.

main.c
 
/* Definitions for TouchGFXTask */
osThreadId_t TouchGFXTaskHandle;
const osThreadAttr_t TouchGFXTask_attributes = {
  .name = "TouchGFXTask",
  .priority = (osPriority_t) osPriorityHigh,
  .stack_size = 2048
};
 
/* Definitions for myTask02 */
osThreadId_t myTask02Handle;
const osThreadAttr_t myTask02_attributes = {
  .name = "myTask02",
  .priority = (osPriority_t) osPriorityLow,
  .stack_size = 1024
};
 
<....>
 
int main (void) {
<....>
  osKernelInitialize();
 
  TouchGFXTaskHandle = osThreadNew(TouchGFX_Task, NULL, &TouchGFXTask_attributes);
  myTask02Handle = osThreadNew(StartTask02, NULL, &myTask02_attributes);
 
  osKernelStart();
 <....>
} 
 
<....>
__weak void TouchGFX_Task(void *argument)
{
  /* USER CODE BEGIN 5 */
  for(;;)
  {
	osDelay(1);
  }
}
 
void StartTask02(void *argument)
{
  /* Infinite loop */
  for(;;)  {
	//osThreadSuspend(TouchGFXTaskHandle);
        <....>  <--- time sensitive code goes here
	//osThreadResume(TouchGFXTaskHandle);
	osDelay(1000);
  }
}

Any help or hints to solution or further reading material is appreciated;

1 ACCEPTED SOLUTION

Accepted Solutions
Alexandre RENOUX
Principal

Hello,

The fact that your custom task requires about 30ms uninterrupted run is a problem.

Because the TouchGFX thread shouldn't be stopped that long. 30 ms is equivalent to almost two new frames (because 60 Hz is equivalent to 1 frame every 16.6 ms).

Therefore, if it was stopped, you wouldn't be able to start rendering, sending new frame or retrieving the touch coordinates for 30 whole milliseconds. It's normal that your app is not working after that.

Unfortunately, I don't how you can make TouchGFX work with a custom task taking that long.

/Alexandre

View solution in original post

4 REPLIES 4
Alexandre RENOUX
Principal

Hello,

The fact that your custom task requires about 30ms uninterrupted run is a problem.

Because the TouchGFX thread shouldn't be stopped that long. 30 ms is equivalent to almost two new frames (because 60 Hz is equivalent to 1 frame every 16.6 ms).

Therefore, if it was stopped, you wouldn't be able to start rendering, sending new frame or retrieving the touch coordinates for 30 whole milliseconds. It's normal that your app is not working after that.

Unfortunately, I don't how you can make TouchGFX work with a custom task taking that long.

/Alexandre

MM..1
Chief

Hi

you dont write what task2 do, but maybe you can USE ofload technique as DMA or timed interrupts for improve.

And recommend is use Normal priority for both tasks.

EmiM
Associate

Thanks for support and suggestions.

Offloaded communications to DMA together with some trial and error for data rates so got it working for now, takes about 4ms now and haven't observed any issues so far.

Hello, your answer is already some years old. 

But I have a question:

You wrote: "Because the TouchGFX thread shouldn't be stopped that long. 30 ms is equivalent to almost two new frames"

Why could it be a problem to suspend the TouchGFX for e.g. several seconds? (Or does it not apply with the use of FreeRTOS)