Now for the blink demo that uses blocking time delays (which make me ill):
proc main() =
const greenPinBit = 1'u32 shl 3 # P1.03/LED1/RAK19007 Green
const bluePinBit = 1'u32 shl 4 # P1.04/LED2/RAK19007 Blue
P1.DIRSET = greenPinBit or bluePinBit
while true:
P1.OUTSET = greenPinBit or bluePinBit
delay(1000)
P1.OUTCLR = greenPinBit or bluePinBit
delay(1000)
Note that I said minimal. This demo program is 100% static. It runs without NimMain being called, so you can't fork this and expect sequences to work. The nimble build process automatically exports an objdump so you can see the resulting assembly:
00026124 <main__c2lora_u17>:
26124: f04f 41a0 mov.w r1, #1342177280 @ 0x50000000
26128: 2418 movs r4, #24
2612a: b508 push {r3, lr}
2612c: f8c1 4818 str.w r4, [r1, #2072] @ 0x818
26130: f8c1 4808 str.w r4, [r1, #2056] @ 0x808
26134: f44f 707a mov.w r0, #1000 @ 0x3e8
26138: f7ff ffe4 bl 26104 <delay__c2lora_u3>
2613c: f8c1 480c str.w r4, [r1, #2060] @ 0x80c
26140: f44f 707a mov.w r0, #1000 @ 0x3e8
26144: f7ff ffde bl 26104 <delay__c2lora_u3>
26148: e7f2 b.n 26130 <main__c2lora_u17+0xc>
0002614a <Reset_Handler>:
2614a: b508 push {r3, lr}
2614c: f7ff ffea bl 26124 <main__c2lora_u17> Awesome to see a pure Nim bringup using svd! I’m looking forward to more updates. Especially if you get Bluetooth running.
Btw, for the tasks I’d recommend considering moving the tasks to a config.nims file. Then you can run it simply with nim build. That skips the Nimble reliance which introduces too many slowdowns and magic failures in my experience (eg silently adding lib paths that can override your hardcoded lib paths, etc).
Though you have to change after blocks to a task and call it in the build task. Like a “context” task can be called using ‘convertTask()’ at the end of the build task.
Another nice thing with this pattern is that it’s easy to include deps/nrf/builds.nims with predefined tasks at the top of your config.nims and reuse the tasks and settings! This can break nimble packages though so not recommended in the project nimble file.
I’ve moved my Nesper/esp32 project to this pattern and it’s been great. You can use git submodules or atlas for deps and things just work and run faster.
Does that sound of interest to anyone?