Linux Arduino: Digging Into Project Guts

Introduction



The previous article described the process of turning Qt Creator into a full-fledged IDE for projects on the Arduino platform. The steps were described in detail, but without a description of the meaning of what is happening, so the effect of such an article is small. In each particular case, various nuances can arise and arise and understand them without an understanding of how the project works.



Therefore, in this article we will understand the structure and settings of the project.



1. Arduino Core and main () function



As you know, the execution of any program in C / C ++ begins with the function main (), including the microcontroller firmware. In one form or another, this function is present in any project. To create a project in the Arduino IDE, we are immediately offered a sketch file (also with a stupid * .ino extension), hiding the location of the entry point from the developer.



In Archa, the Arduino Core sources are located along the path / usr / share / arduino / hardware / archlinux-arduino / avr / cores / arduino and contain the following



Arduino Core file list
$ ls -l  320 -rw-r--r-- 1 root root 1222  3 2017 abi.cpp -rw-r--r-- 1 root root 7483  3 2017 Arduino.h -rw-r--r-- 1 root root 11214  3 2017 binary.h -rw-r--r-- 1 root root 8078  9 2017 CDC.cpp -rw-r--r-- 1 root root 1529  3 2017 Client.h -rw-r--r-- 1 root root 2605  3 2017 HardwareSerial0.cpp -rw-r--r-- 1 root root 2315  3 2017 HardwareSerial1.cpp -rw-r--r-- 1 root root 1975  3 2017 HardwareSerial2.cpp -rw-r--r-- 1 root root 1975  3 2017 HardwareSerial3.cpp -rw-r--r-- 1 root root 7743  3 2017 HardwareSerial.cpp -rw-r--r-- 1 root root 5262  3 16:57 HardwareSerial.h -rw-r--r-- 1 root root 4469  3 2017 HardwareSerial_private.h -rw-r--r-- 1 root root 1142  3 2017 hooks.c -rw-r--r-- 1 root root 2851  3 2017 IPAddress.cpp -rw-r--r-- 1 root root 2861  3 2017 IPAddress.h -rw-r--r-- 1 root root 1372  3 2017 main.cpp -rw-r--r-- 1 root root 1027  3 2017 new.cpp -rw-r--r-- 1 root root 979  3 2017 new.h -rw-r--r-- 1 root root 2725  3 2017 PluggableUSB.cpp -rw-r--r-- 1 root root 2063  3 2017 PluggableUSB.h -rw-r--r-- 1 root root 1335  3 2017 Printable.h -rw-r--r-- 1 root root 5442  3 2017 Print.cpp -rw-r--r-- 1 root root 2963  3 16:57 Print.h -rw-r--r-- 1 root root 963  3 2017 Server.h -rw-r--r-- 1 root root 8804  3 17:23 Stream.cpp -rw-r--r-- 1 root root 6060  3 17:23 Stream.h -rw-r--r-- 1 root root 15022  3 2017 Tone.cpp -rw-r--r-- 1 root root 4363  18 16:52 Udp.h -rw-r--r-- 1 root root 6261  3 16:57 USBAPI.h -rw-r--r-- 1 root root 20086  18 16:52 USBCore.cpp -rw-r--r-- 1 root root 8435  3 2017 USBCore.h -rw-r--r-- 1 root root 1519  3 2017 USBDesc.h -rw-r--r-- 1 root root 4576  3 2017 WCharacter.h -rw-r--r-- 1 root root 9409  3 2017 WInterrupts.c -rw-r--r-- 1 root root 7850  3 2017 wiring_analog.c -rw-r--r-- 1 root root 12024  3 2017 wiring.c -rw-r--r-- 1 root root 4978  3 2017 wiring_digital.c -rw-r--r-- 1 root root 2255  3 2017 wiring_private.h -rw-r--r-- 1 root root 3435  3 2017 wiring_pulse.c -rw-r--r-- 1 root root 6022  3 2017 wiring_pulse.S -rw-r--r-- 1 root root 1550  3 2017 wiring_shift.c -rw-r--r-- 1 root root 1641  3 2017 WMath.cpp -rw-r--r-- 1 root root 16989  3 2017 WString.cpp -rw-r--r-- 1 root root 9910  3 2017 WString.h
      
      







