How to change arduino-builder to arduino-cli in arduino IDE 1.8.19

I wrote earlier about the problem on github, but I was redirected to the forum.
How to change arduino-builder to arduino-cli in arduino IDE 1.8.19 · Issue #375 · arduino/arduino-builder · GitHub

I use arduino IDE 1.8.19 for code
When I click the checkmark, the code is compiled.
In the IDE settings, I specified the output of details - verbose.
And when compiling the sketch, I see many many lines that begin with the following lines
C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Admin\AppData\Local\Arduino15\packages -hardware C:\Users\Admin\Documents\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Admin\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Admin\Documents\Arduino\libraries
Link about arduino builder arduino-builder
I realized that the program is deprecated, and it is recommended to use the new version of arduino-cli.
But, after reading the branch about arduino-cli, I got completely confused a very complex tool for a not very advanced programmer.
The main problem, I use the arduino IDE and the core from STMicroelectronics to work with stm32 Arduino_Core_STM32
Every programmer knows how many times to compile code during debugging and programming.
This is tens of hundreds of times a day.
The problem with the kernel from ST is that it takes a very, very long time to compile for the Windows platform.
About 20-30 sec on 1 non-biggest scketch.
One solution is to switch to Linux, but this option has not yet been considered by me.
Therefore I look towards the command line.
My actions are the following:

  1. The Arduino builder is outdated, so I don’t consider it at all, but it is still used when compiling code from the Arduino IDE
  2. Use an arduino-cli, but a very complex entry threshold and there are no examples as such. Documentation for advanced programmers. There is little information on the Internet, on YouTube.
  3. Use the command line from the CT kernel itself Arduino_Core_STM32, but it involves the use of Smake and this is also very, very difficult for me.
    Tell me to set up the compiler in step 2, i.e. using arduino cli.
    Examples and some hints.
    I use power shell as command line.
    I registered the global path to the arduino-folder where the arduino-cli is located and I can run the arduino-cli from anywhere.

    But difficulties with setting up the compiler.
    I will be glad for any help.
    When I compile the sketch and load it into the black pill STM32F401CCU6 via SWD from the arduino IDE, all is well.
    But I want to use arduino cli to compile and upload without resorting to using arduino IDE.
    I'm already using a third party code editor, Notepad++, check the Arduino IDE settings (use external code editor) and write the code.
    Some commands put me in a stupor through arduino-cli.
    For example:
PS C:\Users\Admin> arduino-cli board attach
Error opening sketch: main file missing from sketch: C:\Users\Admin\Admin.ino

Firstly, the command to display the list of boards does not see anything.
This is probably due to the connection of the black pill through the SWD, but when you work from the Arduino IDE, everything works without problems.
Скриншот 13-06-2023 12.35.33

When you try to update the stm32 kernel, it doesn't find anything at all.

PS C:\Users\Admin> arduino-cli core update-index
Downloading index: package_index.tar.bz2 downloaded
Downloading index: package_esp8266com_index.json downloaded
Downloading index: package_esp32_index.json downloaded
Downloading index: package_STM32duino_index.json downloaded
Downloading index: package_stmicroelectronics_index.json downloaded

What could be the problem?
I don't understand why the arduino IDE, when compiling from the editor, uses the default arduino builder, and not the arduino cli or at least the operocd?
How can I make it clear to the Arduino-cli command line that I have a SVD programmer slink version 2 connected?
It is defined in the system as a USB device, not a COM port.
The most incomprehensible thing is that the arduino cli is kind of the same as the arduino IDE, only in the form of a command line.
But for some reason this command line does not work as an arduino IDE, it does not even see the boards and ports.

PS C:\Users\Admin> arduino-cli board list
Порт Protocol Тип               Board Name FQBN Core
COM1 serial   Serial Port       Unknown
COM4 serial   Serial Port       Unknown
COM5 serial   Serial Port       Unknown
COM8 serial   Serial Port (USB) Unknown

I do not want to use Arduino IDE 2.0 yet, because I see the use of the new version of the IDE as just an additional load on the PC.
I have notepad++ and I'm pretty good at coding in it.
I just need a command line to compile and download the black pill firmware via ST link version 2 (or as specified in kernel Arduino_Core_STM32 SWD).

Have you seen the getting started guide? If you follow it through from top to bottom, you should have a working sketch.

[edit]

If you are familiar with Makefiles, you may be interested in the one I use:

FQBN := arduino:avr:pro
PORT := /dev/ttyUSB0
BUILD := build
FLAGS := -pedantic

ARDUINO := arduino-cli
PICOCOM := picocom

SKETCH := $(wildcard *.ino)
LIBS := $(wildcard *.cpp *.h *.tcc)
HEX := $(BUILD)/$(addsuffix .hex, $(SKETCH))


all: $(HEX)

$(HEX): $(SKETCH) $(LIBS)
        $(ARDUINO) compile --fqbn $(FQBN) --warnings all --output-dir $(BUILD) \
    --build-property compiler.cpp.extra_flags="$(FLAGS)"

upload: $(HEX)
        $(ARDUINO) upload --fqbn $(FQBN) --port $(PORT) --input-file $(HEX)

comm:
        $(PICOCOM) -q $(PORT)
1 Like

I am connecting the Black Pill board via ST-Link v.2.
Examples and your link have been studied by me up and down.
And there the connection is only through the USB port.
I followed the steps from the manual, and on some steps I got either an error or empty answers in the arduino-cli command line.

The following works for me.

Install the core (see its getting started guide).

