cancel
Showing results for 
Search instead for 
Did you mean: 

hardware and display controllings are not working at same time

kishor
Associate II

 

 

sir we are using stm32f7508-dk board , we generated code through touchgfx , as per our application  requirement  code is modified in that. but i need to control the  8 relays using the io pins , when we are going initialize the io pin in cube ide  dipslay part is not working hardware controlling also not working .. can you suggest me how merge both dispaly  and hardware control 

1 REPLY 1

Hello @kishor ,

To program the GPIOs of your MCU, you need to use the STM32CubeMX project, not STM32CubeIDE. In that project, you can name or label the available general pins, and then use them in your TouchGFX project.

For instance, to control the LED on the board, first I create a project in TouchGFX.

TouchGFX ProjectTouchGFX Project

 
Then, I open the STM32CubeMX project (.ioc file) created by TouchGFX, and by using the schematics of the board available at here , I set the pin for the Green LED (PI1) as output, so I can turn it on or off. And then, I press Generate Code.
CubeMX GPIO settingsCubeMX GPIO settings
Now, I go back to the TouchGFX project. I put a button to control the LED and regenerate code. After that, I go the Model.hpp and define a function called "setLEDStateTo(bool state)" , then in Model.cpp I write :

#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>

#ifndef  SIMULATOR
#include "stm32f7xx.h"
#include "main.h"
#endif

Model::Model() : modelListener(0)
{

}

void Model::tick()
{

}

void Model::setLEDStateTo(bool state)
{
#ifndef  SIMULATOR
    if (state)
    {
#if defined(GREEN_LED_GPIO_Port) && defined(GREEN_LED_Pin)
        HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET);
#endif
    }
    else
    {
#if defined(GREEN_LED_GPIO_Port) && defined(GREEN_LED_Pin)
        HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_RESET);
#endif
    }
#endif //  SIMULAATOR
}

Now, I have to connect the Model to my Screen using Presenter. So, in my screen's presenter I define this function (for simplicity I defined the function in the ScreenPresenter.hpp but it's not a good programming practice):

virtual void setLEDStateTo(bool state)
{
    model->setLEDStateTo(state);
}

Finally, I go to my ScreenView.hpp and define:
(I defined toggleLED as an Interaction for the button when it's clicked)

    virtual void toggleLED();
protected:
    bool LED_Status;

And in ScreenView.cpp:

Screen1View::Screen1View():LED_Status(false)
{

}

//Other functions

void Screen1View::toggleLED()
{
    LED_Status = !LED_Status;
    presenter->setLEDStateTo(LED_Status);
}

When I press "Program and Run Target", I can turn the small green LED on and off via the button. 

 

You can read more about the connection of TouchGFX application with the hardware here , and you can see more examples in the Demos section of TouchGFX in the Board Specific Demo tab.
Board Specific DemosBoard Specific Demos

 

I hope this is helpful,
Good luck

Mohammad MORADI
ST Software Developer | TouchGFX