cancel
Showing results for 
Search instead for 
Did you mean: 

How to use CAN bus with TouchGFX ?

FFont.18
Associate II

Hello, I am new to TouchGFX. I am developping an UI forSTM32F746G-DISCOVERY board. The goal of my UI is that the user can choose some value of variables and then send it to an other device using CAN bus. All the graphical part is working well, I use three screens and model to acces the variables from all the screens.

However, when I want to use the CAN, I face some issues. CAN driver have been made by my teamworker. I wanted to include the CAN driver file to the Model.cpp but I have includes errors. So I tried to include the stm32f7xx_hal_can.h provided by the project but it doesn't work.

Any idea for including the CAN driver? Maybe I should not include it in the main.cpp.

Thank you

Lucas

Compilation error message:

Converting images

Compiling gui/src/model/Model.cpp

In file included from gui/src/model/../../../../Drivers/STM32F7xx_HAL_Driver/Inc/stm32f7xx_hal_can.h:45:0,

                from gui/src/model/Model.cpp:3:

gui/src/model/../../../../Drivers/STM32F7xx_HAL_Driver/Inc/stm32f7xx_hal_def.h:46:23: fatal error: stm32f7xx.h: No such file or directory

 #include "stm32f7xx.h"

                      ^

compilation terminated.

simulator/gcc/Makefile:220: 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

simulator/gcc/Makefile:182: recipe for target 'generate_assets' failed

make[1]: *** [generate_assets] Error 2

simulator/gcc/Makefile:40: recipe for target 'all' failed

make: *** [all] Error 2

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions

Hi @FFont.18​,

Oh, yes, definitely! You are correct. The simulator makefile is very different.

If you have any target specific code in your project please sorround it with the following to prevent it being compiled for the simulator.

#ifndef SIMULATOR
...
#endif

View solution in original post

12 REPLIES 12
Martin KJELDSEN
Chief III

Looks like you're missing an include path in your Makefile.

Generally, i'd advise for handling CAN communication in a seperate OS task and then using a message queue to communicate with the GUI Task (in Model::tick() ). But if you just want to get it working, doing the work in the GUI task is okay for now - Any time spend handling communication will take away from your frame render time.

Martin KJELDSEN
Chief III

I created a sticky a while back about the subject of interfacing with hardware in TouchGFX applications:

https://community.st.com/s/question/0D50X0000AU4zodSQB/interfacing-with-hardware-in-touchgfx-applications

FFont.18
Associate II

Hello Martin, thank you for your quick reply. I tried adding one line (number 217) to include the CAN driver file. However I could not figure out what I should modify in the makefile to get the linker working. Any hint of which par of the makefile is interesting in my case?

Thanks for the link,I will watch your webinar tomorrow and I am sure it will give me a betetr understanding on interfacing my hardware.

Lucas

Martin KJELDSEN
Chief III

Hi,

You can add your include paths to line 170.

include_paths := $(library_includes) $(foreach comp, $(all_components), $(comp)/include) $(framework_includes) $(source_Middlewares_paths) my/include/path

Your include path is relative to the root of the application.

Hope that helps.

Best regards,

Martin

FFont.18
Associate II

Hello Martin,

I watched the webinar and it gave me useful informations. I decides to keep it very simple by creating a new project and trying to include the HAL_can driver. I could not get it working . So I

-created a new project

-added the include line in the model.cpp

extern "C" {
#include "../../../../Drivers/STM32F7xx_HAL_Driver/Inc/stm32f7xx_hal_can.h"
}

-added include paths to the makefile :

include_paths := $(library_includes) $(foreach comp, $(all_components), $(comp)/include) $(framework_includes) ../Drivers/CMSIS/Device/ST/STM32F7xx/Include ../Drivers/CMSIS/Device/ST/STM32F7xx/Include ../Drivers/CMSIS/Include

This compilation is made for simulation mode and not working. When I try it in run target mode it works without makefile modification. Do you thinks it has to do with the fact that hal_can_library is not supported by simulator? Since it seems to be working with my discovery board, I can continue with my project.

The errors I get are:

Converting images

Compiling gui/src/model/Model.cpp

In file included from c:\touchgfx\4.10.0\env\mingw\include\windows.h:44:0,

                from ../Middlewares/ST/TouchGFX/touchgfx//framework/include/touchgfx/Utils.hpp:22,

                from gui/include/gui/model/Model.hpp:4,

                from gui/src/model/Model.cpp:1:

../Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f746xx.h:917:17: error: expected unqualified-id before numeric constant

  __IO uint32_t LPTR;    /*!< QUADSPI Low Power Timeout register,                Address offset: 0x30 */

                ^

In file included from c:\touchgfx\4.10.0\env\mingw\include\windows.h:46:0,

                from ../Middlewares/ST/TouchGFX/touchgfx//framework/include/touchgfx/Utils.hpp:22,

                from gui/include/gui/model/Model.hpp:4,

                from gui/src/model/Model.cpp:1:

../Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f7xx.h:187:3: error: expected identifier before numeric constant

  ERROR = 0U,

  ^

../Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f7xx.h:187:3: error: expected '}' before numeric constant

../Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f7xx.h:187:3: error: expected unqualified-id before numeric constant

In file included from gui/src/model/../../../../Drivers/STM32F7xx_HAL_Driver/Inc/stm32f7xx_hal_def.h:46:0,

                from gui/src/model/../../../../Drivers/STM32F7xx_HAL_Driver/Inc/stm32f7xx_hal_can.h:45,

                from gui/src/model/Model.cpp:5:

../Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f7xx.h:189:3: error: 'ErrorStatus' does not name a type

 } ErrorStatus;

  ^~~~~~~~~~~

gui/src/model/Model.cpp:6:1: error: expected declaration before '}' token

 }

 ^

simulator/gcc/Makefile:221: 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

simulator/gcc/Makefile:183: recipe for target 'generate_assets' failed

make[1]: *** [generate_assets] Error 2

simulator/gcc/Makefile:40: recipe for target 'all' failed

make: *** [all] Error 2

Martin KJELDSEN
Chief III

Hi @FFont.18​,

I forgot about this problem you were having. Did you get anywhere on your own?

Best regards,

Martin

FFont.18
Associate II

Hi Martin, I still have the same issue for including the stm32f7xx_hal_can.h library to my Touchgfx Project. I have tried to manually edit the paths of the include and I could get some progress in the includes. However, at one point I have this issue0690X000008BTLrQAO.png

I also tried to add an include path in the mainfile: include_paths := $(library_includes) $(foreach comp, $(all_components), $(comp)/include) $(framework_includes) Drivers/CMSIS/Device/ST/STM32F7xx/Include

but I still have that error:

In file included from gui/src/model/../../../../Drivers/STM32F7xx_HAL_Driver/Inc/stm32f7xx_hal_can.h:45:0,

                from gui/src/model/Model.cpp:3:

gui/src/model/../../../../Drivers/STM32F7xx_HAL_Driver/Inc/stm32f7xx_hal_def.h:46:23: fatal error: stm32f7xx.h: No such file or directory

 #include "stm32f7xx.h"

                      ^

Maybe it has to do that the HAL CAN library is not supposed to work with the simulator?

Hi @FFont.18​,

Oh, yes, definitely! You are correct. The simulator makefile is very different.

If you have any target specific code in your project please sorround it with the following to prevent it being compiled for the simulator.

#ifndef SIMULATOR
...
#endif

Thank you very much I could include my library.