cancel
Showing results for 
Search instead for 
Did you mean: 

Getting started with STM32 bare metal, but with standard library

Philipp Krause
Senior II
Posted on February 18, 2018 at 19:55

A few days ago I got a few STM32 boards (STM32F0-Discovery, STM32F031 Nucleo-32, STM32F302 Nucleo-64) to have a quick look at the STM

Is there some simple 'Hello, World!'-style tutorial, that shows setting up an UART for printf() and possibly basic use of timers? I want to use a free toolchain (I have the arm-none-eabi-gcc Debian package installed, and compiled texane stlink). I want to avoid the use of complex or non-free stuff (IDE, Cube, libraries such as SPL or HAL). Basically I'm looking for a tutorial like the

http://www.colecovision.eu/stm8/STM8S-DISCOVERY%20Serial.shtml

, but for an STM

Philipp

P.S.: By 'with standard library' I mean that functions from the standard library that make sense for, but are not required by, a freestanding C implementation (e.g. the string.h stuff) should be available.

#bare-metal-arm #gcc #stm32f0 #tutorial

Note: this post was migrated and contained many threaded conversations, some content may be missing.
49 REPLIES 49
Posted on February 20, 2018 at 14:10

The startup code from GitHub mentioned above above states '

COPYRIGHT 2012 STMicroelectronics […] You may obtain a copy of the License

at

:

http://www.st.com/software_license_agreement_liberty_v2

[…]'.

Conditions 4 and 5 of that license obviously make the startup code non-free.

Philipp

Posted on February 20, 2018 at 14:48

Not within the context of tour endeavor here. Unless you attempt to make it non compliant deliberately.

Posted on February 20, 2018 at 14:49

I said Cube, not some random source from the internets.

Don't confuse Cube with CubeMX - the latter is configuration software, the former is the 'library'. It comes suffixed with the family name, i.e. go for CubeF0

JW

PS. Every licence poses some restrictions and the perception of freedom in them is subjective. Said clause 4 is IMO very reasonable and limits only morally dubious use. Clause 5 is in fact redundant as changing licence terms is exclusive right of the author. That this might prevent using them with GPL or other 'viral' licenced software is in fact expression of lack of certain freedoms in GPL... IANAL of course.

Posted on February 20, 2018 at 14:50

He didn't claim it to be non-reinventing.

Looks like he just wanted to dumb down to an absolute minimum number of source files so even a dimwit can compile it with minimum understanding of the device or the environment....

It is not meant to be useful for anything other than that.

Posted on February 21, 2018 at 10:52

Here I wanted both simplicity (preferably no extra files) and freedom. In particular, for

http://stdcbench.org/

, I wanted to add example ports to the STM32F051 and STM32F302 (which I have done by now). The example ports for stdcbench usually consist of a Makefile, a portme.c and a portme.h. Having additonal header files or startup code would break this simple structure of ports.

Philipp

Vincenzo Gibiino
Associate II
Posted on February 24, 2018 at 15:43

hello, like you i would like to start with stm32, I am still in the phase of gathering information around google

stm bought atollic so 

https://atollic.com/truestudio/

  is now free and i think it would be a very good starting point

about the libraries i am quite confused with all these SMSIS, HAL, SPL. the HAL should be made directly by STM but really i am not sure nor i know where is it available if someone have more information it would be useful

Posted on February 24, 2018 at 16:14

the op has a very specific set of goals so unless you share his specific set of goals, it is probably a mistake for you to take the same approach as he does.

CMSIS is a set of API provided by ARM to other chip makers that utilize the ARM core. ARM has overtime broadened its CMSIS coverage for a few things but for the most part, people use CMSIS to refer to the core/core-peripheral specific interface. You can use your chips without it, but in my view it would be a mistake.

SPL/HAL/LL, and other OEM libraries, are frameworks introduced by the chip makers (ST in this case) to help their customers work on those chips. those tools can be quite helpful for newbies getting on a chip; but they can be a source of frustration. you don't have to use those tools in your applications and many don't.

Posted on March 05, 2018 at 15:08

It turned out that the flash speed is much more than just 'a little bit' of the results. Despite the prefetch buffer, those flash wait states matter a lot! In stdcbench 0.4 on a STM32F103RB, at 36 Mhz with prefetch buffer enabled, the stdcbench 0.4 score is more than 22% higher when using 1 flash wait state vs. 2 flash wait states.

Philipp

Posted on March 05, 2018 at 21:20

It turned out that the flash speed is much more than just ''a little bit'' of the results.

Of course it is. The prefetch buffer helps you only with linear portion of code - and the FLASH prefetch just augments the internal prefetch queue of the Cortex-M3. At every jump (branch), the prefetches are flushed and the FLASH latency in its entirety is applied.

But the 'F1 are ancient measured by the pace of how the STM32s are developing. Take a 'F2/'F4 and measure the impact of the jumpcache (aka ART accelerator).

And that also highlights the fallacy of number-crunching-data-lifting - these benchmarks often contain lots of short loops, and then it's just too easy to adjust the jumpcache's size so that it almost entirely mitigates the slowness of FLASH. While this has dubious value for real-world controller programs, it allows the marketing to make broad claims, like

0690X00000609w8QAA.png

So this is why

https://community.st.com/thread/47559-getting-started-with-stm32-bare-metal-but-with-standard-library#comment-186018

JW

Posted on March 05, 2018 at 21:49

The flash speed on the STM32 CM0(+) has a very deleterious effect on speed. At 48 MHz it will be fractionally faster than 24 MHz with no wait states. I don't have the numbers with me, but if it behaved as though it was running at 27-29 MHz it wouldn't surprise me in the least.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..