STEmWin with Touch Screen on STM32F746G Dicovery – Part 2

This is continuing from part 1 of tutorial.

We prepared everything in previous tutorial now let’s initialize the display and write our simple “Hello world!”

We need to put following inside USER CODE 2 in main.c

Now we need to compile this and program our board.

For the first time we need to right click on project name in Project Explorer and select Run As -> 1 Ac6 STM32 C/C++ Application

It will program and run our application and on display you should see nice Hello world!

Now we know that everything works and we should move on to STEmWin 🙂

First we need to make a few directories inside our project:

Copy all .h files from ‘$Library_path\STM32Cube_FW_F7_VX.X.X\Middlewares\ST\STemWin\inc\’ to GUI/inc folder inside project.

Copy file ‘$Library_path\STM32Cube_FW_F7_VX.X.X\Middlewares\ST\STemWin\Lib\STemWin532_CM7_GCC.a’ to folder GUI\lib iside our project. This is a precompiled library for EmWin from Segger.

Next we need to add this library to our project. We do this in project properties under C/C++ General -> Libraries -> Add… and write ‘:STemWin532_CM7_GCC.a’ It is important to just write this not input link to this file!

Note: While I was writing this tutorial the number of this file changed from 528 to 532. There might be some settings as 528 and some like 532 in this tutorial. Just use latest for everything and it will be ok.

We also need to tell the compiler path to this library, we do this under Project Properties -> C/C++ General -> Library Paths -> Add…

Enter ‘GUI/Lib

We also need to copy file GUIConf.c from ‘$Library_path\STM32Cube_FW_F7_VX.X.X\Middlewares\ST\STemWin\Config\’ to folder ‘src‘ inside root of our project. In this file we provide EmWin with memory for functioning.

We need to change line 65 to:

We also need to copy file GUIConf.h from $Library_path\STM32Cube_FW_F7_VX.X.X\Middlewares\ST\STemWin\Config\ to folder \Inc’ in root of our project.

Next we need to copy file $Library_path\STM32Cube_FW_F7_VX.X.X\Middlewares\ST\STemWin\OS\GUI_X.c to folder \Src’ in root of our project.

We need to add a few more include directories in our include list:

Inside ‘inc’ folder in root of our project is ‘main.h’ file. We need to add this lines of code inside it:

This include of stm32746g_discovery_lcd.h makes a lot of errors which I have some workaround to solve, but I am not sure what causes them, but I will explain how to get rid of them.

In my case first error is something like: “…stm32746g_discovery_sdram.h:128:1: error: unknown type name ‘uint8_t’ “. It seems that linker doesn’t have the correct sequence of include files so it does not understand uint8_t type of number yet. We correct this by including stdint.h in stm32746g_discovery_sdram.h.

After this is done, all the rest of errors are like “stm32746g_discovery.h:316:41: error: unknown type name ‘UART_HandleTypeDef’ ” each of them is missing some kind of type name.

To correct this there are a few steps needed for each of them and a few times after we solve one error there are more errors than before, but ultimately every error is solved.

Let’s take a look at first one: “stm32746g_discovery_sdram.h:135:27: error: unknown type name ‘FMC_SDRAM_CommandTypeDef’ “:

First we double click on the error to see where it is.

Next we right click on the missing type, in this case FMC_SDRAM_CommandTypeDef and select Open Declaration. This opens the file in which this type is defined. In our case it is stm32f7xx_ll_fmc.h.

This means that we need to include stm32f7xx_ll_fmc.h inside stm32746g_discovery_sdram.h:

If we try to compile now, we see that error is gone, but there are a lot still remaining. Let’s remove another one so that you will understand what to do:

Next one is “stm32746g_discovery_sdram.h:141:27: error: unknown type name ‘SDRAM_HandleTypeDef’ “

We double click on it and see it is still in the same file as before, but if we right click on it and select Open Declaration we noe see that this one is defined inside stm32f7xx_hl_sdram.h. So we include another file inside stm32746g_discovery_sdram.h:

We continue this way until all of the type errors are gone… If someone knows better solution to this I would be very happy if they would let me know how to properly solve this!!!

After solving all of the errors we continue with the tutorial.

We need some kind of time base. We need to increment OS_TimeMS each milisecond and for this we will use SysTick Timer.

We start in ‘$Project_name\Src\stm32f7xx_it.c’ which takes care of interrupts and exceptions. In here is a function:

which is executed each millisecond. This one calls another function:

This one also calls another “__weak” function:

__weak means that if compiler needs function with this name it uses __weak function unless there is strong (non __weak) function defined.

We will be making strong function inside main:

And this function will increment OS_TimeMS each millisecond.

Now we need driver for display. We can make our own or we can just copy it from example, which we will do.

We need to copy ‘LCDConf.c‘ from ‘$Library_path\STM32Cube_FW_F7_VX.X.X\Projects\STM32746G-Discovery\Applications\STemWin\STemWin_HelloWorld\Src\’ to /src folder under root of our project.

and we need to copy ‘LCDConf.h‘ from ‘$Library_path\STM32Cube_FW_F7_VX.X.X\Projects\STM32746G-Discovery\Applications\STemWin\STemWin_HelloWorld\Inc\’ to /inc folder under root of our project.

To get rid of a few errors we need to comment a few lines of code inside ‘Src/stm32f7xx_hal_msp.c‘:

You might get an error like main.c:105: undefined reference to `OS_TimeMS’ this means that You forgot to copy GUI_X.c.


All we need to do now is to test if it works. We need to change code between /* USER CODE BEGIN 2 */ and  /* USER CODE END 2 */:

I changed GUI_SetColor to dark gray so that I could get better picture with my camera. And here is the result you should get on display: *Don’t use GUI_SetColor with version 1.8.0, there looks like there is some bug somewhere and it doesn’t work! Solved the problem! We need to add single line at the end of GUI_Conf.h#define GUI_USE_ARGB (0) :


This concludes this tutorial! And here is the link for part 3.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.