STM32F746G-Discovery Setup Using STMCube

by Gilissen Erno in Circuits > Microcontrollers

1007 Views, 0 Favorites, 0 Comments

STM32F746G-Discovery Setup Using STMCube

DISCO_F746NG.jpg.250x250_q85.jpg

The STM32F746G-Discovery board has a big display and is cheap. The board has an Arduino-Uno compliant expansion connector.

The STMCube (at present 1.5.0) environment is very nice to generate set up code for the peripherals using a graphical interface. One can find info how to use the display on other environments, but not combined with STMCube and the graphical interface to set up devices.

Prerequisites:

- STMCube installed (1.5.0 or higher if available). A free of charge Eclipse based IDE.

- STM32Cube_FW_F7_V1.16.0 (and STM32Cube_FW_F7_V1.15.0 repositories installed (the latter contains the latest factory firmware in case you want to restore it, otherwise V1.15 isn't required)).

Notes:

- I may use mix slash and backslash in the description. This system was set up in Windows. So if one uses a Windows tool to copy, one has to use backslash instead of slash. The Cube settling - even in Windows - accept slash. I developed most of my x86/x64 code on Linux and micro controller code on Windows, so where I can I use slash and only use backslash if the Windows system doesn't accept slash.

- Some minor changes are made to the provided sources because of my personal preferences.

Create Your STM32 Project in STM Cube.

LTDC.png

- Typically one can put all peripherals to default mode in STM Cube. However, take into account ST Cube software sets Arduino timer pins by default in timer mode, while an AVR comes out of reset with pin set to input mode (I haven't checked if Arduino changes this default).

- Note if one needs 2 UARTS: this is possible since UART7 Rx/Tx pins are available in the Arduino range.

- I've put the LTDC in RGB565 mode. Since the FMC has a hardware 16-bit bus to the SDRAM - being used as GRAM - I'd preferred this option as 1 pixel on the screen matches a single SD RAM cell. The LTDC anyway converts the input data to 8-bit R, G and B signals.

- When ready, save the IOC file and select "Generate Code". Depending on how you use STMCube it may propose to generate code or one has to select manually (one option is to right click the project and select "Generate Code".

Copy ST Discovery Driver Files to Your Project

- In your project is a "Drivers" directory ("Drivers" was generated by the Cube code generator). Create there a new directory and name it "BSP".

- Create in that BSP directory a new directory, named "STM32746G-Discovery".

- The STM repository is installed the moment you started the Cube project based on STM32F746G-Discovery board. In your home directory (on windows this is typically "c:\users\\STM32Cube\Repository") locate

"STM32Cube_FW_F7_Vx.xx.x" (at present V1.16.0 is the latest version). Descent into

"Drivers\BSP\STM32746G-Discovery"

- Copy the files from the Cube repository into your own project new created "STM32746G-Discovery" directory.

- Select your project, click right and select refresh if the copied files are not visible in Cube (This is the case if you copied the files outside Cube).

Copy ST Component Drivers to Your Project

- Locate in your project the "Utilities" directory. Create in there a new directory, name it "Components".

- In the STM repository (on windows this is typically "c:\users\<yourname>\STM32Cube\Repository"), switch to "Drivers/BSP/Components). There one finds a series of directories.

- Copy at minimal the following directories to your new project "Components" directory: "Common", "ft5336", "n25q128a", "ov9655", "rk043fn48h" and "wm8994". I used Windows Explorer for that, so you have to refresh the project view (right click on it) after the move has finished.

Copy the Font Files to Your Project

- Create in your project, under directory "Utilities" a new directory and name it "Fonts".

- Switch in the ST repository (on windows this is typically "c:\users\\STM32Cube\Repository") to subdirectory "Utilities\Fonts".

- Copy the files found in the above directory to your newly created "Fonts" directory.

Set Search Paths

paths.png
lazy.png

All the extra directories must be added to the "Paths & Symbols". See the image.

Notes

- The leading slash can be ignored.

- To avoid a lot of setup hassle, I use the feature "Add to all configurations" and "All languages" so I only have to provide the paths once. Feel free to add paths to individual configurations / languages.

Main.c Updates

- In /* USER CODE BEGIN Includes */ section I added these includes:
#include "stm32746g_discovery.h"

#include "stm32746g_discovery_sdram.h"

#include "stm32746g_discovery_ts.h"

#include "stm32746g_discovery_lcd.h"

- In /* USER CODE BEGIN PV */ I made the LTDC Layer config static, since I add a test for the LTDC configuration (later on):

LTDC_LayerCfgTypeDef pLayerCfg;

- In /* USER CODE BEGIN 0 */ I added the touch interface, but this isn't needed for the 'Hello World':

TS_StateTypeDef ts;

char xTouchStr[10];

- In /* USER CODE BEGIN 1 */, I enabled instruction & data caches (maybe not required but expect it speeds up things):

SCB_EnableICache ();

SCB_EnableDCache ();

In /* USER CODE BEGIN 2 */ the add an "Hello World" message:

uint16_t* baseAddr = (uint16_t*) (pLayerCfg.FBStartAdress);

if (pLayerCfg.PixelFormat != LTDC_PIXEL_FORMAT_RGB565) myError_Handler ("LTDC Pixel Format Unexpected_181");

uint16_t xWidth = pLayerCfg.ImageWidth; //480.

uint16_t yWidth = pLayerCfg.ImageHeight; //272.

BSP_SDRAM_Init ();

__HAL_RCC_CRC_CLK_ENABLE ();

BSP_LCD_Init ();

BSP_LCD_LayerDefaultInit (0, pLayerCfg.FBStartAdress);

BSP_LCD_DisplayOn ();

BSP_LCD_SelectLayer (0);

BSP_LCD_Clear (LCD_COLOR_BLUE);

BSP_LCD_DisplayStringAt (20, 20, "Hello World", LEFT_MODE);

if ( (xWidth < 1)

|| (yWidth < 1)) myError_Handler ("LTDC Pixel Dimensions Unexpected_187");

/* USER CODE END 2 */

Note: if you don't have dedicated error handler, just adapt to the internal one by removing the text and change to Error_Handler.

- Something I haven't figured out yet: fact is that HAL_ETH_Init (&heth) generates an error code - possibly if there's no ethernet connected. So comment out the error handler:

if
(HAL_ETH_Init(&heth) != HAL_OK)

{

//Error_Handler();

}

Source Changes

Untitled.png

- For whatever reason, ST included C files in the provided sources (personally I do not prefer this)

So open in your project "Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.c" and comment out the included .c files. You can also consider to remove the paths from the environment settling but one cannot combine both.

- Some compile errors functions are defined twice popped up in my case; I had to open "/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_sd.c" file and remove

void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd)

void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)

Just remove those functions: they are already in the HAL driver from the auto generated code.

Time to Connect Your Board and Build / Run the Code

DISCO_F746NG.jpg.250x250_q85.jpg

This all should now compile. On my system, the build analyzer shows around 5% Flash memory is used by this code. Of course, this is a minimal configuration build: the touch controller is not yet read and only messages can be printed to the display.