I am a newbie to embedded system. I decided to buy an STM32 board to get started. The problem now is that I would like to know if there is a simple way to write some C++ code in a simple text file then compile it (maybe with g++) and load it on the board without using some strange online compiler.
I am used to writing code on Linux with Vim and then simply compiling it with g++ and then run the executable. I would like to use the same approach to program the STM32 board. Is it even possible?
If yes, could someone explain how to do it considering that I am very new to this word of embedded systems?
-
1\$\begingroup\$ What do you mean by "online compiler"? Almost all IDEs use arm-gcc under the hood, so of course it is possible. \$\endgroup\$Justme– Justme2021年06月27日 19:19:07 +00:00Commented Jun 27, 2021 at 19:19
-
\$\begingroup\$ It may seem simpler to use VIM/gcc to build something, but given the learning curve associated with initializing all the hardware, it is much easier to use STM32CubeIDE (free, cross platform) to generate the initialization code. It is eclipse based and dramatically simplifies hello world applications. \$\endgroup\$Dean Franks– Dean Franks2021年06月27日 19:24:00 +00:00Commented Jun 27, 2021 at 19:24
-
\$\begingroup\$ I mean that there is a website called Mbed where there is an online editor that compile your code and produce a .bin file to upload on the stm32 nucleo board. But I want just to write and compile my programs from my linux distribution via command line @Justme \$\endgroup\$RIXS– RIXS2021年06月27日 19:26:50 +00:00Commented Jun 27, 2021 at 19:26
-
\$\begingroup\$ @Dean Franks Yes but in this way I do not understan what is the happening, I want to understand how it works from the plain text file code to the final executable to load on the board \$\endgroup\$RIXS– RIXS2021年06月27日 19:29:50 +00:00Commented Jun 27, 2021 at 19:29
-
\$\begingroup\$ From ST,com Traditional integrated development environments (IDEs) with C/C++ compilers and debuggers from major 3rd-party suppliers (free versions with up to 64 Kbytes of code are available) as well as the embedded software libraries required to configure and initialize the MCU or MPU and monitor its behavior in run time. \$\endgroup\$Gil– Gil2021年06月27日 19:52:11 +00:00Commented Jun 27, 2021 at 19:52
2 Answers 2
You need a cross-compiler; a compiler that will run on your Linux machine but compile code for the ARM Cortex-M. I don't want to recommend specific products but that's what you should search for.
Then you need a physical interface to your microcontroller board that will let you download the executable code. The default interface for the Cortex-M processors is ARM's SWD (single-wire debug). Again, a web search will reveal several suitable products.
For debugging you can use gdb over the SWD interface.
There are several companies that offer integrated development environments (IDE) that bundle all of this together with a graphical interface.
With a little searching you can find versions of all of these tools that will run under Linux. I've done it myself.
Search on "gnu arm-none-eabi". That's where you'll find toolchains designed for no operating system (the "none" part) and the embedded application binary interface (the "eabi" part).
There's Debian repositories for this. The last time I worked on this, you could just get all the relevant tools and libraries with apt. apt search arm-none-eabi
isn't a bad starting point.
Expect to struggle a bit to get it working. Actually getting to the point where you're piping "hello world" out a serial port or even blinking an LED will be an accomplishment the first time around, because there's a lot to setting the hardware up correctly.
Explore related questions
See similar questions with these tags.