> For the complete documentation index, see [llms.txt](https://docs.feelix.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.feelix.xyz/uploading-files/setting-up-stm32.md).

# Setting up STM32

### Prepare

{% stepper %}
{% step %}
**Install the** [**STM32CubeProgrammer**](< https://www.st.com/en/development-tools/stm32cubeprog.html >) to upload to the STM32 microcontroller (available for Windows and MacOS 64 bit).

Check the [troubleshoot page](/uploading-files/troubleshoot.md#stm32-cube-programmer-installation) if you experience issues with installing the STM32CubeProgrammer on MacOS
{% endstep %}

{% step %}
**Install the** [**Dependencies**](/uploading-files/simplefoc.md)
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Make sure the device is in **BOOT mode** when uploading with Arduino IDE / Platform IO
{% endhint %}

{% hint style="info" %}
The **RESET** button on the STM32 micrcontroller needs to be pressed after switching between **BOOT** and **RUN mode** in order to read the change
{% endhint %}

<figure><img src="/files/52l55LKElkrgBgqVN3rK" alt=""><figcaption></figcaption></figure>

### Option 1: Arduino IDE

{% stepper %}
{% step %}
Open Preferences > Additional Boards Manager URLs
{% endstep %}

{% step %}
Add a new line with the following URL: *<https://github.com/stm32duino/BoardManagerFiles/raw/main/package\\_stmicroelectronics\\_index.json>*

{% hint style="danger" %}
Installed Libaries and Boards Managers should match the version specified in the documentation below.
{% endhint %}

<figure><img src="/files/B4OpnqZ4OZPoqQQWsn8b" alt=""><figcaption><p>Additional Boards Manager URLs window</p></figcaption></figure>
{% endstep %}

{% step %}
Open the **Boards Manager** from the Tools menu.
{% endstep %}

{% step %}
Search for '**STM32 MCU based boards**' and click **INSTALL v2.12.0**

<figure><img src="/files/VZ7VJqk5VoddAesIS58g" alt="" width="551"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Update the **Board Settings** in the Tools menu

* Set board to '**Generic STM32F4 series**'&#x20;
* Board part number to '**Generic F401RETx**'
* Upload method to '**STM32CubeProgrammer (DFU)**'
* USB support to '**CDC (generic 'Serial' supersede U(S)ART)**'
* U(S)ART support to '**Disabled (no Serial support)'**
* USB speed to '**Low/Full Speed**'

<figure><img src="/files/belklEaVFq2pRcwA28by" alt=""><figcaption><p>Arduino IDE Board Settings</p></figcaption></figure>

{% hint style="warning" %}
The USB Serial port is only used for **Serial Monitor**, when the device is in **RUN mode** the USB Serial port will appear in the Arduino IDE (Tools > Port)
{% endhint %}

{% hint style="info" %}
**The USB Serial port** **does&#x20;*****not*****&#x20;have to be specified** (having one specified should not cause any problems either).
{% endhint %}

{% endstep %}

{% step %}
Now you are ready to **upload** [**your program**](/downloads/c-library.md#library-for-exported-feelix-effects) using the upload button in the Arduino IDE&#x20;

After uploading the Arduino IDE or Platform IO will enable **RUN mode** automatically. \
If the board has been **RESET** or disconnected from the **POWER**, the switch should be manually changed to **RUN mode** in order to run the program.

After manually switching to **RUN mode** press the **RESET** button on the STM32 microcontroller.

The program should be running now, if not check out the [**troubleshoot page**](/uploading-files/troubleshoot.md).

{% hint style="info" %}
Press the **RESET** button when the device is not recognized by the computer. Make sure the switch is set to **RUN mode**.
{% endhint %}
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Method with Platform IO has not been tested recently.
{% endhint %}

### Option 2: Visual Studio & Platform IO

{% stepper %}
{% step %}
Add STM32 boards (search for ST STM)
{% endstep %}

{% step %}
When starting a new project, select STM32F401RE with framework Arduino

<figure><img src="/files/sizUdafepK2JQEV64LT4" alt=""><figcaption><p>Visual Studio Project Board Settings</p></figcaption></figure>
{% endstep %}

{% step %}
Make sure the settings in the platform.ini file are as follows

```scheme
[env:genericSTM32F401RE]
platform = ststm32
board = genericSTM32F401RE
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 = stm32f401ret6
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_F401RETX\""
	-D HAL_PCD_MODULE_ENABLED
lib_deps = askuric/Simple FOC@^2.4.0
```

{% endstep %}

{% step %}
**Upload** your program using the upload button in Visual Studio

After uploading the Arduino IDE or Platform IO will enable **RUN mode** automatically. \
If the board has been **RESET** or disconnected from the **POWER**, the switch should be manually changed to **RUN mode** in order to run the program.

After manually switching to **RUN mode** press the **RESET** button on the STM32 microcontroller.

The program should be running now.
{% endstep %}
{% endstepper %}

{% hint style="info" %}
Press the **RESET** button when the device is not recognized by the computer. \
Check out the [troubleshoot page](/uploading-files/troubleshoot.md) when issues persist.
{% endhint %}
