Stm32 - i want to learn


#1

Hey. I want to learn programming STMs but i dont know which toolchain should i use:

  • HAL - nice graphical CUBEMX editor
  • SPL - i think Oliver uses this, but a lot of people dont recommend it
  • LowLevel registers etc. - i think i dont want to :thinking:
  • mbed?
  • stm32duino?
    (i used to program avrs and arduino in past and looking for something better :))
    sorry for noob questions :confused:
    thanks in advance

#2

I was in your same position a year ago so I thought to share my experiences. Take from it what you will as I am also a noob. Tl;dr, CubeMX + HAL worked fine for me, but don’t be like me and overlook the Mutable development toolchain, which does a lot of the hard stuff very well and might be more fun for getting started. I don’t know anything about mbed or stm32duino, so others might be able to better advise on those.

I used a discovery board to get started, and CubeMX includes starter projects for the discovery boards to get you off the ground. Additionally, you can load and hack example firmware from ST (which is mostly in SPL, if you want to try that). CubeMX can generate projects for SW4STM32, an eclipse-based toolchain providing full programming and debugging support. Once I got code to compile and flash, the fun stuff came much faster.

Since I had absolutely no idea what I was doing, this was the path of least resistance. I had a successful experience with SW4STM32, but its far from the end-all-be-all.

If you are a more experienced programmer than I was (or just wiser), you would probably get a lot from studying Olivier’s stmlib along with how it is implemented across different modules. Rather than building up from a discovery board, you could also hack Mutable modules to get your feet wet, as you already have a ui and audio peripherals at your disposal along with a comprehensive development environment/toolchain, the mutable-dev-environment.

A note about toolchain vs. abstraction layer: HAL, LL, SPL, and CMSIS are all hardware abstractions, basically C code, and within a given toolchain, you can write code that uses any of the above (so far as I am aware, I have never used LL or SPL).

I found that HAL worked for initializing the hardware, and it comes with more documentation than your average ST software. It allowed me to set up interrupts, timers, and DMA, all of which proved crucial to a responsive, efficient embedded audio device. It also plays nice with CubeMX projects. I would even go so far as to recommend using CubeMX-generated HAL for setting up a custom board.

Vis a vis using register level programming, I was terrified but ended up learning it anyways. I scrapped all of the HAL code that was executed at runtime because the error checking and abstraction built into the functions adds a lot of unnecessary overhead. I did, however, study it and find the necessary bits for my particular needs. Those ended up being CMSIS, which is a lower level abstraction underlying STM’s HAL library. Now I like CMSIS :slight_smile:

The Mutable code again provides ample examples of efficient register-level programming. Now that I know what to look for, its a great reference. As a general framework, it does a phenomenal job of handling non-DSP tasks efficiently so that the processor can focus on doing lots of cool DSP.

I hope this helps; this is my first time posting on a music technology forum :sweat_smile: Others with more experience might have better advice.