wget https://downloads.arduino.cc/arduino-1.8.13-linux64.tar.xz tar xvf arduino-1.8.13-linux64.tar.xz
cd arduino-1.8.13/ mkdir portable
portable
directory modiffies the base behaviour of the ArduinoIDE environment. From now on, all the libraries, compilers, utilities, and conffiguration files are always contained within the portable folder.cd arduino-1.8.13/ ./arduino
Use External Editor
option.Upload
and Serial Console normally../arduino --port /dev/ttyUSB0 --board Arrow:samd:SmartEverything_Fox_native --preserve-temp-files --pref build.path=/home/jsanchez/tmp/arduinobuild --verify || OR || --upload ./MYSKETCH.ino
--port
must be set to your serial device port.--board
must be set to your board model (more on this next).--preserve-temp-files
tells the compiler to build only the updated files instead of all the code.--verify
only compiles the code without uploading it to the board (nice for debugging).--upload
compiles and uploads the code to the board.
Don't forget the ./
in front of your sketch name!!
./arduino --port /dev/ttyUSB0 --board Arrow:samd:SmartEverything_Fox_native --preserve-temp-files --pref build.path=/home/jsanchez/tmp/arduinobuild --verify || OR || --upload ./MYSKETCH.ino
--board
must be set to your board model.hardware/arduino/avr/boards.txt portable/packages/Arrow/hardware/samd/2.1.0/boards.txt portable/packages/arduino/hardware/samd/1.6.18/boards.txt
You can build the board following the dir names and within the boards.txt file itself:
SmartEverything_Fox_native.name=SmartEverything Fox (Native USB Port)
.ino
file, you can place additional source files within your sketch folder.#include
, extern
, etc..c
file without rewriting code.#define DEBUG
. #ifdef DEBUG #define PRINT(...) Serial.print(__VA_ARGS__) #define PRINTLN(...) Serial.println(__VA_ARGS__) #define PRINT_ARRAY(add, len) \ do { \ int i; \ for (i = 0 ; i < (len) ; i++) { \ Serial.print((unsigned int)((uint8_t*)(add))[i], HEX); \ } \ Serial.println(); \ } while(0) #else /* DEBUG */ #define PRINT(...) #define PRINTLN(...) #define PRINT_ARRAY(add, len) #endif /* DEBUG */
PRINT(var)
.
PRINT ARRAY(address, len)
function simply prints in HEX an array passed as an argument.
#define DEBUG
must be writen before the previous code block.
Use example:
uint8_t foo[255]; int bar = 7; ... PRINTLN(bar); PRINT_ARRAY(foo, sizeof(foo)) // These prints only if the DEBUG macro was defined. 7 EE FF 01 25 ...
picocom -g "logs/serial_console_log.txt" # Save the consolo text in a log file -r # NO-reset - avoid reseting the device -b 115200 # Baudrate - MUST MATCH ARDUINOIDE! --omap crcrlf # Mapping of EOL characters /dev/ttyACM0
Ctrl+A
, Ctrl+X
.
Se pueden meter archivos .c
y sus respectivos .h
en el mismo directorio que el sketch:
Fuente: https://forum.arduino.cc/index.php?topic=45003.0
C++, which the Arduino is programmed in, performs name-mangling. C, which your external functions are written in, does not.
Name-mangling means that the actual function that gets called is called using a name that is composed of the class name, function name, and argument type names.
In order to call a C function from a C++ function, the compiler needs to know that it should use C calling syntax, not C++ calling syntax.
In the header file, before any function declarations, add:
#ifdef __cplusplus extern "C" { #endif
After all function declarations, add:
#ifdef __cplusplus } #endif
This will allow the C functions to be called from C++.
IMPORTANT Make sure that the files that you are compiling appear in the ArduinoIDE as tabs. If not, the compiler does not recognize them. Always rename your .c
files to .cpp
.
Reducir el tamaño de los firmwares
Por defecto, arduino le pasa al compilador el Flag -g
, este flat añade a los archivos .o
varios campos de depuración,
que son listados en el .map
como .debug_info
, .debug_range
, etc. Este código incrementa considerablemente el
tamaño del firmware.
Para eliminar el código de depuración de los archivos objeto, editar el archivo platform.txt
y quitar la opción
-g
de todos los flags de compilación.
platform.txt
, son líneas con el nombre compiler
.
E.g.:
arduino-1.8.0/portable/packages/Arrow/hardware/samd/2.1.0/platform.txt
Luego compilar los firmwares respectivos, abrir el directorio de compilación y utilizar el script:
python3 ~/bin/analyze_map.py coap_eap_integration.ino.map
Los archivos que pertenecen a cada una de las partes del código están listados en el readme de cada firmware.
Ejemplo de lo que estamos hablando:
Coap /tmp/arduino_build_288104/sketch/coap_eap_integration.ino.cpp.o 1916 (code : 1724 data : 192) /tmp/arduino_build_288104/sketch/eap-peer.cpp.o 611 (code : 432 data : 179) /tmp/arduino_build_288104/sketch/eax.cpp.o 787 (code : 608 data : 179) /tmp/arduino_build_288104/sketch/eap-psk.cpp.o 1207 (code : 995 data : 212) /tmp/arduino_build_288104/sketch/aes.cpp.o 1719 (code : 1541 data : 178) /tmp/arduino_build_288104/sketch/cantcoap.cpp.o 4592 (code : 4413 data : 179) TOTAL : 7989 : 927 : 8916 /tmp/arduino_build_288104/sketch/at_client.cpp.o 828 (code : 649 data : 179) /tmp/arduino_build_288104/sketch/bg96.cpp.o 1740 (code : 1561 data : 179) TOTAL : 2213 : 358 : 2571 ### PANA /tmp/arduino_build_319025/sketch/panatiki_integration.ino.cpp.o 1392 (code : 1188 data : 204) /tmp/arduino_build_319025/sketch/eap-peer.cpp.o 632 (code : 449 data : 183) /tmp/arduino_build_319025/sketch/eax.c.o 787 (code : 608 data : 179) /tmp/arduino_build_319025/sketch/eap-psk.cpp.o 1203 (code : 975 data : 228) /tmp/arduino_build_319025/sketch/aes.c.o 1719 (code : 1541 data : 178) /tmp/arduino_build_319025/sketch/state-machine.cpp.o 3245 (code : 3066 data : 179) TOTAL : 6639 : 947 : 7586 /tmp/arduino_build_319025/sketch/at_client.cpp.o 828 (code : 649 data : 179) /tmp/arduino_build_319025/sketch/bg96.cpp.o 1743 (code : 1564 data : 179) TOTAL : 2213 : 358 : 2571