2024-07-15 12:19 PM
Hello everyone,
I am using a STM32f746 DISCO eval board. I am still trying to learn about this board but I have already done some small programs to get a feel for it and make sure that I can flash STM32CubeIDE and TouchGFX programs on it. Which I done successfully. However, I can't seem to figure out how to connect the two. I've tried watching some videos but I would like more direct help.
Goal: I have a CubeIDE program that sends a command through serial6/uart6 when the blue user button is pressed but the GUI remains pure white. I have a touchgfx program that has the button to press and can show up on the screen but does nothing with ports. I want the button on the screen to send my serial command instead of the user button on the board. How do I put everything together? Having trouble getting the generated code to the cubeide.
2024-07-16 05:15 AM
Hello @LevyCake ,
I can understand the struggle.
In order to achieve your goal, you should understand how TouchGFX applications can communicate with the hardware, or in other words, how you can send external events to your GUI. This is handled through the Model.cpp file, and you can read this document for a thorough explanation.
In addition, you can take a look at the available Board Specific Demo for STM32F746G-Disco that exactly demonstrates how to achieve the functionality you are looking for.
To briefly mention the process, after enabling UART in your STM32CubeMX project (.ioc file), you need to define a queue and a task in the FreeRTOS configuration for handling the data. Then, in the Model.cpp you can access the queue and read/write from/to it, and based on the data, you can call functions that have been defined in your GUI, through the ModelListener.
I hope this helps you!
Don't hesitate to ask more questions.
2024-07-21 08:16 AM
I tested out the demo on my board and it does work with the blue button and the green led on the board! Thank you for pointing it out to me. I think I will mostly be using the UI event to Backend part of this demo for now.
I was able to find the Model.cpp file you mentioned also. This holds the virtual function calls like the "toggleLED" in the demo seems like. I should be able to create my own virtual functions and edit them here as well right? Projectname->TouchGFX->gui->src->model->Model.cpp
I have enabled UART6 on the board and I have tested a program out that sends a message to my arduino Nano board thats connected serially. It sends the message when the BLU_BTN is pressed on the board. This did work so the UART is at least transmitting correctly.
Now you said I need to define a queue and a task in the FreeRTOS config. Can you walk me through this some more? Though I should probably have a TouchGFX also on this project but when I try to generate the code and import it onto this project, I cant get it to debug properly so I think I am not adding TouchGFXs generated code to my existing project right. I need help figuring that out too.
2024-07-23 04:45 AM
Yes, you can define your own functions in Model.cpp.
To enable TouchGFX code generation for your project, you need to follow instruction at Enabling TouchGFX Generator, but since you don't have a custom boards, it would be much easier for you if you just use the available TouchGFX Board Setup (TBS) to develop your project. This project has already configured all the required settings for developing your GUI. You just need to enable UART6 again.
Anyway, I will assume that you have your TouchGFX generator ready and I will continue explaining based on the demo so you can see the steps conveniently.
Since we are using UART, it is not possible to wait for the data to be received by the GUI because it will block the GUI or we might lose the data. Therefore, we need a task to read or send the data and a queue to store them. In the demo, the UART is not used and instead the data are send directly from the blue button (the state of blue button) and state of the green LED. However, the process is exactly the same and you just need to switch handling the button and LED with receiving/sending data with UART.
In the STM32CubeMX project, Middleware and Software Packs -> FREERTOS -> Tasks and Queues you can see that one task named StartButtonAndLEDTask is defined, and its "Code Generation Option" is set to "As external" which means the definition of the task is in another file and that file is main_user.c for the demo.
(You can read more about the task definitions here)
In addition, two queues are defined one for messages related to the LED and the other related to the Blue Button (Obviously, you don't need two queues if you are only dealing with one type of message). We can access them by the structs that are generated by in main.c (guiQueueHandle and buttonQueueHandle), and using FreeRTOS functions for handling queues.
So, in main_user.c, we first set up the LED and the button, and then, we read the messages regarding the state of the green LED (because it is controlled from the GUI), and send the state of the Blue button to the GUI. Here you can do the same for instance reading from the UART and sending the received data to the queue.
Then, in TouchGFX -> gui ->src -> model -> Model.cpp we handle the functions that should happen when the LED button in the GUI is pressed, or the state of the Blue button has changed. Keep in mind that these functions should be defined between the preprocessors of #ifndef SIMULATOR and #endif since they don't work when the GUI is run in the simulator. Moreover, the flow of function calls are like this:
ModelListener -> Presenter -> Screen or Screen -> Presenter -> Model
Hence, in Model.cpp you can see that every tick we check for the state of the Blue button and based on it we call the required function, and if the Blink button in the GUI is clicked, we call Model::toggleLED()
I hope this gives you a better overview of how to handle the communication between the GUI and UART. You can read more about the communication with backend here.