3

I'm making a simple language for Arduino, and want to compile this with LLVM.

I tried to generate LLVM IR (to understand what LLVM IR is generated from the Arduino code). I used this command:

> clang -S -emit-llvm -Os -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -x c++ -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I "C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" -I "C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" Blink.cc -o ./Blink.cc.ll -I "C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include" --target=avr

It generates Blink.ll. And likewise, I also can compile the source code to .o (object) file.

But this file is not able to upload to the Arduino board. To upload to the Arduino, I have to use avrdude. But it requires.hex file. And LLVM outputs .o file, only. I have no clue what have I do to upload this file to the Arduino board.

  • https://arduino.stackexchange.com/q/15893 etc, just need to convert obj to hex. – Dave Newton Aug 04 '19 at 13:32
  • Yes, I tried this: `llvm-objcopy -O ihex Blink.cpp.o Blink.cpp.hex -B avr`. But it does not work. The error is `llvm-objcopy.exe: error: Invalid output format: 'ihex'.`. And I think this is weird because [LLVM Doc](https://llvm.org/docs/CommandGuide/llvm-objcopy.html#supported-formats) says that output format `ihex` is supported. – Donghyeok Tak Aug 04 '19 at 15:18
  • 1
    can you kindly confirm the version of llvm-objcopy? there is a bug-report for ihex format for the same please see https://bugs.llvm.org/show_bug.cgi?id=39841 it is fixed, the link is in the bug report as well. or you can use the avr-objcopy instead. – Chirag Patel Aug 06 '19 at 08:04
  • 1
    use `avr-objcopy` instead of `llvm-objcopy`.it's built for avr. – Erfan Azhdari Aug 06 '19 at 09:38
  • Huge thanks for all! I just installed WSL and ran these on LLVM-Clang-8. avr-objcopy works exactly! – Donghyeok Tak Aug 07 '19 at 00:51

0 Answers0