The main () function is located in the main.cpp file and looks like this



 #include <Arduino.h> // Declared weak in Arduino.h to allow user redefinitions. int atexit(void (* /*func*/ )()) { return 0; } // Weak empty variant initialization function. // May be redefined by variant files. void initVariant() __attribute__((weak)); void initVariant() { } void setupUSB() __attribute__((weak)); void setupUSB() { } int main(void) { init(); initVariant(); #if defined(USBCON) USBDevice.attach(); #endif setup(); for (;;) { loop(); if (serialEventRun) serialEventRun(); } return 0; }
      
      





You can see that there is nothing supernatural in the sketch: the setup () and loop () functions are called directly from main (). The led-blink.cpp file that we created earlier contains the definitions of these functions. If we remove this file from the project



 #  #INCLUDEPATH += ./include #HEADERS += $$files(./include/*.h) #   #SOURCES += $$files(./src/*.cpp)
      
      





get a logical linker error







Thus, all the modules that we add to the project will be linked to the Arduino core, which implements the basic functionality. Here is a brief description of the Arduino Core headers:





Thus, even in the simplest LED blinking program, a mass of unnecessary code is included. Such is the fee for ease of development and low entry threshold. However, speaking of this, I am cunning: the example shown in the last article does not correspond to what is obtained after building in the Arduino IDE.



2. Cut the fat from the firmware



In the Arduino IDE, the Core is assembled into a separate static library core.a, which is then linked with the object files of the sketch into a ready-made binary. Do the same in Qt Creator.



Create a core project with the following structure







The qmake script for this project is presented below:



core.pro
 #      DESTDIR = ../../lib TARGET = core #    INCLUDEPATH += $$ARDUINO_DIR/cores/arduino INCLUDEPATH += $$ARDUINO_DIR/variants/standard INCLUDEPATH += $$ARDUINO_DIR/libraries INCLUDEPATH += /usr/avr/include #   C QMAKE_CC = /usr/bin/avr-gcc QMAKE_CFLAGS += -c -g -Os -w -ffunction-sections -fdata-sections QMAKE_CFLAGS += -MMD -mmcu=$$ARDUINO_MCU -DF_CPU=$$ARDUINO_FCPU QMAKE_CFLAGS += -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR #   C++ QMAKE_CXX = /usr/bin/avr-g++ QMAKE_CXXFLAGS += -c -g -Os -w -ffunction-sections -fdata-sections QMAKE_CXXFLAGS += -fno-exceptions -fno-threadsafe-statics QMAKE_CXXFLAGS += -MMD -mmcu=$$ARDUINO_MCU -DF_CPU=$$ARDUINO_FCPU QMAKE_CXXFLAGS += -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR #  Arduino Core HEADERS += $$files($$ARDUINO_DIR/cores/arduino/*.h) HEADERS += $$files($$ARDUINO_DIR/variants/standard/*.h) #  Arduino Core SOURCES += $$files($$ARDUINO_DIR/cores/arduino/*.c) SOURCES += $$files($$ARDUINO_DIR/cores/arduino/*.cpp)
      
      





The project contains only code Arduino Core. Its assembly gives the output library libcore.a



Now side by side we create a firmware project containing the sketch code







blink.pro
 #     #    Arduino Core ARDUINO_DIR=/usr/share/arduino/hardware/archlinux-arduino/avr/ #    (Arduino Uno, Nano, Mini) ARDUINO_MCU=atmega328p #    ARDUINO_FCPU = 16000000L #  ,   Qt   ! QT -= gui core CONFIG -= qt #   - ,      ELF TEMPLATE = app #      DESTDIR = ../../bin TARGET = blink #    INCLUDEPATH += $$ARDUINO_DIR/cores/arduino INCLUDEPATH += $$ARDUINO_DIR/variants/standard INCLUDEPATH += $$ARDUINO_DIR/libraries INCLUDEPATH += /usr/avr/include #   C QMAKE_CC = /usr/bin/avr-gcc QMAKE_CFLAGS += -c -g -Os -w -ffunction-sections -fdata-sections QMAKE_CFLAGS += -MMD -mmcu=$$ARDUINO_MCU -DF_CPU=$$ARDUINO_FCPU QMAKE_CFLAGS += -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR #   C++ QMAKE_CXX = /usr/bin/avr-g++ QMAKE_CXXFLAGS += -c -g -Os -w -ffunction-sections -fdata-sections QMAKE_CXXFLAGS += -fno-exceptions -fno-threadsafe-statics QMAKE_CXXFLAGS += -MMD -mmcu=$$ARDUINO_MCU -DF_CPU=$$ARDUINO_FCPU QMAKE_CXXFLAGS += -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR #   QMAKE_LINK = /usr/bin/avr-gcc QMAKE_LFLAGS = -w -Os -Wl,--gc-sections -mmcu=$$ARDUINO_MCU QMAKE_LIBS = -lm #  QMAKE_POST_LINK += /usr/bin/avr-objcopy -O ihex -j .text -j .data -S ${TARGET} ${TARGET}.hex LIBS += -L../../lib -lcore #  INCLUDEPATH += ./include HEADERS += $$files(./include/*.h) #   SOURCES += $$files(./src/*.cpp)
      
      







