Skip to content

Manage the STM32duino boards

STM32duino supports a wide range of STM32-based boards.

For an exact list of the supproted boards,

Install

To install the STM32 boards,

  • Ensure the Arduino tools, CLI or IDE, are installed.

  • Ensure the arduino-cli.yaml configuration file for Arduino-CLI or the Additional boards manager URLs for Arduino IDE includes

https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
  • Open a Terminal window.

  • Run

$
arduino-cli core install STMicroelectronics:stm32

For more information,

Install the uploader and debugger utilities

STMicroelectronics recommends ST-Link, part of the STM32CubeProgrammer software for all STM32 package. However, it requires Java.

  • Download and install STM32CubeProgrammer.

To update the PATH environmnent variable,

  • Open .bashrc.
$
nano ~/.bashrc
  • Add
export PATH=$PATH:~/Applications/STM32CubeProgrammer/bin
  • Save and close with Ctrl+O Ctrl+X.

Two open-source alternatives include OpenOCD for Open On-Chip Debugger, the Arduino Tools from STM3232duino, and Texane ST-Link, a native version of the STMicroelectronics ST-Link tools.

Please refer to

Update the firmware of the boards

The application STLinkUpgrade updates the firmware of the ST-Link, ST-Link/V2 and ST-Link/V2-1 boards through the USB port. It requires the Java Runtime Environment.

  • Download the STSW-LINK007 package .

  • Install the STLinkUpgrade application.

  • Connect the board and launch the application.

For more information on the firmware upgrade for ST-Link, ST-Link/V2, ST-Link/V2-1 and ST-Link-V3 boards,

Develop

Manage old versions of boards

STM32duino release 2.6.0 manages correctly the system clock, even for old versions of the boards.

Prior releases of STM32duino may need adding a specific clock function for old versions of the boards.

  • Just add on the main sketch the SystemClock_Config().
extern "C" void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {};

  /* Configure the main internal regulator output voltage */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
  /* Initializes the CPU, AHB and APB busses clocks */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  RCC_OscInitStruct.PLL.PLLQ = 7;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
    Error_Handler();
  }
  /* Initializes the CPU, AHB and APB busses clocks */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
                                | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
    Error_Handler();
  }
}

For more information,

Debug

  • Edit the launch.json file to add the configuration for the board.
Example

The example below targets the Nucleo-64 STM32F401R board.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "cortex-debug",
            "request": "launch",
            "name": "STM32F401 OpenOCD",
            "servertype": "openocd",
            "cwd": "${workspaceRoot}",
            "executable": "${workspaceRoot}/.builds/embeddedcomputing.elf",
            "gdbPath": "/usr/bin/gdb-multiarch",
            "configFiles": [
                "board/st_nucleo_f4.cfg"
            ],
            "preLaunchTask": "Fast"
        }
    ]
}