avr-gccã§Arduino IDEç¨ã®*.inoãã¡ã¤ã«ãä¸çºã³ã³ãã¤ã«ãã
Arduinoãçµã¿è¾¼ãã èªä½ä»®æ³ã¢ããã°æè¨ (gsclock) ã®ã¤ã³ã¹ãã¼ã«ãããç°¡åã«ãããã¨æããä»åã¯Arduino IDEç¡ãã§Arduino IDEåãã½ã¼ã¹ãã³ã³ãã¤ã«ããæ¹æ³ãæ¢ãã¦ã¿ã¾ãããï¼ãªãåæ§ã®ç®çã®ãã®ã¨ãã¦arduino-mkãarduino-builderãarduino-cliãªã©ããããããªã®ã§æ®éã®äººã¯ãã£ã¡ã試ããæ¹ãè¯ãããããã¾ãããï¼
ã¾ãã¯AVRåãã®ã¯ãã¹ã³ã³ãã¤ã©ãæ¨æºCã©ã¤ãã©ãªãArduinoã³ã¢ã©ã¤ãã©ãªãå ¥ãã¾ãã
sudo apt install gcc-avr avr-libc arduino-core-avr
ããã§æ³¨æã§ãããArduinoã³ã¢ã©ã¤ãã©ãªã¯æªã³ã³ãã¤ã«ã®ç¶æ ã®ããã§ãããã®ããæ¬å½ã¯äºåã³ã³ãã¤ã«ããã¦ã©ã¤ãã©ãªãä½ãã®ãæ£æ»æ³ã ã¨æãã®ã§ãããä»åã¯æ¨ªçãã¦èªä½ããã°ã©ã ã¨åæã«ã©ã¤ãã©ãªãã³ã³ãã¤ã«ãããã¨ã«ãã¾ãã
åé¡ã¯Arduinoã³ã¢ã©ã¤ãã©ãªã«Cè¨èªã¨C++è¨èªãæ··å¨ãã¦ããããã³ãã³ãã©ã¤ã³ã§ãªãã·ã§ã³ãä¸æ¬æå®ãã§ããªããã¨ã§ãããããæ®éãªãMakefileã使ã£ã¦ã©ãããããã¨ãããªã®ã§ãããä»ã«è¯ãæ¹æ³ã¯ç¡ãããªã¨æ¢ããã¨ããGCCã«ã¯cc1 (gccç¸å½)ã¨cc1plus (g++ç¸å½)ã«æ¸¡ããã©ã¡ã¼ã¿ãåå¥ã«å¤æ´ã§ããSpecsファイルã¨ãããã®ãããããã§ããä»åã¯ããã使ã£ã¦ã¿ã¾ãã
ã¾ãã¯AVRåãgccã®æ¨æºSpecsãã¡ã¤ã«ããã³ããã¾ãã
avr-gcc -dumpspecs > avr-gcc-arduino.specs
次ã«avr-gcc-arduino.specsã®cc1ã¨cc1plusã®ãã©ã¡ã¼ã¿ãå¤æ´ãã¾ãã
*cc1: -%(cc1_n_flash) %(cc1_errata_skip) %(cc1_rmw) %(cc1_non_bit_addressable_registers_mask) %(cc1_absdata) +%(cc1_n_flash) %(cc1_errata_skip) %(cc1_rmw) %(cc1_non_bit_addressable_registers_mask) %(cc1_absdata) -flto -fuse-linker-plugin
*cc1plus: -%(cc1) %{!frtti:-fno-rtti} %{!fenforce-eh-specs:-fno-enforce-eh-specs} %{!fexceptions:-fno-exceptions} +%(cc1) %{!frtti:-fno-rtti} %{!fenforce-eh-specs:-fno-enforce-eh-specs} %{!fexceptions:-fno-exceptions} -std=c++14 -fno-threadsafe-statics -fno-exceptions
ã¾ãã¯hello worldã試ããã¨ã«ãã¾ãã以ä¸ãhello.inoã¨ãã¦ä¿åãã¾ãã
#include <Arduino.h> /*ããã¯ä»ã®æå¤ãã¾ãã*/ void setup() { Serial.begin(9600); } void loop() { Serial.println("Hello, World, from avr-gcc!"); delay(500); }
ããã§ä½æããSpecsãã¡ã¤ã«ã使ã£ã¦ãããã³ã³ãã¤ã«ãã¦ã¿ã¾ããä»åã¯MPUãatmega328p 16MHzã®Arduino Uno R3åãã§ãã
avr-gcc -specs=avr-gcc-arduino.specs -Os -Wall -mmcu=atmega328p -ffunction-sections -fdata-sections -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/usr/share/arduino/hardware/arduino/avr/cores/arduino -I/usr/share/arduino/hardware/arduino/avr/variants/standard /usr/share/arduino/hardware/arduino/avr/cores/arduino/*.cpp /usr/share/arduino/hardware/arduino/avr/cores/arduino/*.c -x c++ hello.ino -o hello.elf
ããã¤ã¹ã«ã¢ãããã¼ãã§ããããã«hexå½¢å¼ã«å¤æãã¾ãã
avr-objcopy -O ihex hello.elf hello.hex
ããã¤ã¹ã«ã¢ãããã¼ãããããã®avrdudeãã¤ã³ã¹ãã¼ã«ãã¾ãã
sudo apt install avrdude
avrdudeã§ã¢ãããã¼ããã¾ããä»åã®ãã¼ã㯠/dev/ttyACM0 ã§ããã
$ avrdude -c arduino -p atmega328p -b 115200 -P /dev/ttyACM0 -U flash:w:hello.hex 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 "hello.hex" avrdude: input file hello.hex auto detected as Intel Hex avrdude: writing flash (6502 bytes): Writing | ################################################## | 100% 1.04s avrdude: 6502 bytes of flash written avrdude: verifying flash memory against hello.hex: avrdude: load data flash data from input file hello.hex: avrdude: input file hello.hex auto detected as Intel Hex avrdude: input file hello.hex contains 6502 bytes avrdude: reading on-chip flash data: Reading | ################################################## | 100% 0.84s avrdude: verifying ... avrdude: 6502 bytes of flash verified avrdude: safemode: Fuses OK (E:00, H:00, L:00) avrdude done. Thank you.
ãããã«ã·ãªã¢ã«ã³ã³ã½ã¼ã«ã«ç¹ãã§ã¿ã¾ã:
$ tail -f /dev/ttyACM0 Hel, World, from avr-gcc! Hello, World, from avr-gcc! Hello, World, from avr-gcc! Hello, World, from avr-gcc! Hello, World, from avr-gcc! Hello, World, from avr-gcc! Hello, World, from avr-gcc! Hello, World, from avr-gcc!
ã¡ããã¨åãã¦ã¾ããããã æ©ç¨®åºå®ãã¡ãã£ã¦æè»æ§ãä¸ãã£ã¦ããããã¥ã¼ãã³ã¨ã©ã¼ãèµ·ãããããªã£ã¦ããããã®ã§ããã¾ããªã¹ã¹ã¡ã¯ãã¾ãããä»å¾ã©ããããã¯è¿·ãä¸ã§ãã