Engee documentation

STM32 Support Package

Page in progress.

Target Hardware is a mode that provides pre-configuration of the project before code generation, firmware assembly and download, as well as launching the model on a microcontroller.

To work with STM32 boards in this mode, the EDM-Target-STM32 block is used, which provides generation, assembly and loading of firmware, as well as running the model on a microcontroller.

EDM-Target-STM32 Block Parameters

The EDM-Target-STM32 unit adjusts the interaction with the microcontroller through the following parameters:

  • Path to the CubeMX project — the full path to the generated STM32CubeMX project.

  • The path to the toolchain:[A toolchain is a set of console tools (compiler, linker, and utilities) that assemble firmware for a microcontroller from the source files of a project.] — full path to the compiler arm-none-eabi-gcc.

    When specifying <auto> first, it is searched in the paths where CubeIDE puts them (if it is installed). Then in the PATH and in the system paths.

    • An example for Windows:

      C:\ST\STM32CubeIDE_1.13.2\STM32CubeIDE\plugins\
      com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_2.0.100.202309141235\
      tools\bin\
    • An example for Linux:

      /opt/st/stm32cubeide_1.13.2/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.linux64_2.0.100.202309141235/tools/bin/arm-none-eabi-gcc
  • Path to STM32CubeProgrammerCLI — full path to the executable file STM32CubeProgrammerCLI.

    To automatically detect an installed tulchain, use the expression <auto> in ways to define a tulchain:

    stm32 1

  • UART module — the USART number to be used for interactive mode.

    This number must match the module that must be pre-configured in STM32CubeMX for UART data transmission. For detailed instructions, see Interactive mode.

    After configuring in CubeMX, specify the same USART number in the "UART module" parameter of the EDM-Target-STM32 block (for example, 2 for USART2).

  • COM port — the serial port corresponding to the selected UART module (for example, COM3 or /dev/ttyUSB0).

To operate the unit, you must install the STMicroelectronics software in advance (see the section "Required Software").

Required Software

To work with STM32, you need to install the following tools:

  • STM32CubeMX — for configuring the microcontroller peripherals and generating a project.

  • STM32CubeIDE is a recommended development environment that includes a compiler and debugging tools.

It is allowed to work without STM32CubeIDE. In this case, it must be installed separately.:

  • The compiler gcc-arm-none-eabi

  • A utility for firmware STM32CubeProgrammerCLI

Utilities can be used in two ways:

  • Specifying utilities manually — in this case, simply set the full path to the compiler and STM32CubeProgrammerCLI in the EDM-Target-STM32 block parameters. Variable PATH it is not used in this case.

  • Mode <auto> — then Engee will search for utilities automatically. In this case, the environment variable is PATH it is applied, and utilities should be available through it.

Engee Preparation

Make sure that the hardware support package is installed and configured. Its installation is described in detail in the section Hardware connection.

If the support package is already installed, then you can proceed to launch the client program and connect using the provided URL.

Preparation of the STM32 project

  1. Install and configure STM32CubeMX.

  2. Create a project for your STM32 board and perform basic peripheral configuration.

  3. Click GENERATE CODE and save the project to a convenient directory.

  4. Install STM32CubeIDE or configure the compiler and firmware utility separately if you use an external toolchain.

The detailed configuration of the CubeMX project for working with Engee is described below in the Setting up and launching the model section.

Setting up and launching the model

  1. Open the Engee model.

  2. Click on the target platform selection button and select the mode Target Hardware:

    target hardware 1

  3. Add the EDM-Target-STM32 block from block libraries on the Engee canvas. If the block is missing, update the support package with the command:

    engee.package.start("Engee-Device-Manager")
  4. Set up the project in STM32CubeMX:

    • In the Project ManagerProject section, select Copy only the necessary library files.

    • In the Project ManagerToolchain / IDE section, be sure to set the value to CMake.

      stm32 3

      The choice of CMake is mandatory. Without this, the project format will be incompatible with Engee.

    • In the Code Generator section, select Generate peripheral initialization as a pair of '.c/.h' files per peripheral.

      stm32 2

    • Configure the necessary peripherals and click GENERATE CODE.

      stm32 4

    • Specify the path to the generated project in the CubeMX project path parameter of the EDM-Target-STM32 block.

      stm32 5

  5. Select the model execution mode:

    • Run the model on hardware target hardware 4 — interactive execution with control from Engee.

    • Run in independent mode target hardware 3 — offline execution without control from Engee.

  6. Click the start button.

