0% found this document useful (0 votes)
155 views

dm00116575 Getting Started With Stm32cubef3 For stm32f3 Series Stmicroel PDF

Uploaded by

OmarBinNaeem
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views

dm00116575 Getting Started With Stm32cubef3 For stm32f3 Series Stmicroel PDF

Uploaded by

OmarBinNaeem
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

UM1766

User manual
Getting started with STM32CubeF3 for STM32F3 Series

Introduction
STMCube™ initiative is an STMicroelectronics original initiative to ease developers life by
reducing development efforts, time and cost. STM32Cube covers STM32 portfolio.
STM32Cube Version 1.x includes:
• The STM32CubeMX, a graphical software configuration tool that allows to generate C
initialization code using graphical wizards.
• A comprehensive embedded software platform, delivered per series (such as
STM32CubeF3 for STM32F3 Series)
– The STM32Cube HAL, an STM32 abstraction layer embedded software, ensuring
maximized portability across STM32 portfolio
– A consistent set of middleware components such as RTOS, USB, STMTouch, FatFS
and Graphics
– All embedded software utilities coming with a full set of examples
The STMCube™ package is a free solution that can be downloaded from ST website at
http://www.st.com/stm32cube.
This user manual describes how to get started with the STM32CubeF3 firmware package.
Section 1 describes the main features of STM32CubeF3 firmware, part of the STM32Cube
initiative.
Section 2 and Section 3 provide an overview of the STM32CubeF3 architecture and
firmware package structure.

December 2016 DocID026352 Rev 8 1/29


www.st.com 1
UM1766 Contents

Contents

1 STM32CubeF3 main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 STM32CubeF3 architecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 8


2.1 Level 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1.1 Board Support Package (BSP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1.2 Hardware Abstraction Layer (HAL) and Low Layer (LL) . . . . . . . . . . . . . 9
2.1.3 Basic peripheral usage examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2 Level 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2.1 Middleware components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2.2 Examples based on the middleware components . . . . . . . . . . . . . . . . . 11
2.3 Level 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11

3 STM32CubeF3 firmware package overview . . . . . . . . . . . . . . . . . . . . . 12


3.1 Supported STM32F3 devices and hardware . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Firmware package overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

4 Getting started with STM32CubeF3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18


4.1 Running the first example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.2 Developing your own application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2.1 HAL application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2.2 LL application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.3 Using STM32CubeMX to generate the initialization C code . . . . . . . . . . 23
4.4 Getting STM32CubeF3 release updates . . . . . . . . . . . . . . . . . . . . . . . . . 23

5 FAQs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.1 What is the license scheme for the STM32CubeF3 firmware? . . . . . . . . 24
5.2 Which boards are supported by the STM32CubeF3 firmware package? . 24
5.3 Are any examples provided with the ready-to-use toolset projects? . . . . 24
5.4 Is there any link with Standard Peripheral Libraries? . . . . . . . . . . . . . . . . 24
5.5 Does the HAL take benefit from interrupts or DMA?
How can this be controlled? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.6 How are the product/peripheral specific features managed? . . . . . . . . . . 25
5.7 How can STM32CubeMX generate code based on embedded software? 25

DocID026352 Rev 8 2/29


3
Contents UM1766

5.8 How can the user get regular updates on the latest
STM32CubeF3 firmware releases? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.9 When to use HAL versus LL drivers? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.10 How can the user include LL drivers in his/her environment?
Is there any LL configuration file as for HAL? . . . . . . . . . . . . . . . . . . . . . 25
5.11 Can HAL and LL drivers be used together?
If yes, what are the constraints? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
5.12 Are there any LL APIs not available with HAL? . . . . . . . . . . . . . . . . . . . . 26
5.13 Why are SysTick interrupts not enabled on LL drivers? . . . . . . . . . . . . . . 26
5.14 How are LL initialization APIs enabled? . . . . . . . . . . . . . . . . . . . . . . . . . . 26

6 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

3/29 DocID026352 Rev 8


UM1766 List of tables

List of tables

Table 1. Macros for STM32F3 Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12


Table 2. Boards for STM32F3 Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Table 3. Number of examples available for each board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Table 4. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

DocID026352 Rev 8 4/29


4
List of figures UM1766

List of figures

Figure 1. STM32Cube firmware components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7


Figure 2. STM32CubeF3 firmware architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 3. STM32CubeF3 firmware package structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 4. STM32CubeF3 example overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

5/29 DocID026352 Rev 8


UM1766 STM32CubeF3 main features

1 STM32CubeF3 main features

STM32CubeF3 gathers together, in a single package, all the generic embedded software
components required to develop an application on STM32F3 microcontrollers. In line with
the STM32Cube initiative, this set of components is highly portable, not only within
STM32F3 Series but also to other STM32 Series.
STM32CubeF3 is fully compatible with STM32CubeMX code generator that allows the user
to generate initialization code. The package includes a low level hardware abstraction layer
(HAL) that covers the microcontroller hardware, together with an extensive set of examples
running on STMicroelectronics boards. The HAL is available in open-source BSD license for
user convenience.
STM32CubeF3 package also contains a set of middleware components with the
corresponding examples. They come in very permissive license terms:
• Full USB Device stack supporting many classes: Audio, HID, MSC, CDC and DFU,
• CMSIS-RTOS implementation with FreeRTOS open source solution,
• FAT File system based on open source FatFS solution,
• STMTouch touch sensing library solution,
• STemWin, a professional graphical stack solution available in binary format and based
on ST partner solution SEGGER emWin.
Several applications and demonstrations implementing all these middleware components
are also provided in the STM32CubeF3 package.

DocID026352 Rev 8 6/29


28
STM32CubeF3 main features UM1766

Figure 1. STM32Cube firmware components

670&XEH0;±,QLWLDOL]DWLRQ&FRGHJHQHUDWRU