blink.h
 #ifndef LED_BLINK_H #define LED_BLINK_H #include <Arduino.h> #endif // LED_BLINK_H
      
      







blink.cpp
 #include "blink.h" #define LED_STAND_PIN 13 unsigned long time = 0; unsigned long DELAY = 1000000; bool on = false; //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ void setup() { pinMode(LED_STAND_PIN, OUTPUT); } //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ void loop() { if ( micros() >= time + DELAY ) { time = micros(); on = !on; } uint8_t state = on ? HIGH : LOW; digitalWrite(LED_STAND_PIN, state); }
      
      







We will build both projects together using the โ€œsubdirectoryโ€ project type available in qmake



led-blink2.pro
 TEMPLATE = subdirs SUBDIRS += ./core SUBDIRS += ./blink
      
      







We assemble the project, launch it on the board and look at the firmware log



Log blink.hex firmware
 avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.00s avrdude: Device signature = 0x1e950f (probably m328p) avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed To disable this feature, specify the -D option. avrdude: erasing chip avrdude: reading input file "/mnt/data/Arduino/led-blink2/bin/blink.hex" avrdude: writing flash (1040 bytes): Writing | ################################################## | 100% 0.18s avrdude: 1040 bytes of flash written avrdude: verifying flash memory against /mnt/data/Arduino/led-blink2/bin/blink.hex: avrdude: load data flash data from input file /mnt/data/Arduino/led-blink2/bin/blink.hex: avrdude: input file /mnt/data/Arduino/led-blink2/bin/blink.hex contains 1040 bytes avrdude: reading on-chip flash data: Reading | ################################################## | 100% 0.15s avrdude: verifying ... avrdude: 1040 bytes of flash verified avrdude: safemode: Fuses OK (E:00, H:00, L:00) avrdude done. Thank you.
      
      







Here we pay attention to the amount of occupied memory.



 avrdude: verifying ... avrdude: 1040 bytes of flash verified
      
      





Yeah, the firmware is already 1040 bytes against 2838 in the draft from the previous article. But still, a similar sketch in the Arduino IDE takes 882 bytes. Having carefully studied the arduino environment build log, we add compiler C keys to blink and core projects



 QMAKE_CFLAGS += -flto -fno-fat-lto-objects
      
      





and C ++ compiler keys



 QMAKE_CXXFLAGS += -fpermissive -flto -fno-devirtualize -fno-use-cxa-atexit
      
      





Reassemble, sew, run and ...



 avrdude: verifying ... avrdude: 882 bytes of flash verified
      
      





Ok, the desired 882 bytes are reached. What makes it go like this?



First, let's take a look at the ELF files that are obtained when building the current and previous projects, namely, let's pay attention to the symbolic information that will give an idea of โ€‹โ€‹what the functions and classes of the Arduino Core end up in the binary. Give the command



 $ avr-objdump -t led-blink
      
      





