Nov 22, 2016 4 Comments Tutorials
STM32: Gettting Started - Programming Resources
There are multiple ways to write program for the STM32 development boards. Some most common ways are:
- STM32 Standard Peripheral Libraries: I guess this is the old way, where you can write device specific code using the STM32 standard libraries for that particular microcontroller using Keil, etc.
- mbed: mbed is a great platform, especially if you are using ST Nucleo boards. It has excellent online IDE and easy way of programming, where you write code in an online free IDE and compile it online itself and then just save the binary files to the device, which will emulate as a removable disk drive. But I like desktop programming environments more, also mbed supports few boards. Generic boards does not come with mbed pre-loaded, and I faced difficulty in migrating to generic boards or Desktop environment.
- STM32Duino: This is my favorite way, partly because I had prior experience with Arduino and Arduino for ESP8266, etc.
This is a great and easiest way to program low cost generic boards. I didn't spend time on bootloader and serial programming like Arduino, but I simply used a ST-LINK programmer. This is as simple as copy the Arduino_STM32 folder into the Arduino/hardware folder, connect a ST-LINK programmer, open the blink sketch, change the LED from 13 to PC13 (on my board, its PC13) and hit Upload.
I guess I am loving it, the USB on my board acts as a Serial COM device (with little modifications), STM32Duino takes away all the pain writing CDC classes. Supports RTOS, and almost all the Arduino libraries will work with little modifications. I have tried OLED, GPS, RFID (RC522) and few other libraries. Used STM32 with GSM A6 and GPS A7 boards. All worked well, with little effort.
- STM32CubeMX: This is the most powerful way for serious development. STM32CubeMX is a graphical tool to generate project solutions and configurations for few common commercial IDE. I installed STM32CubeMX and Keil and generated solution for Keil IDE. This tool takes away the pain of writing configurations. In the graphical tools itself, you can define which GPIO pins are input or output, USART, CPU Frequency and clock, etc.
The benefit of this approach is easier debugging, optimized code which is much closer to the hardware and so you can use all the features of the microcontroller, as you are not limited by some 3rd party like STM32Duino to provide some fix or feature. You lose the convenience of Arduino and libraries for Arduino, at the cost of more power and easier debugging. Instead of using J-LINK or ST-LINK, I used ULINK2 which is more standard way when using Keil for any microcontroller, not just STM32.
The newer libraries, makes code more portable across all STM32 microcontroller, as it uses Hardware Abstraction Layer (HAL). With STM32CueMX Getting started is much easier, code is more portable. Only worry, costly IDE and tools. Losing favorite Arduino IDE and libraries, but much more power and features.