cancel
Showing results for 
Search instead for 
Did you mean: 

How add additional FreeRTOS task (to control hardware) to TouchGFX project?

Clark Sann
Senior

I am trying to add an additional task to my TouchGFX project. The purpose of the additional task is to control stepper motors. I am following the procedure given in the c_task_conderser_example from the TouchGFX website.

My problem is that whenever I add a task my display freezes. This occurs even if the task is a simple task that does nothing.

Here is my code:

void stepperTask(void const * argument).    <---- most simple task I could create
{
	for(;;)
	{
//		vTaskDelay(500);
		osDelay(500);
	}
}
 
int main(void)
{
 
  HAL_Init();
 
 [BUNCH OF INITIALIZATION CODE REMOVED FROM HERE TO IMPROVE CLARITY]
 
/* Initialise the graphical hardware */
  GRAPHICS_HW_Init();
 
  /* Initialise the graphical stack engine */
  GRAPHICS_Init();
 
  /* Create the thread(s) */
  /* definition and creation of defaultTask */
  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
 
  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  osThreadDef(stepperTask1, stepperTask, osPriorityNormal, 0, 4096);
  osThreadCreate(osThread(stepperTask1), NULL);  <----- the display works if I comment this out. If not commented out, the display freezes.
 
  osKernelStart();

Also, when I add the 2nd task, I get the following warnings but I'm not sure what they mean:

Building file: /Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Core/Src/main.cpp

Invoking: MCU G++ Compiler

/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/SW4STM32/StepperController/Debug

arm-none-eabi-g++ -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 '-D__weak=__attribute__((weak))' '-D__packed="__attribute__((__packed__))"' -DUSE_HAL_DRIVER -DSTM32F746xx -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/FATFS/Target" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/FATFS/App" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Core/Inc" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/TouchGFX/target" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/USB_HOST/App" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/USB_HOST/Target" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/TouchGFX/generated/fonts/include" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/TouchGFX/generated/texts/include" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/TouchGFX/generated/images/include" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/TouchGFX/generated/gui_generated/include" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/TouchGFX/gui/include" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Middlewares/ST/TouchGFX/touchgfx/framework/include" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Drivers/STM32F7xx_HAL_Driver/Inc" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Drivers/STM32F7xx_HAL_Driver/Inc/Legacy" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Middlewares/Third_Party/FatFs/src" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Middlewares/Third_Party/FreeRTOS/Source/include" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Middlewares/ST/STM32_USB_Host_Library/Core/Inc" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Drivers/CMSIS/Device/ST/STM32F7xx/Include" -I"/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Drivers/CMSIS/Include" -Og -g3 -Wall -fmessage-length=0 -ffunction-sections -c -fno-exceptions -fno-rtti -MMD -MP -MF"Application/User/Core/main.d" -MT"Application/User/Core/main.o" -o "Application/User/Core/main.o" "/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Core/Src/main.cpp"

In file included from /Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Core/Src/main.cpp:53:0:

/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Core/Src/main.cpp: In function 'int main()':

/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:470:54: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

 { #name, (thread), (priority), (instances), (stacksz)}

                           ^

/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Core/Src/main.cpp:262:3: note: in expansion of macro 'osThreadDef'

  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);

  ^~~~~~~~~~~

/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h:470:54: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

 { #name, (thread), (priority), (instances), (stacksz)}

                           ^

/Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Core/Src/main.cpp:267:3: note: in expansion of macro 'osThreadDef'

  osThreadDef(stepperTask1, stepperTask, osPriorityNormal, 0, 4096);

  ^~~~~~~~~~~

Finished building: /Users/clark/Documents/EclipseWorkspaces/STM32_Workspace/StepperController/Core/Src/main.cpp

19 REPLIES 19
Martin KJELDSEN
Chief III

Hi @Clark Sann​,

You may need to increase the size of your FreeRTOS heap, inside your FreeRTOS config file since you're adding on another task with a stack of its own.

Martin KJELDSEN
Chief III

And remember that the stack sizes are in words, not bytes. And the heap size (configTOTAL_HEAP_SIZE) in freertos config is in bytes.

Clark Sann
Senior

Hi @Martin KJELDSEN​ 

Thank you for answering on a weekend. That's good service! You ST guys are great!

Well I have gradually increased the Total_Heap_Size from 32768 to 200000. It works for a few seconds then the display freezes again. I currently have commented out all my stepper code.

All my task does right now is send a string out UART1 whenever one of the controls on the GUI is changed. I have a queue from the model to my task. The model inserts a command struct into the queue. My task receives that command, determines what command has been received, then transmits a short message out the USART (for debug purposes).

I see a few messages, then the GUI freezes again. Any thoughts on what is happening?

Clark

Martin KJELDSEN
Chief III

@Clark Sann​, those are big numbers. Not sure about the memory memory configuration but you could reduce both stack and heap sizes significantly. Just remember to multiply the stack sizes by 4 and ensure that the Freertos heap size is above that (it's in bytes). e.g. If you have two tasks with a stack size of 900, then your heap should be > 900 * 4 * 2.

Do you have any FreeRTOS plugin for your IDE so you can see the state of the tasks? Is the GUI Task blocked but the application/OS is still running or are you in a hard fault state?

Martin KJELDSEN
Chief III

Which board are you running this example on? There's a few other examples in the article you got the condenser example from written for the STM32F769-DISCO board.

https://touchgfx.zendesk.com/hc/en-us/articles/205074561-Connecting-the-UI-to-your-system

I wrote the following two examples (TouchGFX 4.9.3 - Can be upgraded to 4.10.0) for a webinar i held on connecting the UI to your system. It discusses general things about how events can be propagated to the GUI and takes a few different approaches to achieve the same thing. Both examples use multiple tasks - One example uses polling and the other uses interrupts and they're described in the above article.

http://ftp.draupnergraphics.com/TouchGFX/knowledgebase/hw_integration_tasks_gpio.4.9.3.zip

http://ftp.draupnergraphics.com/TouchGFX/knowledgebase/hw_integration_tasks_exti.4.9.3.zip

Maybe the webinar could give some additional background to what we're trying to do here trying to present data from peripherals in a TouchGFX Application and how we can stimulate the "outside" world by reacting to user input through a touch screen.

https://youtu.be/jQO7zhX0e0Q

Best regards,

Martin

Clark Sann
Senior

I’m running on a 32F746G-DISCO board. IDE is SW4STM32. I raised the heap number gradually from 32k to 200k. I bet there is another problem causing the GUI to freeze. I’ll look at your examples this afternoon. Thanks for that!

Its clear that I don’t know enough about FreeRTOS and my IDE doesn’t give much feedback. I will do some research to see if there are any plugins that would help. I’d hate having to switch IDEs. It took a long time to get running with this one.

Clark Sann
Senior

Hello @Martin KJELDSEN​ 

I fixed my problem!

I made a stupid mistake in my C program containing the task to command the stepper actions. The model put a command into the queue based on operator commands via the GUI. This task received the message from a queue and controlled the stepper motors. My problem was I had an error in the task which caused the task to end. That no doubt damaged the queue which caused the GUI task to freeze when the GUI next tried to put a command in the now non-existent queue.

Sigh...

I now need to put in my stepper commands.

As soon as I get this project completed, I'm going to take a FreeRTOS course that covers all the topics you mentioned. It uses Segger SystemView to monitor FreeRTOS. I'm looking forward to learning more about FreeRTOS.

BTW, GUI task uses 4K stack space. That is also how I have configured my stepperTask. (I haven't tried to set it lower yet. I don't know how to estimate the stack space.) So I have set my heap space to 4K * 4 * 2 as you said. I actually set it to 40000 and everything is working fine.

I appreciate your help.

Martin KJELDSEN
Chief III

@Clark Sann​, that's great news! Glad you fixed it. Knowing more about FreeRTOS queues and tasks is definitely a good move and having some way of inspecting the current state of both types really helps debugging sometimes.

Pavel A.
Evangelist III

> when I add the 2nd task, I get the following warnings but I'm not sure what they mean

This is basically what you get for pushing C++ everywhere, even for code that is plain old C.

C++ once was planned to be a perfect superset of C, but this haven't happened.

-- pa