Skip to main content
Associate
July 18, 2026
Question

Need some help on "bare-metal" initialization for STM32 MCU

  • July 18, 2026
  • 6 replies
  • 80 views

Embedded veteran here, been involved in all manner of MCUs and MPUs professionally (especially safety-critical) but for personal use most of my prior experience has been with PIC16F and 18F (to save money obviously), of course those are only 8-bitters. I’m very interested in learning STM32 MCUs (gee they look ALMOST like DSPs except it’s single-cycle multiply not MAC and no simultaneous pointer adjustments etc.). Thing is my PIC experience has given me a pretty decent collection of chip initialization routines that I can adapt as necessary for small differences with peripheral features and such. My “inherent bias” is bare metal, no FreeRTOS, I understand I may be “going against the grain” a little but I want to get my hands on every nanosecond I may have coming. I don’t necessarily need this in C language, but I would like to get my hands on at least a very detailed list of all the HW registers that COULD need to be set, and the EXACT order in which this is “most safely accomplished”. (Now I don’t really feel it’s unreasonable to ask this, since the reference manuals for the PIC parts that it took me months to understand tended to run about 500 pages in length, whereas the STM32 parts are running about TWICE that.) For right now I would be quite happy with an answer that is correct up to about say STM32F03xxxxx (from what I understand I might be interested in using so far). I guess if I weren’t such a newbie I would know where this might reside on GitHub or something, but hopefully there is a file someone can offer to me they have used successfully on a project somewhere. Thank you for your attention!

6 replies

mƎALLEm
ST Technical Moderator
July 18, 2026

Hello ​@jlawton11 and welcome to the ST community,

That depends on which level of “beremetal” you are meaning here:

  • No RTOS but using C APIs
  • Direct access to the registers

For the first case, you can use directly the HAL (the hardware abstraction layer) provided by ST, available here on Github (fr STM32F0 devices): https://github.com/STMicroelectronics/STM32CubeF0. Some examples are available under the same package for some specific boards in https://github.com/STMicroelectronics/STM32CubeF0/tree/master/Projects. These examples can be tailored to any other board. You can also do the initialization and code generation using CubeMx tool available here for download: https://www.st.com/en/development-tools/stm32cubemx.html. Then use STM32CubeIDE to compile and debug your application available here for download: https://www.st.com/en/development-tools/stm32cubeide.html

Please refer to this tutorial: STM32CubeIDE 2.0.0 workflow tutorial

For the second case, you need definetly read the reference manual, obviously not all the RM document but the sections related to the peripherals you plan to use, basically RCC, Flash, GPIO to start a very basic project. You need also to read the datasheet for some specific electrical parameters.

To accelerate things, you can inspire from the HAL implementation and how the registers are accessed in their correct order.

Hope that helps.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
waclawek.jan
Super User
July 20, 2026

> ALMOST like DSPs

They can’t be further.

JW

unsigned_char_array
Lead III
July 20, 2026

Couldn’t have said it better. I often consider the bigger 32-bit ARMs to be closer to an MPU than an MCU, since you often use them with external memories. But SoC is a better description. The peripherals no longer feel connected. They are practically external, but happen to be on the same die. The processor runs at a high clock rate, but has poor latency.

I often miss simple 8-bit MCUs when working with 32-bit ARMs. A week ago we had an issue where SPI started transferring before the chip select line switched to low. The cause was a race and even though we set the GPIO pin low first before we started the transfer, the SPI peripheral received its command before the pin switched. We had to insert a DSB() to make sure the pin had actually switched.

 

"Kudo posts if you have the same problem and kudo replies if the solution works.Click ""Accept as Solution"" if a reply solved your problem. If no solution was posted please answer with your own."
AScha.3
Super User
July 20, 2026

Hi,

Let me tell about me first: I came from the other side, AVR 8bit, also in assembly programmed.

Naturally, as most effective and not really complex to learn.

Then began with the arm CPU, with the first learning set available, the Primer, with stm32f103 .

.…

Now latest hobby project: audio player with stm32h743zi CPU, plays wav, flac, MP3, web radio, from SD-card or USB stick, to 3 dacs, with active filters for multi way speakers.

Now… The Times They Are A-Changing …

 

I just can tell you my experience and recommendations:

"Datasheet" for stm32h743 is about 4000 pages, to add arm core manual and programming manual. And then the funny arm assembly, with it's delicious optimization possibilities. Forget to learn this in reasonable time and do it at the level of GCC with optimizer level -O2 .

So take to learn in short time a cheap nucleo board, with st-link debug probe on board.

Then use the older IDE version, Cube IDE V 1.19. , learn how to use it, how to setup a pinout in Cube, generate code, compile and start debug.

This for sure is the best and fastest way to get it running.

Then try a small program, optimizer on -O2 or -Ofast, and then comes the time to think about optimizing something by hand, just using the Hal library for the initialization and standard init, like USB host etc, , then using registers for doing something at highest possible speed.

And use our new electric friends, to ask and get optimized C code. They do it in seconds.

Or ms.

A nice older CPU is the f303, fast ADC; so maybe NUCLEO-F303RE is a good starter for 20$.

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
David Littell
Senior II
July 20, 2026

“… I want to get my hands on every nanosecond I may have coming.”  Some famous old guy once said, “Premature optimization is the root of much evil.”  He was right, of course.  Most old guys are.  Another old guy said, “First, make it work.  Then make it fast (but only if you really, really have to).”

TDK
July 20, 2026

> I would like to get my hands on at least a very detailed list of all the HW registers that COULD need to be set, and the EXACT order in which this is “most safely accomplished”

The reference manual is the proper resource here. It lists all of the peripherals, their registers, and how they operate. It also lists the steps needed to do common things, like sending something out over SPI.

ST has explicitly decided not to publish register-level examples for peripherals. You can find some examples floating around, but they aren’t from ST and are of varying quality. Their answer for this is the LL library, which I do not recommend.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Pavel A.
July 20, 2026

Hello jlawton11,

Let me join the welcoming chorus and wish you to have as much fun with STM32 as we do ))

> hopefully there is a file someone can offer to me they have used successfully on a project somewhere.

STM32s are very popular so there are lots of various videos, course materials, books and example projects. The problem is exactly in the amount and variety. It’s overflowing. The genuine ST documentation is the most reliable source, it takes some time to get used to. For every STM32 chip usually there are 4 main documents: the data sheet (DS), Reference manual (RM), Programming manual (PM) - this one describes the common ARM processor of the STM32 (registers, instruction set, interrupt controller... beginners often miss this). And the Errata.

Fortunately the AI assistant can read all those PDFs for you and explain stuff. Please try it.

 

The only thing you have to tell the AI assistant upfront is the STM32 family. If you want DSP-like functionality and high speed, maybe don’t be shy and start with a powerful STM32H7 or F7 rather than F0 ?

Read the entire collection of tips from ​@waclawek.jan - each one is brilliant.