Software Install and Use

The STM32CubeIDE Integrated Development Environment (IDE) is one of several IDEs available for programming STM32 microcontrollers. Others include AC6 System Workbench, IAR Systems, ARM KEIL, etc. We will use STM32CubeIDE as it is (1) free and (2) provided from STMicroelectronics directly.

Note

Alternatively, STM publishes extensions to VSCode to provide a reduced development environment (as compared to STM32CubeIDE) within VSCode. The VSCode environment does provide a rudimentary debugging toolset; likely sufficient for most, if not all, activities in this class. Students are welcome to use this environment instead of STM32CubeIDE with the understanding that the instructor and/or TAs may not be able to provide functional support of the environment; however, it has been verified to work!

Further, [few] students have previously set up command-line build environments for the class and have been successful.

1. STM32CubeIDE Installation

  • Download the installer for your operation system here: STM32CubeIDE Get Software

    • Note:In order to download the software, you will have to register with st.com.

  • Unzip the downloaded archive

Windows and MacOS

  • Run it and click through the install. Leave all defaults as-is.

  • Done.

Linux

  • If using the -Lnx installer, the installation must be done through the command line (I have not used the -DEB and -RPM installers).

  • Within a terminal, launch the installer:

    $ chmod +x st-stm32cubeide_*_amd64.sh
    $ ./st-stm32cubeide_*_adm64.sh
    
  • Accept the license: [Y] (press spacebar to read through, Q to skip to end)

  • “Do you want to install STLinkServer and Udev rules…” [Y]

  • Set your desired install directory. Default is usually fine (you must have write access to it). [Enter]

  • Installer will ask for [sudo] password. This is needed to install the udev rules.

  • “Do you want to continue?” [Y] (prompt to continue to install udev-rules)

  • Accept more licenses…

  • “Do you want to install Segger J-Link udev rules?” [Enter]

  • Accept another license…

  • Installer should finish after that. If you’re lucky, the installer should have given you a stm32cubeide.desktop file in your ~/.local/share/applications/ folder which should give you the program in your applications menu.

2. STM32CubeIDE Preparation

  1. Start the STM32CubeIDE program. Upon each start, the program will ask you to select a workspace. * This may be avoided by checking Use this as the default and do not ask again.

_images/selectworkspace.png
  1. Select a workspace folder that is convenient for you to access. The folder path should not have any spaces or special characters.

  2. Click Launch. STM32CubeIDE will finish loading.

  3. Download the stm32lib.zip library and extract the contents to the workspace you just created.

    • Ensure that there is not two nested stm32lib folders! If there is, move the inner folder to the workspace. The workspace structure should now have the below structure:

    • Note: This library is a subset of the software provided within the STM32CubeF7 GitHub repository. Please see this link for associated licenses, etc.

workspace/
    stm32lib/
        CMSIS/
        STM32F7xx_HAL_Driver/

3. Terminal Emulator Program

A Serial Terminal program is also required. It is suggested though not required to use PuTTY on Windows and minicom/picocom on Linux. MacOS: Find one you like.

Windows - PuTTY

Installation

Download the most recent version of PuTTY from the PuTTY Downloads page. Either the MSI Installer or just putty.exe will work. The 64-bit x86 version is the applicable version for almost all Windows based computers.

  • If the MSI Installer was selected, follow the installation instructions. This version will place the PuTTY program (among others: PuTTYgen, PSFTP, etc.) within the Windows program menu.

  • If using putty.exe, it is highly suggested to pin the program to the taskbar to make accessing the program easy and quick.

Connecting

  1. Launch PuTTY. If installed using MSI Installer, select the PuTTY application from the program menu and not PuTTYgen, PSFTP, etc.

  2. In the window that appears, do the following:

    1. Select the Serial radio button near the upper right, not the “Serial” option on the bottom left.

    2. Change Speed to 115200.

    3. Change Serial line to the necessary COM port as determined by Finding Serial Port.

    4. Click on Terminal (on left). Select Enable Blinking Text.

    5. Click on Terminal→Keyboard (on left). Select the VT100+ radio button.

  3. Click Open. This will launch a terminal session if configured properly.

  4. If the development board was removed and reconnected, the terminal session may be restarted by right clicking the PuTTY window title and selecting

