The Arduino IDE is great for casual explorations with embedded electronics -- writing and uploading code is quick, clear, and accessible. However, we trade ease of use for power and control. Occasionally, like when we're bringing our maker tools to work, we need more control over the hardware. For example, maybe we need a low power device and want to set all unused IO pins to analog to reduce the chip's power consumption. While this is difficult to do with Arduino IDE, fortunately it's much more straightforward using the ST software toolchain!
This guide provides a beginner-friendly introduction to the ST toolchain via their Arduino-compatible breakout Nucleo boards. I'm using a Nucleo-64, which has a similar form factor to the Arduino Uno. You can also follow along with different Nucleo boards (just be sure to select the proper board along the way!).
In this tutorial, you'll learn how to use the STM32 CubeMX and STM32 CubeIDE to configure and program ST chips via the Nucleo board interface.
Note: all the software used in this tutorial is free, although ST does require you to give them your e-mail.
Step 0: Background Knowledge and SoftwareTo follow along successfully, it is helpful to have the following knowledge:
- Experience using and programming hardware in Arduino IDE or similar (with C/C++ language).
- Familiarity with hardware terminology like IC/chip, IO, etc.
Before starting,download the STM32 Cube MX program and the STM32 Cube IDE. These are linked in the "Software" section of this guide.
Note on the ST chip numbering system:
STM32xxwwyz
- xx – Family
- ww – subtype: differs in equipment of peripherals and this depend on certain family
- y – Package pin count
- z – FLASH memory size
What is it: This program allows us to configure the IO pins on various ICs and then generate C code with all the initializations and settings we selected.
1. Open the STM32 CubeMX program and navigate to Board Selector. Search for ‘NUCLEO-L476RG, ’ click on the board image, then select ‘Start Project’ and ‘Install all peripherals with default mode.’
2. In the pinout display that opens, select PA5 and choose “GPIO_Output”. This enables the pin as an output and changes its color to green.
3. Click ‘Clock Configuration’ to check/configure the processor clock (set system and peripheral clocks to max speed of 80MHz).
4. Navigate back the pinout tab and enable Serial Debug (System Core under Debug, select ‘Serial Wire’).
5. Optional: check pin configurations in the GPIO Configuration tab.
6. Navigate to Project Manager tab. Input project name, select project folder, and STM32CubeIDE.
7. Select ‘Generate Code’. This will generate C code for the selected configurations.
Step 2: Wire up an LED and resistor!For Nucleo board connections, use the onboard female header pins (inside rows).
1. Using a jumper wire and a breadboard, connect the positive LED leg to the Nucleo D13 pin.
2. On the breadboard, connect the resistor to the negative LED leg.
3. Connect the other resistor leg to the Nucleo GND pin.
Step 3: Write a "Hello, World" program in the STM32 Cube IDE1. Open the CubeIDE and navigate to and open the main.c file (inside the project directory, select Core). At the top of the program, add C code to define the GPIO LED pin:
#define LED_PORT GPIOA
#define LED_PIN GPIO_PIN_5
2. In the infinite loop (while(1)) add C code to turn on the GPIO pin with a delay, then turn off the GPIO LED pin with a delay. (Fig. 9)
3. To upload code, select the ‘Debug’ button from the toolbar. (Fig. 9) This will verify and upload the code.
4. Optional: open the CubeMonitor to monitor variables, RAM, and/or FLASH.
Step 4: Behold: the blinking LED!That's it! You now know how to use the powerful ST toolchain to configure chips! Onward to electrical engineering prowess!
Comments