3RUWDEOH3URJUDPPLQJ,QWHUIDFH±+DUGZDUH$EVWUDFWLRQ/D\HU0LGGOHZDUH 572686%«

670&XEH) 670&XEH) 670&XEH) 670&XEH) 670&XEH) 670&XEH) 670&XEH/ 670&XEH/ 670&XEH/

(PEHGGHG (PEHGGHG (PEHGGHG (PEHGGHG (PEHGGHG (PEHGGHG (PEHGGHG (PEHGGHG (PEHGGHG


VRIWZDUHIRU VRIWZDUHIRU VRIWZDUHIRU VRIWZDUHIRU VRIWZDUHIRU VRIWZDUHIRU VRIWZDUHIRU VRIWZDUHIRU VRIWZDUHIRU
670) 670) 670) 670) 670) 670) 670/ 670/ 670/

6701XFOHR
(YDOXDWLRQERDUGV 'LVFRYHU\ERDUGV 'HGLFDWHGERDUGV
ERDUGV
8WLOLWLHV
$SSOLFDWLRQOHYHOGHPRQVWUDWLRQV

7RXFK )$7ILOH
7&3,3 86% *UDSKLFV 5726 &06,6
/LEUDU\ V\VWHP

0LGGOHZDUHOHYHO 8WLOLWLHV

%RDUG6XSSRUW3DFNDJH %63 /RZ/D\HU // +DUGZDUH$EVWUDFWLRQ/D\HU +$/

'ULYHUVOHYHO

670) 670) 670) 670) 670) 670) 670/ 670/ 670/

+DUGZDUH

069

7/29 DocID026352 Rev 8


UM1766 STM32CubeF3 architecture overview

2 STM32CubeF3 architecture overview

The STM32Cube firmware solution is built around three independent levels that can easily
interact with each other, as described in the Figure 2 below:

Figure 2. STM32CubeF3 firmware architecture

>ĞǀĞůϮ (YDOXDWLRQERDUGDQG'LVFRYHU\.LWGHPRQVWUDWLRQ

$SSOLFDWLRQV

>ĞǀĞůϭ

/LEUDU\DQGSURWRFROEDVHGFRPSRQHQWV
IRUH[DPSOH)DW)6)UHH572686%'HYLFH

