cancel
Showing results for 
Search instead for 
Did you mean: 

Touchgfx and HAL_GPIO_WritePin in simulator

amigafan
Associate III
This piece of code works if I transfer it to my board, but if I use the simulator in TouchGFX, I get an error: gui/src/model/Model.cpp:7:10: fatal error: main.h: No such file or directory #include "main.h".
 
Screen1View.cpp
#include "stm32f7xx_hal.h"
 
// LED Toggle function
void Screen1View::ToggleLED()
{
 if (toggleButton1.getState()) HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
 else HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
}
 
I am using TouchGFX 4.24
BR 
1 ACCEPTED SOLUTION

Accepted Solutions

@LouisB wrote:

 

#ifdef SIMULATOR // Your simulator specific user code here #include "gui/common/myInclude.hpp" #else // Your hardware specific user code here extern "C" { #include "stm32f7xx_hal.h" } #endif

 

 


extern C is not needed as stm32f7xx_hal.h already has this inside the header file. As far as I know all ST header files are like this.

 

This would work:

 

#ifndef SIMULATOR #include "stm32f7xx_hal.h" #endif // LED Toggle function void Screen1View::ToggleLED() { if (toggleButton1.getState()) { #ifndef SIMULATOR HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET); #else //simulate an LED on the screen, for example #endif } else { #ifndef SIMULATOR HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET); #else //simulate an LED on the screen, for example #endif } }

 

 

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.

View solution in original post

7 REPLIES 7
amigafan
Associate III

Ups, the error is:gui/src/model/Model.cpp:7:10: fatal error: stm32f7xx_hal.h: No such file or directory #include "stm32f7xx_hal.h". Sorry

LouisB
ST Employee

Hello @amigafan ,


How did you include the file in your project ? The board and the simulator are built differently.

 

Best regards,
Louis B.

Louis BOUDO
ST Software Engineer | TouchGFX
amigafan
Associate III

?? I wrote #include "stm32f7xx_hal.h" in Screen1View.cpp.

Br

I meant in which folder did you put the file ?

Louis BOUDO
ST Software Engineer | TouchGFX
amigafan
Associate III

It is in STM32CubeIDE, I dit no add a file to any folder.

LouisB
ST Employee

Hello @amigafan,

The issue is the file itself, it's an hardware specific file that will only work on target.

 

#ifdef SIMULATOR // Your simulator specific user code here #include "gui/common/myInclude.hpp" #else // Your hardware specific user code here extern "C" { #include "stm32f7xx_hal.h" } #endif

 

I hope it helps,
Best regards

Louis BOUDO
ST Software Engineer | TouchGFX

@LouisB wrote:

 

#ifdef SIMULATOR // Your simulator specific user code here #include "gui/common/myInclude.hpp" #else // Your hardware specific user code here extern "C" { #include "stm32f7xx_hal.h" } #endif

 

 


extern C is not needed as stm32f7xx_hal.h already has this inside the header file. As far as I know all ST header files are like this.

 

This would work:

 

#ifndef SIMULATOR #include "stm32f7xx_hal.h" #endif // LED Toggle function void Screen1View::ToggleLED() { if (toggleButton1.getState()) { #ifndef SIMULATOR HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET); #else //simulate an LED on the screen, for example #endif } else { #ifndef SIMULATOR HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET); #else //simulate an LED on the screen, for example #endif } }

 

 

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.