markspanbroek / nim-arduino

Arduino bindings for Nim
25 stars 2 forks source link

esp32 compile errors #1

Closed cvanelteren closed 3 years ago

cvanelteren commented 3 years ago

Hi,

Thanks for this project! Nim seems to be very interesting for micro-controller applications. I am trying to get the tutorial running, but I am running in to issues getting it up and running on an esp32 (perhaps not supported). Perhaps you could point me in the right direction in fixing them, any help is greatly appreciated. Best wishes, C

output ``` *** [.pio/build/ttgo-lora32-v2/src/nimcache/stdlib_system.nim.cpp.o] Error 1 In file included from src/nimcache/@mmain.nim.cpp:4:0: .pio/libdeps/ttgo-lora32-v2/nimbase/nimbase.h:493:131: error: size of array 'Nim_and_C_compiler_disagree_on_target_architecture' is negative typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1]; ^ .pio/libdeps/ttgo-lora32-v2/FastLED/src/platforms/esp/32/clockless_rmt_esp32.cpp: In static member function 'static void ESP32RMTController::interruptHandler(void*)': .pio/libdeps/ttgo-lora32-v2/FastLED/src/platforms/esp/32/clockless_rmt_esp32.cpp:318:10: warning: unused variable 'stuff_to_do' [-Wunused-variable] bool stuff_to_do = false; ^ src/nimcache/@mmain.nim.cpp:21:53: error: conflicting declaration of 'void setup()' with 'C' linkage extern "C" N_LIB_PRIVATE N_NIMCALL(void, setup)(void); ^ In file included from src/nimcache/@mmain.nim.cpp:5:0: /home/casper/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:118:6: note: previous declaration with 'C++' linkage void setup(void); ^ src/nimcache/@mmain.nim.cpp:23:52: error: conflicting declaration of 'void loop()' with 'C' linkage extern "C" N_LIB_PRIVATE N_NIMCALL(void, loop)(void); ^ In file included from src/nimcache/@mmain.nim.cpp:5:0: /home/casper/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:119:6: note: previous declaration with 'C++' linkage void loop(void) ```
main.nim ``` import pkg/nim-arduino/arduino #import arduino setup: pinMode(LED_BUILTIN, OUTPUT) loop: digitalWrite(LED_BUILTIN, HIGH) delay(1000) digitalWrite(LED_BUILTIN, LOW) delay(1000) ```

edit: I also had to add panic override as such

  proc printf(frmt: cstring) {.varargs, importc, header: "<stdio.h>", cdecl.}
proc exit(code: int) {.importc, header: "<stdlib.h>", cdecl.}

{.push stack_trace: off, profiler:off.}

proc rawoutput(s: string) =
  printf("%s\n", s)

proc panic(s: string) =
  rawoutput(s)
  exit(1)

{.pop.}

since it was complaining that this file didn't exist

markspanbroek commented 3 years ago

Hi @cvanelteren, thanks for reporting this. I only have a feather with an ATmega32u4 to play around with, so I haven't tested esp32 yet. But if you could give me your platformio.ini file, I could try to reproduce the build issue that you're seeing.

Also, thanks for mentioning the panicoverride. I also had to add it, but forgot to mention it in the Readme.

cvanelteren commented 3 years ago

No worries! The config is attached.

platformio.ini ``` [platformio] default_envs = ttgo-lora32-v2 [env:ttgo-lora32-v2] ; build_unflags = -std=gnu++11 ; build_flags = -std=c++17 platform = espressif32 board = ttgo-lora32-v2 framework = arduino lib_deps = https://github.com/markspanbroek/nim-arduino monitor_speed = 115200 board_build.partitions = part.csv ```

I was messing around with more modern cpp, I have both test with and without setting them. Both give the same error. I read somewhere that nim uses 64 bit by default. The error message seems to relate to some disagreement on types, not sure if that is related or a cause.

markspanbroek commented 3 years ago

I hardcoded the cpu type to avr in nim-platformio. When I change avr to esp then compilation works with the platformio config that you provided.

Now I just need to figure out a way to make this configurable...

markspanbroek commented 3 years ago

Thanks for your help @cvanelteren. Your PRs in nim-platformio have fixed the issue.