([DPSOHV

>ĞǀĞůϬ %63GULYHUV
+DUGZDUHDEVWUDFWLRQOD\HU +$/

&RUHGULYHUV RSWLRQDO /RZ/D\HU //

,>

06Y9

2.1 Level 0
This level is divided into three sub-layers:
• Board Support Package (BSP)
• Hardware Abstraction Layer (HAL)
– HAL peripheral drivers
– Low Layer drivers
• Basic peripheral usage examples

DocID026352 Rev 8 8/29


28
STM32CubeF3 architecture overview UM1766

2.1.1 Board Support Package (BSP)


This layer offers a set of APIs relative to the hardware components in the hardware boards
(such as LCD, Audio, microSD, MEMS drivers). It is composed of two parts:
• Component
This is the driver relative to the external device on the board and not related to the
STM32. The component driver provides specific APIs to the BSP driver external
components and can be portable on any other board.
• BSP driver
It permits to link the component driver to a specific board and provides a set of friendly
used APIs. The APIs naming rule is BSP_FUNCT_Action().
Example: BSP_LED_Init(),BSP_LED_On()
The BSP is based on a modular architecture allowing an easy porting on any hardware
by implementing the low level routines.

2.1.2 Hardware Abstraction Layer (HAL) and Low Layer (LL)


The STM32CubeF3 HAL and LL are complementary and cover a wide range of applications
requirements.
• The HAL drivers offer high-level function-oriented highly-portable APIs. They hide the
MCU and peripheral complexity to end user.
The HAL drivers provide generic multi-instance feature-oriented APIs which simplify
user application implementation by providing ready to use process. As example, for the
communication peripherals (I2S, UART…), it provides APIs allowing initializing and
configuring the peripheral, managing data transfer based on polling, interrupt or DMA
process, and handling communication errors that may raise during communication.
The HAL driver APIs are split in two categories:
– Generic APIs providing common and generic functions to all the STM32 Series
– Extension APIs, which provide specific and customized functions for a specific
family or a specific part number.
• The Low Layer APIs provide low-level APIs at register level, with better optimization but
less portability. They require a deep knowledge of MCU and peripheral specifications.
The LL drivers are designed to offer a fast light-weight expert-oriented layer that is
closer to the hardware than the HAL. Contrary to the HAL, LL APIs are not provided for
peripherals where optimized access is not a key feature, or for those requiring heavy
software configuration and/or complex upper-level stack (such as USB).
The LL drivers feature:
– A set of functions to initialize peripheral main features according to the parameters
specified in data structures
– A set of functions used to fill initialization data structures with the reset values
corresponding to each field
– Function for peripheral de-initialization (peripheral registers restored to their
default values)
– A set of in-line functions for direct and atomic register access
– Full independence from HAL and capability to be used in standalone mode
(without HAL drivers)
– Full coverage of the supported peripheral features.

9/29 DocID026352 Rev 8


UM1766 STM32CubeF3 architecture overview

2.1.3 Basic peripheral usage examples


This layer encloses the examples built over the STM32 peripheral and that use only the HAL
and BSP resources.

2.2 Level 1
This level is divided into two sub-layers:
• Middleware components
• Examples based on the middleware components

2.2.1 Middleware components


The middleware is a set of Libraries covering USB Device library, STMTouch touch sensing
library, graphical STemWin library, FreeRTOS and FatFS. Horizontal interactions between
the components of this layer is done directly by calling the feature APIs while the vertical
interaction with the low level drivers is done through specific callbacks and static macros
implemented in the library system call interface. As example, the FatFs implements the disk
I/O driver to access microSD drive or the USB Mass Storage Class.
The main features of each middleware component are as follows:
• USB Device Library
– Several USB classes supported (Mass-Storage, HID, CDC, DFU, AUDIO, MTP)
– Supports multi packet transfer features: allows sending big amounts of data
without splitting them into max packet size transfers.
– Uses configuration files to change the core and the library configuration without
changing the library code (Read Only).
– RTOS and Standalone operation,
– The link with low-level driver is done through an abstraction layer using the
configuration file to avoid any dependency between the Library and the low-level
drivers.
• STemWin Graphical stack
– Professional grade solution for GUI development based on SEGGER emWin
solution.
– Optimized display drivers.
– Software tools for code generation and bitmap editing (STemWin Builder…).
• FreeRTOS
– Open source standard,
– CMSIS compatibility layer,
– Tickless operation during low-power mode,
– Integration with all STM32Cube middleware modules.
• FAT File system
– FATFS FAT open source library,
– Long file name support,
– Dynamic multi-drive support,
– RTOS and standalone operation,

DocID026352 Rev 8 10/29


28
STM32CubeF3 architecture overview UM1766

– Examples with microSD.


• STM32 Touch Sensing Library
– Robust STMTouch capacitive touch sensing solution supporting proximity,
touchkey, linear and rotary touch sensor using a proven surface charge transfer
acquisition principle.

2.2.2 Examples based on the middleware components


Each middleware component comes with one or more examples (also called Applications)
showing how to use it. Integration examples that use several middleware components are
also provided.

2.3 Level 2
This level is composed of a single layer, which is a global real-time and graphical
demonstration based on the middleware service layer, the low level abstraction layer and
the basic peripheral usage applications for board based functionalities.

11/29 DocID026352 Rev 8


UM1766 STM32CubeF3 firmware package overview

3 STM32CubeF3 firmware package overview

3.1 Supported STM32F3 devices and hardware


STM32Cube offers highly portable Hardware Abstraction Layer (HAL) built around a generic
architecture and allows the build-upon layers, like the middleware layer, to implement its
functions without knowing, in-depth, the MCU used. This improves the library code
re-usability and guarantees an easy portability on other devices.
The layered architecture of the STM32CubeF3 offers the full support of the whole STM32F3
Series. The user only needs define the right macro in stm32f3xx.h.
Table 1 below provides the macro to define depending on the used STM32F3 device (this
macro must also be defined in the compiler preprocessor).

Table 1. Macros for STM32F3 Series


Macro defined in
STM32F3 devices
stm32f3xx.h

STM32F301K6, STM32F301C6, STM32F301R6,


STM32F301x8
STM32F301K8, STM32F301C8 and STM32F301R8
STM32F302K6, STM32F302C6, STM32F302R6,
STM32F302x8
STM32F302K8, STM32F302C8 and STM32F302R8
STM32F302CB, STM32F302RB, STM32F302VB,
STM32F302xC
STM32F302CC, STM32F302RC and STM32F302VC
STM32F302RD, STM32F302VD, STM32F302ZD, STM32F302RE, STM32F302VE
STM32F302xE
and STM32F302ZE
STM32F303K6, STM32F303C6, STM32F303R6,
STM32F303x8
STM32F303K8, STM32F303C8 and STM32F303R8
STM32F303CB, STM32F303RB, STM32F303VB,
STM32F303xC
STM32F303CC, STM32F303RC and STM32F303VC
STM32F303RD, STM32F303VD, STM32F303ZD, STM32F303RE, STM32F303VE
STM32F303xE
and STM32F303ZE
STM32F373C8, STM32F373R8, STM32F373V8,
STM32F373xC STM32F373CB, STM32F373RB, STM32F373VB,
STM32F373CC, STM32F373RC and STM32F373VC
STM32F334K4, STM32F334C4, STM32F334R4,
STM32F334x8 STM32F334K6, STM32F334C6, STM32F334R6,
STM32F334K8, STM32F334C8 and STM32F334R8
STM32F318xx STM32F318K8 and STM32F318C8
STM32F328xx STM32F328C8 and STM32F328R8
STM32F358xx STM32F358CC, STM32F358RC and STM32F358VC
STM32F378xx STM32F378CC, STM32F378RC and STM32F378VC
STM32F398xx STM32F398VE

DocID026352 Rev 8 12/29


28
STM32CubeF3 firmware package overview UM1766

STM32CubeF3 features a rich set of examples and applications at all levels making it easy
to understand and use any HAL driver and/or middleware components. These examples are
running on the STMicroelectronics boards listed in Table 2.

Table 2. Boards for STM32F3 Series


Board part number STM32F3 devices supported

NUCLEO-F303RE STM32F303RE
STM32303E-EVAL STM32F303VE
32F3348DISCOVERY STM32F334C8
NUCLEO-F334R8 STM32F334R8
NUCLEO-F302R8 STM32F302R8
STM32373C-EVAL STM32F373VC
NUCLEO-F303K8 STM32F303K8
NUCLEO-F303ZE STM32F303ZE
STM32F3DISCOVERY STM32F303VC
STM32303C-EVAL STM32F303VC

STM32CubeF3 supports Nucleo-32, Nucleo-64 and Nucleo-144 boards.


• Nucleo-64 and Nucleo-144 boards support Adafruit LCD display Arduino™ UNO
shields which embed a microSD connector and a joystick in addition to the LCD.
• Nucleo-32 boards support Gravitech 7-segment display Arduino™ NANO shields
which allow displaying up to four-digit numbers and characters.
The Arduino™ shield drivers are provided within the BSP component. Their usage is
illustrated by a demonstration firmware.
The STM32CubeF3 firmware can run on any compatible hardware. Simply update the BSP
drivers to port the provided examples on your board if its hardware features are the same
(e.g. LED, LCD display, buttons).

13/29 DocID026352 Rev 8


UM1766 STM32CubeF3 firmware package overview

3.2 Firmware package overview


The STM32CubeF3 firmware solution is provided in one single zip package having the
structure shown in Figure 3.

Figure 3. STM32CubeF3 firmware package structure

%63GULYHUVIRUWKHVXSSRUWHGERDUGV
ƒ(YDOXDWLRQERDUGV
ƒ'LVFRYHU\NLW
ƒ1XFOHRNLW

&RQWDLQV670)[[&06,6ILOHV 'ULYHUVRIH[WHUQDOFRPSRQHQWV
WKDWGHILQHWKHSHULSKHUDOUHJLVWHU
GHFODUDWLRQVELWGHILQLWLRQVDQG
WKHDGGUHVVPDSSLQJ
670)[[+$/DQG//
GULYHUVIRUDOOSHULSKHUDOV

67HP:LQSURIHVVLRQDOVWDFN 7RXFK6HQVLQJ/LEUDU\
FRPLQJIURP6(**(5DQG
DYDLODEOHLQELQDU\IRUP

86%'HYLFH/LEUDU\RIIHULQJFODVVHV
+,'06&&'&DQG')8
6HWRI([DPSOHV$SSOLFDWLRQV
DQG'HPRQVWUDWLRQVRUJDQL]HG
E\ERDUGDQGSURYLGHGE\
SUHFRQILJXUHGSURMHFW 2SHQVRXUFHVPLGGOHZDUHVWDFNV

0LVFHOODQHRXVXWLOLWLHV
8VHUPRGLILDEOHILOHV

/LEUDU\ILOHVQRWWREH 0HGLDILOHV DXGLRLPDJHV«


PRGLILHGE\WKHXVHU
069

For each board, a set of examples are provided with pre-configured projects for EWARM,
MDK-ARM™, TrueSTUDIO® and SW4STM32 toolchains.

DocID026352 Rev 8 14/29


28
STM32CubeF3 firmware package overview UM1766

Figure 4 shows the structure of projects for the STM32303E-EVAL board.

Figure 4. STM32CubeF3 example overview

The examples are organized depending on the STM32Cube level they apply to, and are
named as described below:
• Examples in level 0 are called Examples, Examples_LL and Examples_MIX. They use,
respectively, HAL drivers, LL drivers and a mix of HAL and LL drivers without any
middleware component.
• Examples in level 1 are called Applications. They provide typical use cases of each
middleware component.
The template projects available in the Templates and Templates_LL directories allow to
quickly build any firmware application on a given board.

15/29 DocID026352 Rev 8


UM1766 STM32CubeF3 firmware package overview

All examples have the same structure,


• \Inc folder that contains all header files
• \Src folder for the sources code
• \EWARM, \MDK-ARM, \TrueSTUDIO and \SW4STM32 folders contain the pre-
configured project for each toolchain.
• readme.txt describing the example behavior and needed environment to make it
working
Table 3 provides the number of projects available for each board.

DocID026352 Rev 8 16/29


28
UM1766
Table 3. Number of examples available for each board
Nucleo- STM32303E- STM32F3348- Nucleo- Nucleo- STM32373C- Nucleo- STM32F3- Nucleo- STM32303C-
Level Total
F303RE EVAL Discovery F334R8 F302R8 EVAL F303K8 Discovery F303ZE EVAL

Templates_LL 1 1 1 1 1 1 1 1 1 1 10
Templates 1 1 1 1 1 1 1 1 1 1 10
Examples_MIX 0 0 0 9 1 0 0 0 0 0 10
Examples_LL 0 0 1 67 5 0 0 0 1 0 74
Examples 26 43 24 4 33 42 30 40 38 57 337
Demonstrations 1 0 1 1 1 0 1 1 1 0 7
Applications 8 19 1 1 3 22 1 3 3 16 77
Total 37 64 29 84 45 66 34 46 45 75 525
DocID026352 Rev 8

STM32CubeF3 firmware package overview


17/29
UM1766 Getting started with STM32CubeF3

4 Getting started with STM32CubeF3

4.1 Running the first example


This section explains how to run a first example within STM32CubeF3, using as illustration
the generation of a simple LED toggle running on STM32F302R8 Nucleo board:
1. Download the STM32CubeF3 firmware package. Unzip it into a directory of your
choice. Make sure not to modify the package structure shown in Figure 4. Note that it is
also recommended to copy the package at a location close to your root volume (for
example C:\Eval or G:\Tests) because some IDEs encounter problems when the
path length is too long.
2. Browse to \Projects\STM32F302R8-Nucleo\Examples
3. Open \GPIO, then \GPIO_EXTI folder
4. Open the project with your preferred toolchain (*)
5. Rebuild all files and load your image into target memory
6. Run the example: each time you press the USER push button, the LED2 toggles (for
more details, refer to the example readme file).
(*) The following section provides a quick overview on how to open, build and run an
example with the supported toolchains:
• EWARM
– Under the example folder, open \EWARM subfolder
– Launch the Project.eww workspace(a)
– Rebuild all files: Project->Rebuild all
– Load the project image: Project->Debug
– Run the program: Debug->Go(F5)
• MDK-ARM™
– Under the example folder, open \MDK-ARM subfolder
– Launch the Project.uvproj workspace(a)
– Rebuild all the files: Project->Rebuild all target files
– Load the project image: Debug->Start/Stop Debug Session
– Run the program: Debug->Run (F5)
• TrueSTUDIO®
– Open the TrueSTUDIO® toolchain
– Select File->Switch Workspace->Other and browse to TrueSTUDIO workspace
directory
– Select File->Import, select General->'Existing Projects into Workspace' and then
Select "Next".
– Browse to the TrueSTUDIO workspace directory, select the project
– Rebuild all the project files: select the project in the "Project explorer"
window then select Project->build project menu.
– Run the program: Run->Debug (F11)

a. The workspace name may change from one example to another.

DocID026352 Rev 8 18/29


28
Getting started with STM32CubeF3 UM1766

• SW4STM32
a) Open the SW4STM32 toolchain.
b) Click File->Switch Workspace->Other and browse to the SW4STM32
workspace directory.
c) Click File->Import, select General->'Existing Projects into Workspace' and
then click "Next".
d) Browse to the SW4STM32 workspace directory and select the project.
e) Rebuild all project files: select the project in the "Project explorer" window then
click Project->build project menu.
f) Run program: Run->Debug (F11).

4.2 Developing your own application

4.2.1 HAL application


This section describes the steps required to create your own application using
STM32CubeF3.
1. Create your project
To create a new project you can either start from the Template project provided for each
board under \Projects\<STM32xxx_yyy>\Templates or from any available
project under \Projects\<STM32xxy_yyy>\Examples or
\Projects\<STM32xx_yyy>\Applications (where <STM32xxx_yyy> refers to
the board name, for example STM32303C_EVAL).
The Template project provides an empty main loop function. It is a good starting point
to get familiar with project settings for the STM32CubeF3. The template has the
following characteristics:
a) It contains sources of HAL, CMSIS and BSP drivers which are the minimal
components to develop a code on a given board.
b) It contains the include paths for all the firmware components.
c) It defines the STM32F3 device supported, allowing to configure the CMSIS and
HAL drivers accordingly.
d) It provides ready-to-use user files pre-configured as shown below
- HAL is initialized with the default timebase with ARM Core SysTick,
- SysTick ISR is implemented for HAL_Delay() purpose,
- System clock is configured with the minimum frequency of the device (HSI) for
an optimum power consumption.
Note: When copying an existing project to another location, make sure to update the included
paths.
2. Add the necessary middleware to your project (optional)
The available middleware stacks are: USB Device Library, STemWin, Touch Sensing
Library, FreeRTOS and FatFS. To know which source files you need to add in the
project files list, refer to the documentation provided for each middleware. You may
also look at the Applications available under
\Projects\STM32xxx_yyy\Applications\<MW_Stack> (where <MW_Stack>
refers to the middleware stack, for example USB_Device) to see which sources files
and include paths need to be added.

