Feelix
Search
K

Setting up STM32

Follow the steps bellow to setup programming STM32 microcontrollers with the Arduino IDE (1) or Visual Studio and Platform IO (2).

Prepare

STM32CubeProgrammer is used by Arduino to compile for STM32 Installation on MacOS needs to be done from the command line
Make sure the device is in BOOT mode when uploading with Arduino IDE / Platform IO (see pinout diagram)
The RESET on the STM32 micrcontroller needs to be pressed after switching between BOOT and RUN mode in order to read the change

Option 1: Arduino IDE

  • Open Preferences > Additional Boards Manager URLs
  • Add a new line with the following url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
Additional Boards Manager URLs
  • Open the Boards Manager from the Tools menu.
  • Search for 'STM32 MCU based boards' and click INSTALL
Arduino Boards Manager
  • Set the board to 'Generic STM32F4'
  • Board part number to 'Generic F401RCT'
  • U(S)ART support to 'Disabled (no Serial support)'
  • USB support to 'CDC (generic 'Serial' supersede U(S)ART)'
  • USB speed to 'Low/Full Speed'
  • Upload method to 'STM32CubeProgrammer (DFU)'
The port does not have to be specified (having one specified should not cause any problems either).
Settings for uploading to STM32F401
  • Upload your program using the upload button in the Arduino IDE
  • Change to RUN mode when the upload process is successful
  • Press the RESET button on the STM32 microcontroller
  • The program should be running now
Press the RESET button when the device is not recognized by the computer

Option 2: Visual Studio & Platform IO

  • Add STM32 boards (search for ST STM)
  • When starting a new project, select STM32F401RC with framework Arduino
  • Make sure the settings in the platform.ini file are as follows
[env:genericSTM32F401RC]
platform = ststm32
board = genericSTM32F401RC
framework = arduino
upload_protocol = dfu
monitor_speed = 115200
;only for monitoring serial data
;the monitor port name can be read when the device is in RUN mode
;monitor_port = COM3
board_build.mcu = stm32f401rct6
board_build.f_cpu = 84000000L
board_build.core = ststm32
build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-D USBD_VID=0x0483
-D USBD_PID=0x0003
-D USB_MANUFACTURER="Unknown"
-D USB_PRODUCT="\"GENERIC_F401RCTX\""
-D HAL_PCD_MODULE_ENABLED
lib_deps = askuric/Simple FOC@^2.1.1
  • Upload your program using the upload button in Visual Studio
  • Change to RUN mode when the upload process is successful
  • Press the RESET button on the STM32 micrcontroller
  • The program should be running now
Press the RESET button when the device is not recognized by the computer