STMicroelectronics STM32CubeG0 User Manual
STMicroelectronics STM32CubeG0 is an embedded software package including hardware abstraction layer (HAL), low-level APIs, and board support package (BSP) components for STM32G0 microcontrollers. It provides a comprehensive set of tools and resources for developing embedded applications with maximized portability across the STM32 portfolio and best performance with high degree of user control over the hardware.
Key features of STM32CubeG0 include:
- Comprehensive hardware abstraction layer (HAL) for STM32G0 microcontrollers, offering a set of portable and standardized APIs for accessing and controlling the peripherals and features of the device.
Advertisement
Advertisement
UM2568
User manual
STM32CubeG0 STM32G0316-DISCO demonstration firmware
Introduction
STM32Cube is an STMicroelectronics original initiative to significantly improve designer's productivity by reducing development effort, time and cost. STM32Cube covers the whole STM32 portfolio.
STM32Cube includes:
• A set of user-friendly software development tools to cover project development from the conception to the realization, among which:
– STM32CubeMX , a graphical software configuration tool that allows the automatic generation of C initialization code using graphical wizards
– STM32CubeIDE , an all-in-one development tool with IP configuration, code generation, code compilation, and debug features
– STM32CubeProgrammer ( STM32CubeProg ), a programming tool available in graphical and command-line versions
– STM32CubeMonitor-Power ( STM32CubeMonPwr ), a monitoring tool to measure and help in the optimization of the power consumption of the MCU
– STM32CubeMonitor-UCPD ( STM32CubeMonUCPD ), a monitoring tool to measure and help in the configuration of
USB Type-C ™ and Power Delivery applications
• STM32Cube MCU & MPU Packages , comprehensive embedded-software platforms specific to each microcontroller and microprocessor series (such as STM32CubeG0 for the STM32G0 Series), which include:
– STM32Cube hardware abstraction layer (HAL), ensuring maximized portability across the STM32 portfolio
– STM32Cube low-layer APIs, ensuring the best performance and footprints with a high degree of user control over the
HW
– A consistent set of middleware components such as FAT file system, RTOS, USB Device, and USB Power Delivery
– All embedded software utilities with full sets of peripheral and applicative examples
• STM32Cube Expansion Packages , which contain embedded software components that complement the functionalities of the STM32Cube MCU & MPU Packages with:
– Middleware extensions and applicative layers
– Examples running on some specific STMicroelectronics development boards
The STM32CubeG0 demonstration firmware running on the STM32G0316-DISCO board is built around the STM32Cube hardware abstraction layer (HAL) and low-layer (LL) APIs, and board support package (BSP) components. It embeds several applications that demonstrate various features of the STM32G030J6 device.
UM2568 - Rev 1 - June 2019
For further information contact your local STMicroelectronics sales office.
www.st.com
UM2568
STM32CubeG0 main features
1
Note:
STM32CubeG0 main features
STM32CubeG0 gathers, in a single package, all the generic embedded software components, required to develop an application on STM32G0 microcontrollers. In line with the STM32Cube initiative, this set of components is highly portable, not only to the STM32G0 Series but also to other STM32 series.
STM32CubeG0 is fully compatible with the STM32CubeMX code generator that allows the generation of initialization code.
The package includes a driver layer (HAL) proposing a set of abstraction services and a low-level hardware layer
(LL) proposing a set of register-level functions, together with an extensive set of examples running on
STMicroelectronics boards. HAL is available in open-source BSD license for user convenience.
•
•
The STM32CubeG0 MCU Package also contains a set of middleware components with the corresponding examples. They come in free user-friendly license terms:
• FAT file system based on open source FatFS solution
CMSIS-RTOS implementation with FreeRTOS ™ open source solution
USB PD Devices and Core libraries
Several applications and demonstrations implementing all these middleware components are also provided in the
STM32CubeG0 MCU Package.
shows the block diagram of STM32Cube.
Figure 1. STM32CubeG0 firmware components
Evaluation boards
Discovery boards
Application level demonstrations
STM32 Nucleo boards
Dedicated boards
User application Utilities
USB PD
Middleware level (1)
FAT file system RTOS
CMSIS
Utilities
Board support package (BSP)
HAL and LL APIs
(1) The set of middleware components depends on the product Series.
Low-layer APIs (LL)
Hardware abstraction layer APIs
(HAL)
The demonstration firmware for the STM32G0316-DISCO board comes on top of the STM32CubeG0 MCU
Package, which is based on a modular architecture allowing the reuse of software components separately in standalone applications. The STM32Cube demonstration kernel manages all the modules, allows the addition of new modules dynamically, and the access to the storage, graphical, and components common resources.
The demonstration firmware is built on the light kernel and services provided by the BSP as well as components based on the STM32Cube HAL It makes extensive use of the STM32G0 device capability to offer a wide scope of usages.
The STM32G0 microcontrollers are based on the Arm ® 32-bit Cortex ® -M0+ processor.
Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
UM2568 - Rev 1 page 2/20
2
2.1
2.2
UM2568
Getting started with the demonstration
Getting started with the demonstration
Hardware requirements
The hardware requirements to start the demonstration are the following:
• One STM32G0316-DISCO board (MB1454)
• One USB cable to power the STM32G0316-DISCO board from its ST-LINK USB
The STM32G0 Discovery board connects to the host PC by means of the USB cable. It does not require any external power supply.
For detailed information on the hardware part, refer to UM2603 .
Hardware settings
The STM32CubeG0 -based demonstration supports the STM32G030J6 device and runs on the STM32G0316-
DISCO board from STMicroelectronics presented in
.
Figure 2. STM32G0316-DISCO top and bottom views (MB1454)
UM2568 - Rev 1 page 3/20
UM2568
Demonstration firmware programming
2.3
2.3.1
2.3.2
Demonstration firmware programming
The user may program the demonstration using the two methods detailed below.
Using binary file
To program the demonstration’s binary image in the internal Flash memory, the user must handle the STM32Cube
G0_Demo_STM32G0316-DISCO.hex
file located under Projects\STM32G0316-DISCO\Demonstrations\B inary , using tool such as STM32Cube Programmer .
Using preconfigured projects
The user selects the folder corresponding to his preferred toolchain (MDK-ARM, EWARM or SW4STM32). Then the user:
1.
Opens the demonstration project and rebuild all sources.
2.
Loads the project image through his debugger.
3.
Restarts the Discovery kit.
UM2568 - Rev 1 page 4/20
3
3.1
UM2568
Demonstration firmware package
Demonstration firmware package
Demonstration repository
shows the demonstration folder organization.
Figure 3. STM32CubeG0 Firmware package folder organization
The demonstration sources are located in the Projects folder of the STM32CubeG0 MCU Package for each supported board. The folder selected here is STM32G0316-DISCO for the Discovery board.
The demonstration firmware highlights the possibility to use PF2 pin for different purposes (Reset or GPIO), but also the possibility to use different pins on the same pad (multi-bonding).
illustrates the organization of the Demonstrations folder.
Figure 4. STM32G0316-DISCO Demonstrations folder organization
UM2568 - Rev 1
The Demonstrations folder contains the following sub-folders:
•
•
•
Binary : contains link to demo compiled binary file in Hex format
Inc : Demonstration application header files
Src : Software development environments
– EWARM : IAR Embedded Workbench ™
– MDK-ARM : Keil ® Microcontroller Development Kit
– SW4STM32 : SW4STM32 , system workbench for STM32 page 5/20
3.2
UM2568
Demonstration architecture overview
Demonstration architecture overview
shows the top-level software architecture of the STM32G0316-DISCO demonstration firmware.
Dedicated sub-sections briefly describe the software elements mentioned in this diagram.
Figure 5. STM32G0316-DISCO demonstration firmware architecture
Application
Hardware abstraction layer
(HAL)
Hardware
Board support package
(BSP)
STM32G0316-DISCO (MB1454)
3.2.1
3.2.2
Application
The main application initializes the HAL, configures the clock and then starts the demonstration.
HAL and BSP level
HAL level layer consists in the stm32g0xx.HAL
drivers together with the STM32G0316-DISCO board support package (BSP).
UM2568 - Rev 1 page 6/20
UM2568
Microcontroller resources
3.3
3.3.1
Microcontroller resources
The following sections detail the peripherals of the STM32G030J6 microcontroller used by the demonstration.
Peripherals
shows the peripherals used by the demonstration.
Figure 6. STM32G031J6 peripherals
LED
RCC
RTC
GPIO
USER button
STM32G031J6
STM32G0316-DISCO
EXTI
FLASH
IWDG
PWR
Component on board MCU peripheral
indicates which STM32G030J6 peripherals are used by the demonstration firmware and for which purpose.
Peripheral
RCC
IWDG
FLASH
GPIO
EXTI
RTC
PWR
Table 1. STM32G030J6 peripherals used by the demonstration firmware
Usage description
Configures the system clock, checks and resets flags status when the demonstration firmware is started.
When the demonstration firmware operates in PF2-NRST mode, IWDG is used as internal reset source so that the user may check generation of a pulse on the PF2 pin.
Changes the PF2 pin configuration (NRST or GPIO) through option bytes programming.
When the demonstration firmware operates in PF2-GPIO mode, PF2 can be used to enter standby mode or to trigger option-bytes re-configuration.
When the demonstration firmware operates in PF2-GPIO mode PF2 related EXTI line is configured to generate an interrupt upon PF2 rising and falling edges.
Controls LED2 using the auto-reload wakeup timer capability of this peripheral.
When the demonstration firmware operates in PF2-GPIO mode, PWR configures the wakeup pin and enters standby mode.
UM2568 - Rev 1 page 7/20
UM2568
Microcontroller resources
3.3.2
Interrupts
shows all the external interrupts used by the demonstration.
Interrupt
SysTick
RTC_TAMP_IRQHandler
EXTI line 0
EXTI line 1
EXTI line 2
Table 2. STM32G031J6 demonstration interrupts usage
Usage description
Delay management
Wakeup timer interrupt management
PA0 interrupt mode, USER button management
PA1 interrupt mode, USER button management
PF2 interrupt mode, falling edge, USER button management
UM2568 - Rev 1 page 8/20
UM2568
Running the demonstration
4
4.1
4.2
4.2.1
4.2.2
Running the demonstration
Overview
This demonstration provides the possibility to use PF2 pin for different purposes (RESET or GPIO), and the possibility to use different pins on the same pad (multi-bonding).
When the Discovery kit is powered on, the demonstration firmware checks the PF2 pin capability by reading the option bytes. The demonstration firmware has two functioning modes, which depend on the PF2 pin capability:
• When PF2 pin is configured in RESET Input/Output mode, the demonstration firmware enters the PF2-
NRST mode. In this mode, reset can be forced by grounding the PF2 pin and internal resets are propagated to the PF2 pin (20 μs pulse generation).
• When PF2 is configured in GPIO mode, the demonstration firmware enters the PF2-GPIO mode. In this mode, PF2 can be used as a standard GPIO, with all functionalities (Input/Output/Alternate functions/
Analog) available.
Modes description
PF2-NRST mode
When the demonstration firmware operates in PF2-NRST mode, the independent watchdog is configured to regularly reset the system. The user may then check that a pulse occurs on the PF2 pin.
If the user presses the RST/USER button, option bytes are updated to configure PF2 in GPIO mode. When option bytes loading operation ends, system resets and the demonstration firmware switches to the PF2-GPIO mode.
•
PF2-GPIO mode
When the demonstration firmware operates in PF2-GPIO mode, RST/USER button selects amongst the following sub-modes:
•
•
Short press on the RST/USER button: the system goes in Standby mode. The user may then measure the power consumption using the JP1 pins. Another press on the RST/USER button wakes up the system from
Standby mode.
Double press on the RST/USER button: independent watchdog is configured to reset the system after a short delay. It shows that even without Reset input, system reset can be triggered.
Long press on the RST/USER button: option bytes are updated to configure PF2 in RESET mode. When option bytes loading operation ends, system resets and the demonstration firmware switches back to the
PF2-NRST.
At each new reset in GPIO mode, a new GPIO is configured as input mode. Corresponding external interrupt and interrupt vector are configured accordingly. This demonstrates G0 multi-bonding feature, in which several IOs can be redirected to a single PAD. PA0, PA1, PA2 and PF2 are all linked to PAD 4.
UM2568 - Rev 1 page 9/20
UM2568
Functional description
4.3
4.3.1
Functional description
State machine
The state machine in
illustrates the functioning of the demonstration firmware.
Figure 7. Functional state machine of the STM32G0316-DISCO demonstration firmware
PF2-NRST
POWER ON AND NRST_MODE != GPIO
5s delay expiration / Start IWDG NRST_BLINK_WAIT
5s delay expiration / Start IWDG
Independent watchdog reset occurred
Independent watchdog reset occurred
NRST_BLINK_OBL NRST_BLINK_IWDG
POWER_OFF
POWER ON AND NRST_MODE == GPIO
Press RST/USER button / Set NRST_MODE to GPIO
Launch option byte loading
Long press RST/USER button / Set NRST_MODE to Bidirectional reset
Launch option byte loading
PF2-GPIO
5s delay expiration
Double press RST/USER button / start IWDG
Reset from Option byte loading occurred
GPIO_BLINK_WAIT
Independent watchdog reset occurred
5s delay expiration
Single press RST/USER button / enter standby mode
GPIO_BLINK_OBL
GPIO_STANDBY (LED off)
5s delay expiration
Press RST/USER button
GPIO_BLINK_WAKEUP
GPIO_BLINK_IWDG
•
•
•
Whatever the operating mode is (PF2-NRST or PF2-GPIO), the demonstration firmware performs the following steps:
• Identification of the reset origin, reported during five seconds to the user, thanks to LED2 (one toggling scheme per reset origin).
Exit from Standby mode reset: four fast successive blinks of LED2 in one second
Independent watchdog reset: three fast successive blinks of LED2 in one second
Option byte loader reset: two fast successive blinks of LED2 in one second: Power reset
After five seconds, LED-blinking scheme indicates to the user in which mode the PF2 pin is configured:
• PF2-GPIO: slow blinking (two seconds)
• PF2-NRST: fast blinking (one second)
UM2568 - Rev 1 page 10/20
UM2568
Functional description
4.3.2
LED toggling scheme
illustrates the LED2-toggling scheme used by the demonstration firmware.
Figure 8. STM32G0316-DISCO demonstration firmware LED blinking scheme
LD2 status
ON
OFF
1s
DemoState::NRST_BLINK_OBL
5s
LD2 status
ON
OFF
1s
DemoState::NRST_BLINK_IWDG
5s
LD2 status
ON
OFF
2s
DemoState::GPIO_BLINK_OBL
5s
LD2 status
ON
OFF
DemoState::GPIO_BLINK_IWDG
2s
5s
LD2 status
ON
OFF
DemoState::GPIO_BLINK_WAKEUP
2s
5s
1s
1s
DemoState::GPIO_BLINK_WAIT
2s
DemoState::GPIO_BLINK_WAIT
2s
2s
DemoState::NRST_BLINK_WAIT
DemoState::NRST_BLINK_WAIT
DemoState::GPIO_BLINK_WAIT t t t t t
UM2568 - Rev 1 page 11/20
5
5.1
5.2
UM2568
Software architecture
Software architecture
Following sections detail the application in charge of initializing demonstration application, HAL, interrupt handler and launching the main module.
Clock control
Here is the configuration of the various system clocks in this demonstration application:
• STM32G031 internal clocks are derived from the HSI running at 16 MHz in RST mode.
• PLL is used as the system clock source in GPIO mode. System clock and HCLK frequency are set to
64 MHz.
Only the RTC is clocked by a 32 kHz external oscillator.
Main application API overview
provides a description of all the actions performed by the different functions in main.c
.
Main
Functions (main.c)
Table 3. Main function description
Description
Initialize the HAL, configure the clock and then start the demonstration
The file stm32g0xx_it.c
is also part of the application and is used, as usual, to map the interrupt vector on the
HAL driver, depending on the module requirement.
explains the main demonstration functionalities in main.c
.
PushButtonInputScan
GetDemoMode
SetDemoMode
BackupDomainAccessEnable
CheckBootReason
Table 4. Main applications functions description
Functions (main.c)
MainNrstDemoMode
MainGpioDemoMode
GpioDemoModeShortPress
GpioDemoModeLongPress
GpioDemoModeDoublePress
LedBlinkSchemeOn
LedBlinkSchemeOff
PushButtonConfig
Description
Main function of PF2-NRST demonstration mode
Main function of PF2-GPIO demonstration mode
GPIO Sub Mode short press handler
GPIO Sub Mode Long press handler
GPIO Sub Mode double press handler
Configure and Turn on LED blinking scheme
Turn off Led blinking scheme
Configure push button (PF2)
Scan push button input signal in order to determine short, long or double key press
Get current demo sub-mode
Set demo sub-mode: SUBDEMO_MODE_GPIO or
SUBDEMO_MODE_NRST
Enable backup domain access
Check boot reason and save them
UM2568 - Rev 1 page 12/20
5.3
5.4
UM2568
STM32G0316-DISCO BSP API overview
Functions (main.c)
ExecuteBootReason
HAL_GPIO_EXTI_Falling_Callback
HAL_RTCEx_WakeUpTimerEventCallback
ErrorHandler
RtcConfig
SystemClock
Description
Check boot reason and warn the user in case of option byte reload reset, IWDG reset and Standby exit
EXTI line detection callback
Wakeup timer callback
Functional error report to the user: LED stays ON forever
Configure RTC
Set the rights clocks for Flash and RCC
STM32G0316-DISCO BSP API overview
shows STM32G0316-DISCO BSP API functions.
BSP_LED_Init
BSP_LED_DeInit
BSP_LED_Toggle
BSP_LED_On
BSP_LED_Off
BSP_GetVersion
Functions
Table 5. STM32G0316-DISCO BSP API
Description
Configure LED
Put LEDs in unconfigured state
Toggle the selected LED
Turn the selected LED on
Turn the selected LED off
Return the STM32G0316-DISCO BSP driver revision
Dynamic memory use
The demonstration is currently using:
• CSTACK = 0x400
• HEAP = 0x200
UM2568 - Rev 1 page 13/20
6
UM2568
Memory footprint
Memory footprint
This chapter sums up RAM and ROM consumptions per software blocks.
also gives the total demonstration firmware consumption.
Full demonstration firmware
Demo Application
BSP Drivers
HAL Drivers
STM32G030J6 Device
Others (linker...)
Grand Total
Table 6. RAM and ROM consumption
ROM code (Byte)
1298
118
3828
338
420
6002
ROM data (Byte)
58
1
6
2
32
99
RAM data (Byte)
208
4
12
4
1024
1252
UM2568 - Rev 1 page 14/20
Revision history
Date
26-Jun-2019
Version
1
Table 7. Document revision history
Changes
Initial release.
UM2568
UM2568 - Rev 1 page 15/20
UM2568
Contents
Contents
UM2568 - Rev 1 page 16/20
UM2568
Contents
UM2568 - Rev 1 page 17/20
UM2568
List of tables
List of tables
UM2568 - Rev 1 page 18/20
UM2568
List of figures
List of figures
UM2568 - Rev 1 page 19/20
UM2568
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. For additional information about ST trademarks, please refer to www.st.com/trademarks . 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.
© 2019 STMicroelectronics – All rights reserved
UM2568 - Rev 1 page 20/20
Download
Advertisement