Saving Settings

PuTTY can save a session configurations to avoid having to repeat the above steps each time. However, it is possible that the COM port will not be consistent across different sessions. To save settings:

  1. Complete the Connecting instrutions above up to step 2.

  2. Type a name into the Saved Sessions box.

  3. Click Save on the right.

  4. A new item will appear with the name provided in the Saved Sessions box below.

Loading Settings

There are two options here:

  1. Double-click on the saved settings that are desired. This will automatically start the terminal session using these sessions.

  2. Single-click on the saved settings that are desired.

    1. Click Load

    2. Change any settings (such as the desired COM port)

    3. Click Open.

Logging Output

Logging of PuTTY sessions is useful in cases where the data needs to be saved. To do this: 1. Prior to launching the session, click Logging under Session on the left after loading/configuring the settings. 2. Change Session logging to Printable output. 3. Select the file to save the output to under Log file name. 4. Change any other settings here as desired. Note that these logging settings will be saved with the saved settings mentioned above. 5. Click Open to launch the logged session.

Linux – picocom

picocom is a small command line program to support serial connections.

Installation

Use your distribution’s preferred method for installing programs. This is a common program and should exist in most distribution repositories. For example, if using apt (command line):

$ sudo apt install picocom

Connecting

  1. Determine the target serial device via the instructions in Finding Serial Port.

  2. Launch picocom to connect to the target serial device with a baud rate of 115200. Note that the full path to the target serial port is required. For example:

    picocom -b 115200 /dev/ttyACM0
    
  3. To exit picocom, either close the active terminal window or press Control+a followed by Control+q.

Logging Output

Logging of picocom sessions is useful in cases where the data needs to be saved. To do this, add the logging flag and a target filename, -g LOGFILENAME to the command:

picocom -b 115200 /dev/ttyACM0 -g test.log

Standard Window Size

picocom will launch within the active terminal window, which will not be the standard 80x24 terminal window size. Further, depending on the terminal emulator used, the VT100+ commands used in Lab1 may not render properly. I prefer to to use launch picocom within an xterm terminal emulator like so:

xterm -vb -fa Monospace -fs 12 -e "picocom -b 115200 /dev/ttyACM0"

4. Finding Serial Port

The development board presents itself as a serial port device and as a mass storage device. This class only needs to interact with the serial port. Determining the appropriate name or path for the serial port is dependent on the OS.

Windows

  1. Ensure that the development board is connected to the computer.

  2. Open the Windows Device Manager.

  3. Under Ports, find the entry XDS110 Class Application/User UART (COMx). The cooresponding COMx name and number is the required serial port. This value may change when the device is remove and readded to the computer, though if plugged into the same USB port, it usually will stay the same.

Linux

