command-line stm32duino

krbonne
Sun Apr 10, 2016 10:11 pm
Hi all,

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.


RogerClark
Sun Apr 10, 2016 11:57 pm
You could write your own make file

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 :-( )


mrburnette
Mon Apr 11, 2016 12:06 am
The general process: http://playground.arduino.cc/Learning/CommandLine

You will have to adjust for how the IDE handles the STM32.

Ray


tiger762
Tue Apr 26, 2016 10:54 pm
You and me both :mrgreen:

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.


stevech
Wed Apr 27, 2016 4:32 am
I used makefiles way back.
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!


WereCatf
Wed Apr 27, 2016 8:28 am
stevech wrote:Now I used nice IDEs. Arduino’s IDE is ridiculous. It’s an attempt to dumb down for the artsy-fartsy university crowd.

tiger762
Wed Apr 27, 2016 11:24 am
OK, had some success last night. Stayed up late and went mental on this :mrgreen:

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);
}


mrburnette
Wed Apr 27, 2016 12:15 pm
tiger762 wrote:OK, had some success last night. Stayed up late and went mental on this :mrgreen:
<…>

Slammer
Wed Apr 27, 2016 1:26 pm
You can also use the makefile from here:
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)


mrburnette
Wed Apr 27, 2016 1:38 pm
Slammer wrote:<…>
It is a bit automated, <…>

Rick Kimball
Wed Apr 27, 2016 1:44 pm
I’ve used this in the past:

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]

Slammer
Wed Apr 27, 2016 2:37 pm
Yes, you are correct.
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).


Rick Kimball
Wed Apr 27, 2016 2:49 pm
Slammer wrote:… 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. …

Slammer
Wed Apr 27, 2016 3:24 pm
For me, the arduino is not the ide, is not the building system, is not the hardware itself, is not the bootloader …. arduino is the community and the libraries. OK, ide is a fast way to do things, to test a small piece of code but for real programming I prefer the bare “metal approach” taking as much as I can from the platform.

martinayotte
Wed Apr 27, 2016 3:31 pm
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 … :ugeek:

tiger762
Wed Apr 27, 2016 5:08 pm
Oh, I hear ya. I started off with the Arduino IDE when I was messing about with the ATMEGA328’s. Since then, my development space has gotten fragmented with different versions of the same particular library and/or others’ versions of a library. The IDE just gets itself plum confused. It’s not so much that I’m nostalgic for the mid-90’s (well, I am but for other reasons) rather I need to be able to pull away the facade and understand what the heck is going on.

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


tiger762
Wed Apr 27, 2016 5:33 pm
yes, exactly :D All I was shooting for was to be able to control the compilation process in a way I am more familiar with.

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 … :ugeek:


mrburnette
Wed Apr 27, 2016 9:05 pm
Slammer wrote:For me, the arduino is not the ide, is not the building system, is not the hardware itself, is not the bootloader …. arduino is the community and the libraries. OK, ide is a fast way to do things, to test a small piece of code but for real programming I prefer the bare “metal approach” taking as much as I can from the platform.

RogerClark
Wed Apr 27, 2016 9:25 pm
mrburnette wrote: I believe the essence of Arduino is the core files, bootloader, and the build, compile, link, upload methodology all kicked-off by a single click. If we look back in time to Arduino’s introduction, it was quiet a clever package.

Ray


tiger762
Wed Apr 27, 2016 9:25 pm
mrburnette wrote: If we look back in time to Arduino’s introduction, it was quiet a clever package.
Ray

Slammer
Wed Apr 27, 2016 10:56 pm
My first attempt to ARM world was before about 10 years with a LPC1114 (a small Cortex-M0 with 32KB/8KB) and a LPC2106(ARM7 with 128KB/64KB)
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” :ugeek:
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)

RogerClark
Wed Apr 27, 2016 11:25 pm
Slammer wrote: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)

mrburnette
Thu Apr 28, 2016 1:55 pm
RogerClark wrote:Slammer wrote:As a rule for any real project, I want libraries and sources to be under the project’s directory, this includes libraries and core. <…>

kbahey
Sun May 06, 2018 7:28 pm
I found a solution that works, without any additional installs of anything 3rd party.

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


Leave a Reply

Your email address will not be published. Required fields are marked *