cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX - Library functions used (maths, strings).

AMars.4
Associate III

Hi all,

I currently working on a project using TouchGFX, multiple tasks are using functions from <math.h> which are not re-entrant, so I have them mutex protected. The drivers using these functions are written in C.

Does anyone know if the TouchGFX library uses any non re-entrant library functions? Do I need to be careful with anything I use in the application?

Kind Regards,

Anthony 

1 ACCEPTED SOLUTION

Accepted Solutions

These should all be thread and interrupt safe on ARM processors. May be need a different library?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

11 REPLIES 11
Panchev68
Senior

What do you think is the relationship between TouchGFX and <math.h>

You have one FreeRTOS task with which the TouchGFX layer is started.

what is the role of this mutex?!?

These are functions that do not use a shared resource

Use the MPV.
In most projects I've done, there are several functions in the Screen classes that update variables on the display. Everything else is in the model

Which functions in math.h ?

I can see string.h perhaps strtok() it would be better to use strsep()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I have multiple other tasks using the maths functions, not just the TouchGFX task.

Some functions in <math.h> are #defined out by _REENT_ONLY, such as sqrt(). So if I want to use this function from multiple tasks safely I need to make sure access to this function is mutex protected.

I do use MVP, just that some of the calculations I am doing in the other tasks so that the UI task doesn't have to handle everything.

I was curious as to whether the renderer core library makes use of these maths functions, but source code is not provided, maybe there is another way to find out.

From <math.h>

/* Reentrant ANSI C functions.  */

#ifndef __math_68881
extern double atan (double);
extern double cos (double);
extern double sin (double);
extern double tan (double);
extern double tanh (double);
extern double frexp (double, int *);
extern double modf (double, double *);
extern double ceil (double);
extern double fabs (double);
extern double floor (double);
#endif /* ! defined (__math_68881) */

/* Non reentrant ANSI C functions.  */

#ifndef _REENT_ONLY
#ifndef __math_68881
extern double acos (double);
extern double asin (double);
extern double atan2 (double, double);
extern double cosh (double);
extern double sinh (double);
extern double exp (double);
extern double ldexp (double, int);
extern double log (double);
extern double log10 (double);
extern double pow (double, double);
extern double sqrt (double);
extern double fmod (double, double);
#endif /* ! defined (__math_68881) */
#endif /* ! defined (_REENT_ONLY) */

 

Yes, I avoid strtok() and use a function similar to what you suggest. 

Maths functions include sqrt, atan2, cosh, sinh, and some of the other hyperbolic functions, but I noticed the issue through two tasks both using sqrt().

These should all be thread and interrupt safe on ARM processors. May be need a different library?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Interesting, I did also read that (ARM website somewhere).

Probably best to set up an experiment and test whether the problem is related to those functions  or some other issue is at play.

Panchev68
Senior

Sorry, I haven't had a similar problem. For me, the only solution is a wrapper with mutexes

The routines and the task swapping should push and save MCU and FPU context.

If the FPU context isn't saved all the math using it will be compromised,  by interrupts or task changes.

Build without the FPU, so it uses the software math library.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I will double check this, I am currently building with FPU.

At some point I noticed my project didn't have ENABLE_FPU (CubeMX freertos option), but this is now enabled, I should remove the mutexes and see if it now works with this defined.

It sounds very much like the FPU context not being saved, so will investigate based on that.

Thanks.