Revising to Latest ST Software Design

A project log for Tiny Arduino for Hackers

A dime-sized, ARM-based Arduino complete with a programming/development system.

doctekdoctek 09/03/2023 at 00:140 Comments

Starting somewhere between release 2.0.0 (I think that's where it started) and the current 2.6.0 release of the STM32 MCU Based Boards, ST significantly revised the directory structure for variants and the contents of the variant files themselves.

The process documented in the Project Log "Adding tArmDuino to the Arduino IDE" is still correct in principle, but the details are incorrect. In this Project Log, I will basically follow the aforementioned, but I will provide correct details. Reading the old log will help anyone who wants to really understand this process.

For reference, I'm now running Ubuntu 18.04, but this should work with other recent versions and operating systems. My Arduino version is 1.8.15, but more recent versions should work also. However, I haven't tried Arduino 2.0 or later.

Let's get started. To begin, install the STM32 MCU Based Boards version 2.6.0. This isn't quite as clean as it might be and can't be done from the Arduino Boards manager as might be expected. Fortunately, ST provides simple instructions. Follow these, restart Arduino, and verify that the ST processors show up in the boards menu as shown in the instructions. (I'm not sure if you need to install STM32CubeProgrammer or not. If you try uploading to the tArm Duino from Arduino and it doesn't work, then install the STM32CubeProgrammer per the instructions.) I don't know exactly how to test this on my system, since I have all the tools in place.
There is still no entry in the STM32 Boards menu that is specific to the STM32L071, so I revised my previous board definition to meet ST's new requirements and added it to Arduino. This mainly required comparing my file and directory structures to versions in the ST directories. On my system, these are in ~/.arduino15/packages/STMicroelectronics/hardware/stm32/2.6.0. To guide these changes, the most useful references as of 2023 include these: Arduino documentation and Stm32duino documentation.

These resources still point to three key details. First, I needed a board.txt file which defines the features of my board, and a platform.txt file which would define my programming method. All the software modifications are in the "variant" directory. I copied my old variant directory for the LO71K and began modifications. Comparing my files and directory structure to an ST32L072 gave me the information I needed to make things work again.. The modified files and directory structure are provided in the Files section as Here are the modifications to the earlier versions:

platform.txt - I just added uploader tool and debugger configuration from ~/.arduino15/packages/STMicroelectronics/hardware/stm32/2.6.0/platform.txt. I'm not sure all these are needed, but things work. Currently, only the SWD uploader is used.
boards.txt - For this new version, I'm dropping the L031 variant and will only have the L071 variant. Several changes are needed in this file. Looking at ~/.arduino15/packages/STMicroelectronics/hardware/stm32/2.6.0/boards.txt showed me what to do. First, change the build.core definition from STM32:arduino to STMicroelectronics:arduino. Then add definitions for flash_offset and variant_h to the build section and change the value for variant

The second detail is to provide the directory structure required by ST for the variant. The following pictures show the structure from the Arduino Sketchbook leading to the L071K directory. (This structure is described further below.)

Seem a bit messy? All I can say is that ST is a European company, and the Europeans love structure. Perhaps the structure could be modified, but I don't see much point in trying to do that. Easier to just copy the structure.  Anyway, inside the L071K directory, the files PeripheralPins.c, variant_SMALL_L071K.h and variant_SMALL_L071K.cpp define the pins on my board, the functions they support, and the mapping to Arduino digital and analog pin numbers (like D0 or A5). Note that pins PB_4, PA_13 and PA_14 are removed from PeripheralPins.c as these are unavailable on my boards. I also copied files ldscript.ld and PinNamesVar.h from the ~/.arduino15/packages/STMicroelectronics/hardware/stm32/2.6.0/variants/STM32L0xx/L072K(B-Z)U_L082K(B-Z)U directory. These latest versions are needed to work properly with the new ST structure.
The third and final detail is exactly where to put the files so that my board will show up in the Arduino Tools/Board menu and my code will be compiled properly for it. The file map above starts with the location of the Arduino Sketchbook. The Arduino Sketchbook location is found from the Arduino IDE using File > Preferences. The Sketchbook location is the first entry in the window.

On my system, it is in ~/Arduino. In that location, I create a new directory named "hardware" (without the quotes).  For anyone wanting to duplicate this, download the file and simply unzip it into the Arduino/hardware folder you created. Restart Arduino and you will find an entry for "tArmDuinoL071" under the title "tArmDuino Boards (in Sketchbook)"

Two minor notes if you try to duplicate my work: 1) Be sure you install the stm32duino files first! 2) The debug version and the tArmDuino version of the STM32L071 hardware are identical from the software side. One entry covers them both.