Determining the serial port on Linux can be done several ways. Here are two:

  1. Using dmesg:

    1. Prior to plugging the development board in, run dmesg in the follow mode:

    $ dmesg -w
    
    1. Plug the development board into the computer. This should result in a dmesg output of something along the lines as this:

    usb 5-3.4: new full-speed USB device number 5 using xhci_hcd
    usb 5-3.4: New USB device found, idVendor=0483, idProduct=374b, bcdDevice= 1.00
    usb 5-3.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
    usb 5-3.4: Product: STM32 STLink
    usb 5-3.4: Manufacturer: STMicroelectronics
    usb 5-3.4: SerialNumber: 066EFF565251887067043218
    usb-storage 5-3.4:1.1: USB Mass Storage device detected
    scsi host5: usb-storage 5-3.4:1.1
    cdc_acm 5-3.4:1.2: ttyACM0: USB ACM device
    usbcore: registered new interface driver cdc_acm
    cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
    scsi 5:0:0:0: Direct-Access     MBED     microcontroller  1.0  PQ: 0 ANSI: 2
    sd 5:0:0:0: Attached scsi generic sg1 type 0
    sd 5:0:0:0: [sdb] 12360 512-byte logical blocks: (6.33 MB/6.04 MiB)
    sd 5:0:0:0: [sdb] Write Protect is off
    sd 5:0:0:0: [sdb] Mode Sense: 03 00 00 00
    sd 5:0:0:0: [sdb] No Caching mode page found
    sd 5:0:0:0: [sdb] Assuming drive cache: write through
    sd 5:0:0:0: [sdb] Attached SCSI removable disk
    
    1. Determine the target serial port from the dmesg output: The line of interest is highlighted above. The target serial port is shown as ttyACM0. The full path to this port is then /dev/ttyACM0

  2. Directory listing:

    1. Prior to plugging the development board in, list the contents of the /dev/ directory looking for any entries that start with either ttyACM or ttyUSB:

    $ ls /dev/tty{ACM*,USB*} 2> /dev/null
    
    1. Take note of the any entries listed from the output of this command. These are the existing serial ports.

    2. Plug in the development board and run the above command again.

    3. A single new entry should appear in the output. This one is the target serial port.

  • Note that the target serial port will not change upon removal and reconnection of the development board as long as:

    1. A different device that presents itself as a serial port was added to the computer, or

    2. An active serial terminal session was not exited at reconnection.

Therefore, the device determined above may generally be used for all subsequent connections.

MacOS

???

5. Project Import and Debugging

To demonstrate how to import and run or debug a project, we’ll use the Lab 1 template project: Lab01-ANSI_Term-GPIO_Template.zip.

  1. In STM32CubeIDE, click File→Import… . This will bring up the import dialog.

  2. In the Import dialog, select General→Existing Projects into Workspace and click next.

  3. Select the Select archive file option, then locate the zipped lab folder using the active Browse… button on the right.

  4. Click Finish to import the project.

_images/importproject.png
  1. The IDE should update with the project now listed on the left of the screen.

    • If the listing is not visible, go to Window→Show View→Project Explorer. To pin this pane to the IDE, click the Restore icon: restore

_images/correctImport.png
  1. Open up the src folder and double click hello.c. This is the main code for the project.

  2. Compile/build the code. This may be done by selecting Project→Build All or by pressing the hammer icon: hammer

    • If all went well, you should see something like this output in the Console pane:

    _images/console.png
    • Note that this build had “0 errors, 0 warnings”. You can ignore anything before “Build of configuration Debug for Project Lab01-ANSI-Term-GPIO_Template” seen if scrolled up.

    • If any red text appears in the console, indicating a build error, then a step above was likely skipped or done incorrectly. This is commonly the installation of the stm32lib.zip was incorrect.

  3. Plug in your STM32 board using a regular micro-usb cable, connected to the port labeled “ST_LINK”.

  4. Click the “Bug” icon bug on the top toolbar. This starts the “Debugging” tool, which will download the code and allow you to run and debug it on the microcontroller.

    • Alternatively, you may click the “Run” icon run instead. This will download the code and run it without entering the debugging tool.

  5. On the first launch of a project, STM32CubeIDE may pop up a “Edit Configuration” window. Simply click OK here.

  6. The device should be programmed at this point and the IDE will ask you to confirm a “Perspective Switch” to the “Debug” perspective. It is suggested to select “Remember my decision” and click “Switch”.

  7. The IDE will now look something like this:

_images/debug_perspective.png
  1. Before the code is run, the serial terminal should be connected. The speed for communication must be set to 115200 baud.

  2. Click the “Resume” icon resume to run the program. If all went well, text should appear in the serial terminal window.

    • Important: If the serial terminal is connected after the program is run, any text “printed” prior to the serial connection will not be shown.