19/29 DocID026352 Rev 8


UM1766 Getting started with STM32CubeF3

3. Configure the firmware components


The HAL and middleware components offer a set of build time configuration options
using macros “#define” declared in a header file. A template configuration file is
provided within each component, it has to be copied to the project folder (usually the
configuration file is named xxx_conf_template.h, the word “_template” needs to be
removed when copying the file into the project folder). The configuration file provides
enough information to know the impact of each configuration option; more detailed
information is available in the documentation provided for each component.
4. Start the HAL Library
After jumping to the main program, the application code calls the HAL_Init() API to
initialize the HAL Library, which does the following:
a) configuration of the Flash prefetch and SysTick interrupt priority (configured by
user through macros defined in stm32f3xx_hal_conf.h),
b) configuration of the SysTick to generate an interrupt each 1 ms at the SysTick
interrupt priority TICK_INT_PRIO defined in stm32f3xx_hal_conf.h, which is
clocked by the HSI (at this stage, the clock is not yet configured and thus the
system is running from the internal HSI at 8 MHz),
c) Setting of NVIC Group Priority to 4,
d) Calling of HAL_MspInit() callback function defined in the user file
stm32f3xx_hal_msp.c, to run the global low level hardware initializations.
5. Configure the system clock
The system clock configuration is done by calling the two APIs described below:
a) HAL_RCC_OscConfig(): configures the internal and/or external oscillators, PLL
source and factors. The user may select to configure one oscillator or all
oscillators. The PLL configuration can be skipped if there is no need to run the
system at high frequency.
b) HAL_RCC_ClockConfig(): configures the system clock source, the Flash latency
and AHB and APB prescalers.
The parameters of the clock configuration functions can be evaluated thanks to the
Clock Configuration tab of the STM32CubeMX tool.
6. Peripheral initialization
a) Start by writing the peripheral HAL_PPP_MspInit function. For this function,
please proceed as follows:
- Enable the peripheral clock.
- Configure the peripheral GPIOs.
- Configure the DMA channel and enable the DMA interrupt (if needed).
- Enable the peripheral interrupt (if needed).
b) Edit the stm32xxx_it.c to call the required interrupt handlers (peripheral and DMA),
if needed.
c) Write process complete callback functions if you plan to use peripheral interrupt or
DMA.
d) In your main.c file, initialize the peripheral handle structure then call the function
HAL_PPP_Init() to initialize your peripheral.

