Sei sulla pagina 1di 11

In this article I'll show you the needed steps to start programming with this development board using

a free
Eclipse/GCC tool-chain. We'll create a simple app that prints a jumping string on the LCD.Even if the application is
really trivial, it will give us the opportunity to set-up a complete environment to start programing with STM32F746GDISCO board.

Assumptions and requirements


In this tutorial Ill assume you have:

A complete Eclipse/GCC ARM tool-chain with required plugins as described in this post or in my book about
STM32 development. Ill assume that the whole tool-chain in installed in C:\STM32Toolchain or
~/STM32Toolchain if you have a UNIX-like system.
The linked post is designed to cover the Nucleo-F4 development board. However, the process to setup the toolchain is perfectly valid for all STM32 MCUs, and it's completely useless to repeat it here. There is only an
important difference, however. At the time of writing this post (13th July 2015) the official stable release of
OpenOCD is the 0.9 and it doesn't support the STM32F7 processor. We'll need to compile a "patched" version of
OpenOCD able to support the STM32F746G-DISCO board. So, if you don't already have OpenOCD installed in
your tool-chain, you can skip instructions about it in that tutorial, and follow the instructions here.
The latest version of STM32Cube-F7 framework from ST already downloaded and extracted.
an STM32F746G-DISCO board. I think that its also simple to arrange this procedure for other boards.

Create an empty project


The fist step is creating a skeleton project where well put HAL library from ST. So, start Eclipse and go to File->New>C Project and select Hello World ARM Cortex-M C/C++ project. You can choose the project name you want (I chose
test1). Click on Next.

In the next step you should configure the processor characteristics. But, since the GNU ARM Plugin still lacks of a
support for Cortex-M7 processors, you can completely skip this step, leaving the settings as shown in the following
picture:

In the next step leave all parameters unchanged except for the last one: Vendor CMSIS name. Change it from
DEVICE to stm32f7xx. Click on Next. You can leave the default parameters in the next steps. The final step is about
the GCC tool-chain. You can use these values:
tool-chain name: GNU Tools for ARM Embedded Processors (arm-none-eabi-gcc)
tool-chain path: C:\STM32Toolchain\gnu-arm\4.8-2014q3\bin
Click Finish.

Importing STM32Cube-HAL in the Eclipse project


Ok. Now we can start importing HAL files in our project. The project generated by GNU ARM Plug-in for Eclipse is a
skeleton containing Cortex Microcontroller Software Interface Standard (CMSIS) by ARM. CMSIS is a vendorindependent hardware abstraction layer for the Cortex-M processor series. It enables consistent and simple software
interfaces to the processor for interface peripherals, real-time operating systems, and middleware. Its intended to
simplify software re-use and reducing the learning. However, the CMSIS package is not sufficient to start programming
with an STM32 chip. Its also required a vendor specific Hardware Abstraction Layer (HAL). This is what ST provides
with its STM32Cube framework.

The above diagram try to explain better all the components involved in the final firmware generation. CMSIS is the
universal set of features developed by ARM, and its common to all Cortex-M vendors (ST, ATMEL, etc). ST HAL is
the hardware abstraction layer developed by ST for its specific devices, and its related to the STM32 family (F0, F1,
etc). The Device HAL is a sort of connector that allows the two subsystem to talk each other. Its a really simplified
view, but this is sufficient to start programming with this architecture.
Lets have a look to the generated project.

/src and /include folders contain our main application. The plug-in generated a bare bone main.c file.
We dont use these files, as well seen soon, but well place our main in that folder.
/system folder essentially contains the ARM CMSIS package.
/system/include/stm32f7xx and /system/src/stm32f7xx are the folders where well place the
STM32Cube HAL.
/ldscripts contains script for the GNU Link Editor (ld). These scripts instruct the linker to partition the
memory and do several stuffs in configuring interrupts and entry point routines.

Lets now have a look to cortexm subfolder.

The files Ive highlighted in blue in the above picture are generated automatically by the GNU ARM Eclipse plug-in.
They are part of what its called the Device HAL in the previous diagram. These files are substantially empty, and
should be replaced by custom code, both specific for the single vendor (ST in our case), both specific for the given
MCU. We are going to delete them.
So the first step is downloading the latest version of STM32Cube-F7 (or the one corresponding to your MCU) from ST
web site, unpack it and place it inside the folder C:\STM32Toolchain. Once extracted, rename the folder from
STM32Cube_FW_F7_V1.1.0 to STM32Cube_FW_F7.
Next, go in the Eclipse project and delete the following files:

/src/[main.c, Timer.c]

/include/Timer.h

/system/include/cmsis/[stm32f7xx.h,system_stm32f7xx.h]

/system/src/cmsis/[system_stm32f7xx.c,vectors_stm32f7xx.c]
Now we have to copy HAL and other files from STM32Cube to the Eclipse project.

HAL: go inside the STM32Cube_FW_F7/Drivers/STM32F7xx_HAL_Driver/Src folder and drag ALL the


files contained to the Eclipse folder /system/src/stm32f7xx. Eclipse will ask you how to copy these files in
the project folder. Select the entry Copy, as shown below (use always this choice):

Next, go inside the STM32Cube_FW_F7/Drivers/STM32F7xx_HAL_Driver/Inc folder and drag ALL the


files contained to the Eclipse folder /system/include/stm32f7xx.

Device HAL: go inside


