cancel
Showing results for 
Search instead for 
Did you mean: 

Custom project set up using Touch GFX on Riverdi STM32H7 Embedded Display

koderboi22
Associate III

I have generated a new project with Touch GFX Designer where I created a text area and also created a button, to which I have linked an interaction. This interaction will call on a new virtual function which I then plan on integrating with my external project files. I've created my projects .c and .h files in which I'm writing a simple arithmetic calculation. Note that my project files are in C whereas the Touch GFX generated files are in C++, I now want to call the arithmetic function in the model.cpp file and I'm unable to run the simulator on the Designer as it gives me an error. 

File Path for Touch GFX generated files -> C:\TouchGFXProjects\MyApplication_2\CM7\TouchGFX\gui\src

Below are the files:

 

view.cpp    
#include <gui/screen1_screen/Screen1View.hpp>



Screen1View::Screen1View()

{



}



void Screen1View::setupScreen()

{

   Screen1ViewBase::setupScreen();



}



void Screen1View::tearDownScreen()

{

   Screen1ViewBase::tearDownScreen();

}



void Screen1View::ButtonClicked(){

 presenter->MathTest(7, 4);



}



void Screen1View::GetResult(uint16_t Result){



   char buffer[20]; // Adjust the buffer size as needed

   snprintf(buffer, sizeof(buffer), "%u", Result);

   Unicode::strncpy(textArea1Buffer, buffer, TEXTAREA1_SIZE);

   textArea1.invalidate();

}

 

 

view.hpp 

#ifndef SCREEN1VIEW_HPP

#define SCREEN1VIEW_HPP

#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>

#include <gui/screen1_screen/Screen1Presenter.hpp>

#include <cstdio>


class Screen1View : public Screen1ViewBase

{

public:

   Screen1View();

   virtual ~Screen1View() {}

   virtual void setupScreen();

   virtual void tearDownScreen();

   void ButtonClicked();  //remove virtual

   void GetResult(uint16_t Result);

protected:

};


#endif // SCREEN1VIEW_HPP

 

 

 

presenter.cpp 
#include <gui/screen1_screen/Screen1View.hpp>

#include <gui/screen1_screen/Screen1Presenter.hpp>


Screen1Presenter::Screen1Presenter(Screen1View& v)

   : view(v)

{

}


void Screen1Presenter::activate()

{

}


void Screen1Presenter::deactivate()

{

}


void Screen1Presenter::MathTest(uint16_t x, uint16_t y)

{

model->MathTest(x,y);

}


void Screen1Presenter::GetResult(uint16_t Result)

{

view.GetResult(Result);

}

 

 

 

presenter.hpp  
#ifndef SCREEN1PRESENTER_HPP

#define SCREEN1PRESENTER_HPP



#include <gui/model/ModelListener.hpp>

#include <mvp/Presenter.hpp>



using namespace touchgfx;



class Screen1View;



class Screen1Presenter : public touchgfx::Presenter, public ModelListener

{

public:

   Screen1Presenter(Screen1View& v);



   /**

    * The activate function is called automatically when this screen is "switched in"

    * (ie. made active). Initialization logic can be placed here.

    */

   virtual void activate();



   /**

    * The deactivate function is called automatically when this screen is "switched out"

    * (ie. made inactive). Teardown functionality can be placed here.

    */

   virtual void deactivate();



   virtual ~Screen1Presenter() {}



   virtual void MathTest(uint16_t x, uint16_t y);

    // ModelListener callback

    virtual void GetResult(uint16_t result);



private:

   Screen1Presenter();



   Screen1View& view;

};



#endif // SCREEN1PRESENTER_HPP

 

Model.cpp 

#include <gui/model/Model.hpp>

#include <gui/model/ModelListener.hpp>





#ifndef SIMULATOR

#include "Mytest.h"

#include "stdio.h"

#endif



Model::Model() : modelListener(0)

{



}



void Model::tick()

{



}

uint16_t Model::MathTest(uint16_t x, uint16_t y)

{

#ifdef SIMULATOR

   uint16_t Result = MathOp(x,y);///

   modelListener->GetResult(Result);

   return Result;

#else

  return 0.0;

#endif

}

 

 Model.hpp 
#ifndef MODEL_HPP

#define MODEL_HPP



#include <cstdint>



class ModelListener;



class Model

{

public:

   Model();



   void bind(ModelListener* listener)

   {

       modelListener = listener;

   }



   void tick();

   uint16_t MathTest(uint16_t x, uint16_t y);



protected:

   ModelListener* modelListener;

};



#endif // MODEL_HPP

 

 

A source file (Mytest.c) -> C:\TouchGFXProjects\MyApplication_2\CM7\Core\Src

Myfile.h -> C:\TouchGFXProjects\MyApplication_2\CM7\Core\Inc

 

#include "Mytest.h"


uint16_t MathOp(uint16_t x, uint16_t y)

{

return x+y;

}

 

#ifndef APPLICATION_USER_CORE_MYTEST_H_

#define APPLICATION_USER_CORE_MYTEST_H_


#include <stdint.h> // Include <cstdint> for uint16_t


uint16_t MathOp(uint16_t x, uint16_t y);



#endif /* APPLICATION_USER_CORE_MYTEST_H_ */

 

 

 

The function MathOp was created for the arithmetic calculation which was called in the model.cpp file. Below is the error from the simulator on Touch GFX Designer:

 