DocID026352 Rev 8 20/29


28
Getting started with STM32CubeF3 UM1766

7. Develop your application


At this stage, your system is ready and you can start developing your application code.
a) The HAL provides intuitive and ready to use APIs to configure the peripheral, and
support polling, IT and DMA programming model, to accommodate any
application requirements. For more details on how to use each peripheral, refer to
the extensive set of examples provided.
b) If your application has some real time constraints, you can find a large set of
examples showing how to use FreeRTOS and its integration with all middleware
stacks provided within STM32CubeF3. This can be a good starting point for your
development.
Caution: In the default HAL implementation, SysTick timer is the source of time base. It is used to
generate interrupts at regular time intervals. Take care if HAL_Delay() is called from the
peripheral ISR process. The SysTick interrupt must have higher priority (numerically lower)
than the peripheral interrupt. Otherwise, the caller ISR process is blocked. Functions
affecting the time base configurations are declared as __weak to make the override
possible in case of other implementations in user file (using a general purpose timer for
example or other time source). For more details please refer to HAL_TimeBase example.

21/29 DocID026352 Rev 8


UM1766 Getting started with STM32CubeF3

4.2.2 LL application
This section describes the steps needed to create your own LL application using
STM32CubeF3.
1. Create your project
To create a new project you can either start from the Templates_LL project provided for
each board under \Projects\<STM32xxx_yyy>\Templates_LL or from any available
project under \Projects\<STM32xxy_yyy>\Examples_LL (<STM32xxx_yyy> refers to
the board name, such as NUCLEO-F334R8).
The Template project provides an empty main loop function, however it is a good
starting point to get familiar with project settings for STM32CubeF3.
Template main characteristics are the following:
– It contains the source codes of the LL and CMSIS drivers which are the minimal
components needed to develop code on a given board.
– It contains the include paths for all the required firmware components.
– It selects the supported STM32F3 device and allows to configure the CMSIS and
LL drivers accordingly.
– It provides ready-to-use user files, that are pre-configured as follows:
main.h : LED & USER_BUTTON definition abstraction layer.
main.c : System clock configuration for maximum frequency.
2. Port an existing project to another board
To port an existing project to another target board, start from the Templates_LL project
provided for each board and available under
\Projects\<STM32xxx_yyy>\Templates_LL:
a) Select a LL example
To find the board on which LL examples are deployed, refer to the list of LL
examples STM32CubeProjectsList.html, to Table 3: Number of examples
available for each board or to application note “STM32Cube firmware examples
for STM32F3 Series” (AN4734)
b) Port the LL example
– Copy/paste the Templates_LL folder - to keep the initial source - or directly update
existing Templates_LL project.
– Then porting consists principally in replacing Templates_LL files by the
Examples_LL targeted project.
– Keep all board specific parts. For reasons of clarity, board specific parts have been
flagged with specific tags:
/* ============== BOARD SPECIFIC CONFIGURATION CODE BEGIN ============== */
/* ============== BOARD SPECIFIC CONFIGURATION CODE END ============== */
Thus the main porting steps are the following:
– Replace the stm32F3xx_it.h file
– Replace the stm32F3xx_it.c file
– Replace the main.h file and update it: Keep the LED and user button definition of
the LL template under "BOARD SPECIFIC CONFIGURATION" tags.