the STM32Cube_FW_F7/Drivers/CMSIS/Device/ST/STM32F7xx/Include folder and drag ALL the files
contained to the Eclipse folder /system/include/cmsis.
We now need another two files. If you remember, weve deleted so far two files from the generated
project: system_stm32f7xx.c and vectors_stm32f7xx.c. We now need two files that do the same
job (essentially, they contain the startup routines). The file vectors_stm32f7xx.c should contain the startup
code when MCU resets. Well use an assembler file provided by ST. Go
inside STM32Cube_FW_F7/Drivers/CMSIS/Device/ST/STM32F7xx/Source/Templates/gcc folder and
drag the startup_stm32f746xx.s file inside the Eclipse folder /system/src/cmsis. Now, since Eclipse is
not able to manage files ending with .s, we have to change the file extension to .S (capital s). So the final
filename is startup_stm32f746xx.S.
Just another step. We still need a system_stm32f7xx.c file. but we need one specific for the MCU of our board.
Go inside the STM32Cube_FW_F7/Drivers/CMSIS/Device/ST/STM32F7xx/Source/Templates folder
and drag the system_stm32f7xx.c file inside the Eclipse folder /system/src/cmsis.

CMSIS: the STM32Cube_F7 package contains the updated release of CMSIS includes. The ones included by
GNU ARM Eclipse plug-in are rather old. So, let's update them. Go inside
the STM32Cube_FW_F7/Drivers/CMSIS/Device/Include folder and drag ALL the files contained to the
Eclipse folder /system/include/cmsis. When prompted, ask "Yes to all" to overwrite existing files.

BSP: the STM32F746G-DISCO board is a complex piece of hardware with several components (display,
memories, audio devices, etc). This requires specific software modules to properly handle all those functionalities
and to simplify the development process. ST grouped them in a software layer, named Board Support Package
(BSP). Let's import it in our project. First create two folders named BSP into
the /system/include and /system/src Eclipse folders, as shown below.

Go inside the STM32Cube_FW_F7_V1.1.0/Drivers/BSP folder and drag the Components subfolder inside
the /system/include Eclipse folder. Next, go inside
the STM32Cube_FW_F7_V1.1.0/Drivers/BSP/STM32746G-Discovery folder and drag all *.h files inside
the /system/include/BSP Eclipse folder, and all *.c files in /system/src/BSP. The following picture shows

the final result.

Utilities: go inside the folder STM32Toolchain/STM32Cube_FW_F7 folder and drag the Utility subfolder
inside the root of your Eclipse project (for the sake of completeness, I have to say that the whole content of this
folder is not needed. However, to simplify this tutorial drag it entirely. When finished, you can try by your self what
delete from it - Media and PC_Software subfolders are not needed).

We are almost at the end of the whole procedure. We only need to setup few other things. First, we have to declare
which MCU we are using defining a global macro inside the project configuration. Go inside the project properties (on
the main Eclipse menu go to Project->Properties), then C/C++ Build->Settings. Click on Tool Settings and go

in Cross ARM C Compiler->Preprocessor. Click on the Add icon (


) and add the macro STM32F746xx. Repeat
this step also for Cross ARM GNU Assembler and Cross ARM C++ Compiler sections.

Second, we have to setup the proper Cortex core for the STM32F7. Without leaving the project settings dialog, go
in Target Processor section and choose cortex-m7. Now we have to make Eclipse aware of other include folders
(the folder BSP and Components we have added to the project). Go in Cross ARM C Compiler->Preprocessor and

add "../system/include/BSP" and "../system/include/Components" to the Includes section, as shown


below.

You can close che Project Settings dialog clicking on "OK". Finally, open the ldscripts/mem.ld file and set the
FLASH and RAM memory regions in the following way :

Ok. The framework is essentially configured and we can start programming our Discovery board. The
complete procedure should now use the STCubeMX tool to properly generate HAL configuration and initializations
files. However, this would require a separated tutorial. To simplify this post, I'll skip this step. You can find other
tutorials on my blog that show how to do this. If you are not new to STM32 programming, it will be really easy to start
programming using this bare bone project.

To finish the tutorial, you can take a complete example project from my github account and copy all files contained
in /src and /include folders in the corresponding Eclipse folder (or, if you want, you can import the whole project and
start testing it). The main.c file is really simple. This is the excerpt of main()function:

During the compilation process you'll see a lot of warnings to the Eclipse CDT console. To disable them, go in
the Project Settings->C/C++ Build->Settings and in the Warnings sections uncheck the entry "Enable all common
warnings (-Wall)".

Building OpenOCD
As I've said at the beginning of this tutorial, the current stable release of OpenOCD (0.9) can't be used to flash
STM32F7 processors, since they have a different internal flash from other STM32 MCUs, which requires a different
programming procedure. Fortunately, Rmi PRUD'HOMME (I think an ST engineer) has submitted a patch to
OpenOCD to enable support STM32F7 family and STM32F746-DISCO board. This patch has been merged in the
development OpenOCD repo. So, we can compile a custom version easily. However, I'll not give instructions on how
to compile OpenOCD on the Windows platform (read this comment to download a precompiled patched version).
Please, check OpenOCD instructions about this.
First let's clone the development repo of OpenOCD in this way:

Next, we can compile OpenOCD in the following way:

Once compiled, you can configure Eclipse to use this version of OpenOCD. If you are new to this procedure, please
refer to this post. To start OpenOCD from command line, type:

If all is OK, these messages appears on command line:

Conclusions
With the instructions of this tutorial, you are ready to starting having fun with your new toy. I hope all instructions are
clear. If they worked for you, please consider leaving a comment on the bottom. I really appreciate it.

Potrebbero piacerti anche