Commit from GitHub Actions

This commit is contained in:
Lee Lup Yuen 2021-12-31 11:09:25 +00:00
parent 1a366bd791
commit 381714ee35

View file

@ -73,25 +73,30 @@
<li><a href="#device-eui-join-eui-and-app-key">4 Device EUI, Join EUI and App Key</a><ul>
<li><a href="#secure-element">4.1 Secure Element</a><ul></ul></li></ul></li>
<li><a href="#lorawan-frequency">5 LoRaWAN Frequency</a><ul></ul></li>
<li><a href="#run-the-firmware">6 Run The Firmware</a><ul></ul></li>
<li><a href="#join-network">7 Join Network</a><ul></ul></li>
<li><a href="#send-data">8 Send Data</a><ul></ul></li>
<li><a href="#event-loop">9 Event Loop</a><ul></ul></li>
<li><a href="#lorawan-nonce">10 LoRaWAN Nonce</a><ul></ul></li>
<li><a href="#random-number-generator">11 Random Number Generator</a><ul></ul></li>
<li><a href="#build">12 Build</a><ul></ul></li>
<li><a href="#nimble-porting-layer">13 NimBLE Porting Layer</a><ul></ul></li>
<li><a href="#gpio-interrupts">14 GPIO Interrupts</a><ul></ul></li>
<li><a href="#build-nimble">15 Build NimBLE</a><ul></ul></li>
<li><a href="#sx1262-busy">16 SX1262 Busy</a><ul></ul></li>
<li><a href="#logging">17 Logging</a><ul></ul></li>
<li><a href="#message-size">18 Message Size</a><ul></ul></li>
<li><a href="#troubleshoot-lorawan">19 Troubleshoot LoRaWAN</a><ul></ul></li>
<li><a href="#spi-with-dma">20 SPI with DMA</a><ul></ul></li>
<li><a href="#whats-next">21 Whats Next</a><ul></ul></li>
<li><a href="#notes">22 Notes</a><ul></ul></li>
<li><a href="#appendix-gpio-issue">23 Appendix: GPIO Issue</a><ul></ul></li>
<li><a href="#appendix-callout-issue">24 Appendix: Callout Issue</a><ul></ul></li></ul></nav><p>📝 <em>7 Jan 2022</em></p>
<li><a href="#build-the-firmware">6 Build The Firmware</a><ul></ul></li>
<li><a href="#run-the-firmware">7 Run The Firmware</a><ul></ul></li>
<li><a href="#join-network">8 Join Network</a><ul></ul></li>
<li><a href="#send-data">9 Send Data</a><ul></ul></li>
<li><a href="#event-loop">10 Event Loop</a><ul></ul></li>
<li><a href="#lorawan-nonce">11 LoRaWAN Nonce</a><ul></ul></li>
<li><a href="#random-number-generator">12 Random Number Generator</a><ul></ul></li>
<li><a href="#build">13 Build</a><ul></ul></li>
<li><a href="#nimble-porting-layer">14 NimBLE Porting Layer</a><ul></ul></li>
<li><a href="#gpio-interrupts">15 GPIO Interrupts</a><ul></ul></li>
<li><a href="#build-nimble">16 Build NimBLE</a><ul></ul></li>
<li><a href="#sx1262-busy">17 SX1262 Busy</a><ul></ul></li>
<li><a href="#logging">18 Logging</a><ul></ul></li>
<li><a href="#message-size">19 Message Size</a><ul></ul></li>
<li><a href="#troubleshoot-lorawan">20 Troubleshoot LoRaWAN</a><ul></ul></li>
<li><a href="#spi-with-dma">21 SPI with DMA</a><ul></ul></li>
<li><a href="#whats-next">22 Whats Next</a><ul></ul></li>
<li><a href="#notes">23 Notes</a><ul></ul></li>
<li><a href="#appendix-build-flash-and-run-nuttx">24 Appendix: Build, Flash and Run NuttX</a><ul>
<li><a href="#build-nuttx">24.1 Build NuttX</a><ul></ul></li>
<li><a href="#flash-nuttx">24.2 Flash NuttX</a><ul></ul></li>
<li><a href="#run-nuttx">24.3 Run NuttX</a><ul></ul></li></ul></li>
<li><a href="#appendix-gpio-issue">25 Appendix: GPIO Issue</a><ul></ul></li>
<li><a href="#appendix-callout-issue">26 Appendix: Callout Issue</a><ul></ul></li></ul></nav><p>📝 <em>7 Jan 2022</em></p>
<p><img src="https://lupyuen.github.io/images/lorawan3-title.jpg" alt="PineDio Stack BL604 RISC-V Board (left) talking LoRaWAN to RAKwireless WisGate LoRaWAN Gateway (right)" /></p>
<p><em>PineDio Stack BL604 RISC-V Board (left) talking LoRaWAN to RAKwireless WisGate LoRaWAN Gateway (right)</em></p>
<p>Last article we got <strong>LoRa</strong> (the long-range, low-bandwidth wireless network) running on <a href="https://lupyuen.github.io/articles/nuttx"><strong>Apache NuttX OS</strong></a></p>
@ -340,9 +345,93 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
<p>(We ought to define this parameter in Kconfig instead)</p>
</li>
</ol>
<h1 id="run-the-firmware" class="section-header"><a href="#run-the-firmware">6 Run The Firmware</a></h1>
<h1 id="build-the-firmware" class="section-header"><a href="#build-the-firmware">6 Build The Firmware</a></h1>
<p>Lets build the NuttX Firmware that contains our <strong>LoRaWAN Library</strong></p>
<ol>
<li>
<p>Install the build prerequisites…</p>
<p><a href="https://lupyuen.github.io/articles/nuttx#install-prerequisites"><strong>“Install Prerequisites”</strong></a></p>
</li>
<li>
<p>Assume that we have downloaded the NuttX Source Code with LoRaWAN Library…</p>
<p><a href="https://lupyuen.github.io/articles/lorawan3#download-source-code"><strong>“Download Source Code”</strong></a></p>
</li>
<li>
<p>Configure the build…</p>
<div class="example-wrap"><pre class="language-bash"><code>cd nuttx
# For BL602: Configure the build for BL602
./tools/configure.sh bl602evb:nsh
# For ESP32: Configure the build for ESP32.
# TODO: Change &quot;esp32-devkitc&quot; to our ESP32 board.
./tools/configure.sh esp32-devkitc:nsh
# Edit the Build Config
make menuconfig </code></pre></div></li>
<li>
<p>Enable the <strong>GPIO Driver</strong> in menuconfig…</p>
<p><a href="https://lupyuen.github.io/articles/nuttx#enable-gpio-driver"><strong>“Enable GPIO Driver”</strong></a></p>
</li>
<li>
<p>Enable the <strong>SPI Peripheral</strong>, <strong>SPI Character Driver</strong> and <strong>SPI Test Driver</strong> “/dev/spitest0”…</p>
<p><a href="https://lupyuen.github.io/articles/spi2#enable-spi"><strong>“Enable SPI”</strong></a></p>
</li>
<li>
<p>Enable <strong>GPIO and SPI Logging</strong> for easier troubleshooting, but uncheck <strong>“Enable Informational Debug Output”</strong>, <strong>“GPIO Informational Output”</strong> and <strong>“SPI Informational Output”</strong></p>
<p><a href="https://lupyuen.github.io/articles/spi2#enable-logging"><strong>“Enable Logging”</strong></a></p>
</li>
<li>
<p>TODO: Random Number Generator</p>
</li>
<li>
<p>Click <strong>“Library Routines”</strong> and enable the following libraries…</p>
<p><strong>“LoRaWAN Library”</strong></p>
<p><strong>“NimBLE Porting Layer”</strong></p>
<p><strong>“Semtech SX1262 Library”</strong></p>
</li>
<li>
<p>Enable our <strong>LoRaWAN Test App</strong></p>
<p>Check the box for <strong>“Application Configuration”</strong><strong>“Examples”</strong><strong>“LoRaWAN Test App”</strong></p>
</li>
<li>
<p>Save the configuration and exit menuconfig</p>
<p><a href="https://gist.github.com/lupyuen/d0487cda965f72ed99631d168ea4f5c8">(Heres the .config for BL604)</a></p>
</li>
<li>
<p><strong>For ESP32:</strong> Edit <a href="https://github.com/lupyuen/incubator-nuttx/blob/spi_test/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c#L118-L426"><strong>esp32_bringup.c</strong></a> to register our SPI Test Driver <a href="https://lupyuen.github.io/articles/spi2#register-device-driver">(See this)</a></p>
</li>
<li>
<p>Build, flash and run the NuttX Firmware on BL602 or ESP32…</p>
<p><a href="https://lupyuen.github.io/articles/lorawan3#appendix-build-flash-and-run-nuttx"><strong>“Build, Flash and Run NuttX”</strong></a></p>
</li>
</ol>
<h1 id="run-the-firmware" class="section-header"><a href="#run-the-firmware">7 Run The Firmware</a></h1>
<p>TODO</p>
<h1 id="join-network" class="section-header"><a href="#join-network">7 Join Network</a></h1>
<p>Finally we run the NuttX Firmware and test our <strong>LoRaWAN Library</strong></p>
<ol>
<li>
<p>In the NuttX Shell, enter…</p>
<div class="example-wrap"><pre class="language-bash"><code>ls /dev</code></pre></div>
<p>Our SPI Test Driver should appear as <strong>“/dev/spitest0”</strong></p>
<p><img src="https://lupyuen.github.io/images/spi2-newdriver10.png" alt="Our SPI Test Driver appears as “/dev/spitest0”" /></p>
</li>
<li>
<p>In the NuttX Shell, enter…</p>
<div class="example-wrap"><pre class="language-bash"><code>sx1262_test</code></pre></div></li>
<li>
<p>We should see these <strong>SX1262 Register Values</strong> (pic below)…</p>
<div class="example-wrap"><pre class="language-text"><code>Register 0x00 = 0x00
...
Register 0x08 = 0x80
Register 0x09 = 0x00
Register 0x0a = 0x01</code></pre></div>
<p><a href="https://gist.github.com/lupyuen/1e732f5b1e0e4a80d1eb351ab3aadede">(See the Output Log)</a></p>
<p>Our LoRa SX1262 Library talks OK to the SX1262 Transceiver!</p>
<p>Note that the values above will change when we <strong>transmit and receive LoRa Messages</strong>. Lets do that now.</p>
</li>
</ol>
<h1 id="join-network" class="section-header"><a href="#join-network">8 Join Network</a></h1>
<p>TODO</p>
<p>Lets connect Apache #NuttX OS to a #LoRaWAN Gateway … RAKwireless WisGate D4H with ChirpStack</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-title.jpg" alt="PineDio Stack BL604 RISC-V Board (left) talking LoRaWAN to RAKwireless WisGate LoRaWAN Gateway (right)" /></p>
@ -355,7 +444,7 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
<p>TODO56</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run3.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/a8e834e7b4267345f01b6629fb7f5e33">(Run Log)</a></p>
<h1 id="send-data" class="section-header"><a href="#send-data">8 Send Data</a></h1>
<h1 id="send-data" class="section-header"><a href="#send-data">9 Send Data</a></h1>
<p>TODO</p>
<p>Heres how we send a #LoRaWAN Data Packet on #NuttX OS … And validate the Packet Size before sending</p>
<p>TODO68</p>
@ -365,14 +454,14 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
<ul>
<li><a href="https://github.com/lupyuen/LoRaMac-node-nuttx"><strong>LoRaMac-node-nuttx</strong></a></li>
</ul>
<h1 id="event-loop" class="section-header"><a href="#event-loop">9 Event Loop</a></h1>
<h1 id="event-loop" class="section-header"><a href="#event-loop">10 Event Loop</a></h1>
<p>TODO</p>
<p>Heres our #LoRaWAN Event Loop for #NuttX OS … Implemented with NimBLE Porting Library … No more polling!</p>
<p>TODO54</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-npl1.png" alt="" /></p>
<p>TODO58</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run5a.png" alt="" /></p>
<h1 id="lorawan-nonce" class="section-header"><a href="#lorawan-nonce">10 LoRaWAN Nonce</a></h1>
<h1 id="lorawan-nonce" class="section-header"><a href="#lorawan-nonce">11 LoRaWAN Nonce</a></h1>
<p>TODO</p>
<p>Our #NuttX App resends the same Nonce to the #LoRaWAN Gateway … Which (silently) rejects the Join Request due to Duplicate Nonce … Lets fix our Random Number Generator</p>
<p>TODO34</p>
@ -390,7 +479,7 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
<p>TODO36</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-nonce7a.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/8f012856b9eb6b9a762160afd83df7f8">(Log)</a></p>
<h1 id="random-number-generator" class="section-header"><a href="#random-number-generator">11 Random Number Generator</a></h1>
<h1 id="random-number-generator" class="section-header"><a href="#random-number-generator">12 Random Number Generator</a></h1>
<p>TODO</p>
<p>For #NuttX Random Number Generator, select the Entropy Pool … To generate Strong Random Numbers for our #LoRaWAN Nonce</p>
<p>TODO35</p>
@ -398,7 +487,7 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
<p>We enable the Entropy Pool in #NuttX OS … To generate Strong Random Numbers for our #LoRaWAN Nonce</p>
<p>TODO52</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-nonce3a.png" alt="" /></p>
<h1 id="build" class="section-header"><a href="#build">12 Build</a></h1>
<h1 id="build" class="section-header"><a href="#build">13 Build</a></h1>
<p>TODO</p>
<p>#LoRaWAN on #NuttX OS: Lets stub out the functions for Non-Volatile Memory and Real Time Clock … And watch what happens 🌋</p>
<p>TODO39</p>
@ -414,7 +503,7 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
</li>
</ul>
<p><img src="https://lupyuen.github.io/images/spi2-pinedio1.jpg" alt="Inside PineDio Stack BL604" /></p>
<h1 id="nimble-porting-layer" class="section-header"><a href="#nimble-porting-layer">13 NimBLE Porting Layer</a></h1>
<h1 id="nimble-porting-layer" class="section-header"><a href="#nimble-porting-layer">14 NimBLE Porting Layer</a></h1>
<p>TODO</p>
<p>Our #NuttX App was waiting for the #LoRaWAN Join Request to be transmitted before receiving the Join Response … But because were polling SX1262, we missed the Join Response … Lets fix this with the multithreading functions from NimBLE Porting Layer</p>
<ul>
@ -424,7 +513,7 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
<p><img src="https://lupyuen.github.io/images/lorawan3-run4a.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/d3d9db37a40d7560fc211408db04a81b">(Log)</a></p>
<p>NimBLE Porting Layer is a portable library of Multithreading Functions … Weve used it for #LoRa on Linux and FreeRTOS … Now we call it from Apache #NuttX OS</p>
<h1 id="gpio-interrupts" class="section-header"><a href="#gpio-interrupts">14 GPIO Interrupts</a></h1>
<h1 id="gpio-interrupts" class="section-header"><a href="#gpio-interrupts">15 GPIO Interrupts</a></h1>
<p>TODO</p>
<p>SX1262 will trigger a GPIO Interrupt on #NuttX OS when it receives a #LoRa Packet … We wait for the GPIO Interrupt to be Signalled in a Background Thread</p>
<p>TODO46</p>
@ -440,7 +529,7 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
<p><a href="https://github.com/lupyuen/lora-sx1262/blob/lorawan/src/sx126x-nuttx.c#L863-L892">(Source)</a></p>
<p>#LoRaWAN runs neater on Apache #NuttX OS … After implementing Timers and Multithreading with NimBLE Porting Layer … No more sleep()!</p>
<p><a href="https://gist.github.com/lupyuen/cad58115be4cabe8a8a49c0e498f1c95">(Log)</a></p>
<h1 id="build-nimble" class="section-header"><a href="#build-nimble">15 Build NimBLE</a></h1>
<h1 id="build-nimble" class="section-header"><a href="#build-nimble">16 Build NimBLE</a></h1>
<p>TODO</p>
<p>To build NumBLE Porting Layer on #NuttX OS we need to enable: 1⃣ POSIX Timers &amp; Message Queues 2⃣ Clock Monotonic 3⃣ Work Queues 4⃣ SIGEV_THHREAD</p>
<ul>
@ -450,13 +539,13 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
<p><img src="https://lupyuen.github.io/images/lorawan3-config1.png" alt="" /></p>
<p>TODO14</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-config4.png" alt="" /></p>
<h1 id="sx1262-busy" class="section-header"><a href="#sx1262-busy">16 SX1262 Busy</a></h1>
<h1 id="sx1262-busy" class="section-header"><a href="#sx1262-busy">17 SX1262 Busy</a></h1>
<p>TODO</p>
<p>Heres how we check the SX1262 Busy Pin on #NuttX OS … By reading the GPIO Input</p>
<p>TODO49</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-gpio1.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/lora-sx1262/blob/lorawan/src/sx126x-nuttx.c#L184-L199">(Source)</a></p>
<h1 id="logging" class="section-header"><a href="#logging">17 Logging</a></h1>
<h1 id="logging" class="section-header"><a href="#logging">18 Logging</a></h1>
<p>TODO</p>
<p>Our #NuttX App was too busy to receive the #LoRaWAN Join Response … Lets disable the logging</p>
<p>TODO62</p>
@ -470,7 +559,7 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
<p>TODO44</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-chirpstack5.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/0d301216bbf937147778bb57ab0ccf89">(Log)</a></p>
<h1 id="message-size" class="section-header"><a href="#message-size">18 Message Size</a></h1>
<h1 id="message-size" class="section-header"><a href="#message-size">19 Message Size</a></h1>
<p>TODO</p>
<p>Our #NuttX App sent an empty #LoRaWAN Message because our message is too long for LoRaWAN Data Rate 2 (max 11 bytes) … Lets increase the Data Rate to 3</p>
<p>TODO65</p>
@ -488,14 +577,14 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
<p>TODO45</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-chirpstack6.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/83be5da091273bb39bad6e77cc91b68d">(Log)</a></p>
<h1 id="troubleshoot-lorawan" class="section-header"><a href="#troubleshoot-lorawan">19 Troubleshoot LoRaWAN</a></h1>
<h1 id="troubleshoot-lorawan" class="section-header"><a href="#troubleshoot-lorawan">20 Troubleshoot LoRaWAN</a></h1>
<p>TODO</p>
<p>Check the LoRa Frequency, Sync Word, Device EUI and Join EUI</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run2a.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/b91c1f88645eedb813cfffa2bdf7d7a0">(Run Log)</a></p>
<h1 id="spi-with-dma" class="section-header"><a href="#spi-with-dma">20 SPI with DMA</a></h1>
<h1 id="spi-with-dma" class="section-header"><a href="#spi-with-dma">21 SPI with DMA</a></h1>
<p>TODO</p>
<h1 id="whats-next" class="section-header"><a href="#whats-next">21 Whats Next</a></h1>
<h1 id="whats-next" class="section-header"><a href="#whats-next">22 Whats Next</a></h1>
<p>TODO</p>
<p>CBOR, TTN, Temperature Sensor</p>
<p>In our next article well move on to <strong>LoRaWAN!</strong></p>
@ -524,7 +613,7 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
</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/lorawan3.md"><code>lupyuen.github.io/src/lorawan3.md</code></a></p>
<h1 id="notes" class="section-header"><a href="#notes">22 Notes</a></h1>
<h1 id="notes" class="section-header"><a href="#notes">23 Notes</a></h1>
<ol>
<li>
<p>This article is the expanded version of <a href="https://twitter.com/MisterTechBlog/status/1473593455699841027">this Twitter Thread</a></p>
@ -568,13 +657,197 @@ git clone --recursive --branch lorawan https://github.com/lupyuen/incubator-nutt
<p>It might! But first lets get LoRaWAN (and ST7789) running on PineDio Stack.</p>
</li>
</ol>
<h1 id="appendix-gpio-issue" class="section-header"><a href="#appendix-gpio-issue">23 Appendix: GPIO Issue</a></h1>
<h1 id="appendix-build-flash-and-run-nuttx" class="section-header"><a href="#appendix-build-flash-and-run-nuttx">24 Appendix: Build, Flash and Run NuttX</a></h1>
<p><em>(For BL602 and ESP32)</em></p>
<p>Below are the steps to build, flash and run NuttX on BL602 and ESP32.</p>
<p>The instructions below will work on <strong>Linux (Ubuntu)</strong>, <strong>WSL (Ubuntu)</strong> and <strong>macOS</strong>.</p>
<p><a href="https://nuttx.apache.org/docs/latest/quickstart/install.html">(Instructions for other platforms)</a></p>
<p><a href="https://popolon.org/gblog3/?p=1977&amp;lang=en">(See this for Arch Linux)</a></p>
<h2 id="build-nuttx" class="section-header"><a href="#build-nuttx">24.1 Build NuttX</a></h2>
<p>Follow these steps to build NuttX for BL602 or ESP32…</p>
<ol>
<li>
<p>Install the build prerequisites…</p>
<p><a href="https://lupyuen.github.io/articles/nuttx#install-prerequisites"><strong>“Install Prerequisites”</strong></a></p>
</li>
<li>
<p>Assume that we have downloaded and configured our NuttX code…</p>
<p><a href="https://lupyuen.github.io/articles/lorawan3#download-source-code"><strong>“Download Source Code”</strong></a></p>
<p><a href="https://lupyuen.github.io/articles/lorawan3#build-the-firmware"><strong>“Build the Firmware”</strong></a></p>
</li>
<li>
<p>To build NuttX, enter this command…</p>
<div class="example-wrap"><pre class="language-bash"><code>make</code></pre></div></li>
<li>
<p>We should see…</p>
<div class="example-wrap"><pre class="language-text"><code>LD: nuttx
CP: nuttx.hex
CP: nuttx.bin</code></pre></div>
<p><a href="https://gist.github.com/lupyuen/8f725c278c25e209c1654469a2855746">(See the complete log for BL602)</a></p>
</li>
<li>
<p><strong>For BL602:</strong> Copy the <strong>NuttX Firmware</strong> to the <strong>blflash</strong> directory…</p>
<div class="example-wrap"><pre class="language-bash"><code># For Linux and macOS:
# TODO: Change $HOME/blflash to the full path of blflash
cp nuttx.bin $HOME/blflash
# For WSL:
# TODO: Change /mnt/c/blflash to the full path of blflash in Windows
# /mnt/c/blflash refers to c:\blflash
cp nuttx.bin /mnt/c/blflash</code></pre></div>
<p>(Well cover <strong>blflash</strong> in the next section)</p>
<p>For WSL we need to run <strong>blflash</strong> under plain old Windows CMD (not WSL) because it needs to access the COM port.</p>
</li>
<li>
<p>In case of problems, refer to the <strong>NuttX Docs</strong></p>
<p><a href="https://nuttx.apache.org/docs/latest/platforms/risc-v/bl602/index.html"><strong>“BL602 NuttX”</strong></a></p>
<p><a href="https://nuttx.apache.org/docs/latest/platforms/xtensa/esp32/index.html"><strong>“ESP32 NuttX”</strong></a></p>
<p><a href="https://nuttx.apache.org/docs/latest/quickstart/install.html"><strong>“Installing NuttX”</strong></a></p>
</li>
</ol>
<blockquote>
<p><img src="https://lupyuen.github.io/images/nuttx-build2.png" alt="Building NuttX" /></p>
</blockquote>
<h2 id="flash-nuttx" class="section-header"><a href="#flash-nuttx">24.2 Flash NuttX</a></h2>
<p><strong>For ESP32:</strong> <a href="https://nuttx.apache.org/docs/latest/platforms/xtensa/esp32/index.html#flashing"><strong>See instructions here</strong></a> <a href="https://popolon.org/gblog3/?p=1977&amp;lang=en">(Also check out this article)</a></p>
<p><strong>For BL602:</strong> Follow these steps to install <strong>blflash</strong></p>
<ol>
<li>
<p><a href="https://lupyuen.github.io/articles/flash#install-rustup"><strong>“Install rustup”</strong></a></p>
</li>
<li>
<p><a href="https://lupyuen.github.io/articles/flash#download-and-build-blflash"><strong>“Download and build blflash”</strong></a></p>
</li>
</ol>
<p>We assume that our Firmware Binary File <strong>nuttx.bin</strong> has been copied to the <strong>blflash</strong> folder.</p>
<p>Set BL602 / BL604 to <strong>Flashing Mode</strong> and restart the board…</p>
<p><strong>For PineDio Stack BL604:</strong></p>
<ol>
<li>
<p>Set the <strong>GPIO 8 Jumper</strong> to <strong>High</strong> <a href="https://lupyuen.github.io/images/pinedio-high.jpg">(Like this)</a></p>
</li>
<li>
<p>Press the Reset Button</p>
</li>
</ol>
<p><strong>For PineCone BL602:</strong></p>
<ol>
<li>
<p>Set the <strong>PineCone Jumper (IO 8)</strong> to the <strong><code>H</code> Position</strong> <a href="https://lupyuen.github.io/images/pinecone-jumperh.jpg">(Like this)</a></p>
</li>
<li>
<p>Press the Reset Button</p>
</li>
</ol>
<p><strong>For BL10:</strong></p>
<ol>
<li>
<p>Connect BL10 to the USB port</p>
</li>
<li>
<p>Press and hold the <strong>D8 Button (GPIO 8)</strong></p>
</li>
<li>
<p>Press and release the <strong>EN Button (Reset)</strong></p>
</li>
<li>
<p>Release the D8 Button</p>
</li>
</ol>
<p><strong>For Pinenut and MagicHome BL602:</strong></p>
<ol>
<li>
<p>Disconnect the board from the USB Port</p>
</li>
<li>
<p>Connect <strong>GPIO 8</strong> to <strong>3.3V</strong></p>
</li>
<li>
<p>Reconnect the board to the USB port</p>
</li>
</ol>
<p>Enter these commands to flash <strong>nuttx.bin</strong> to BL602 / BL604 over UART…</p>
<div class="example-wrap"><pre class="language-bash"><code># TODO: Change ~/blflash to the full path of blflash
cd ~/blflash
# For Linux:
sudo cargo run flash nuttx.bin \
--port /dev/ttyUSB0
# For macOS:
cargo run flash nuttx.bin \
--port /dev/tty.usbserial-1420 \
--initial-baud-rate 230400 \
--baud-rate 230400
# For Windows: Change COM5 to the BL602 / BL604 Serial Port
cargo run flash nuttx.bin --port COM5</code></pre></div>
<p><a href="https://gist.github.com/lupyuen/9c0dbd75bb6b8e810939a36ffb5c399f">(See the Output Log)</a></p>
<p>For WSL: Do this under plain old Windows CMD (not WSL) because <strong>blflash</strong> needs to access the COM port.</p>
<p><a href="https://github.com/apache/incubator-nuttx/issues/4336">(Flashing WiFi apps to BL602 / BL604? Remember to use <strong>bl_rfbin</strong>)</a></p>
<p><a href="https://lupyuen.github.io/articles/flash#flash-the-firmware">(More details on flashing firmware)</a></p>
<p><img src="https://lupyuen.github.io/images/nuttx-flash2.png" alt="Flashing NuttX" /></p>
<h2 id="run-nuttx" class="section-header"><a href="#run-nuttx">24.3 Run NuttX</a></h2>
<p><strong>For ESP32:</strong> Use Picocom to connect to ESP32 over UART…</p>
<div class="example-wrap"><pre class="language-bash"><code>picocom -b 115200 /dev/ttyUSB0</code></pre></div>
<p><a href="https://popolon.org/gblog3/?p=1977&amp;lang=en">(More about this)</a></p>
<p><strong>For BL602:</strong> Set BL602 / BL604 to <strong>Normal Mode</strong> (Non-Flashing) and restart the board…</p>
<p><strong>For PineDio Stack BL604:</strong></p>
<ol>
<li>
<p>Set the <strong>GPIO 8 Jumper</strong> to <strong>Low</strong> <a href="https://lupyuen.github.io/images/pinedio-low.jpg">(Like this)</a></p>
</li>
<li>
<p>Press the Reset Button</p>
</li>
</ol>
<p><strong>For PineCone BL602:</strong></p>
<ol>
<li>
<p>Set the <strong>PineCone Jumper (IO 8)</strong> to the <strong><code>L</code> Position</strong> <a href="https://lupyuen.github.io/images/pinecone-jumperl.jpg">(Like this)</a></p>
</li>
<li>
<p>Press the Reset Button</p>
</li>
</ol>
<p><strong>For BL10:</strong></p>
<ol>
<li>Press and release the <strong>EN Button (Reset)</strong></li>
</ol>
<p><strong>For Pinenut and MagicHome BL602:</strong></p>
<ol>
<li>
<p>Disconnect the board from the USB Port</p>
</li>
<li>
<p>Connect <strong>GPIO 8</strong> to <strong>GND</strong></p>
</li>
<li>
<p>Reconnect the board to the USB port</p>
</li>
</ol>
<p>After restarting, connect to BL602 / BL604s UART Port at 2 Mbps like so…</p>
<p><strong>For Linux:</strong></p>
<div class="example-wrap"><pre class="language-bash"><code>sudo screen /dev/ttyUSB0 2000000</code></pre></div>
<p><strong>For macOS:</strong> Use CoolTerm (<a href="https://lupyuen.github.io/articles/flash#watch-the-firmware-run">See this</a>)</p>
<p><strong>For Windows:</strong> Use <code>putty</code> (<a href="https://lupyuen.github.io/articles/flash#watch-the-firmware-run">See this</a>)</p>
<p><strong>Alternatively:</strong> Use the Web Serial Terminal (<a href="https://lupyuen.github.io/articles/flash#watch-the-firmware-run">See this</a>)</p>
<p>Press Enter to reveal the <strong>NuttX Shell</strong></p>
<div class="example-wrap"><pre class="language-text"><code>NuttShell (NSH) NuttX-10.2.0-RC0
nsh&gt;</code></pre></div>
<p>Congratulations NuttX is now running on BL602 / BL604!</p>
<p><a href="https://lupyuen.github.io/articles/flash#watch-the-firmware-run">(More details on connecting to BL602 / BL604)</a></p>
<p><img src="https://lupyuen.github.io/images/nuttx-boot2.png" alt="Running NuttX" /></p>
<p><strong>macOS Tip:</strong> Heres the script I use to build, flash and run NuttX on macOS, all in a single step: <a href="https://gist.github.com/lupyuen/cc21385ecc66b5c02d15affd776a64af">run.sh</a></p>
<p><img src="https://lupyuen.github.io/images/spi2-script.png" alt="Script to build, flash and run NuttX on macOS" /></p>
<p><a href="https://gist.github.com/lupyuen/cc21385ecc66b5c02d15affd776a64af">(Source)</a></p>
<h1 id="appendix-gpio-issue" class="section-header"><a href="#appendix-gpio-issue">25 Appendix: GPIO Issue</a></h1>
<p>TODO</p>
<p>Switching a #NuttX GPIO Interrupt Pin to Trigger On Rising Edge … Crashes with an Assertion Failure … Ill submit a NuttX Issue, meanwhile I have disabled the assertion</p>
<p>TODO50</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-int.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/incubator-nuttx/blob/lorawan/drivers/ioexpander/gpio.c#L544-L547">(Source)</a></p>
<h1 id="appendix-callout-issue" class="section-header"><a href="#appendix-callout-issue">24 Appendix: Callout Issue</a></h1>
<h1 id="appendix-callout-issue" class="section-header"><a href="#appendix-callout-issue">26 Appendix: Callout Issue</a></h1>
<p>TODO</p>
<p>NimBLE Porting Layer doesnt work for multiple Callout Timers on #NuttX OS, unless we loop the thread … Will submit a Pull Request to Apache NimBLE 👍</p>
<p>TODO42</p>