Led-blink symbol table
 led-blink:   elf32-avr SYMBOL TABLE: 00800100 ld .data 00000000 .data 00000000 ld .text 00000000 .text 00800122 ld .bss 00000000 .bss 00000000 ld .stab 00000000 .stab 00000000 ld .stabstr 00000000 .stabstr 00000000 ld .comment 00000000 .comment 00000000 ld .note.gnu.avr.deviceinfo 00000000 .note.gnu.avr.deviceinfo 00000000 ld .debug_info 00000000 .debug_info 00000000 ld .debug_abbrev 00000000 .debug_abbrev 00000000 ld .debug_line 00000000 .debug_line 00000000 ld .debug_str 00000000 .debug_str 00000000 l df *ABS* 00000000 WInterrupts.c 0000003e l *ABS* 00000000 __SP_H__ 0000003d l *ABS* 00000000 __SP_L__ 0000003f l *ABS* 00000000 __SREG__ 00000000 l *ABS* 00000000 __tmp_reg__ 00000001 l *ABS* 00000000 __zero_reg__ 00000112 l F .text 00000002 nothing 00800100 l O .data 00000004 intFunc 00000000 l df *ABS* 00000000 HardwareSerial.cpp 0000003e l *ABS* 00000000 __SP_H__ 0000003d l *ABS* 00000000 __SP_L__ 0000003f l *ABS* 00000000 __SREG__ 00000000 l *ABS* 00000000 __tmp_reg__ 00000001 l *ABS* 00000000 __zero_reg__ 00000000 l df *ABS* 00000000 IPAddress.cpp 0000003e l *ABS* 00000000 __SP_H__ 0000003d l *ABS* 00000000 __SP_L__ 0000003f l *ABS* 00000000 __SREG__ 00000000 l *ABS* 00000000 __tmp_reg__ 00000001 l *ABS* 00000000 __zero_reg__ 0000078a l F .text 00000016 _GLOBAL__sub_I_IPAddress.cpp 008001c8 l O .bss 00000006 _ZL11INADDR_NONE 00000000 l df *ABS* 00000000 Tone.cpp 0000003e l *ABS* 00000000 __SP_H__ 0000003d l *ABS* 00000000 __SP_L__ 0000003f l *ABS* 00000000 __SREG__ 00000000 l *ABS* 00000000 __tmp_reg__ 00000001 l *ABS* 00000000 __zero_reg__ 0080011c l O .data 00000001 _ZL9tone_pins 000000b8 l O .text 00000001 _ZL21tone_pin_to_timer_PGM 00000000 l df *ABS* 00000000 led-blink.cpp 0000003e l *ABS* 00000000 __SP_H__ 0000003d l *ABS* 00000000 __SP_L__ 0000003f l *ABS* 00000000 __SREG__ 00000000 l *ABS* 00000000 __tmp_reg__ 00000001 l *ABS* 00000000 __zero_reg__ 00000000 l df *ABS* 00000000 wiring_digital.c 0000003e l *ABS* 00000000 __SP_H__ 0000003d l *ABS* 00000000 __SP_L__ 0000003f l *ABS* 00000000 __SREG__ 00000000 l *ABS* 00000000 __tmp_reg__ 00000001 l *ABS* 00000000 __zero_reg__ 00000304 l F .text 00000052 turnOffPWM 00000000 l df *ABS* 00000000 HardwareSerial0.cpp 0000003e l *ABS* 00000000 __SP_H__ 0000003d l *ABS* 00000000 __SP_L__ 0000003f l *ABS* 00000000 __SREG__ 00000000 l *ABS* 00000000 __tmp_reg__ 00000001 l *ABS* 00000000 __zero_reg__ 00000694 l F .text 0000005a _GLOBAL__sub_I_HardwareSerial0.cpp 00000000 l df *ABS* 00000000 _clear_bss.o 000000ea l .text 00000000 .do_clear_bss_start 000000e8 l .text 00000000 .do_clear_bss_loop 00000000 l df *ABS* 00000000 wiring.c 0000003e l *ABS* 00000000 __SP_H__ 0000003d l *ABS* 00000000 __SP_L__ 0000003f l *ABS* 00000000 __SREG__ 00000000 l *ABS* 00000000 __tmp_reg__ 00000001 l *ABS* 00000000 __zero_reg__ 00800122 l O .bss 00000001 timer0_fract 00000000 l df *ABS* 00000000 main.cpp 0000003e l *ABS* 00000000 __SP_H__ 0000003d l *ABS* 00000000 __SP_L__ 0000003f l *ABS* 00000000 __SREG__ 00000000 l *ABS* 00000000 __tmp_reg__ 00000001 l *ABS* 00000000 __zero_reg__ 00000000 l df *ABS* 00000000 Print.cpp 0000003e l *ABS* 00000000 __SP_H__ 0000003d l *ABS* 00000000 __SP_L__ 0000003f l *ABS* 00000000 __SREG__ 00000000 l *ABS* 00000000 __tmp_reg__ 00000001 l *ABS* 00000000 __zero_reg__ 0000081e l F .text 0000001e _ZN5Print5writeEPKc.part.2 00000000 l df *ABS* 00000000 _udivmodsi4.o 00000ac6 l .text 00000000 __udivmodsi4_ep 00000aac l .text 00000000 __udivmodsi4_loop 00000000 l df *ABS* 00000000 _exit.o 00000af2 l .text 00000000 __stop_program 00000000 l df *ABS* 00000000 hooks.c 0000003e l *ABS* 00000000 __SP_H__ 0000003d l *ABS* 00000000 __SP_L__ 0000003f l *ABS* 00000000 __SREG__ 00000000 l *ABS* 00000000 __tmp_reg__ 00000001 l *ABS* 00000000 __zero_reg__ 0000010e w .text 00000000 __vector_22 00800127 g O .bss 00000004 timer0_overflow_count 0000094a g F .text 0000002a _Z6noToneh 00000772 g F .text 00000018 _ZN9IPAddressC1Ehhhh 000000ae g O .text 0000000a port_to_mode_PGM 00000114 g F .text 0000004e __vector_1 0000ffa0 g *ABS* 00000000 __DATA_REGION_LENGTH__ 00800123 g O .bss 00000004 timer0_millis 00000442 g F .text 0000001c _ZN14HardwareSerial4peekEv 0000084a g F .text 00000098 _ZN5Print11printNumberEmh 000007c4 g F .text 0000005a _ZN5Print5writeEPKhj 00000068 g .text 00000000 __trampolines_start 008001cf g O .bss 00000002 timer2_pin_port 00000af4 g .text 00000000 _etext 0000042a g F .text 00000018 _ZN14HardwareSerial9availableEv 0000010e w .text 00000000 __vector_24 00000a34 g F .text 0000006c loop 000004c0 g F .text 00000042 _ZN14HardwareSerial17_tx_udr_empty_irqEv 0000010e w .text 00000000 __vector_12 000007a0 w F .text 00000002 initVariant 000006ee g F .text 00000084 _ZNK9IPAddress7printToER5Print 00000542 g F .text 0000008e _ZN14HardwareSerial5writeEh 0000010e g .text 00000000 __bad_interrupt 00000b16 g *ABS* 00000000 __data_load_end 0000010e w .text 00000000 __vector_6 008001d5 g O .bss 00000001 on 00000068 g .text 00000000 __trampolines_end 0000010e w .text 00000000 __vector_3 000003ce g F .text 0000005c digitalWrite 00000356 g F .text 00000078 pinMode 00000090 g O .text 00000014 digital_pin_to_port_PGM 0000010e w .text 00000000 __vector_23 00000af4 g *ABS* 00000000 __data_load_start 000000be g .text 00000000 __dtors_end 008001da g .bss 00000000 __bss_end 00000400 g *ABS* 00000000 __LOCK_REGION_LENGTH__ 0000010e w .text 00000000 __vector_25 0000090a g F .text 00000040 _Z12disableTimerh 0000010e w .text 00000000 __vector_11 00000486 g F .text 0000001e _ZN14HardwareSerial17availableForWriteEv 000000be w .text 00000000 __init 000008fc g F .text 0000000e _ZN5Print5printEhi 00000772 g F .text 00000018 _ZN9IPAddressC2Ehhhh 000004a4 w F .text 0000001c _Z14serialEventRunv 00000502 g F .text 00000040 _ZN14HardwareSerial5flushEv 0000010e w .text 00000000 __vector_13 0000010e w .text 00000000 __vector_17 00000634 g F .text 0000004c __vector_19 00000974 g F .text 000000b8 __vector_7 0080012b g O .bss 0000009d Serial 00800104 w O .data 00000012 _ZTV14HardwareSerial 000000e0 g .text 00000010 .hidden __do_clear_bss 0000083c g F .text 0000000e _ZN5Print5printEc 00000680 g F .text 00000014 _Z17Serial0_availablev 00810000 g .stab 00000000 __eeprom_end 0000007c g O .text 00000014 digital_pin_to_bit_mask_PGM 00800116 w O .data 00000006 _ZTV9IPAddress 00000000 g .text 00000000 __vectors 00800122 g .data 00000000 __data_end 00000000 w .text 00000000 __vector_default 0000010e w .text 00000000 __vector_5 00000400 g *ABS* 00000000 __SIGNATURE_REGION_LENGTH__ 00000ae4 g .text 0000000c .hidden __tablejump2__ 0000028e g F .text 00000076 init 000000ba g .text 00000000 __ctors_start 000000ca g .text 00000016 .hidden __do_copy_data 0080011d g O .data 00000004 DELAY 00800122 g .bss 00000000 __bss_start 000007a2 g F .text 00000022 main 0000010e w .text 00000000 __vector_4 008001d6 g O .bss 00000004 time 00000244 g F .text 0000004a micros 008001ce g O .bss 00000001 timer2_pin_mask 00000000 w *ABS* 00000000 __heap_end 0000010e w .text 00000000 __vector_9 00000162 g F .text 0000004e __vector_2 00000400 g *ABS* 00000000 __USER_SIGNATURE_REGION_LENGTH__ 0000010e w .text 00000000 __vector_21 0000010e w .text 00000000 __vector_15 000000a4 g O .text 0000000a port_to_output_PGM 000008e2 g F .text 0000001a _ZN5Print5printEmi 00000a2c g F .text 00000008 setup 008001da g .stab 00000000 __heap_start 000000be g .text 00000000 __dtors_start 000000be g .text 00000000 __ctors_end 000008ff w *ABS* 00000000 __stack 00800122 g .data 00000000 _edata 008001da g .stab 00000000 _end 0000010e w .text 00000000 __vector_8 00000068 g O .text 00000014 digital_pin_to_timer_PGM 00000af0 w .text 00000000 .hidden exit 0000045e g F .text 00000028 _ZN14HardwareSerial4readEv 00000aa0 g .text 00000044 .hidden __udivmodsi4 00010000 g *ABS* 00000000 __EEPROM_REGION_LENGTH__ 00000af0 g .text 00000000 .hidden _exit 0000010e w .text 00000000 __vector_14 0000010e w .text 00000000 __vector_10 008001d1 g O .bss 00000004 timer2_toggle_count 000001b0 g F .text 00000094 __vector_16 00800100 g .data 00000000 __data_start 000005d0 g F .text 00000064 __vector_18 00000400 g *ABS* 00000000 __FUSE_REGION_LENGTH__ 00020000 g *ABS* 00000000 __TEXT_REGION_LENGTH__ 0000010e w .text 00000000 __vector_20 000000f0 g .text 00000016 .hidden __do_global_ctors
      
      







