On this page

Getting started with projects based on STM32G071RB Board using STM32CubeIDE

Check out our Control Board!

Getting started with a 32-bit ARM-based microcontroller is always a little daunting. There are too many of available microcontrollers, platforms, development boards, tools, and software. This note describes step by step how to begin a LED project.

Getting started: about Development Board STM32G071RB

STM32 Nucleo-G071RB development board with ST-LINK debugger section, Arduino and Morpho headers

Features:

  • Core: Arm® 32-bit Cortex®-M0+ CPU, frequency up to 64 MHz
  • Up to 128 Kbytes of Flash memory, 36 Kbytes of SRAM
  • 7-channel DMA controller with flexible mapping
  • 12-bit, 0.4 µs ADC (up to 16 ext. channels)
  • Two 12-bit DACs, low-power sample-and-hold
  • Two I2C, Four USARTs , one low-power UART , two SPIs

 

Getting started: Install STM32CubeIDE

You can download STM32CubeIDE from their st.com.  It’ s free. Install STM32CubeIDE following STM32CubeIDE installation guide.

 

Before we can start writing code we need to create a project. This is similar to most other IDEs – projects are used to bundle together all of your settings, code, and definitions into a single collection all managed from the same application.

STM32CubeIDE Launcher dialog selecting the mySTM32codes folder on drive D as the workspace

 

Empty STM32CubeIDE workspace window after launch, with Console and Build Analyzer panels

 

STEP 1: Start a new project, From the top left icon ( Or under the menu File > New > STM32 Project) to get started.

STM32CubeIDE File > New menu with STM32 Project selected

STM32 Project target selection with part number STM32G071RB entered and the LQFP64 device selected

 

Step 2: Project name: G0_LED, then click Finish Button.

STM32 Project setup dialog with project name G0_LED, C language, executable and STM32Cube project type

From schematic diagram that the LED4 is controlled by STM32G071 and the port is PA5.

Nucleo board schematic highlighting green LED4 driven by pin PA5 (D13) on the Arduino connector

Step 3: From System Core > SYS, select Serial Wire, setup PA5 as GPIO_OUTPUT.

STM32CubeMX pinout view with SYS set to Serial Wire and pin PA5 configured as GPIO_Output

Setup use label for PA5 as LED_GREEN as below:

STM32G071RBTx LQFP64 pinout with PA5 set as GPIO_Output and labeled LED_GREEN

 

Step 4: Then Generate code.

STM32CubeIDE toolbar with the Generate Code button highlighted

 

CubeIDE, which this functionality is developed upon, generates C files to work with under a Src directory, and puts a HAL (Hardware Abstraction Layer) into an Includes directory. It appears CubeIDE works the exact same way. Expand the folders on the right under the project view and see what it has generated to work for you.

 

STM32CubeIDE Project Explorer showing linked libraries, generated source, HAL drivers, .ioc file and linker script

 

Step 5: Let’ s add a smidge of C code of our own now! After the Infinite Loop area, we’re going to add code to toggle the LED under section 3 as below:

 

main.c while loop with HAL_GPIO_TogglePin for LED_GREEN and HAL_Delay(500) added

 

Compiling the project and downloading it to the board

STM32CubeIDE actually makes it pretty easy to compile our work and get it onto the STM32 chip.  The first step is to produce the compiled .elf ( a binary version of our code).  To generate the .elf, we need to do a build. This is as easy as pressing the build button on the toolbar.

STM32CubeIDE toolbar with the Build button highlighted for the Debug configuration

Now, build information is presented in the console at the bottom of the screen.

Build console showing G0_LED.elf built with 0 errors and 0 warningsNow what we want to do is send this compiled binary onto the STM32 microcontroller.

Let’s plug in the dev kit:

Nucleo development board connected by USB, with its red power and communication LEDs litThe Red power LED (to the left of the blue switch) is lit, as is the larger communication LED (by the USB cable). Inside STM32CubeIDE, select the run button.

STM32CubeIDE toolbar with the Run button highlightedThis will open the Run dialog ( as it’s the first time we’ve run it). The settings we choose now will be saved as a run configuration which we can re-use or edit later.

Edit Configuration dialog for the G0_LED Debug launch configuration using Debug/G0_LED.elfSimply press Apply and then OK and the download will proceed. The Console will now fill with some interesting text:

Console output: ST-LINK download of 5360 bytes to 0x08000000 complete and verified successfullyThe LED is on and off every 500ms. you’ve got everything set up.

Need a display built to your own spec? Start a custom project and our engineers respond within one business day.

Start a Custom Project

Have a display project in mind?

Talk to an engineer about the display your application needs.