2020-06-15 03:03 AM
Hi to all!,
I try to run a Gui designed with TouchGFX on my hardware ( a Nucleo-F767ZI board and a 7" display with touchscreen).
I have created a new c++ project for doing this and I have selected the LL implementations of the periphericals that i use in my project. The first issue that I have noticed are that all files generated have a .c and .h extentions. Also the code generated from the device configuration tool aren't in OO style, but are the standard c style, i don't see any object in this files.
However the code generated by the TouchGfx designer are in the OO style.
The problem now is that i need to call a c++ function from the c code
(for example the OSWrappers::signalVSync function from my EXTI interrupt routine), and this cause some compile problems. At this point I don't know if I need to implements some wrapper module to call a c++ code or if I have done some error to configure the project.
The TouchGFX documentation, don't tell nothing about this, so i'm expect that the link from TouchGFX and my hardware is a simple task and not an invasive task (create a wrapper for example).
Please, someone can explain me how i correctly link the TouchGFX project in the STM32CubeIDE?
Solved! Go to Solution.
2020-06-15 05:58 AM
Hello,
Yes you will probably need a wrapper. If you look at the Application Templates available in TouchGFX Designer, you will find in the code how TouchGFX is linked to the C code project (for instance you can take F746G-DISCO Application Template).
To sum it up (considering you are using FreeRTOS but with bare metal it is also possible to link), you call MX_TouchGFX_Init() defined in app_touchgfx.c (this is the wrapper). Then it will call touchgfx_init() in TouchGFXConfiguration.cpp. With the same idea, you also declare a thread in main.c that you create and start in main() function. This function will call MX_TouchGFX_Process() defined in app_touchgfx.c, which will call touchgfx_taskEntry() defined in TouchGFXConfiguration.cpp.
/Alexandre
2020-06-15 05:58 AM
Hello,
Yes you will probably need a wrapper. If you look at the Application Templates available in TouchGFX Designer, you will find in the code how TouchGFX is linked to the C code project (for instance you can take F746G-DISCO Application Template).
To sum it up (considering you are using FreeRTOS but with bare metal it is also possible to link), you call MX_TouchGFX_Init() defined in app_touchgfx.c (this is the wrapper). Then it will call touchgfx_init() in TouchGFXConfiguration.cpp. With the same idea, you also declare a thread in main.c that you create and start in main() function. This function will call MX_TouchGFX_Process() defined in app_touchgfx.c, which will call touchgfx_taskEntry() defined in TouchGFXConfiguration.cpp.
/Alexandre
2020-06-15 09:00 AM
Hi Alexandre, thank you so much for the reply.
I'ts not a problem to create a wrapper. Now i look into the Application Templates in TouchGFX Designer to see the details.
Is there any documents that explain how to extends the TouchGFX and the STM32CubeIDE code using custom code?
I'm new to the STM32 enviroment and it's not easy for me (in the software engineering way) understand how to extends the code generate from the device configuration tool and integrate this code with my code.
Obviosly everything can be done, but if extist a standard way I would to follows this way! So any application note, documents, guidelines that explain the structure and how integrate the code of an STM32 project (including TouchGFX and other STM32 framework's) it's really appreciate from me.
2020-06-16 12:31 AM
Hello,
I don't know for the other frameworks but you will find some information on how to create a TouchGFX project at the following link : https://support.touchgfx.com/docs/development/board-bring-up/board-introduction
Personally, I think looking at the Applications Templates code and their CubeMX configuration helps a lot in understanding how a TouchGFX project is structured.
/Alexandre
2020-06-16 08:16 AM
Hi Alexandre, many thanks for the reply!
looking into the TouchGFX documentation I found an usefull article on how TouchGFX project is structured, it's is located a few pages after the document that you linked me:
https://support.touchgfx.com/docs/development/touchgfx-hal-development/touchgfx-generator
In this page it's explaned what are the files that the user can modify with custom code. After I finish the TouchGFX part of my project, i try to search if there is the same documentation for the CubeMX.
I think that this problem (how the generated code is structured) it's not trivial because with the code generator, the user can't write his code everywhere, so i think that is usefull to know what files one can modify.
In my case I have added an "extern C method" in the TouchGFXHAL class (that is located in the TouchGFX target folder) and I have created a wrapper module in the Core src folder that call the "extern C method" defined in the TouchGFXHAL class. I haven't tested yet, so i don't know if this work at the moment.
However my criticism is about the "spaghetti style" of this approach. I prefer to mantain the TouchGFX code in the TouchGFx folder and not in other folder, but at this moment i think that this is not possible because I need to modify the TouchGFX code generator project pattern if I want to add some files in the TouchGFX folder, or i'm wrong?
2020-06-16 08:45 AM
Hi,
No I think you can definitely add .c or .cpp files to the TouchGFX folder. As these files will be with the names you decided, CubeMX does not know these files names and therefore should not delete those or rewrite them in any ways. Regarding what's editable or not, you have to look for the the USER CODE Sections in the code. Sometimes, like TouchGFXHAL.cpp, the entire file is encapsulated in a USER CODE Section so that you can modify the entire file.
Regarding the "Spaghetti style" unfortunate feeling, this was necessary to match the requirements of CubeMX. The main purpose is to help the developer as much as possible by generating as much code as possible just by setting some parameters in CubeMX. This removes a lot of complexity (having to setup all by yourself the Flash, Cache management, entire GUI HAL development, I2C, UART, FMC, QuadSPI, etc.) and allows the user to create a project from scratch in a way shorter amount of time.
/Alexandre
2020-06-16 10:55 AM
Hi Alexandre,
your answer is very helpull! Now i try to put my file in the TouchGFX folder, maybe in a subfolder. I know the USER CODE Sections I put always my custom code in this sections.
I undestand that the "Spaghetti style" is necessary for the CubeMX requirements, but believe me, it's not easy for the new user as me to integrate the custom code with the generated code. It's not difficult, but it's no easy! ;)
Many thanks for the help!