DocID026352 Rev 8 22/29


28
Getting started with STM32CubeF3 UM1766

– Replace the main.c file and update it:


Keep the clock configuration of the SystemClock_Config() LL template function
under "BOARD SPECIFIC CONFIGURATION" tags.
Depending on LED definition, replace each LEDx occurrence with another LEDy
available in main.h.
Thanks to these adaptations, the example should be functional on the targeted board.

4.3 Using STM32CubeMX to generate the initialization C code


An alternative to steps 1 to 6 described in Section 4.2 consists of using the STM32CubeMX
tool to generate the code for the initialization of the system, the peripherals and middleware
(steps 1 to 6 above) through a step-by-step process:
• Select the STMicroelectronics STM32 microcontroller that matches the required set of
peripherals.
• Configure each required embedded software using the pinout-conflict solver, a clock-
tree setting helper, a power consumption calculator, and the utility performing MCU
peripheral configuration (for example GPIO, USART) and middleware stacks (for
example USB).
• Generate the initialization C code based on the configuration selected. This code is
ready to use within several development environments. The user code is kept at the
next code generation.
For more information refer to STM32CubeMX user manual UM1718, available on
www.st.com.

4.4 Getting STM32CubeF3 release updates


The STM32CubeF3 firmware package comes with an updater utility: STM32CubeUpdater,
also available as a menu within STM32CubeMX code generation tool.
The updater solution detects new firmware releases and patches available on www.st.com
and proposes the download on the user’s computer.

