STEmWin with Touch Screen on STM32F746G Dicovery – Part 1

In this series of articles I will show you how to get STEmWin working on STM32F746G Discovery board.

I used this site to help me make everything work. There is also a lot deeper explanation of how everything works. I will only show the steps needed to make everything work. Now let’s start!

I could explain how to set everything but I rather prepared an .ioc file for use with CubeMX. Download it and open it with CubeMX. It can be downloaded here. (Right click -> Save As…)

 

After that we need to set project settings (we need to adjust everything marked red) and click Ok:

Then we need to generate project and open it in SW4STM32:

  • generating

  • opening

  • confirmation of sucsessful opening

Now we need to test everything os okay. We do this by right clicking on project we just inported and selecting Build Project:

Well it won’t work, since there is some bug present. It will show four errors in main.c:

And we need to comment out those two lines. It seems that CubeMX is ahead of firmware and those functions are not yet implemented under firmware but are in CubeMX.

For the first time this takes a while and when it is finished you should see some blue text in console telling you something like “Build finished took “a lot” seconds. 🙂

This means that the project is ready for some serious coding…

 

No we will start to add components to our program. First is some BSP files (board support package files). These are needed for our hardware that is added beside microcontroler on discovery board. We can find all of BSPs inside folder of our CubeMX repository. On windos that is under “C:\Users\%USER%\STM32Cube\Repository”. There is usually more than one subfolder here. What we are interestd in is folder STM32Cube_FW_F7_Vx.x.x where x.x.x is the version, just use the latest.

We need to add three drivers here:

  • stm32746g_discovery -> main file that glues everything together
  • stm32746g_discovery_sdram -> for SDRAM
  • stm32746g_discovery_lcd -> for LCD display
  • stm32746g_discovery_ts -> for touch screen

We do this by first creating place for drivers by creating subfolder BSP, with two subfolders inc and src in it in our project. Right click on Drivers folder in project, select New and Folder.

In new window enter BSP and click Finish. This will create BSP folder.

Do the same for two subfolders inside this (BSP) folder. Finally you should have folders like screenshot below:

Now let’s add the needed files in our project. We always copy .c files in src folders and .h files in inc folders.

We need to copy

stm32746g_discovery.c
stm32746g_discovery_sdram.c
stm32746g_discovery_lcd.c
stm32746g_discovery_ts.c

from $Library_path\STM32Cube_FW_F7_VX.X.X\Drivers\BSP\STM32746G-Discovery\ to Drivers/BSP/src folder and

stm32746g_discovery.h
stm32746g_discovery_sdram.h
stm32746g_discovery_lcd.h
stm32746g_discovery_ts.h

from $Library_path\STM32Cube_FW_F7_VX.X.X\Drivers\BSP\STM32746G-Discovery\ to Drivers/BSP/inc folder

We also need drivers for Components

Create new folder under Drivers named Components.

In here we copy drivers for chip for LCD display (RK043FN48H) and chip for touch screen (FT5336)

They are found in $Library_path\STM32Cube_FW_F7_VX.X.X\Drivers\BSP\Components\ for these we copy complete folder for each in our Components subfolder:

We need to add touch screen function and for this we need one file “ts.h”

First we need to create Common subfolder under Components and then copy ts.h from $Library_path\STM32Cube_FW_F7_VX.X.X\Drivers\BSP\Components\Common\ into it.

We also need fonts for display. We copy these into Utilities folder under Drivers we also need to create. They are found in $Library_path\STM32Cube_FW_F7_VX.X.X\Utilities\Fonts\

Now we have all the files where they need to be for now, but if we try to compile, we get error of files not found, that is because we haven’t defined the included directories yet. We do this now by right clicking on project name and selecting Properties.

Then go to: C/C++ General -> Paths and Symbols and select GNU C

Next click Add and add all of the following:

It should look something like this after you are finished: And then just click Ok.

We also need to add a few include files into our main.c file so that it is used when compiling:

Now it is time to try to compile to see if everything is Ok…

…believe it or not it doesn’t work yet. 🙁 It says there is problem with fonts. To solve this we need to comment a few lines of code in ‘$Project_name\Drivers\BSP\src\stm32746g_discovery_lcd.c’:

Now it should compile Ok. And this concludes part 1 of our STEmWin tutorial.

Here is link to part 2 of this tutorial.

Leave a Reply

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