-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
auto.html
1067 lines (1024 loc) · 65.8 KB
/
auto.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<title>Auto Flash and Test NuttX on RISC-V BL602</title>
<!-- Begin scripts/articles/*-header.html: Article Header for Custom Markdown files processed by rustdoc, like chip8.md -->
<meta property="og:title"
content="Auto Flash and Test NuttX on RISC-V BL602"
data-rh="true">
<meta property="og:description"
content="How we automagically flash and test the daily build of Apache NuttX OS on BL602 RISC-V SoC"
data-rh="true">
<meta property="og:image"
content="https://lupyuen.github.io/images/auto-title.jpg">
<meta property="og:type"
content="article" data-rh="true">
<link rel="canonical" href="https://lupyuen.org/articles/auto.html" />
<!-- End scripts/articles/*-header.html -->
<!-- Begin scripts/rustdoc-header.html: Header for Custom Markdown files processed by rustdoc, like chip8.md -->
<link rel="alternate" type="application/rss+xml" title="RSS Feed for lupyuen" href="/rss.xml" />
<link rel="stylesheet" type="text/css" href="../normalize.css">
<link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle">
<link rel="stylesheet" type="text/css" href="../dark.css">
<link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle">
<link rel="stylesheet" type="text/css" href="../prism.css">
<script src="../storage.js"></script><noscript>
<link rel="stylesheet" href="../noscript.css"></noscript>
<link rel="shortcut icon" href="../favicon.ico">
<style type="text/css">
#crate-search {
background-image: url("../down-arrow.svg");
}
</style>
<!-- End scripts/rustdoc-header.html -->
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<!-- Begin scripts/rustdoc-before.html: Pre-HTML for Custom Markdown files processed by rustdoc, like chip8.md -->
<!-- Begin Theme Picker -->
<div class="theme-picker" style="left: 0"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg"
width="18" alt="Pick another theme!"></button>
<div id="theme-choices"></div>
</div>
<!-- Theme Picker -->
<!-- End scripts/rustdoc-before.html -->
<h1 class="title">Auto Flash and Test NuttX on RISC-V BL602</h1>
<nav id="rustdoc"><ul>
<li><a href="#bl602-basics" title="BL602 Basics">1 BL602 Basics</a><ul></ul></li>
<li><a href="#connect-bl602-to-single-board-computer" title="Connect BL602 to Single-Board Computer">2 Connect BL602 to Single-Board Computer</a><ul></ul></li>
<li><a href="#control-gpio-with-linux" title="Control GPIO with Linux">3 Control GPIO with Linux</a><ul>
<li><a href="#enable-gpio" title="Enable GPIO">3.1 Enable GPIO</a><ul></ul></li>
<li><a href="#configure-gpio-output" title="Configure GPIO Output">3.2 Configure GPIO Output</a><ul></ul></li>
<li><a href="#enter-flashing-mode" title="Enter Flashing Mode">3.3 Enter Flashing Mode</a><ul></ul></li>
<li><a href="#reset-bl602" title="Reset BL602">3.4 Reset BL602</a><ul></ul></li>
<li><a href="#flash-bl602" title="Flash BL602">3.5 Flash BL602</a><ul></ul></li>
<li><a href="#exit-flashing-mode" title="Exit Flashing Mode">3.6 Exit Flashing Mode</a><ul></ul></li>
<li><a href="#show-bl602-output" title="Show BL602 Output">3.7 Show BL602 Output</a><ul></ul></li></ul></li>
<li><a href="#run-the-script" title="Run The Script">4 Run The Script</a><ul>
<li><a href="#download-nuttx" title="Download NuttX">4.1 Download NuttX</a><ul></ul></li>
<li><a href="#flash-nuttx" title="Flash NuttX">4.2 Flash NuttX</a><ul></ul></li>
<li><a href="#boot-nuttx" title="Boot NuttX">4.3 Boot NuttX</a><ul></ul></li>
<li><a href="#test-nuttx" title="Test NuttX">4.4 Test NuttX</a><ul></ul></li></ul></li>
<li><a href="#nuttx-crash-analysis" title="NuttX Crash Analysis">5 NuttX Crash Analysis</a><ul>
<li><a href="#decode-stack-trace" title="Decode Stack Trace">5.1 Decode Stack Trace</a><ul></ul></li>
<li><a href="#disassemble-the-firmware" title="Disassemble The Firmware">5.2 Disassemble The Firmware</a><ul></ul></li>
<li><a href="#decode-addresses" title="Decode Addresses">5.3 Decode Addresses</a><ul></ul></li>
<li><a href="#auto-analysis" title="Auto Analysis">5.4 Auto Analysis</a><ul></ul></li></ul></li>
<li><a href="#lorawan-test" title="LoRaWAN Test">6 LoRaWAN Test</a><ul></ul></li>
<li><a href="#merge-updates-from-nuttx" title="Merge Updates From NuttX">7 Merge Updates From NuttX</a><ul></ul></li>
<li><a href="#whats-next" title="What’s Next">8 What’s Next</a><ul></ul></li>
<li><a href="#notes" title="Notes">9 Notes</a><ul></ul></li>
<li><a href="#appendix-build-nuttx-with-github-actions" title="Appendix: Build NuttX with GitHub Actions">10 Appendix: Build NuttX with GitHub Actions</a><ul>
<li><a href="#build-schedule" title="Build Schedule">10.1 Build Schedule</a><ul></ul></li>
<li><a href="#install-build-tools" title="Install Build Tools">10.2 Install Build Tools</a><ul></ul></li>
<li><a href="#install-toolchain" title="Install Toolchain">10.3 Install Toolchain</a><ul></ul></li>
<li><a href="#checkout-source-files" title="Checkout Source Files">10.4 Checkout Source Files</a><ul></ul></li>
<li><a href="#configure-build" title="Configure Build">10.5 Configure Build</a><ul></ul></li>
<li><a href="#build-nuttx" title="Build NuttX">10.6 Build NuttX</a><ul></ul></li>
<li><a href="#upload-build-outputs" title="Upload Build Outputs">10.7 Upload Build Outputs</a><ul></ul></li>
<li><a href="#publish-release" title="Publish Release">10.8 Publish Release</a><ul></ul></li></ul></li>
<li><a href="#appendix-fix-lorawan-nonce" title="Appendix: Fix LoRaWAN Nonce">11 Appendix: Fix LoRaWAN Nonce</a><ul></ul></li></ul></nav><p>📝 <em>26 Jan 2022</em></p>
<p><img src="https://lupyuen.github.io/images/auto-title.jpg" alt="PineCone BL602 RISC-V Board (bottom) connected to Single-Board Computer (top) for Auto Flash and Test" /></p>
<p><em>PineCone BL602 RISC-V Board (bottom) connected to Single-Board Computer (top) for Auto Flash and Test</em></p>
<p><a href="https://lupyuen.github.io/articles/auto2"><strong>UPDATE:</strong> Check out the new article on Automated Testing for PineDio Stack BL604</a></p>
<p>Suppose we’re <strong>testing embedded firmware</strong> on the <a href="https://lupyuen.github.io/articles/pinecone"><strong>BL602 RISC-V SoC</strong></a>. And the firmware changes <strong>every day</strong> (due to Daily Updates from upstream).</p>
<p>Instead of flipping a jumper, restarting the board, flashing over UART, restarting again, repeating every day…</p>
<p>Is there a way to <strong>Automatically Flash and Test</strong> the Daily Updates?</p>
<p>Yes we can, by connecting BL602 to a <strong>Linux Single-Board Computer</strong>!</p>
<p>Today we shall create a Linux Script that will…</p>
<ul>
<li>
<p><strong>Auto-Flash</strong> the Daily Build of <a href="https://lupyuen.github.io/articles/nuttx"><strong>Apache NuttX OS</strong></a> to BL602</p>
</li>
<li>
<p><strong>Auto-Boot</strong> NuttX on BL602 after flashing</p>
</li>
<li>
<p><strong>Auto-Test</strong> NuttX by sending a command that tests the GPIO Input / Output / Interrupts, SPI, ADC, Timers, Message Queues, PThreads, Strong Random Number Generator and Internal Temperature Sensor</p>
<p><a href="https://www.youtube.com/watch?v=JtnOyl5cYjo"><strong>Watch the demo on YouTube</strong></a></p>
<p>(Spoilers: It’s LoRaWAN!)</p>
</li>
<li>
<p>If NuttX crashes, <strong>Auto-Decode</strong> the NuttX Stack Trace and show us the Source Code that caused the crash</p>
<p><a href="https://www.youtube.com/watch?v=Kf3G1hGoLIs"><strong>Watch the demo on YouTube</strong></a></p>
</li>
</ul>
<p><em>Why are we doing this?</em></p>
<ul>
<li>
<p>Might be useful for <strong>Release Testing</strong> of NuttX (and other operating systems) on real hardware</p>
</li>
<li>
<p>By auto-testing the <strong>LoRaWAN Stack</strong> on NuttX, we can be sure that GPIO Input / Output / Interrupts, SPI, ADC, … are all working OK with the latest Daily Build of NuttX</p>
</li>
<li>
<p>I write articles about NuttX OS. I need to pick the <strong>Latest Stable Build</strong> of NuttX for testing the NuttX code in my articles. <a href="https://lupyuen.github.io/articles/book#nuttx-on-bl602">(Like these)</a></p>
</li>
<li>
<p>BL602 Devs can easily download the <strong>latest tested build</strong> from GitHub Releases…</p>
<p><a href="https://github.com/lupyuen/nuttx/releases?q=%22download%2Frelease%22&expanded=true"><strong>NuttX Releases for BL602</strong></a></p>
</li>
</ul>
<p><em>Will this work for other microcontrollers?</em></p>
<ul>
<li>
<p><strong>ESP32</strong> has 2 buttons for flashing (BOOT and EN), very similar to BL602. Our Auto Flash and Test Script might work for ESP32 with some tweaking.</p>
</li>
<li>
<p><strong>Arm Microcontrollers</strong> may be auto flashed and debugged with an OpenOCD Script. <a href="https://github.com/lupyuen/remote-pinetime-bot">(Check out Remote PineTime)</a></p>
</li>
</ul>
<p><img src="https://lupyuen.github.io/images/pinecone-jumperh.jpg" alt="PineCone BL602 in Flashing Mode with GPIO 8 set to High. Sorry the jumper got mangled due to a soldering accident 🙏" /></p>
<p><em>PineCone BL602 in Flashing Mode with GPIO 8 set to High. Sorry the jumper got mangled due to a soldering accident</em> 🙏</p>
<h1 id="bl602-basics"><a class="doc-anchor" href="#bl602-basics">§</a>1 BL602 Basics</h1>
<p>This is how we work with BL602…</p>
<ol>
<li>
<p><strong>Connect BL602</strong> to our computer’s USB port</p>
</li>
<li>
<p>Flip the <strong>GPIO 8 Jumper</strong> to <strong>High</strong> (pic above)</p>
</li>
<li>
<p>Press the <strong>Reset Button (RST)</strong>.</p>
<p>BL602 is now in <strong>Flashing Mode</strong>.</p>
</li>
<li>
<p>Flash BL602 over USB UART with <a href="https://github.com/spacemeowx2/blflash"><strong>blflash</strong></a>…</p>
<div class="example-wrap"><pre class="language-bash"><code>$ blflash flash nuttx.bin --port /dev/ttyUSB0
Start connection...
Connection Succeed
Sending eflash_loader...
Program flash...
...
Success</code></pre></div></li>
<li>
<p>Flip the <strong>GPIO 8 Jumper</strong> to <strong>Low</strong> (pic below)</p>
<p><img src="https://lupyuen.github.io/images/pinecone-jumperl.jpg" alt="PineCone BL602 in Normal Mode with GPIO 8 set to Low" /></p>
</li>
<li>
<p>Press the <strong>Reset Button (RST)</strong>.</p>
<p>BL602 is now in <strong>Normal Mode</strong>. (Non-Flashing)</p>
</li>
<li>
<p>Launch a <strong>Serial Terminal</strong> to test the BL602 Firmware</p>
</li>
<li>
<p>When we’re done, close the Serial Terminal and repeat the <strong>Flash-Test Cycle</strong></p>
</li>
</ol>
<p>Over the past <strong>14 months</strong> I’ve been doing this over and over again. Until last week I wondered…</p>
<p>Can we automate this with a <strong>Single-Board Computer</strong>?</p>
<p>And indeed we can! (Duh!) Here’s how…</p>
<p><img src="https://lupyuen.github.io/images/auto-title.jpg" alt="PineCone BL602 RISC-V Board (lower right) connected to Single-Board Computer (top) and Semtech SX1262 LoRa Transceiver (lower left)" /></p>
<p><em>PineCone BL602 RISC-V Board (lower right) connected to Single-Board Computer (top) and Semtech SX1262 LoRa Transceiver (lower left)</em></p>
<h1 id="connect-bl602-to-single-board-computer"><a class="doc-anchor" href="#connect-bl602-to-single-board-computer">§</a>2 Connect BL602 to Single-Board Computer</h1>
<p>Connect BL602 to a <strong>Single-Board Computer (SBC)</strong> as shown in the pic above…</p>
<div><table><thead><tr><th>SBC</th><th>BL602</th><th>Function</th></tr></thead><tbody>
<tr><td><strong>GPIO 2</strong></td><td>GPIO 8</td><td>Flashing Mode (Long Green)</td></tr>
<tr><td><strong>GPIO 3</strong></td><td>RST</td><td>Reset (Long Yellow)</td></tr>
<tr><td><strong>GND</strong></td><td>GND</td><td>Ground</td></tr>
<tr><td><strong>USB</strong></td><td>USB</td><td>USB UART</td></tr>
</tbody></table>
</div>
<p>(Ground is missing from the pic)</p>
<p>Check that BL602 is <strong>firmly seated</strong> on the Breadboard! The USB Connector tends to <strong>dislodge the BL602 Board</strong> from the Breadboard when the USB Cable wriggles too much.</p>
<p>For auto-testing LoRaWAN, we also connect BL602 to <a href="https://www.semtech.com/products/wireless-rf/lora-core/sx1262"><strong>Semtech SX1262 LoRa Transceiver</strong></a> (pic above)…</p>
<ul>
<li><a href="https://lupyuen.github.io/articles/spi2#connect-sx1262"><strong>“Connect SX1262”</strong></a></li>
</ul>
<p>Clearer pic of the <strong>GPIO 8</strong> (Flashing Mode) and <strong>Reset Pins</strong> on PineCone BL602…</p>
<p><img src="https://lupyuen.github.io/images/auto-connect2.jpg" alt="GPIO 8 and Reset Pins" /></p>
<p>No more flipping the jumper and smashing the button! Let’s control GPIO 8 and Reset Pins with our Linux SBC.</p>
<h1 id="control-gpio-with-linux"><a class="doc-anchor" href="#control-gpio-with-linux">§</a>3 Control GPIO with Linux</h1>
<p>Recall that <strong>GPIO 2 and 3</strong> on our Linux SBC are connected to BL602 for the <strong>Flashing and Reset</strong> Functions…</p>
<div><table><thead><tr><th>SBC</th><th>BL602</th><th>Function</th></tr></thead><tbody>
<tr><td><strong>GPIO 2</strong></td><td>GPIO 8</td><td>Flashing Mode</td></tr>
<tr><td><strong>GPIO 3</strong></td><td>RST</td><td>Reset</td></tr>
</tbody></table>
</div>
<p>Let’s control GPIO 2 and 3 with a Bash Script…</p>
<ul>
<li><a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh"><strong>remote-bl602/scripts/test.sh</strong></a></li>
</ul>
<p><img src="https://lupyuen.github.io/images/auto-script2.png" alt="Control GPIO with Linux" /></p>
<h2 id="enable-gpio"><a class="doc-anchor" href="#enable-gpio">§</a>3.1 Enable GPIO</h2>
<p>Our Bash Script begins by <strong>enabling GPIO 2 and 3</strong>: <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L42-L48">test.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Enable GPIO 2 and 3 (if not already enabled)
if [ ! -d /sys/class/gpio/gpio2 ]; then
echo 2 >/sys/class/gpio/export
sleep 1
fi
if [ ! -d /sys/class/gpio/gpio3 ]; then
echo 3 >/sys/class/gpio/export
sleep 1
fi</code></pre></div>
<p><a href="https://www.ics.com/blog/gpio-programming-using-sysfs-interface">(<strong>/sys/class/gpio</strong> comes from the Linux sysfs Interface)</a></p>
<p>After enabling GPIO 2 and 3, these <strong>GPIO Interfaces</strong> will appear in Linux…</p>
<ul>
<li>
<p><strong>/sys/class/gpio/gpio2</strong></p>
</li>
<li>
<p><strong>/sys/class/gpio/gpio3</strong></p>
</li>
</ul>
<p>Let’s configure them.</p>
<h2 id="configure-gpio-output"><a class="doc-anchor" href="#configure-gpio-output">§</a>3.2 Configure GPIO Output</h2>
<p>Our script configures GPIO 2 and 3 for <strong>GPIO Output</strong> (instead of GPIO Input): <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L50-L52">test.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Set GPIO 2 and 3 as output
echo out >/sys/class/gpio/gpio2/direction
echo out >/sys/class/gpio/gpio3/direction</code></pre></div>
<p>Now we’re ready to toggle GPIO 2 and 3 to flash and reset BL602!</p>
<h2 id="enter-flashing-mode"><a class="doc-anchor" href="#enter-flashing-mode">§</a>3.3 Enter Flashing Mode</h2>
<p>To enter <strong>Flashing Mode</strong>, our script sets GPIO 2 to <strong>High</strong>: <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L54-L55">test.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Set GPIO 2 to High (BL602 Flashing Mode)
echo 1 >/sys/class/gpio/gpio2/value
sleep 1</code></pre></div>
<p>But to make it happen we need to restart BL602, coming up next…</p>
<h2 id="reset-bl602"><a class="doc-anchor" href="#reset-bl602">§</a>3.4 Reset BL602</h2>
<p>To <strong>restart BL602</strong> (and actually enter Flashing Mode), our script toggles GPIO 3 <strong>High-Low-High</strong>: <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L57-L65">test.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Toggle GPIO 3 High-Low-High (Reset BL602)
echo 1 >/sys/class/gpio/gpio3/value
sleep 1
echo 0 >/sys/class/gpio/gpio3/value
sleep 1
echo 1 >/sys/class/gpio/gpio3/value
sleep 1</code></pre></div>
<p>BL602 is now in <strong>Flashing Mode</strong>!</p>
<h2 id="flash-bl602"><a class="doc-anchor" href="#flash-bl602">§</a>3.5 Flash BL602</h2>
<p>Our script runs <a href="https://github.com/spacemeowx2/blflash"><strong>blflash</strong></a> to flash BL602 over USB UART: <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L67-L72">test.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## BL602 is now in Flashing Mode.
## Flash BL602 over USB UART with blflash.
blflash flash \
/tmp/nuttx.bin \
--port /dev/ttyUSB0
sleep 1</code></pre></div>
<p><a href="https://lupyuen.github.io/articles/auto#appendix-build-nuttx-with-github-actions">(<strong>nuttx.bin</strong> is the Daily Upstream Build of NuttX OS, as explained in the Appendix)</a></p>
<p>Our firmware has been flashed automagically!</p>
<h2 id="exit-flashing-mode"><a class="doc-anchor" href="#exit-flashing-mode">§</a>3.6 Exit Flashing Mode</h2>
<p>Now we return to <strong>Normal Mode</strong> (Non-Flashing) by setting GPIO 2 to <strong>Low</strong>: <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L74-L80">test.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Set GPIO 2 to Low (BL602 Normal Mode)
echo 0 >/sys/class/gpio/gpio2/value
sleep 1</code></pre></div>
<p>We effect the change by <strong>restarting BL602</strong>…</p>
<div class="example-wrap"><pre class="language-bash"><code>## Toggle GPIO 3 High-Low-High (Reset BL602)
echo 1 >/sys/class/gpio/gpio3/value
sleep 1
echo 0 >/sys/class/gpio/gpio3/value
sleep 1
echo 1 >/sys/class/gpio/gpio3/value
sleep 1</code></pre></div>
<p>BL602 starts booting our firmware, but we need some prep…</p>
<h2 id="show-bl602-output"><a class="doc-anchor" href="#show-bl602-output">§</a>3.7 Show BL602 Output</h2>
<p>We’re ready to show the output from our BL602 Firmware (NuttX). Our script sets the USB UART’s Baud Rate to <strong>2 Mbps</strong>: <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L82-L98">test.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## BL602 is now in Normal Mode.
## Set USB UART to 2 Mbps.
stty \
-F /dev/ttyUSB0 \
raw 2000000</code></pre></div>
<p>(Otherwise the output will be garbled)</p>
<p>Then our script <strong>streams the output</strong> from BL602 over USB UART…</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code># Show the BL602 output and capture to /tmp/test.log.
# Run this <span class="kw">in </span>the background so we can kill it later.
cat /dev/ttyUSB0 \
| tee /tmp/test.log <span class="kw-2">&</span></code></pre></div>
<p>And captures the output to <strong>test.log</strong> for analysis. (Which we’ll explain shortly)</p>
<p>This runs as a <strong>Background Task</strong> (<code>&</code>) because we want the script to continue running (in the Foreground) as the BL602 output continues to stream (in the Background).</p>
<p><em>But nothing appears in the output?</em></p>
<p>Yep because BL602 has <strong>already booted</strong> our firmware. The Boot Messages have whooshed by before we captured them.</p>
<p>To see the <strong>Boot Messages</strong>, our script restarts BL602 yet again…</p>
<div class="example-wrap"><pre class="language-bash"><code>## Toggle GPIO 3 High-Low-High (Reset BL602)
echo 1 >/sys/class/gpio/gpio3/value ; sleep 1
echo 0 >/sys/class/gpio/gpio3/value ; sleep 1
echo 1 >/sys/class/gpio/gpio3/value ; sleep 1
## Wait a while for BL602 to finish booting
sleep 1
## Omitted: Send test command and analyse the BL602 output
...</code></pre></div>
<p>(We’ll talk later about the output analysis)</p>
<p>Remember that the BL602 output is still being streamed in a Background Task. Our script <strong>terminates the Background Task</strong> like so: <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L196-L197">test.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Kill the background task that captures the BL602 output
kill %1</code></pre></div>
<p>And we’re done!</p>
<p><em>So this script totally replaces a human flipping the jumper and smashing the button on BL602?</em></p>
<p>Yep our Linux Script totally controls the <strong>Flashing and Reset</strong> Functions on BL602… No more human intervention!</p>
<p>Here’s a demo of our script flipping GPIO 2 and 3 and switching the flashing mode…</p>
<ul>
<li><a href="https://www.youtube.com/watch?v=d8x0Y-OraXo"><strong>Watch the demo on YouTube</strong></a></li>
</ul>
<h1 id="run-the-script"><a class="doc-anchor" href="#run-the-script">§</a>4 Run The Script</h1>
<p>We’ve seen the <strong>Auto Flash and Test</strong> Script, let’s run it on our Linux SBC!</p>
<p>Enter this at the Linux command prompt…</p>
<div class="example-wrap"><pre class="language-bash"><code>## Allow the user to access the GPIO and UART ports
sudo usermod -a -G gpio $USER
sudo usermod -a -G dialout $USER
## Logout and login to refresh the permissions
logout
## Install Rust: https://rustup.rs/
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
## Add Rust to the PATH
source $HOME/.cargo/env
## Install blflash
cargo install blflash
## Download the script
git clone --recursive https://github.com/lupyuen/remote-bl602
## Optional: Select the type of build (upstream / downstream / release)
## export BUILD_PREFIX=upstream
## Optional: Select the date of the build
## export BUILD_DATE=2022-01-19
## Run the script
remote-bl602/scripts/test.sh</code></pre></div>
<p>(For Arch Linux and Manjaro: Change “dialout” to “uucp”)</p>
<p>Our script flashes and runs NuttX on BL602 like so…</p>
<ul>
<li><a href="https://www.youtube.com/watch?v=_82og3-gEwA"><strong>Watch the demo on YouTube</strong></a></li>
</ul>
<p>Let’s study the script output: <a href="https://github.com/lupyuen/nuttx/releases/tag/upstream-2022-01-21"><strong>upstream-2022-01-21</strong></a></p>
<p><img src="https://lupyuen.github.io/images/auto-run.jpg" alt="Auto Flash and Test Script" /></p>
<h2 id="download-nuttx"><a class="doc-anchor" href="#download-nuttx">§</a>4.1 Download NuttX</h2>
<p>Our script begins by <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L20-L40"><strong>downloading Today’s Upstream Build</strong></a> of NuttX: <a href="https://github.com/lupyuen/nuttx/releases/tag/upstream-2022-01-21">upstream-2022-01-21</a></p>
<div class="example-wrap"><pre class="language-text"><code>+ BUILD_PREFIX=upstream
+ BUILD_DATE=2022-01-21
----- Download the latest upstream NuttX build for 2022-01-21
+ wget -q \
https://github.com/lupyuen/nuttx/releases/download/upstream-2022-01-21/nuttx.zip \
-O /tmp/nuttx.zip</code></pre></div>
<p><a href="https://lupyuen.github.io/articles/auto#appendix-build-nuttx-with-github-actions">(<strong>nuttx.zip</strong> is built daily by GitHub Actions, as explained in the Appendix)</a></p>
<p>Our script unzips <strong>nuttx.zip</strong>, which includes the following files…</p>
<div class="example-wrap"><pre class="language-text"><code>+ pushd /tmp
+ unzip -o nuttx.zip
Archive: nuttx.zip
inflating: nuttx
inflating: nuttx.S
inflating: nuttx.bin
inflating: nuttx.config
inflating: nuttx.hex
inflating: nuttx.manifest
inflating: nuttx.map
+ popd</code></pre></div>
<ul>
<li>
<p><strong>nuttx</strong>: Firmware in ELF Format</p>
</li>
<li>
<p><strong>nuttx.bin</strong>: Firmware Binary to be flashed</p>
</li>
<li>
<p><strong>nuttx.S</strong>: RISC-V Disassembly for the firmware</p>
</li>
<li>
<p><strong>nuttx.map</strong>: Linker Map for the firmware</p>
</li>
<li>
<p><strong>nuttx.config</strong>: Build Configuration (from .config)</p>
</li>
</ul>
<h2 id="flash-nuttx"><a class="doc-anchor" href="#flash-nuttx">§</a>4.2 Flash NuttX</h2>
<p>Next we switch BL602 to <strong>Flashing Mode</strong> by flipping GPIO 2 and 3 (which we’ve seen earlier)…</p>
<div class="example-wrap"><pre class="language-text"><code>Enable GPIO 2 and 3
Set GPIO 2 and 3 as output
Set GPIO 2 to High (BL602 Flashing Mode)
Toggle GPIO 3 High-Low-High (Reset BL602)
Toggle GPIO 3 High-Low-High (Reset BL602 again)
BL602 is now in Flashing Mode</code></pre></div>
<p>We flash the downloaded NuttX Firmware <strong>nuttx.bin</strong> to BL602 with <a href="https://github.com/spacemeowx2/blflash"><strong>blflash</strong></a>…</p>
<div class="example-wrap"><pre class="language-text"><code>----- Flash BL602 over USB UART with blflash
+ blflash flash /tmp/nuttx.bin --port /dev/ttyUSB0
Start connection...
Connection Succeed
Sending eflash_loader...
Entered eflash_loader
Program flash...
Success</code></pre></div><h2 id="boot-nuttx"><a class="doc-anchor" href="#boot-nuttx">§</a>4.3 Boot NuttX</h2>
<p>After flashing, we switch BL602 back to <strong>Normal Mode</strong> by flipping GPIO 2 and 3…</p>
<div class="example-wrap"><pre class="language-text"><code>Set GPIO 2 to Low (BL602 Normal Mode)
Toggle GPIO 3 High-Low-High (Reset BL602)
BL602 is now in Normal Mode
Toggle GPIO 3 High-Low-High (Reset BL602)</code></pre></div>
<p>BL602 boots the NuttX Firmware and starts the <strong>NuttX Shell</strong>…</p>
<div class="example-wrap"><pre class="language-text"><code>----- Here is the BL602 Output...
gpio_pin_register: Registering /dev/gpio0
gpio_pin_register: Registering /dev/gpio1
gpint_enable: Disable the interrupt
gpio_pin_register: Registering /dev/gpio2
bl602_spi_setfrequency: frequency=400000, actual=0
bl602_spi_setbits: nbits=8
bl602_spi_setmode: mode=0
NuttShell (NSH) NuttX-10.2.0
nsh></code></pre></div><h2 id="test-nuttx"><a class="doc-anchor" href="#test-nuttx">§</a>4.4 Test NuttX</h2>
<p>Our script <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L106-L111"><strong>sends a Test Command</strong></a> to BL602 and the NuttX Shell…</p>
<div class="example-wrap"><pre class="language-text"><code>----- Send command to BL602: lorawan_test
lorawan_test
nsh: lorawan_test: command not found
nsh></code></pre></div>
<p><strong>lorawan_test</strong> is missing because the Upstream Build doesn’t include the LoRaWAN Stack.</p>
<p>But that’s OK, we’ll see LoRaWAN in action when we test the Release Build of NuttX.</p>
<div class="example-wrap"><pre class="language-text"><code>===== Boot OK</code></pre></div>
<p>Our script <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L113-L134"><strong>analyses the output</strong></a> and determines that NuttX has booted successfully.</p>
<p>We’re done with the <strong>simplest scenario</strong> for Auto Flash and Test! Now we have a quick and nifty way to discover if Today’s Upstream Build of NuttX boots OK on BL602.</p>
<p><a href="https://github.com/lupyuen/nuttx/releases">(I run the script every day to check the stability of the BL602 build)</a></p>
<p><img src="https://lupyuen.github.io/images/auto-remote.jpg" alt="Flash & Test NuttX on BL602… Remotely from a Phone!" /></p>
<h1 id="nuttx-crash-analysis"><a class="doc-anchor" href="#nuttx-crash-analysis">§</a>5 NuttX Crash Analysis</h1>
<p><em>What happens when NuttX crashes during testing?</em></p>
<p>NuttX shows a <strong>Stack Trace</strong> like this…</p>
<p><img src="https://lupyuen.github.io/images/auto-stack.jpg" alt="NuttX Stack Trace" /></p>
<p><a href="https://github.com/lupyuen/nuttx/releases/tag/upstream-2022-01-17">(Source)</a></p>
<p>Let’s walk through the steps to <strong>decode the Stack Trace</strong>, then we’ll learn how our script decodes the Stack Trace for us.</p>
<h2 id="decode-stack-trace"><a class="doc-anchor" href="#decode-stack-trace">§</a>5.1 Decode Stack Trace</h2>
<p>At the top is the <strong>Assertion Failure</strong> message…</p>
<div class="example-wrap"><pre class="language-text"><code>irq_unexpected_isr: ERROR irq: 1
up_assert: Assertion failed at file:irq/irq_unexpectedisr.c line: 51 task: Idle Task</code></pre></div>
<p><strong>Always enable Debug Assertions</strong> in our NuttX Build Configuration. They are super helpful for catching problems. <a href="https://lupyuen.github.io/articles/spi2#enable-logging">(Here’s how)</a></p>
<p>Next we see the <strong>Register Dump</strong>…</p>
<div class="example-wrap"><pre class="language-text"><code>riscv_registerdump: EPC: deadbeee
riscv_registerdump: A0: 00000002 A1: 420146b0 A2: 42015140 A3: 420141c
riscv_registerdump: A4: 420150d0 A5: 00000000 A6: 00000002 A7: 00000000
riscv_registerdump: T0: 00006000 T1: 00000003 T2: 41bd5588 T3: 00000064
riscv_registerdump: T4: 00000000 T5: 00000000 T6: c48ae7e4
riscv_registerdump: S0: deadbeef S1: deadbeef S2: 420146b0 S3: 42014000
riscv_registerdump: S4: 42015000 S5: 42012510 S6: 00000001 S7: 23007000
riscv_registerdump: S8: 4201fa38 S9: 00000001 S10: 00000c40 S11: 42010510
riscv_registerdump: SP: 420126b0 FP: deadbeef TP: 0c8a646d RA: deadbeef</code></pre></div>
<p>Followed by the <strong>Interrupt Stack</strong>…</p>
<div class="example-wrap"><pre class="language-text"><code>riscv_dumpstate: sp: 420144b0
riscv_dumpstate: IRQ stack:
riscv_dumpstate: base: 42012540
riscv_dumpstate: size: 00002000</code></pre></div>
<p>The <strong>Stack Dump</strong>…</p>
<div class="example-wrap"><pre class="language-text"><code>riscv_stackdump: 420144a0: 00001fe0 23011000 420144f0 230053a0 deadbeef deadbeef 23010ca4 00000033
riscv_stackdump: 420144c0: deadbeef 00000001 4201fa38 23007000 00000001 42012510 42015000 00000001
riscv_stackdump: 420144e0: 420125a8 42014000 42014500 230042e2 42014834 80007800 42014510 23001d3e
riscv_stackdump: 42014500: 420171c0 42014000 42014520 23001cdc deadbeef deadbeef 42014540 23000db4
riscv_stackdump: 42014520: deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 00000000 23000d04</code></pre></div>
<p>The <strong>User Stack</strong>…</p>
<div class="example-wrap"><pre class="language-text"><code>riscv_dumpstate: sp: 420126b0
riscv_dumpstate: User stack:
riscv_dumpstate: base: 42010530
riscv_dumpstate: size: 00001fe0</code></pre></div>
<p>Finally the <strong>Task List</strong>…</p>
<div class="example-wrap"><pre class="language-text"><code>riscv_showtasks: PID PRI USED STACK FILLED COMMAND
riscv_showtasks: ---- ---- 8088 8192 98.7%! irq
riscv_dump_task: 0 0 436 8160 5.3% Idle Task
riscv_dump_task: 1 100 516 8144 6.3% nsh_main</code></pre></div>
<p>(The Interrupt Stack <strong>irq</strong> seems to be overflowing, it might have caused NuttX to crash)</p>
<p>In a while we’ll select the interesting addresses from above and decode them.</p>
<p><img src="https://lupyuen.github.io/images/auto-crash2.png" alt="Stack Overflow?" /></p>
<h2 id="disassemble-the-firmware"><a class="doc-anchor" href="#disassemble-the-firmware">§</a>5.2 Disassemble The Firmware</h2>
<p>Before decoding the addresses, let’s prepare the <strong>RISC-V Disassembly</strong> of our BL602 Firmware…</p>
<div class="example-wrap"><pre class="language-bash"><code>## Dump the disassembly to nuttx.S
riscv64-unknown-elf-objdump \
-t -S --demangle --line-numbers --wide \
nuttx \
>nuttx.S \
2>&1</code></pre></div>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602.yml#L109-L114">(Source)</a></p>
<p>This generates the Disassembly File <strong>nuttx.S</strong>, which we’ll use in the next step.</p>
<p><a href="https://github.com/lupyuen/nuttx/releases/download/upstream-2022-01-17/nuttx.zip">(Here’s a sample <strong>nuttx.S</strong>)</a></p>
<h2 id="decode-addresses"><a class="doc-anchor" href="#decode-addresses">§</a>5.3 Decode Addresses</h2>
<p>From the Stack Trace above, we look for <strong>Code and Data Addresses</strong> and decode them…</p>
<ul>
<li>
<p><strong>BL602 Code Addresses</strong> have the form <strong><code>23xxxxxx</code></strong></p>
</li>
<li>
<p><strong>BL602 Data Addresses</strong> have the form <strong><code>42xxxxxx</code></strong></p>
</li>
</ul>
<p>Let’s pick a Code Address: <strong><code>230053a0</code></strong></p>
<p>We search for the address in the Disassembly File <a href="https://github.com/lupyuen/nuttx/releases/download/upstream-2022-01-17/nuttx.zip"><strong>nuttx.S</strong></a> like so…</p>
<div class="example-wrap"><pre class="language-bash"><code>grep \
--context=5 \
--color=auto \
"230053a0:" \
nuttx.S</code></pre></div>
<p><a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L153-L166">(Source)</a></p>
<p>Which shows…</p>
<div class="example-wrap"><pre class="language-text"><code>nuttx/arch/risc-v/src/common/riscv_assert.c:364
if (CURRENT_REGS)
sp = CURRENT_REGS[REG_SP];</code></pre></div>
<p>This is the <strong>Source Code</strong> for address <strong><code>230053a0</code></strong>.</p>
<p>(Which is in the Assertion Handler, doesn’t look helpful)</p>
<p>Repeat this process for the <strong>other Code Addresses</strong>: <code>230042e2</code>, <code>23001cdc</code>, <code>23000db4</code>, <code>23000d04</code>, …</p>
<p>And we should have a fairly good idea how our firmware crashed.</p>
<p><a href="https://github.com/lupyuen/nuttx/releases/tag/upstream-2022-01-17">(See the results)</a></p>
<p><em>What about the Data Addresses <code>42xxxxxx</code>?</em></p>
<p>Let’s pick a Data Address: <strong><code>42012510</code></strong></p>
<p>We search for the address in the Disassembly File <a href="https://github.com/lupyuen/nuttx/releases/download/upstream-2022-01-17/nuttx.zip"><strong>nuttx.S</strong></a> like this…</p>
<div class="example-wrap"><pre class="language-bash"><code>grep \
--color=auto \
"^42012510" \
nuttx.S \
| grep -v "noinit"</code></pre></div>
<p><a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L177-L190">(Source)</a></p>
<p>Which shows…</p>
<div class="example-wrap"><pre class="language-text"><code>42012510 ... g_idleargv</code></pre></div>
<p>This says that <strong>g_idleargv</strong> is the name of the variable at address <strong><code>42012510</code></strong>.</p>
<p><img src="https://lupyuen.github.io/images/auto-stack2.png" alt="Auto Crash Analysis" /></p>
<p><a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L136-L194">(Source)</a></p>
<h2 id="auto-analysis"><a class="doc-anchor" href="#auto-analysis">§</a>5.4 Auto Analysis</h2>
<p><em>Decoding a NuttX Stack Trace looks mighty tedious!</em></p>
<p>Thankfully our <strong>Auto Flash and Test</strong> Script automates everything for us!</p>
<ul>
<li>
<p>When our script detects that <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L100-L103"><strong>NuttX has crashed</strong></a>…</p>
</li>
<li>
<p>It searches for all <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L143-L151"><strong>BL602 Code Addresses</strong></a> in the NuttX Stack Trace</p>
</li>
<li>
<p>And shows the <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L153-L166"><strong>matching Source Code</strong></a> for the Code Addresses</p>
</li>
<li>
<p>It does the same to <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L168-L190"><strong>decode BL602 Data Addresses</strong></a></p>
</li>
<li>
<p>RISC-V Disassembly for the NuttX Firmware is <a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602.yml#L109-L114"><strong>generated by GitHub Actions</strong></a> during the Daily Upstream Build</p>
</li>
</ul>
<p>Here’s a demo of Auto Flash and Test with <strong>Auto Crash Analysis</strong>…</p>
<ul>
<li>
<p><a href="https://www.youtube.com/watch?v=Kf3G1hGoLIs"><strong>Watch the demo on YouTube</strong></a></p>
</li>
<li>
<p><a href="https://github.com/lupyuen/nuttx/releases/tag/upstream-2022-01-17"><strong>See the Output Log</strong></a></p>
</li>
</ul>
<p>The <strong>Source Code</strong> decoded from a Stack Trace looks like this…</p>
<p><img src="https://lupyuen.github.io/images/auto-stack3.png" alt="Source Code decoded from Stack Trace" /></p>
<p><a href="https://github.com/lupyuen/nuttx/releases/tag/upstream-2022-01-17">(Source)</a></p>
<p>These are the <strong>Data Addresses</strong> decoded from the Stack Trace…</p>
<p><img src="https://lupyuen.github.io/images/auto-stack4.jpg" alt="Data Addresses in Stack Trace" /></p>
<p><a href="https://github.com/lupyuen/nuttx/releases/tag/upstream-2022-01-17">(Source)</a></p>
<p>There’s a <strong>Design Flaw</strong> in our script that needs fixing… It doesn’t detect crashes while running the SPI, LoRaWAN and Touch Panel Tests. <a href="https://gist.github.com/lupyuen/02764452fde605e04b626614be4562ed">(See this)</a></p>
<p>(We should probably use a <strong>State Machine</strong> instead of a long chain of hacky “if-else” statements)</p>
<h1 id="lorawan-test"><a class="doc-anchor" href="#lorawan-test">§</a>6 LoRaWAN Test</h1>
<p><em>What’s the best way to auto-test all the NuttX functions: GPIO, SPI, ADC, Interrupts, Timers, Threads, Message Queues, Random Number Generator, …?</em></p>
<p><a href="https://lupyuen.github.io/articles/lorawan3"><strong>LoRaWAN</strong></a> is the perfect way to give NuttX a <strong>thorough workout</strong>!</p>
<ul>
<li>
<p><strong>GPIO Input</strong>: LoRaWAN reads a GPIO Input to poll the <a href="https://lupyuen.github.io/articles/sx1262#check-busy-state"><strong>Busy State</strong></a> of the LoRa Transceiver</p>
</li>
<li>
<p><strong>GPIO Output</strong>: <a href="https://lupyuen.github.io/articles/sx1262#initialise-spi"><strong>Chip Select</strong></a> for the LoRa Transceiver</p>
</li>
<li>
<p><strong>GPIO Interrupt</strong>: Triggered by LoRa Transceiver when a <a href="https://lupyuen.github.io/articles/sx1262#handle-dio1-interrupt"><strong>LoRa Packet is received</strong></a></p>
</li>
<li>
<p><strong>SPI</strong>: LoRa Transceiver talks on the <a href="https://lupyuen.github.io/articles/sx1262#initialise-spi"><strong>SPI Bus</strong></a></p>
</li>
<li>
<p><strong>ADC</strong>: Used by the Internal Temperature Sensor (See below)</p>
</li>
<li>
<p><strong>Timer</strong>: Triggers the <a href="https://lupyuen.github.io/articles/lorawan3#message-interval"><strong>periodic sending</strong></a> of Data Packets</p>
</li>
<li>
<p><strong>Message Queue</strong>: Handles <a href="https://lupyuen.github.io/articles/sx1262#event-queue"><strong>Transmit / Receive / Timeout Events</strong></a></p>
</li>
<li>
<p><strong>PThread</strong>: LoRaWAN handles events with a <a href="https://lupyuen.github.io/articles/sx1262#start-dio1-thread"><strong>Background Thread</strong></a></p>
</li>
<li>
<p><strong>Strong Random Number Generator</strong>: Generates non-repeating <a href="https://lupyuen.github.io/articles/lorawan3#lorawan-nonce"><strong>LoRaWAN Nonces</strong></a></p>
</li>
<li>
<p><strong>Internal Temperature Sensor</strong>: Seeds the Entropy Pool for the Random Number Generator <a href="https://lupyuen.github.io/articles/auto#appendix-fix-lorawan-nonce">(Here’s why)</a></p>
</li>
</ul>
<p>We shall run this <strong>LoRaWAN Stack</strong> to connect to the LoRaWAN Network (ChirpStack) and transmit a Data Packet…</p>
<ul>
<li><a href="https://lupyuen.github.io/articles/lorawan3"><strong>“LoRaWAN on Apache NuttX OS”</strong></a></li>
</ul>
<p>To run the <strong>LoRaWAN Auto-Test</strong> we switch to the <strong>Release Build</strong> (instead of the Upstream Build)…</p>
<div class="example-wrap"><pre class="language-bash"><code>## Download the Release Build (instead of the Upstream Build)
export BUILD_PREFIX=release
## Download this date of the build
export BUILD_DATE=2022-01-19
## Run the script
remote-bl602/scripts/test.sh</code></pre></div>
<p>(Release Build includes the LoRaWAN Stack)</p>
<p>After booting NuttX, our script sends the <strong>Test LoRaWAN</strong> command to the NuttX Shell: <a href="https://github.com/lupyuen/remote-bl602/blob/main/scripts/test.sh#L106-L116">test.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## If BL602 has not crashed, send the test command to BL602
echo "lorawan_test" >/dev/ttyUSB0
## Wait a while for the test command to run
sleep 30
## Check whether BL602 has joined the LoRaWAN Network
set +e ## Don't exit when any command fails
match=$(grep "JOINED" /tmp/test.log)
set -e ## Exit when any command fails</code></pre></div>
<p>And it watches for this output message…</p>
<div class="example-wrap"><pre class="language-text"><code>###### =========== MLME-Confirm ============ ######
STATUS: OK
###### =========== JOINED ============ ######</code></pre></div>
<p><a href="https://github.com/lupyuen/nuttx/releases/tag/release-2022-01-19">(Source)</a></p>
<p>Which means that BL602 has successfully joined the <strong>LoRaWAN Network</strong>…</p>
<div class="example-wrap"><pre class="language-text"><code>===== All OK! BL602 has successfully joined the LoRaWAN Network</code></pre></div>
<p><a href="https://github.com/lupyuen/nuttx/releases/tag/release-2022-01-19">(Source)</a></p>
<p>And everything has tested OK on NuttX!</p>
<p><img src="https://lupyuen.github.io/images/auto-lorawan2.png" alt="BL602 successfully joins the LoRaWAN Network" /></p>
<p><a href="https://github.com/lupyuen/nuttx/releases/tag/release-2022-01-19">(Source)</a></p>
<p>Here’s the demo of the <strong>LoRaWAN Auto-Test</strong>…</p>
<ul>
<li>
<p><a href="https://www.youtube.com/watch?v=JtnOyl5cYjo"><strong>Watch the demo on YouTube</strong></a></p>
</li>
<li>
<p><a href="https://github.com/lupyuen/nuttx/releases/tag/release-2022-01-19"><strong>See the Output Log</strong></a></p>
</li>
</ul>
<p><img src="https://lupyuen.github.io/images/auto-lorawan.png" alt="LoRaWAN Auto-Test" /></p>
<p><a href="https://github.com/lupyuen/nuttx/releases/tag/release-2022-01-19">(Source)</a></p>
<h1 id="merge-updates-from-nuttx"><a class="doc-anchor" href="#merge-updates-from-nuttx">§</a>7 Merge Updates From NuttX</h1>
<p><em>Back to our original question: Why are we doing all this?</em></p>
<p>My situation is kinda complicated, I need to worry about <strong>3 branches</strong> of the NuttX Code…</p>
<ul>
<li>
<p><strong>Upstream Branch</strong>: Daily Upstream Updates from from the <a href="https://github.com/apache/nuttx"><strong>master branch</strong></a> of Apache’s NuttX Repo</p>
<p>(Without the LoRaWAN Stack)</p>
</li>
<li>
<p><strong>Release Branch</strong>: This is the <a href="https://github.com/lupyuen/nuttx"><strong>master branch</strong></a> of my repo that I reference in my NuttX Articles</p>
<p>(Includes the LoRaWAN Stack)</p>
</li>
<li>
<p><strong>Downstream Branch</strong>: This is the <a href="https://github.com/lupyuen/nuttx/tree/downstream"><strong>downstream branch</strong></a> of my repo that merges the updates from the above 2 branches</p>
<p>(Includes the LoRaWAN Stack)</p>
</li>
</ul>
<p>This is how we keep them <strong>in sync</strong>…</p>
<p><img src="https://lupyuen.github.io/images/auto-merge.jpg" alt="Merge Updates From NuttX" /></p>
<ol>
<li>
<p>We <strong>build Upstream NuttX</strong> every day with GitHub Actions. <a href="https://lupyuen.github.io/articles/auto#appendix-build-nuttx-with-github-actions">(See this)</a></p>
<p>We run our <strong>Auto Flash and Test</strong> Script daily to check if the build boots OK on BL602.</p>
<p>(Upstream NuttX doesn’t include the LoRaWAN Stack)</p>
</li>
<li>
<p>If the Upstream Build is OK, we <strong>merge Upstream NuttX</strong> into our Downstream Branch.</p>
</li>
<li>
<p>We also <strong>merge the Release Branch</strong> (from our previous NuttX Article) to the Downstream Branch.</p>
<p>(Which includes the LoRaWAN Stack)</p>
</li>
<li>
<p>After merging the branches, we run <strong>Auto Flash and Test</strong> to verify that LoRaWAN runs OK on BL602.</p>
</li>
<li>
<p>If LoRaWAN runs OK, we <strong>merge the Downstream Branch</strong> to the Release Branch.</p>
</li>
<li>
<p>We run <strong>Auto Flash and Test</strong> one last time on the Release Branch to be really sure that LoRaWAN is still OK.</p>
</li>
<li>
<p>We feature the <strong>updated Release Branch</strong> in our next NuttX Article.</p>
</li>
</ol>
<p>Looks complicated, but that’s how we keep our NuttX Articles in sync with the latest updates from Upstream NuttX.</p>
<p>(Which ensures that the code in our NuttX Articles won’t go obsolete too soon)</p>
<p><em>How do we run Auto Flash and Test on the Downstream Build?</em></p>
<p>Like this…</p>
<div class="example-wrap"><pre class="language-bash"><code>## Download the Downstream Build (instead of the Upstream Build)
export BUILD_PREFIX=downstream
## Download this date of the build
export BUILD_DATE=2022-01-19
## Run the script
remote-bl602/scripts/test.sh</code></pre></div>
<p><a href="https://github.com/lupyuen/nuttx/releases/tag/downstream-2022-01-19">(See the output)</a></p>
<p><em>Can we solve this by merging the LoRaWAN Stack upstream?</em></p>
<p>The LoRaWAN Stack is <strong>not ready to be upstreamed</strong> because it uses different Coding Conventions. <a href="https://lupyuen.github.io/articles/lorawan3#notes">(See this)</a></p>
<p>Even if we could, we would need an <strong>automated, remote way to test</strong> if the LoRaWAN Stack is still working when there are changes to Upstream NuttX.</p>
<p>(Our Auto Flash and Test Script would be super helpful here)</p>
<p>But for now… No more worries about merging hundreds of upstream commits (and thousands of changed files) into our NuttX Repo! 👍</p>
<p><img src="https://lupyuen.github.io/images/auto-merge.png" alt="Merge updates from upstream" /></p>
<p><a href="https://github.com/lupyuen/nuttx/pull/21">(Source)</a></p>
<h1 id="whats-next"><a class="doc-anchor" href="#whats-next">§</a>8 What’s Next</h1>
<p><a href="https://lupyuen.github.io/articles/auto2"><strong>UPDATE:</strong> Check out the new article on Automated Testing for PineDio Stack BL604</a></p>
<p>After 14 months of flipping the jumper and smashing the button on BL602, I’m so glad we have an automated way to Flash and Test BL602!</p>
<p>I hope the Flash and Test Script will make your NuttX Development more productive on BL602… Possibly on other microcontrollers too!</p>
<p>Many Thanks to my <a href="https://lupyuen.github.io/articles/sponsor"><strong>GitHub Sponsors</strong></a> for supporting my work! This article wouldn’t have been possible without your support.</p>
<ul>
<li>
<p><a href="https://lupyuen.github.io/articles/sponsor">Sponsor me a coffee</a></p>
</li>
<li>
<p><a href="https://www.reddit.com/r/RISCV/comments/sbzwon/auto_flash_and_test_nuttx_on_riscv_bl602/">Discuss this article on Reddit</a></p>
</li>
<li>
<p><a href="https://lupyuen.github.io/articles/book">Read “The RISC-V BL602 / BL604 Book”</a></p>
</li>
<li>
<p><a href="https://lupyuen.github.io">Check out my articles</a></p>
</li>
<li>
<p><a href="https://lupyuen.github.io/rss.xml">RSS Feed</a></p>
</li>
</ul>
<p><em>Got a question, comment or suggestion? Create an Issue or submit a Pull Request here…</em></p>
<p><a href="https://github.com/lupyuen/lupyuen.github.io/blob/master/src/auto.md"><code>lupyuen.github.io/src/auto.md</code></a></p>
<h1 id="notes"><a class="doc-anchor" href="#notes">§</a>9 Notes</h1>
<ol>
<li>This article is the expanded version of <a href="https://twitter.com/MisterTechBlog/status/1482152780051935238">this Twitter Thread</a></li>
</ol>
<p><img src="https://lupyuen.github.io/images/auto-workflow.jpg" alt="Building NuttX with GitHub Actions" /></p>
<h1 id="appendix-build-nuttx-with-github-actions"><a class="doc-anchor" href="#appendix-build-nuttx-with-github-actions">§</a>10 Appendix: Build NuttX with GitHub Actions</h1>
<p>We auto-build the Upstream (Apache) version of NuttX every day with <strong>GitHub Actions</strong>, producing these files…</p>
<ul>
<li>
<p><strong>nuttx</strong>: Firmware in ELF Format</p>
</li>
<li>
<p><strong>nuttx.bin</strong>: Firmware Binary to be flashed</p>
</li>
<li>
<p><strong>nuttx.S</strong>: RISC-V Disassembly for the firmware</p>
</li>
<li>
<p><strong>nuttx.map</strong>: Linker Map for the firmware</p>
</li>
<li>
<p><strong>nuttx.config</strong>: Build Configuration (from .config)</p>
</li>
</ul>
<p>Which are consumed by our Flash and Test Script.</p>
<p>In this section we study the workflow for the Upstream Build…</p>
<ul>
<li><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602.yml"><strong>Upstream Build:</strong> .github/workflows/bl602.yml</a></li>
</ul>
<p>Similar workflows are used for the Release and Downstream Builds…</p>
<ul>
<li>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602-commit.yml"><strong>Release Build:</strong> .github/workflows/bl602-commit.yml</a></p>
</li>
<li>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602-downstream.yml"><strong>Downstream Build:</strong> .github/workflows/bl602-downstream.yml</a></p>
</li>
</ul>
<h2 id="build-schedule"><a class="doc-anchor" href="#build-schedule">§</a>10.1 Build Schedule</h2>
<p>The Upstream Build is scheduled <strong>every day at 0:30 UTC</strong>: <a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602.yml">bl602.yml</a></p>
<div class="example-wrap"><pre class="language-yaml"><code>name: BL602 Upstream
on:
## Run every day at 0:30 UTC, because 0:00 UTC seems too busy for the scheduler
schedule:
- cron: '30 0 * * *'</code></pre></div>
<p>(The build will actually start at around <strong>1:45 UTC</strong>, depending on the available server capacity at GitHub Actions)</p>
<p>Note that the scheduled run is <strong>not guaranteed</strong>, it may be cancelled if GitHub Actions is too busy. <a href="https://github.community/t/no-assurance-on-scheduled-jobs/133753/2">(See this)</a></p>
<h2 id="install-build-tools"><a class="doc-anchor" href="#install-build-tools">§</a>10.2 Install Build Tools</h2>
<p>First we install the <strong>Build Tools</strong> needed by NuttX…</p>
<div class="example-wrap"><pre class="language-yaml"><code>jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install Build Tools
run: |
sudo apt -y update
sudo apt -y install \
bison flex gettext texinfo libncurses5-dev libncursesw5-dev \
gperf automake libtool pkg-config build-essential gperf genromfs \
libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \
libexpat-dev gcc-multilib g++-multilib u-boot-tools util-linux \
kconfig-frontends \
wget</code></pre></div><h2 id="install-toolchain"><a class="doc-anchor" href="#install-toolchain">§</a>10.3 Install Toolchain</h2>
<p>We download the <strong>RISC-V GCC Toolchain</strong> (riscv64-unknown-elf-gcc) hosted at SiFive…</p>
<div class="example-wrap"><pre class="language-yaml"><code> - name: Install Toolchain
run: |
wget https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14.tar.gz
tar -xf riscv64-unknown-elf-gcc*.tar.gz</code></pre></div><h2 id="checkout-source-files"><a class="doc-anchor" href="#checkout-source-files">§</a>10.4 Checkout Source Files</h2>
<p>We checkout the <strong>NuttX Source Files</strong> from the Apache repo…</p>
<div class="example-wrap"><pre class="language-yaml"><code> - name: Checkout Source Files
run: |
mkdir nuttx
cd nuttx
git clone https://github.com/apache/nuttx nuttx
git clone https://github.com/apache/nuttx-apps apps</code></pre></div>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602-commit.yml#L37-L42">(For Release and Downstream Builds we checkout from the repo <strong>lupyuen/nuttx</strong>)</a></p>
<p>We’re almost ready to build NuttX, but first we configure the NuttX Build.</p>
<p><img src="https://lupyuen.github.io/images/auto-workflow2.png" alt="Enable errors, warnings, info messages and assertions" /></p>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602.yml#L50-L114">(Source)</a></p>
<h2 id="configure-build"><a class="doc-anchor" href="#configure-build">§</a>10.5 Configure Build</h2>
<p>For the NuttX Build we <strong>configure BL602</strong> as the target…</p>
<div class="example-wrap"><pre class="language-yaml"><code> - name: Build
run: |
## Add toolchain to PATH
export PATH=$PATH:$PWD/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14/bin
cd nuttx/nuttx
## Configure the build
./tools/configure.sh bl602evb:nsh</code></pre></div>
<p>This creates the Build Config File <strong>.config</strong>.</p>
<p>Then we tweak the Build Config to show <strong>Errors, Warnings, Info Messages and Assertions</strong>…</p>
<div class="example-wrap"><pre class="language-yaml"><code> ## Enable errors, warnings, info messages and assertions
kconfig-tweak --enable CONFIG_DEBUG_ERROR
kconfig-tweak --enable CONFIG_DEBUG_WARN
kconfig-tweak --enable CONFIG_DEBUG_INFO
kconfig-tweak --enable CONFIG_DEBUG_ASSERTIONS
## Enable GPIO errors, warnings and info messages
kconfig-tweak --enable CONFIG_DEBUG_GPIO
kconfig-tweak --enable CONFIG_DEBUG_GPIO_ERROR
kconfig-tweak --enable CONFIG_DEBUG_GPIO_WARN
kconfig-tweak --enable CONFIG_DEBUG_GPIO_INFO
## Enable SPI errors, warnings and info messages
kconfig-tweak --enable CONFIG_DEBUG_SPI
kconfig-tweak --enable CONFIG_DEBUG_SPI_ERROR
kconfig-tweak --enable CONFIG_DEBUG_SPI_WARN
kconfig-tweak --enable CONFIG_DEBUG_SPI_INFO</code></pre></div>
<p><a href="https://lupyuen.github.io/articles/spi2#enable-logging">(See this)</a></p>
<p>We enable <strong>Floating Point, Stack Canaries</strong> and 2 commands: <strong>“help” and “ls”</strong>…</p>
<div class="example-wrap"><pre class="language-yaml"><code> ## Enable Floating Point
kconfig-tweak --enable CONFIG_LIBC_FLOATINGPOINT
## Enable Compiler Stack Canaries
kconfig-tweak --enable CONFIG_STACK_CANARIES
## Enable NuttX Shell commands: help, ls
kconfig-tweak --disable CONFIG_NSH_DISABLE_HELP
kconfig-tweak --disable CONFIG_NSH_DISABLE_LS</code></pre></div>
<p>We enable the <strong>GPIO Driver and Test App</strong>…</p>
<div class="example-wrap"><pre class="language-yaml"><code> ## Enable GPIO
kconfig-tweak --enable CONFIG_DEV_GPIO
kconfig-tweak --set-val CONFIG_DEV_GPIO_NSIGNALS 1
## Enable GPIO Test App
kconfig-tweak --enable CONFIG_EXAMPLES_GPIO
kconfig-tweak --set-str CONFIG_EXAMPLES_GPIO_PROGNAME "gpio"
kconfig-tweak --set-val CONFIG_EXAMPLES_GPIO_PRIORITY 100
kconfig-tweak --set-val CONFIG_EXAMPLES_GPIO_STACKSIZE 2048</code></pre></div>
<p><a href="https://lupyuen.github.io/articles/nuttx#enable-gpio-driver">(See this)</a></p>
<p>We enable the <strong>BL602 SPI Driver</strong>…</p>
<div class="example-wrap"><pre class="language-yaml"><code> ## Enable SPI
kconfig-tweak --enable CONFIG_BL602_SPI0
kconfig-tweak --enable CONFIG_SPI
kconfig-tweak --enable CONFIG_SPI_EXCHANGE
kconfig-tweak --enable CONFIG_SPI_DRIVER</code></pre></div>
<p><a href="https://lupyuen.github.io/articles/spi2#enable-spi">(See this)</a></p>
<p>Finally we copy the Build Config to <strong>nuttx.config</strong> so that we may download and inspect later…</p>
<div class="example-wrap"><pre class="language-yaml"><code> ## Preserve the build config
cp .config nuttx.config</code></pre></div>
<p>We’re ready to build NuttX!</p>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602-commit.yml#L130-L217">(For Release and Downstream Builds we also enable the LoRaWAN Stack)</a></p>
<p><img src="https://lupyuen.github.io/images/auto-workflow3.jpg" alt="For the Release and Downstream Builds we also enable the LoRaWAN Stack" /></p>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602-commit.yml#L130-L217">(Source)</a></p>
<h2 id="build-nuttx"><a class="doc-anchor" href="#build-nuttx">§</a>10.6 Build NuttX</h2>
<p>This builds the <strong>NuttX Firmware</strong>…</p>
<div class="example-wrap"><pre class="language-yaml"><code> ## Run the build
make</code></pre></div>
<p>Which creates the Firmware Binary <strong>nuttx.bin</strong> (for flashing) and the Firmware ELF <strong>nuttx</strong>.</p>
<p>(The build completes in under 3 minutes)</p>
<p>We dump the <strong>RISC-V Disassembly</strong> of the Firmware ELF to <strong>nuttx.S</strong>…</p>
<div class="example-wrap"><pre class="language-yaml"><code> ## Dump the disassembly to nuttx.S
riscv64-unknown-elf-objdump \
-t -S --demangle --line-numbers --wide \
nuttx \
>nuttx.S \
2>&1</code></pre></div>
<p><strong>nuttx.S</strong> will be used by our Flash and Test Script to do Crash Analysis.</p>
<h2 id="upload-build-outputs"><a class="doc-anchor" href="#upload-build-outputs">§</a>10.7 Upload Build Outputs</h2>
<p>We upload all <strong>Build Outputs</strong> (including the Build Config <strong>nuttx.config</strong>) as Artifacts so that we may download later…</p>
<div class="example-wrap"><pre class="language-yaml"><code> - name: Upload Build Outputs
uses: actions/upload-artifact@v2
with:
name: nuttx.zip
path: nuttx/nuttx/nuttx*</code></pre></div>
<p>The NuttX Build Outputs are now available for downloading as Artifacts, but they are <strong>protected by GitHub Login</strong>.</p>
<p>To allow our Flash and Test Script to access the files without GitHub Authentication, we publish the files as a <strong>GitHub Release</strong>…</p>
<h2 id="publish-release"><a class="doc-anchor" href="#publish-release">§</a>10.8 Publish Release</h2>
<p>The final task in our GitHub Actions workflow is to publish the NuttX Build Outputs as a <strong>GitHub Release</strong>.</p>
<p>(Which will be downloaded by our Flash and Test Script)</p>
<p>Let’s run through the steps to <strong>publish a GitHub Release</strong> that looks like this…</p>
<ul>
<li><a href="https://github.com/lupyuen/nuttx/releases/tag/upstream-2022-01-19"><strong>upstream-2022-01-19</strong></a></li>
</ul>
<p>First we zip the NuttX Build Outputs into <strong>nuttx.zip</strong>…</p>
<div class="example-wrap"><pre class="language-yaml"><code> - name: Zip Build Outputs
run: |
cd nuttx/nuttx
zip nuttx.zip nuttx*</code></pre></div>
<p>Next we get the Current Date: <strong>2022-01-19</strong></p>
<div class="example-wrap"><pre class="language-yaml"><code> - name: Get Current Date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"</code></pre></div>
<p>We create a <strong>Draft Release</strong> tagged as <strong>upstream-2022-01-19</strong>…</p>
<div class="example-wrap"><pre class="language-yaml"><code> - name: Create Draft Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: upstream-${{ steps.date.outputs.date }}
release_name: upstream-${{ steps.date.outputs.date }}
draft: true
prerelease: false</code></pre></div>
<p>We upload <strong>nuttx.zip</strong> to the Draft Release…</p>
<div class="example-wrap"><pre class="language-yaml"><code> - name: Upload Release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: nuttx/nuttx/nuttx.zip
asset_name: nuttx.zip
asset_content_type: application/zip</code></pre></div>
<p>And <strong>publish the Release</strong>…</p>
<div class="example-wrap"><pre class="language-yaml"><code> - name: Publish Release
uses: eregon/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ steps.create_release.outputs.id }}</code></pre></div>
<p>The end! That’s how we build Upstream NuttX every day and publish the Build Outputs.</p>
<p>Check out the workflows for the <strong>Release and Downstream</strong> Builds…</p>
<ul>
<li>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602-commit.yml"><strong>Release Build:</strong> .github/workflows/bl602-commit.yml</a></p>
</li>
<li>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602-downstream.yml"><strong>Downstream Build:</strong> .github/workflows/bl602-downstream.yml</a></p>
</li>
</ul>
<p><em>How are they different from the Upstream Build?</em></p>
<p>The <strong>Release and Downstream</strong> Builds…</p>
<ul>
<li>
<p>Are <strong>triggered by commits</strong> to the Release (master) and Downstream Branches (instead of scheduled time)</p>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602-commit.yml#L5-L14">(See this)</a></p>
</li>
<li>
<p>Checkout the Source Files from a different repo: <strong>lupyuen/nuttx</strong></p>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602-commit.yml#L37-L42">(See this)</a></p>
</li>
<li>
<p>Enable the <strong>LoRaWAN Stack</strong></p>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602-commit.yml#L130-L217">(See this)</a></p>
</li>
<li>
<p>Update the <strong>BL602 Pin Definitions</strong> to accommodate the Semtech SX1262 LoRa Transceiver</p>
<p><a href="https://github.com/lupyuen/nuttx/blob/master/.github/workflows/bl602-commit.yml#L44-L80">(See this)</a></p>
</li>
</ul>
<p><img src="https://lupyuen.github.io/images/auto-nonce.png" alt="Duplicate LoRaWAN Nonce" /></p>
<h1 id="appendix-fix-lorawan-nonce"><a class="doc-anchor" href="#appendix-fix-lorawan-nonce">§</a>11 Appendix: Fix LoRaWAN Nonce</h1>
<p><em>What’s a LoRaWAN Nonce?</em></p>