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 18, 2018 at 21:13

https://www.cs.indiana.edu/~geobrown/book.pdf

 
Andrew Neil
Evangelist
Posted on February 18, 2018 at 22:42

For basic getting-started tips, see:

https://community.st.com/0D50X00009XkWm7SAF

Posted on February 18, 2018 at 22:45

Is there some simple 'Hello, World!'-style tutorial, [...] I want to avoid the use of complex or non-free stuff (IDE, Cube, libraries such as SPL or HAL).

Then no.

Welcome to the wonderful 32-bit world!

Jan Waclawek

PS. My take on this at

http://www.efton.sk/STM32/

  but only a few randomly chosen boards and tasks. Some rudimentary example in the

http://www.st.com/en/embedded-software/stm32snippetsf0.html

.

I honestly want you to learn to hate the 32-bitters very quickly as we need you desperately for SDCC.

henry.dick
Senior II
Posted on February 18, 2018 at 23:03

'Basically I'm looking for a tutorial like the

/external-link.jspa?url=http%3A%2F%2Fwww.colecovision.eu%2Fstm8%2FSTM8S-DISCOVERY%2520Serial.shtml

, but for an STM'

that tutorial relies on non-standard libraries, to borrow your terminology.

'P.S.: By 'with standard library' I mean that functions from the standard library'

basically, you have free tools, you have cmd tools, ..... the moment it comes to access onboard peripherals, none of them exist anymore.

so if you have to code with 'standard libraries' exclusively, stay on your PC.

Posted on February 19, 2018 at 08:15

When I wanted to switch to ARM (a few years ago) I was in the same situation. Started with TI ARM as they had nice tutorials at that time. Moved to STM32 because they had more stable IDE (I mean Keil because I used to use TI IDE for TI ARM which was awful for me).

I think I should have started with reading reference guides and programming at the register level. Especially if you are experienced in other MCUs.

When you start with CubeMX/HAL/LL you also need to study RM because the abstraction provided by the HAL/LL is not clear (at least for me).

I think that the mentioned earlier book is good to see the difference between the 8bit MCU and ARMs:

/external-link.jspa?url=https%3A%2F%2Fwww.cs.indiana.edu%2F%7Egeobrown%2Fbook.pdf

But I am only hobbyist, not professional.

Posted on February 19, 2018 at 09:07

I don't see any use of non-standard libraries in the STM8 tutorial.

It uses stdint.h, which is a mandatory standard library header for freestanding implementation of C, and the type uint8_t,the availability of which is implementation-defined, but required for any implementation that has an 8-bit type at all. It also uses stdio.h and printf(). While these are not mandatory for freestanding implementations, they are still useful. The tutorial uses SDCC, and for the printf() that comes with SDCC, the way to specify where the printf() output goes is by the user providing a custom putcher().

Philipp

Posted on February 19, 2018 at 09:26

Don't worry. For now I just want to get a few performance numbers - Scores for the Whetstone, Dhrystone, Coremark and stdcbench benchmarks to compare with the 8-bit devices.

Maybe, in the long term, if I find the time to do so, knowing the STM32 might be helpful in porting the RTOS RIOT from the STM32 to the STM8.

Philipp

Harry May
Associate II
Posted on February 19, 2018 at 11:04

I came to STM32 last year whenI started a professional product for a machine controller.

First of all I got evaluation boards, like you did, and tested the various libraries and rtos.

From my experience the HAL generates more problems than it solves due to its

unnecessary complexity.

My library of choice it the STM32 standard library. It allows me to initialize all hardware components perfectly.

I also use Cube MX, but only to get hints about hardware usage, not to generate software.

I use the System Workbench for STM32 which works very reliably and never made any problem during development of my controller. System Workbench generates a simple and basic skeleton for the software which helps a lot to get started.

For a Hello World style program you can do a LED blinker for your eval boards which is done with a few lines of code.

Good Luck

Harry

Posted on February 19, 2018 at 11:46

Last year I needed simple ARM for simple task and discovered LPC810 (an NXP product). So started from scratch with the new vendor. Of course it's also an ARM so I started from register level programming (and errata documents). This approach was was really good in this case but frankly the LPC810 is not very complicated device (GPIO, UART, I2C, SPI, comparator, and simple clocking system).

To make my comment valuable: this forum is a great source of knowledge and help. There are some very skilled engineers (see the top guys on the rank list) who are willing to help.