I played around with writing nim code for tiny systems (including a micro:bit) 
several months ago. Here are some of the key strategies I learned along the way:

  * check out [https://platformio.org](https://platformio.org) This tool knows 
all about building software for a wide range of embedded systems. It will 
download all the cross-compile tools for you, and compile the libraries with 
all the right flags. I used the command-line version that they call 'Platformio 
Core'.
  * build your software in two distinct stages:
    1. 'nim cpp -c' to generate source files
    2. 'platformio run' to compile and link. This will happily ignore the .nim 
files in the source directory and pick up the generated files in the nimcache 
subdirectory.
  * the microbit and mbed libraries provide large numbers of header files, most 
of which are too "clever" to be digestible by 'c2nim'. I found it much easier 
to write my own modules with '{.importcpp.}' declarations just for the parts of 
each interface that I actually used.


Reply via email to