Installing and running the STM32CubeUpdater program


The STM32CubeUpdater.exe is available under \Utilities\PC_Software.
• Double-click the SetupSTM32CubeUpdater.exe file to launch the installation.
• Accept the license terms and follow the different installation steps.
Upon successful installation, STM32CubeUpdater becomes available as an
STMicroelectronics program under Program Files and is automatically launched. The
STM32CubeUpdater icon appears in the system tray:
Right-click the updater icon and select Updater Settings to configure the Updater
connection and whether to perform manual or automatic checks (see STM32CubeMX User
guide - UM1718 section 3 - for more details on Updater configuration).

23/29 DocID026352 Rev 8


UM1766 FAQs

5 FAQs

5.1 What is the license scheme for the STM32CubeF3 firmware?


The HAL is distributed under a non-restrictive BSD (Berkeley Software Distribution) license.
The middleware stacks made by ST (USB Device Libraries, STemWin) come with a
licensing model that ensures easy reuse, provided it runs on an ST device.
The middleware based on well-known open-source solutions (FreeRTOS and FatFs) have
user-friendly license terms. For more details, refer to the license agreement of each
middleware.

5.2 Which boards are supported by the STM32CubeF3 firmware


package?
The STM32CubeF3 firmware package provides BSP drivers and ready-to-use examples for
the following STM32F3 boards:
• STM32303C-EVAL
• STM32303E-EVAL
• STM32373C-EVAL
• STM32F3DISCOVERY
• 32F3348DISCOVERY
• NUCLEO-F302R8
• NUCLEO-F303RE
• NUCLEO-F303ZE
• NUCLEO-F334R8
• NUCLEO-F303K8.

5.3 Are any examples provided with the ready-to-use toolset


projects?
Yes. STM32CubeF3 provides an extensive set of examples and applications (around 70 for
STM32303C-EVAL). They come with the pre-configured project of several tool sets: IAR™,
Keil® and GCC.

5.4 Is there any link with Standard Peripheral Libraries?


The STM32Cube HAL Layer is the replacement of the Standard Peripheral Library.
The HAL APIs offer a higher abstraction level compared to the standard peripheral APIs.
HAL focuses on peripheral common functionalities rather than hardware. The higher
abstraction level allows to define a set of user friendly APIs that can be easily ported from
one product to another.
Although the existing Standard Peripheral Libraries are supported, they are not
recommended for new designs.

DocID026352 Rev 8 24/29


28
FAQs UM1766

5.5 Does the HAL take benefit from interrupts or DMA?


How can this be controlled?
Yes. The HAL supports three API programming models: polling, interrupt and DMA (with or
without interrupt generation).

5.6 How are the product/peripheral specific features managed?


The HAL offers extended APIs, that is, specific functions as add-ons to the common API to
support features available on some products/lines only.

5.7 How can STM32CubeMX generate code based on embedded