arduino-cli core install STMicroelectronics:stm32 --additional-urls https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json

Create a new sketch.

arduino-cli sketch new test
cd test

Compile the sketch (I got the FBQN from this table).

arduino-cli compile --fqbn STMicroelectronics:stm32:GenF1 --warnings all --output-dir build --build-property compiler.cpp.extra_flags="-pedantic"

To upload the sketch, you could try the following (the --port value should probably be changed).

arduino-cli upload --fqbn STMicroelectronics:stm32:GenF1 --port /dev/ttyUSB0 --input-file build/test.ino.hex

This last step is not tested.

1 Like

I don’t understand why in the examples you need to create a sketch through the command line at all?
A useless step in the manual, where the wiki is not very informative anyway.
After all, the sketch has already been created through the arduino IDE or through a third-party code editor.
And regarding my problem, here is what the commands issue, all the stm32f4 boards are installed, additional URLs are added, but there is no compilation ...

PS C:\Users\Admin> arduino-cli board list
Порт Protocol Тип               Board Name FQBN Core
COM1 serial   Serial Port       Unknown
COM4 serial   Serial Port       Unknown
COM5 serial   Serial Port       Unknown
COM8 serial   Serial Port (USB) Unknown

PS C:\Users\Admin> arduino-cli core update-index
Downloading index: package_index.tar.bz2 downloaded
Downloading index: package_esp8266com_index.json downloaded
Downloading index: package_esp32_index.json downloaded
Downloading index: package_STM32duino_index.json downloaded
Downloading index: package_stmicroelectronics_index.json downloaded

PS C:\Users\Admin> arduino-cli core install STMicroelectronics:stm32 --additional-urls https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
Platform STMicroelectronics:stm32@2.5.0 already installed

PS C:\Users\Admin> arduino-cli compile --fqbn STMicroelectronics:STM32F4:blackpill_f401 C:\Users\Admin\Documents\Arduino\encoder_simple\encoder_simple.ino
Error during build: Platform 'STM32F4:stm32f4' not found: platform not installed
Platform STM32F4:stm32f4 is not found in any known index
Maybe you need to add a 3rd party URL?

Just to make sure the example is valid, if you already have a sketch this step is not needed.

Note that I used a different FBQN (which may be wrong, I got it from the aforementioned table).

[edit]

Using STMicroelectronics:stm32:GenF4 as FBQN also works for me, the term "Black Pill" is also mentioned in this table.

1 Like

20 to 30s, eh? "Kids today!"

Thanks a lot for the tips.
Some of them helped me to overcome the barrier and then everything went like clockwork.
As always in the work of a developer-programmer, there are often obstacles that delay on the way and prevent you from moving on.
And until they are disassembled and passed, well, absolutely nothing works.
Right now I'm compiling the code I'm working with right in Notepad++.
I compile the code with this line
arduino-cli compile --fqbn STMicroelectronics:stm32:GenF4:pnum=BLACKPILL_F401CC C:\Users\Admin\Documents\Arduino\Blink\Blink.ino
If the board flag was without adding a specific black pill model, the code would also compile, but not work when loaded into the board.
I compared the sizes of the compiled code with the arduino IDE and the one I compiled through the arduino-cli and in the latter case the code was 2 kB larger.
I had to study how the Arduino IDE compiles, it uses the arduino builder, an outdated version of the arduino cli.
Just like that, from the detailed log during compilation, I took the line
--fqbn STMicroelectronics:stm32:GenF4:pnum=BLACKPILL_F401CC
And then the code after compilation became smaller in size and was workable on the board.

Moreover, I shortened the flags as indicated here
  -b, --fqbn string                  Fully Qualified Board Name, e.g.: arduino:avr:uno
  -h, --help                         help for upload
      --input-dir string             Directory containing binaries to upload.
  -i, --input-file string            Binary file to upload.
  -p, --port string                  Upload port address, e.g.: COM3 or /dev/ttyACM2
  -m, --profile string               Sketch profile to use
  -P, --programmer string            Programmer to use, e.g: atmel_ice
  -l, --protocol string              Upload port protocol, e.g: serial
  -t, --verify                       Verify uploaded binary after the upload.

And commands for arduino-cli below
arduino-cli compile -b STMicroelectronics:stm32:GenF4:pnum=BLACKPILL_F401CC C:\Users\Admin\Documents\Arduino\Blink\Blink.ino
Next, I upload the compiled code to the black pill board, from the TEMP folder.
Interestingly, I tried to find out what port my ST-Link v.2 occupies, but in the end, arduino-cli somehow determines my programmer on its own and launches the utility, that I don’t even need to specify the port in the line
arduino-cli upload -b STMicroelectronics:stm32:GenF4:pnum=BLACKPILL_F401CC -i C:\Users\Admin\AppData\Local\Temp\arduino\sketches\FF57E48FB1229095E7875998A8DC15BD\Blink.ino.bin
Further, using the NppExec plugin, I added commands for compiling and uploading the firmware to the board in two lines.
And now by the key combination ctrl + F6 and I flash the board in 18 seconds.
As for the increase in the speed of compiling and downloading firmware to the board, honestly, I didn’t win much, except for a couple of seconds.
But taking into account the fact that now the work is going on in a normal IDE, with code highlighting, with no need to switch from arduino IDE to third-party editor and back, I have a significant increase in work productivity.
P.S. If the project is being compiled for the first time, then the time from the start of compilation to loading into the board is about 1 minute, but if there is a re-compilation, the whole process takes 18 seconds.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.