Arduino for STM32

In a previous post I explained how to getting started with STM32 with classical Eclipse or Keil environments. These environments are very cool for starting from scratch in designing firmware. That said, you have to recreate a lot of basic functions and libraries to create your firmware.

On the other hand, the Arduino community is proposing a lot a existing libraries and a development framework with a large number of supported features. The STM32 community looks active and that’s a good way to quickly create advanced firmware.

That said there is different point blocking in my point of view for using Arduino as a professional environment:

  • Outside of the core libs and some nice one, most of the lib are badly written
  • The official editor is a mess if you manage more than 3 files…
  • Writing libraries with official editor is… “impossible”

For this reason, in this tuto, I’ll use Visual Code Studio  to see if the 2 last point can be solved. Regarding the first point, there is nothing better than using well coded libraries and rewrite (and share) the badly written one.

Install the development environment

  • So, as said, I start installing MS Visual Studio Code for MAC. Nothing special to say, we just need to unzip and move the file directly to the Application folder.
  • Now we need a plugin to work with MS VSC:

At first I’ve chosen to start with platformio ide. Unfortunately this plugin does not support STM2duino core but only mbed and CubeMx, so basically that’s what I’ve got with my previous eclipse environment. At the same time, STM32duino only support Arduino IDE platform.

There is another plugin in visual studio code named Arduino proposed by Microsoft. This plugin needs to have Arduino installed.

  • So we need to have Arduino ide installed from the official source.
    • Download and install Arduino IDE
    • Install the compiler for ARM target from the Board Manager, searching for Arduino SAM or Arduino SAMD platform. The SAM cover cortex M3 families, SAMD cortex M0+.
    • In Arduino >> Preference menu, edit Additional Boards Managers URLs and add https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
    • Go to Tool >> Board >> Board Manager and search for stm. Install the STM32 core by ST-Microelectronics. The installation takes a long time…

Now we may have al the needed software for getting started.

The limit of the Arduino approach to that it is limited to existing board and as a consequence once you create your own circuit you need to create a custom board corresponding to this circuit. We will see later how to do that.

Compile a first blink peace of code on Arduino environment

Let’s start by creating a simple blink project with Arduino. The board I’m using is a Nucleo-32 STM32L031. Here are the steps

  • Go to File >> Example >> 01 Basic >> Blink
  • Save this project locally
  • Configure it:
    • Tool >> Board Type >> Nucleo-32
    • Tool >> Part Number >> Nucleo L031K6
    • Tool >> Upload Method >> Mass Storage
    • Tool >> Port >> select the right port
  • Compile and Upload it.

This should make the board led blinking.

Make the same with MS Visual Studio Code

  • Start MS Visual Studio Code
  • Open your Blink project from Document/Arduino/Blink
  • Click on the “ino” file in the editor
  • On the bottom of the IDE you have a blue line where you can select the board type and the serial port.

Once setup you can compile the project with [F1] then searchy for Arduino: Verify or Apple + Alt + r key combination.

The sketch can be uploaded with Apple + ALT + u key combination. /!\ With the Mass storage upload method I had to unplug / plug the board on the usb cable to be able to make a second upload.

This is working correctly with STLink upload method, if you connect the serial console (click on the power plug icon on the bottom) the console is automatically printed after uploading the sketch.

First conclusion

The use of MS Visual Studio Code with Arduino is really changing coding life, as an example you have the method completion on Serial and all other structure and class. You can work only in the VSC environment, no going to the Arduino IDE. The Arduino plugin is making the link launching the Arduino IDE for compiling and uploading the sketch transparently. Performance is good and with announced Arduino CLI it will be improved soon. Editor allows to work on sketch and on Libraries in parallel, simplifying the code organization for large projects. I’ll need to see how can I work with a custom platform instead of using a development board for making real projects with this environment (like we can do with standard platform: Eclipse, Keil…)

This post may be updated soon with these information.

3 thoughts on “Arduino for STM32

  1. thank you for the information, I have followed the steps here and I tried uploading code to bluepill but i get this message:

    Got byte 0x00 instead of ACK
    Starting execution at address 0x08000000… failed.

    what could be going on?
    Thanks

  2. Pingback: STM32 and Arduino, working with a custom board - disk91.com - technology blogdisk91.com – technology blog

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.