STM32

STM32 — Ubuntu / Linux Setup

Install STM32CubeIDE on Ubuntu (or any Debian-based Linux). Linux requires an extra step to configure udev rules so you can access the ST-LINK programmer without sudo.


Prerequisites

  • Ubuntu 22.04 or 24.04 (64-bit)
  • sudo access
  • A free st.com account

Step 1 — Install Required Dependencies

shell
sudo apt update
sudo apt install -y \
  libusb-1.0-0 \
  libusb-dev \
  libc6:i386 \
  libncurses5 \
  libstdc++6:i386 \
  unzip

Step 2 — Download STM32CubeIDE

  1. Go to st.com/en/development-tools/stm32cubeide.html
  2. Click Get Software → log in with your ST account
  3. Download "STM32CubeIDE-Lnx" (the .sh installer)

Step 3 — Run the Installer

shell
# Navigate to your Downloads directory
cd ~/Downloads

# Make the installer executable
chmod +x st-stm32cubeide-*.sh

# Run the installer (do NOT use sudo here)
./st-stm32cubeide-*.sh

The installer will ask:

  • Installation path: Accept the default (~/st/stm32cubeide_1.xx.x) or choose a custom path
  • Create desktop shortcut: Yes
  • Install for all users: No (install for current user only)

Step 4 — Configure udev Rules (CRITICAL)

Without udev rules, you'll get "Permission denied" when trying to flash or debug via ST-LINK.

The installer places udev rules in:

text
~/st/stm32cubeide_1.xx.x/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink.*.linux64/tools/

Install the udev rules:

shell
# Find the udev rules directory
STLINK_DIR=$(find ~/st -name "stlink_udev_rules" -type d 2>/dev/null | head -1)

# Copy all udev rules
sudo cp $STLINK_DIR/*.rules /etc/udev/rules.d/

# OR copy manually (adjust path to your version)
sudo cp ~/st/stm32cubeide_*/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink*/tools/udev_rules/*.rules /etc/udev/rules.d/

Reload udev and add yourself to the plugdev group:

shell
sudo udevadm control --reload-rules
sudo udevadm trigger
sudo usermod -aG plugdev $USER

Log out and log back in

The group change only takes effect after you log out and back in. After doing so, connect your NUCLEO board — it should be recognized without sudo.


Step 5 — Launch STM32CubeIDE

shell
# Launch from terminal
~/st/stm32cubeide_1.xx.x/stm32cubeide &

# Or use the desktop shortcut if you created one during installation

On first launch:

  1. Select a workspace directory (e.g., ~/STM32CubeIDE/workspace)
  2. Click Launch

Connect your NUCLEO board or ST-LINK probe via USB.

shell
# Verify the device is recognized
lsusb | grep -i "ST "
# Expected: Bus XXX Device XXX: ID 0483:374b STMicroelectronics ST-LINK/V2.1

# Check it's accessible without sudo
ls -la /dev/bus/usb/*/*
# ST-LINK device should be readable by plugdev group

In STM32CubeIDE: go to Help → ST-LINK Upgrade — if your board appears in the list, it's working correctly.


Follow the same project creation steps as the Windows guide:

  1. File → New → STM32 Project
  2. Select your board (e.g., NUCLEO-F446RE)
  3. Name it hello_blink
  4. In the while(1) loop of main.c:
c
1while (1)
2{
3 HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
4 HAL_Delay(500);
5}
  1. Build with Ctrl+B
  2. Flash with F11 (Debug) or use Run → Run for release flash

Step 8 — Serial Monitor on Linux

For serial output from USART2 (connected to ST-LINK VCP on NUCLEO):

shell
# The NUCLEO's virtual COM port appears as /dev/ttyACM0
# Install minicom or use any serial terminal
sudo apt install -y minicom

# Open serial terminal at 115200 baud
minicom -D /dev/ttyACM0 -b 115200

Alternatively, use the Serial Monitor extension in VS Code.


Troubleshooting

libusb_open() failed: LIBUSB_ERROR_ACCESS

This means udev rules are not installed or not applied. Retry Step 4 and verify you've logged out and back in.

STM32CubeIDE won't launch

Check if OpenJDK is installed:

shell
java -version

STM32CubeIDE bundles its own JRE. If you see issues, try launching with:

shell
~/st/stm32cubeide_*/stm32cubeide -vm ~/st/stm32cubeide_*/jre/bin/java

libncurses5 not found

shell
# Ubuntu 24.04 may need this
sudo apt install libncurses5-dev libncurses5

Next Steps

Previous
Windows Setup