Compile
        make -f simulator/gcc/Makefile -j8
        Reading ./application.config
        Reading ./target.config
        Compiling gui/src/model/Model.cpp
        gui/src/model/Model.cpp: In member function 'uint16_t Model::MathTest(uint16_t, uint16_t)':
        gui/src/model/Model.cpp:22:23: error: 'MathOp' was not declared in this scope
             uint16_t Result = MathOp(x,y);///
                               ^~~~~~
        gui/src/model/Model.cpp:22:23: note: suggested alternative: 'MathTest'
             uint16_t Result = MathOp(x,y);///
                               ^~~~~~
                               MathTest
        generated/simulator/gcc/Makefile:196: recipe for target 'build/MINGW32_NT-6.2/gui/src/model/Model.o' failed
        make[2]: *** [build/MINGW32_NT-6.2/gui/src/model/Model.o] Error 1
        make[2]: *** Waiting for unfinished jobs....
        generated/simulator/gcc/Makefile:155: recipe for target 'generate_assets' failed
        make[1]: *** [generate_assets] Error 2
        make: *** [all] Error 2
        simulator/gcc/Makefile:32: recipe for target 'all' failed
        Failed
    Failed
 
 

 

21 REPLIES 21

Hi @SofLit, I've made the changes as below but I'm getting an error message when I run the simulator:

 
 
This is the file path to the makefile: C:\TouchGFXProjects\Test\CM7\TouchGFX\simulator\gcc
 
Below is the makefile and as you can see in lines 24 and 25, we've added the additional source and include paths as you mentioned:
 

 

# Helper macros to convert spaces into question marks and back again
e :=
sp := $(e) $(e)
qs = $(subst ?,$(sp),$1)
sq = $(subst $(sp),?,$1)

# Get name of this Makefile (avoid getting word 0 and a starting space)
makefile_name := $(wordlist 1,1000,$(MAKEFILE_LIST))

# Get path of this Makefile
makefile_path := $(call qs,$(dir $(call sq,$(abspath $(call sq,$(makefile_name))))))

# Get path where the Application is
application_path := $(call qs,$(abspath $(call sq,$(makefile_path)../..)))

.PHONY: clean assets all

ifneq ($(words $(makefile_path))$(words $(MAKEFILE_LIST)),11)
all clean assets:
$(error Spaces not allowed in path)
else

# Add new source file and header file paths
ADDITIONAL_SOURCES := C:/TouchGFXProjects/Test/CM7/Core/Src/Mytest.c
ADDITIONAL_INCLUDE_PATHS := C:/TouchGFXProjects/Test/CM7/Core/Inc
ADDITIONAL_LIBRARY_PATHS :=
ADDITIONAL_LIBRARIES :=
export ADDITIONAL_SOURCES ADDITIONAL_INCLUDE_PATHS ADDITIONAL_LIBRARY_PATHS ADDITIONAL_LIBRARIES

all: $(filter assets,$(MAKECMDGOALS))
all assets: $(filter clean,$(MAKECMDGOALS))
all clean assets:
      @$(MAKE) -r -f generated/simulator/gcc/Makefile -s $(MFLAGS) $@ -C "$(application_path)"
endif

 

 

Error message: 

 
Run Simulator
    Generate
        Done
    Generate Assets
        make -f simulator/gcc/Makefile assets -j8
        generated/simulator/gcc/Makefile:159: *** multiple target patterns.  Stop.
        make: *** [assets] Error 2
        simulator/gcc/Makefile:33: recipe for target 'assets' failed
        Failed
    Failed
 
 

Hello @koderboi22 ,

Your architecture is correct, however, you have defined the include files to be called when the simulator is not running and then you have set to call the function MathOp when the simulator is running. So, if you like to test your code in simulator, you should either remove the Marcos for the simulator or set them both to #ifdef simulator

I hope this helps you, don't hesitate to ask more questions.

Mohammad MORADI
ST Software Developer | TouchGFX

@Mohammad MORADI ESFAHANIASL 

Indeed, I didn't see this part of code:

#ifndef SIMULATOR

#include "Mytest.h"

#include "stdio.h"

#endif

 I focused on the makefile!

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hi @Mohammad MORADI ESFAHANIASL ,

I have removed them both from the #ifndef SIMULATOR now:

 

 

#ifndef SIMULATOR

#include <gui/model/Model.hpp>

#include <gui/model/ModelListener.hpp>

#else

#include "C:/TouchGFXProjects/Test/CM7/Core/Inc/Mytest.h"

#endif



// Define the constructor for the Model class

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



// Define the tick function for the Model class

void Model::tick() {}



// Define the MathTest function for the Model class

uint16_t Model::MathTest(uint16_t x, uint16_t y) {



#ifndef SIMULATOR

   // Include header and call MathOp function when not running in the simulator

   return 0;

#else

   // When running in the simulator, just return the sum of x and y

   uint16_t Result = MathOp(x, y);

   modelListener->GetResult(Result);

   return Result;

#endif

}

 

 

If not, can you please guide how to fix this.

Furthermore, I'm still receiving the same error as well.

No.

Since you are using the simulator you need to define the flag SIMULATOR:

Replace:

 

#ifndef SIMULATOR

 

by

 

#ifdef SIMULATOR

 

So you need to remove 'n' from #ifndef

Or simply remove this definition.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I've done this however when I now build the code it says, that there is an undefined reference to the MathOp function.

You need to add Mytest.c file to your project. To my knowledge in the Makefile under simulator\gcc:

 

 

ADDITIONAL_SOURCES := ../CM7/Core/Src/Mytest.c

 

 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

So I've made both the changes as you mentioned however still I'm receiving the error, if there is a way to set up a meeting of some kind it'll be great help.

 

Unfortunately, no meeting is possible.

If you can attach your project so TouchGFX experts can help you. 

If not possible, as said previously, you need to contact your local FAE for an efficient assistance.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@koderboi22 If you wish an experienced programmer to look at your code, review and so on - this is available here and here.