software?
STM32CubeMX has a built-in knowledge of STM32 microcontrollers, including their
peripherals and software. This enables the tool to provide a graphical representation to the
user and generate *.h/*.c files based on the user configuration.

5.8 How can the user get regular updates on the latest
STM32CubeF3 firmware releases?
The STM32CubeF3 firmware package comes with an updater utility, STM32CubeUpdater,
that can be configured for automatic or on-demand checks for new firmware package
updates (new releases or/and patches).
STM32CubeUpdater is also integrated within the STM32CubeMX tool. When using this tool
for STM32F3 configuration and initialization C code generation, the user can benefit from
STM32CubeMX self-updates as well as STM32CubeF3 firmware package updates.
For more details, refer to Section 4.4.

5.9 When to use HAL versus LL drivers?


HAL drivers offer high-level and function-oriented APIs, with a high level of portability.
Product/IPs complexity is hidden for end users.
LL drivers offer low-level APIs at registers level, with a better optimization but less
portability. They require a deep knowledge of product/IPs specifications.

5.10 How can the user include LL drivers in his/her environment?


Is there any LL configuration file as for HAL?
There is no configuration file. Source code shall directly include the necessary
stm32f3xx_ll_ppp.h file(s).

25/29 DocID026352 Rev 8


UM1766 FAQs

5.11 Can HAL and LL drivers be used together?


If yes, what are the constraints?
It is possible to use both HAL and LL drivers. One can handle the IP initialization phase with
HAL and then manage the I/O operations with LL drivers.
The major difference between HAL and LL is that HAL drivers require to create and use
handles for operation management while LL drivers operates directly on peripheral
registers. Mixing HAL and LL is illustrated in Examples_MIX example.

5.12 Are there any LL APIs not available with HAL?


Yes, there are.
A few Cortex® APIs have been added in stm32f3xx_ll_cortex.h e.g. for accessing SCB or
SysTick registers.

5.13 Why are SysTick interrupts not enabled on LL drivers?


When using LL drivers in standalone mode, you do not need to enable SysTick interrupts
because they are not used in LL APIs, while HAL functions requires SysTick interrupts to
manage timeouts.

5.14 How are LL initialization APIs enabled?


The definition of LL initialization APIs and associated resources (structure, literals and
prototypes) is conditioned by the USE_FULL_LL_DRIVER compilation switch.
To be able to use LL APIs, add this switch in the toolchain compiler preprocessor.

DocID026352 Rev 8 26/29


28
Revision history UM1766

6 Revision history

Table 4. Document revision history


Date Revision Changes

17-Jun-2014 1 Initial release.


Updated middleware list in Section : Introduction.
Updated Figure 2: STM32CubeF3 firmware architecture
Added STM32F302xD, STM32F302xE, STM32F303xD,
STM32F303xE and STM32F398xx in Table 1: Macros for STM32F3
Series.
Renamed STM32F3-DISCOVERY and STM32F3348-Discovery part
numbers into STM32F3DISCOVERY and 32F3348DISCOVERY,
20-Nov-2014 2 respectively.
Section 3.1: Supported STM32F3 devices and hardware: updated
Table 2: Boards for STM32F3 Series; replaced NUCLEO-L302R8 and
NUCLEO-L334R8 by NUCLEO-F302R8, NUCLEO-F334R8 and
NUCLEO-F303RE.
Updated Table 3: Number of examples available for each board.
Updated Section 3.2: Firmware package overview.
Updated Section 5: FAQs.
Added SW4STM32 in Section 3.2: Firmware package overview and
12-Jun-2015 3 Section 4.1: Running the first example. Updated Figure 4:
STM32CubeF3 example overview.
Updated Figure 1: STM32Cube firmware components.
10-Sep-2015 4
Added NUCLEO-F303K8 board.
Added NUCLEO-F303ZE in Table 2: Boards for STM32F3 Series.
Added Nucleo-144 in Section 3.1: Supported STM32F3 devices and
hardware.
09-Nov-2015 5
Updated Table 3: Number of examples available for each board.
Updated list of STM32F3 boards in Section 5.2: Which boards are
supported by the STM32CubeF3 firmware package?.
List of STM32F398xx part numbers updated in Table 1: Macros for
27-Apr-2016 6 STM32F3 Series.
Updated Table 3: Number of examples available for each board.

27/29 DocID026352 Rev 8


UM1766 Revision history

Table 4. Document revision history


Date Revision Changes

Updated Section 2: STM32CubeF3 architecture overview with


introduction of Section 2.1: Level 0, Section 2.2: Level 1, Section 2.3:
Level 2 and their subsections.
Updated Section 3.2: Firmware package overview and Section 5:
FAQs.
13-Jun-2016 7 Updated Figure 1: STM32Cube firmware components, Figure 2:
STM32CubeF3 firmware architecture, Figure 3: STM32CubeF3
firmware package structure and Figure 4: STM32CubeF3 example
overview.
Removed footnote from Figure 3.
Updated Table 3: Number of examples available for each board.
Updated Figure 4: STM32CubeF3 example overview.
Updated Table 3: Number of examples available for each board.
13-Dec-2016 8
Added Section 4.2.1: HAL application and Section 4.2.2: LL application
in Section 4.2: Developing your own application.

DocID026352 Rev 8 28/29


28
UM1766

IMPORTANT NOTICE – PLEASE READ CAREFULLY

STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgement.

Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of Purchasers’ products.

No license, express or implied, to any intellectual property right is granted by ST herein.

Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.

ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners.

Information in this document supersedes and replaces information previously supplied in any prior versions of this document.

© 2016 STMicroelectronics – All rights reserved

29/29 DocID026352 Rev 8

You might also like