0
\$\begingroup\$

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?

JRE
74.9k10 gold badges115 silver badges197 bronze badges
asked Jun 27, 2021 at 19:04
\$\endgroup\$
10
  • 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\$ Commented 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\$ Commented 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\$ Commented 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\$ Commented 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\$ Commented Jun 27, 2021 at 19:52

2 Answers 2

3
\$\begingroup\$

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.

answered Jun 27, 2021 at 19:29
\$\endgroup\$
1
\$\begingroup\$

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.

answered Jun 27, 2021 at 21:18
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.