Now compare with the second project



Symbol table blink
 blink:   elf32-avr SYMBOL TABLE: 00800100 ld .data 00000000 .data 00000000 ld .text 00000000 .text 00800100 ld .bss 00000000 .bss 00000000 ld .comment 00000000 .comment 00000000 ld .note.gnu.avr.deviceinfo 00000000 .note.gnu.avr.deviceinfo 00000000 ld .debug_info 00000000 .debug_info 00000000 ld .debug_abbrev 00000000 .debug_abbrev 00000000 ld .debug_line 00000000 .debug_line 00000000 ld .debug_str 00000000 .debug_str 00000000 l df *ABS* 00000000 0000003e l *ABS* 00000000 __SP_H__ 0000003d l *ABS* 00000000 __SP_L__ 0000003f l *ABS* 00000000 __SREG__ 00000000 l *ABS* 00000000 __tmp_reg__ 00000001 l *ABS* 00000000 __zero_reg__ 000000e0 l F .text 00000038 pinMode.constprop.1 000000a4 l O .text 00000014 digital_pin_to_bit_mask_PGM 00000090 l O .text 00000014 digital_pin_to_port_PGM 00000086 l O .text 0000000a port_to_mode_PGM 0000007c l O .text 0000000a port_to_output_PGM 00000118 l F .text 00000090 digitalWrite.constprop.0 00000068 l O .text 00000014 digital_pin_to_timer_PGM 000001a8 l F .text 00000076 init 0000021e l F .text 0000004a micros 00800105 l O .bss 00000004 timer0_overflow_count 0080010a l O .bss 00000004 time 00800109 l O .bss 00000001 on 00800101 l O .bss 00000004 timer0_millis 00800100 l O .bss 00000001 timer0_fract 00000000 l df *ABS* 00000000 _clear_bss.o 000000ce l .text 00000000 .do_clear_bss_start 000000cc l .text 00000000 .do_clear_bss_loop 00000000 l df *ABS* 00000000 _exit.o 00000370 l .text 00000000 __stop_program 000000dc w .text 00000000 __vector_22 000000dc w .text 00000000 __vector_1 0000ffa0 g *ABS* 00000000 __DATA_REGION_LENGTH__ 00000068 g .text 00000000 __trampolines_start 00000372 g .text 00000000 _etext 000000dc w .text 00000000 __vector_24 000000dc w .text 00000000 __vector_12 000000dc g .text 00000000 __bad_interrupt 00000372 g *ABS* 00000000 __data_load_end 000000dc w .text 00000000 __vector_6 00000068 g .text 00000000 __trampolines_end 000000dc w .text 00000000 __vector_3 000000dc w .text 00000000 __vector_23 00000372 g *ABS* 00000000 __data_load_start 000000b8 g .text 00000000 __dtors_end 0080010e g .bss 00000000 __bss_end 00000400 g *ABS* 00000000 __LOCK_REGION_LENGTH__ 000000dc w .text 00000000 __vector_25 000000dc w .text 00000000 __vector_11 000000b8 w .text 00000000 __init 000000dc w .text 00000000 __vector_13 000000dc w .text 00000000 __vector_17 000000dc w .text 00000000 __vector_19 000000dc w .text 00000000 __vector_7 000000c4 g .text 00000010 .hidden __do_clear_bss 00810000 g .comment 00000000 __eeprom_end 00000000 g .text 00000000 __vectors 00000000 w .text 00000000 __vector_default 000000dc w .text 00000000 __vector_5 00000400 g *ABS* 00000000 __SIGNATURE_REGION_LENGTH__ 000000b8 g .text 00000000 __ctors_start 00800100 g .bss 00000000 __bss_start 000002fc g F .text 00000072 main 000000dc w .text 00000000 __vector_4 00000000 w *ABS* 00000000 __heap_end 000000dc w .text 00000000 __vector_9 000000dc w .text 00000000 __vector_2 00000400 g *ABS* 00000000 __USER_SIGNATURE_REGION_LENGTH__ 000000dc w .text 00000000 __vector_21 000000dc w .text 00000000 __vector_15 000000b8 g .text 00000000 __dtors_start 000000b8 g .text 00000000 __ctors_end 000008ff w *ABS* 00000000 __stack 00800100 g .data 00000000 _edata 0080010e g .comment 00000000 _end 000000dc w .text 00000000 __vector_8 0000036e w .text 00000000 .hidden exit 00010000 g *ABS* 00000000 __EEPROM_REGION_LENGTH__ 0000036e g .text 00000000 .hidden _exit 000000dc w .text 00000000 __vector_14 000000dc w .text 00000000 __vector_10 00000268 g F .text 00000094 __vector_16 000000dc w .text 00000000 __vector_18 00000400 g *ABS* 00000000 __FUSE_REGION_LENGTH__ 00020000 g *ABS* 00000000 __TEXT_REGION_LENGTH__ 000000dc w .text 00000000 __vector_20
      
      







The difference is obvious. It can be seen that when compiling core into a separate library, the compiler includes in the firmware only the core parts actually used in it. In particular, we do not use the UART in either case, however, in the first firmware there are classes for working with it. Reducing the amount of firmware with the compiler keys should be discussed separately, like the keys themselves



3. Compiler and linker keys



Compiler options:





Linker options:





As you can see, all the settings are reduced to disabling gadgets used in application programming and enhancing the security code, as well as aimed at maximizing the volume of the final firmware.



findings



I hope that this text puts all the dots on "i". In the Arduino platform, there is nothing supernatural. Its architecture is aimed at hiding from a novice developer of all mechanisms, the use of which is quite usual for those who use pure C or assembler for AVR software development.



In addition, arduinschiki using Linux can work with convenience: this and previous articles, to the best of eloquence and competence of their author, cover the issue of using when developing a normal user-friendly IDE.



Hope this information proved helpful. In the next article, we will probably talk about debugging AVR projects in Qt Creator.



PS: The source code of the sample project from the article can be found here.



All Articles