I am trying to use @zevv's nim-arduino library without the IDE.
I am using the following code heartbeat.nim:
{.passC:"-I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/".}
{.passC:"-I/usr/avr/include/".}
{.passC:"-I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/micro/".}
import arduino
setup:
pinMode LED_BUILTIN, OUTPUT
loop:
digitalWrite LED_BUILTIN, HIGH
delay 500
digitalWrite LED_BUILTIN, LOW
delay 3000
Everthing compiles and the binary gets uploaded to the board (Arduino Nano; atmega328p) successfully. But the led doesn't blink:
nim c -d:danger --os:any heartbeat
avr-objcopy -O ihex -R .eeprom heartbeat heartbeat.hex
avrdude -q -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:heartbeat.hex
If I do the same using .cpp:
/**
* Blink
* Turns on an LED on for one second,
* then off for one second, repeatedly.
*/
#include "Arduino.h"
void setup()
{
// initialize LED digital pin as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
// turn the LED on (HIGH is the voltage level)
digitalWrite(LED_BUILTIN, HIGH);
// wait for a second
delay(500);
// turn the LED off by making the voltage LOW
digitalWrite(LED_BUILTIN, LOW);
// wait for a second
delay(3000);
}
This works.
Any clue about what can I be missing?
I tried with several different values instead of LED_BUILTIN, but I think the value is right.
Right now I am using the following nim.cfg:
avr.any.gcc.path = "/usr/bin"
avr.any.gcc.exe = "avr-gcc"
avr.any.gcc.linkerexe = "avr-gcc"
avr.any.gcc.cpp.path = "/usr/bin"
avr.any.gcc.cpp.exe = "avr-g++"
avr.any.gcc.cpp.linkerexe = "avr-g++"
passC = "-Os"
passC = "-DF_CPU=16000000UL"
passC = "-I/usr/share/arduino/hardware/archlinux-arduino/avr/cores/arduino/"
passC = "-I/usr/share/arduino/hardware/archlinux-arduino/avr/variants/standard/"
passC = "-I/usr/avr/include/"
passC = "-mmcu=atmega328p"
passC = "-flto"
passC = "-Wall"
passC = "-DARDUINO_AVR_BOARD"
passC = "-DHAVE_STDINT_H"
passL = "-mmcu=atmega328p"
passL = "-flto"
cpu = "avr"
gc = "arc"
define = "noSignalHandler"
define = "useMalloc"
deadCodeElim = "on"
exceptions = "quirky" # o "goto"
Mixing @PMunch's, mine, some clues from platfotm.local.txt:
# Install this file into /opt/arduino-1.8.9/hardware/arduino/avr
compiler.nim.flags=--cpu:avr --os:any --gc:arc --exceptions:goto --noMain -d:noSignalHandler -d:danger -d:useMalloc
recipe.preproc.macros="nim_arduino" macros --nimflags="{compiler.nim.flags}" --compiler="{compiler.path}{compiler.cpp.cmd}" --cppflags="{compiler.cpp.flags} {preproc.macros.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes}" --input="{source_file}" --output="{preprocessed_file_path}"
recipe.preproc.includes="nim_arduino" includes --compiler="{compiler.path}{compiler.cpp.cmd}" --cppflags="{compiler.cpp.flags} {preproc.macros.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes}" --input="{source_file}" --output="{preprocessed_file_path}"
recipe.c.o.pattern="nim_arduino" c --compiler="{compiler.path}{compiler.c.cmd}" --cflags="{compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes}" --input="{source_file}" --output="{object_file}"
recipe.cpp.o.pattern="nim_arduino" cpp --compiler="{compiler.path}{compiler.cpp.cmd}" --cppflags="{compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes}" --input="{source_file}" --output="{object_file}"
recipe.c.combine.pattern="nim_arduino" link --linker="{compiler.path}{compiler.c.elf.cmd}" --ldflags="{compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} {build.path}/{archive_file} -L{build.path} -lm" --output="{build.path}/{build.project_name}.elf" --input={object_files}
But still no success :o(