If the EDM-Target-STM32 block is not placed in the model, an error will appear at startup:

ErrorException("EDM-Target-STM32 block not found. To start model in Target Hardware mode, the model must include an EDM-Target-STM32 block.")

Special settings for different modes

Setting up for FreeRTOS

The FreeRTOSfootnote project:[FreeRTOS is a lightweight real-time operating system (RTOS) that provides task scheduling, delays, queues, and other mechanisms that conveniently run the model in parallel with the rest of the firmware logic.] can be configured as simply as possible:

  1. In STM32CubeMX open Pinout & ConfigurationMiddleware and Software Packs.

  2. Turn on FREERTOS.

  3. In the FREERTOS Mode and Configuration section, set Interface to CMSIS_V2.

    stm32 6

  4. Leave the other parameters by default.

  5. Generate the code using the GENERATE CODE button.

In FreeRTOS mode, manual setting of the model execution frequency is not required, unlike in bare-metal mode, where the timer is set manually.

Setting up for bare-metal

In bare-metalfootnote mode:[Bare-metal is the launch of a program without an operating system. The code runs directly on the microcontroller, and all tasks (timers, calls model_tick(), event handling) must be configured manually.] the frequency of model execution is set manually via a timer:

  1. Select a free timer (for example, TIM3).

  2. Set the clock source Internal Clock.

    stm32 7

  3. Calculate the timer parameters using the formula:

    T = ((P + 1) × (R + 1)) / F_CPU

    Where:

    • P — Prescaler

    • R — Counter Period

    • F_CPU — The clock frequency of the microcontroller

      An example for 72 MHz:

      P = 7199
      R = 9
  4. Set the values in the timer parameters.

    stm32 8

  5. In the NVIC Settings tab, enable timer interrupt.

    stm32 9

  6. Add a call to the model_tick() function[1]:

    void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
    {
      if (htim->Instance == TIM1)
      {
        HAL_IncTick();
      }
    
      if (htim->Instance == TIM3)
      {
        model_tick();
      }
    }
  7. After initializing the timer, add startup:

    HAL_TIM_Base_Start_IT(&htim3;);

Interactive mode

Interactive mode uses UART to communicate with Engee:

  1. In STM32CubeMX, select a free USART module.

  2. Set the parameters:

    • Baud Rate — 115200 Bit/s

      stm32 10

    • The other parameters are by default

  3. In the EDM-Target-STM32 block parameters, specify:

    • UART module — USART number

    • COM port — The device port

      stm32 11 Examples:

      • Linux — /dev/ttyUSB0

      • Windows — COM1

        Checking available ports on Linux:

        ls /dev | grep ttyUSB
To display the UART as a COM port, you may need to configure USB_DEVICE. For more information, see the manual: STM32 and USB. USB Virtual COM Port Implementation

Solving possible problems

Problems with the UART connection

When reporting Unable connect to target:

  • Check the reliability of the USB connection

  • Make sure that the TX/RX connection is correct

  • On Linux, add a user to a group that has access to serial devices (for example, wheel, uucp or another one, depending on your distribution).

Firmware issues

If the anchors were removed USER CODE BEGIN or the CubeMX system code:

  • Delete the corrupted project files

  • Generate the project again in CubeMX (by clicking GENERATE CODE)

Assembly problems

  • Errors are displayed in the interface of the client program with a complete output of information about the problem.

  • Check that the paths to the utilities are correct

  • Make sure that the path to the tools is specified correctly in the block parameters and that they are accessible using the specified path.


1. model_tick is an automatically generated Engee function that is responsible for the "clock cycle" of the model. It should be called at the right frequency (usually 1 ms) so that the model runs at the correct frequency.