I don’t know if this has been asked before, but is there a easy way to use stm32duino using plain command-line tools on linux?
I may be a little “old fashion” in this but I still prefer tools like gvim and just plain “make”.
Cheerio! Kr. Bonne.
The thing with the Arduino IDE is that it somehow determines which source files it need to compile.
It may just compile all .c, .cpp and .s files in the core plus you own “sketch” file, but I’m really not sure.
I know there is a way to run the Arduino build from the command line (do a google search)
Or just look at what the IDE does, (in verbose mode), and look at what files it compiles.
Note. The IDE copies all sources to a temp folder to compile them, (including the core), so obviously you would not do that.
(but it makes it harder to work out where the original file locations where
)
You will have to adjust for how the IDE handles the STM32.
Ray
I have been a systems software developer for 20 years in the telecom industry and started off with vi, gcc, make, the suite of RCS tools, gdb, tcpdump, etc.
The cleverness of the Arduino IDE (and probably ones that one has to pay money for) I find disconcerting. I am constantly chasing down compilation errors because the IDE found some source or include file that re #defines “A1”. There’s other weird-ass behavior like it remembering a file that I have changed the suffix of, from “.c” to “.donotcompilethis”
I would prefer having a makefile, in which I compile, then link. An include directory defined therein, with library path as well as source file dependencies.
I’m going to pursue the suggestion Roger makes, to run the IDE in verbose mode and see what the H it is doing…
krbonne wrote:
I may be a little “old fashion” in this but I still prefer tools like gvim and just plain “make”.
Cheerio! Kr. Bonne.
Now I used nice IDEs. Arduino’s IDE is ridiculous. It’s an attempt to dumb down for the artsy-fartsy university crowd.
My favorite is IAR, Keil 2nd place, (free if 32KB limited), Atollic w/GCC (free), Visual Studio Community (Free) with Visual Micro, or Visual GDB $99.
My own preference: I’d never go back to bare makefiles. Linker scripts are enough!
The following assumes you have the Arduino IDE version 1.6.5 installed as well as the ARM toolchain.
I started with the basic “blink” type sketch. This is an STM32F103C8T6 “minimum system development” board. The on-board LED is attached to PC13. Note that the LED is illuminated when PC13 is LOW:
#include <Arduino.h>
void setup () {
pinMode (PC13, OUTPUT);
}
void loop () {
digitalWrite (PC13, HIGH);
delay (100);
digitalWrite (PC13, LOW);
delay (100);
}
<…>
https://github.com/sudar/Arduino-Makefile
It is a bit automated, no need to include every source inside makefile. It uses a small python script to find the correct flags from arduino platform data (it works with avr, stm32, esp8266 etc)
It is a bit automated, <…>
https://github.com/sudar/Arduino-Makefile
It seems like, with a little tweaking, it would be usable with an stm32. It already has support for the arm teensy boards. I haven’t looked at it in a while but I thought it snagged most of what it needs from the platform.txt?
-rick
[Edit] .. just realized Slammer had already mentioned this .. sorry [/Edit]I have tested with stm32 and esp8266 and works as advertised. You have to define first, the path of arduino directory (to find the platform and board definition) and the board….
Actually is doing nothing different than arduino environment itself.
A “bare metal” makefile like tiger762’s in often cleaner and simpler but requires to declare every source file and various options manually, specially if you want to include also libcore files. This way the code is totally independent from arduino system.
I am building my programs with this way either by makefile either by codeblocks ide (you simply include in the project every file, define options, and that is, as a bonus except from a very good editor I have code completion and symbol browsing).
If you want to use “bare-metal”, then this means you’re not using the Arduino libraries at all, you would code everything by yourself, even the basic like digitalWrite(). In other words, “bare-metal” and “command-line” have 2 different meaning …
In general, as I pull in more functionality I just “locate” the relevant CPP and H files and add compilation of them to the makefile. Then add object files to the line that creates the ELF to both tell make to “depend” on the existence of these additional objects, as well as tell the linker to resolve whatever it is missing. As an example:
tiger.elf: tiger.o new_file.o
${GCC} -o tiger.elf tiger.o new_file.o
martinayotte wrote:I think you are using different “wording” each other …
If you want to use “bare-metal”, then this means you’re not using the Arduino libraries at all, you would code everything by yourself, even the basic like digitalWrite(). In other words, “bare-metal” and “command-line” have 2 different meaning … ![]()
Ray
Ray
Always before I use a new chip in a professional project I want to play with it in my spare time, this phase it is more a toy for me than a real job.
While I was very experienced with many 8bit micros, I waste many days trying different toolchains, makefiles, linkscripts and a ton of information scattered in various pages across internet and manuals, to achieve too few things…. finally both boards are somewhere in the “Box of Oblivion”
Some years later, about 2010, I bought an Olimexino-STM32 (an improved maple clone, I am still using it) with STM32F103RBT6, after some hours, using libmaple and the leaflabs-arduino environment I had a working system with LCD screen, UARTs, I2C and plenty of time for application programming.
Arduino gives the opportunity to start and evaluate very fast new hardware (look how many breakout boards are out there with source code examples) and software. There are also brilliant libraries for various problems. This is for me the treasure of arduino.
As building procedure, after the first preliminary stage of development with arduino-ide (yes, the “one-click way” is very usefull), I prefer the makefile for building, the stlink/isp for downloading and my favorite editor for editing.
As a rule for any real project, I want libraries and sources to be under the project’s directory, this includes libraries and core. I dont like the idea to have the core or libraries in a common place, as an update can brake things on old projects (api or/and size changes)
Assuming you are using Linux, save this code as arduino-cli somewhere, and make it executable.
#!/bin/bash
# Run this as:
# /path/to/arduino-cli /path/to/sketch.ino
#
ARDUINO="$HOME/arduino/arduino"
BOARD="Arduino_STM32:STM32F1:genericSTM32F103C:device_variant=STM32F103CB,upload_method=DFUUploadMethod,cpu_speed=speed_72mhz,opt=osstd"
BUILD_DIR="/tmp/build"
if [ "$1" = '' ]; then
echo "No sketch directory/file passed. Nothing to do ..."
exit 1
fi
$ARDUINO \
--board "$BOARD" \
--pref "build.path=$BUILD_DIR" \
--upload $1



