Commit from GitHub Actions

This commit is contained in:
Lee Lup Yuen 2023-12-29 02:34:44 +00:00
parent 5e0776c28d
commit 083565a057

View file

@ -81,10 +81,9 @@
<li><a href="#usleep">13 usleep</a><ul></ul></li>
<li><a href="#documentation">14 Documentation</a><ul></ul></li>
<li><a href="#fix-the-risc-v-timer-with-opensbi">15 Fix the RISC-V Timer with OpenSBI</a><ul></ul></li>
<li><a href="#led-driver-for-ox64-bl808">16 LED Driver for Ox64 BL808</a><ul></ul></li>
<li><a href="#whats-next">17 Whats Next</a><ul></ul></li>
<li><a href="#appendix-build-nuttx-for-qemu">18 Appendix: Build NuttX for QEMU</a><ul></ul></li>
<li><a href="#appendix-build-nuttx-for-ox64">19 Appendix: Build NuttX for Ox64</a><ul></ul></li></ul></nav><p>📝 <em>7 Jan 2024</em></p>
<li><a href="#whats-next">16 Whats Next</a><ul></ul></li>
<li><a href="#appendix-build-nuttx-for-qemu">17 Appendix: Build NuttX for QEMU</a><ul></ul></li>
<li><a href="#appendix-build-nuttx-for-ox64">18 Appendix: Build NuttX for Ox64</a><ul></ul></li></ul></nav><p>📝 <em>7 Jan 2024</em></p>
<p><img src="https://lupyuen.github.io/images/nim-ox64.png" alt="Apache NuttX RTOS on Ox64 BL808 RISC-V SBC: Works great with Nim!" /></p>
<p>Happy New Year! 2024 is here and were running <a href="https://www.hackster.io/lupyuen/8-risc-v-sbc-on-a-real-time-operating-system-ox64-nuttx-474358"><strong>Apache NuttX RTOS</strong></a> (Real-Time Operating System) on Single-Board Computers with <strong>plenty of RAM</strong></p>
<p>Like <a href="https://wiki.pine64.org/wiki/Ox64"><strong>Pine64 Ox64 BL808</strong></a> RISC-V SBC with 64 MB RAM! (Pic below)</p>
@ -409,7 +408,10 @@ Hint: used config file &#39;/workspaces/bookworm/apps/config.nims&#39; [Conf]
....................................................................................................................................
Hint: mm: orc; opt: size; options: -d:danger
92931 lines; 1.214s; 137.633MiB peakmem; proj: /workspaces/bookworm/apps/examples/hello_nim/hello_nim_async.nim; out: /workspaces/bookworm/apps/.nimcache/hello_nim_async.json [SuccessX]
</code></pre></div><h1 id="led-driver-for-ox64"><a href="#led-driver-for-ox64">7 LED Driver for Ox64</a></h1>
</code></pre></div>
<p><img src="https://lupyuen.github.io/images/nim-gpio.jpg" alt="GPIO 29 in BL808 Reference Manual (Page 119)" /></p>
<p><a href="https://github.com/bouffalolab/bl_docs/blob/main/BL808_RM/en/BL808_RM_en_1.3.pdf"><em>GPIO 29 in BL808 Reference Manual (Page 119)</em></a></p>
<h1 id="led-driver-for-ox64"><a href="#led-driver-for-ox64">7 LED Driver for Ox64</a></h1>
<p><em>Our Nim Experiment needs an LED Driver for Ox64…</em></p>
<p><em>Whats the Quickest Way to create a NuttX LED Driver?</em></p>
<p><strong>U-Boot Bootloader</strong> can help! Power up Ox64 and press Enter a few times to reveal the <strong>U-Boot Command Prompt</strong>.</p>
@ -450,48 +452,47 @@ $ md 0x20000938 1
</li>
</ul>
<p><em>How did we figure out the Magic Bits for GPIO 29?</em></p>
<p>TODO</p>
<p>From BL808 Reference Manual Page 56, “Normal GPIO Output Mode”…</p>
<p>From <a href="https://github.com/bouffalolab/bl_docs/blob/main/BL808_RM/en/BL808_RM_en_1.3.pdf"><strong>BL808 Reference Manual</strong></a> Page 56, “Normal GPIO Output Mode”…</p>
<ul>
<li>
<p>Set reg_gpio_xx_oe (Bit 6) to 1 to enable the GPIO output mode <br>
<p>Set <strong>reg_gpio_29_oe</strong> (Bit 6) to <strong><code>1</code></strong> to enable GPIO Output Mode <br>
= (1 &lt;&lt; 6)</p>
</li>
<li>
<p>Set reg_gpio_xx_func_sel (Bits 8 to 12) to 11 to enter the SWGPIO mode <br>
<p>Set <strong>reg_gpio_29_func_sel</strong> (Bits 8 to 12) to <strong><code>11</code></strong> to enter SWGPIO Mode <br>
= (11 &lt;&lt; 8)</p>
</li>
<li>
<p>Set reg_gpio_xx_mode (Bits 30 to 31) to 0 to enable the normal output function of I/O <br>
<p>Set <strong>reg_gpio_29_mode</strong> (Bits 30 to 31) to <strong><code>0</code></strong> to enable Normal Output Function of I/O <br>
= (0 &lt;&lt; 30)</p>
</li>
<li>
<p>Set reg_gpio_xx_pu (Bit 4) and reg_gpio_xx_pd (Bit 5) to 0 to disable the internal pull-up and pull-down functions <br>
<p>Set <strong>reg_gpio_29_pu</strong> (Bit 4) and <strong>reg_gpio_29_pd</strong> (Bit 5) to <strong><code>0</code></strong> to disable Internal Pull-Up and Pull-Down functions <br>
= (0 &lt;&lt; 4)</p>
</li>
<li>
<p>Set the level of I/O pin through reg_gpio_xx_o (Bit 24) <br>
<p>Set the Pin Level (<strong><code>0</code></strong> or <strong><code>1</code></strong>) through <strong>reg_gpio_29_o</strong> (Bit 24) <br>
= Either (0 &lt;&lt; 24) Or (1 &lt;&lt; 24)</p>
</li>
</ul>
<p>TODO: (<strong>GPIO Bits</strong> are listed in the pic above)</p>
<p><a href="https://lupyuen.github.io/images/nim-gpio.jpg">(<strong>GPIO Bits</strong> are listed in the pic above)</a></p>
<p>Which means…</p>
<ul>
<li>
<p>Set GPIO Output to 0 <br>
<p><strong>Set GPIO Output to 0</strong> <br>
= (1 &lt;&lt; 6) | (11 &lt;&lt; 8) | (0 &lt;&lt; 30) | (0 &lt;&lt; 4) | (0 &lt;&lt; 24) <br>
= 0xb40</p>
= <strong><code>0xB40</code></strong></p>
</li>
<li>
<p>Set GPIO Output to 1 <br>
<p><strong>Set GPIO Output to 1</strong> <br>
= (1 &lt;&lt; 6) | (11 &lt;&lt; 8) | (0 &lt;&lt; 30) | (0 &lt;&lt; 4) | (1 &lt;&lt; 24) <br>
= 0x1000b40</p>
= <strong><code>0x100</code> <code>0B40</code></strong></p>
</li>
</ul>
<p>TODO</p>
<p><em>How to flip the GPIO in our NuttX LED Driver?</em></p>
<p>This is how we flip the GPIO in our NuttX LED Driver: <a href="https://github.com/lupyuen2/wip-pinephone-nuttx/blob/nim/boards/risc-v/bl808/ox64/src/bl808_userleds.c#L176-L209">bl808_userleds.c</a></p>
<div class="example-wrap"><pre class="language-c"><code>// Switch the LEDs On and Off according to the LED Set
<p>And we write the above values to <strong>GPIO 29 Register</strong> at <strong><code>0x2000</code> <code>0938</code></strong> (gpio_cfg29)</p>
<p><em>How to flip the GPIO in our LED Driver?</em></p>
<p>We do this in our <strong>NuttX LED Driver</strong>: <a href="https://github.com/lupyuen2/wip-pinephone-nuttx/blob/nim/boards/risc-v/bl808/ox64/src/bl808_userleds.c#L176-L209">bl808_userleds.c</a></p>
<div class="example-wrap"><pre class="language-c"><code>// Flip the LEDs On and Off according to the LED Set
// (Bit 0 = LED 0)
void board_userled_all(uint32_t ledset) {
@ -504,16 +505,16 @@ void board_userled_all(uint32_t ledset) {
// If this is LED 0...
if (i == 0) {
// Switch it On or Off?
// Flip it On or Off?
if (val) {
// Switch LED 0 (GPIO 29) to On:
// Flip LED 0 (GPIO 29) to On:
// Set gpio_cfg29 to (1 &lt;&lt; 6) | (11 &lt;&lt; 8) | (0 &lt;&lt; 30) | (0 &lt;&lt; 4) | (1 &lt;&lt; 24)
// mw 0x20000938 0x1000b40 1
*(volatile uint32_t *) 0x20000938 = 0x1000b40;
} else {
// Switch LED 0 (GPIO 29) to Off:
// Flip LED 0 (GPIO 29) to Off:
// Set gpio_cfg29 to (1 &lt;&lt; 6) | (11 &lt;&lt; 8) | (0 &lt;&lt; 30) | (0 &lt;&lt; 4) | (0 &lt;&lt; 24)
// mw 0x20000938 0xb40 1
*(volatile uint32_t *) 0x20000938 = 0xb40;
@ -1148,198 +1149,7 @@ void up_timer_initialize(void) {
</code></pre></div>
<p>Now the <code>sleep</code> command works correctly in NuttX Shell!</p>
<p><a href="https://gist.github.com/lupyuen/8aa66e7f88d1e31a5f198958c15e4393">Heres the log (ignore the errors)</a></p>
<h1 id="led-driver-for-ox64-bl808"><a href="#led-driver-for-ox64-bl808">16 LED Driver for Ox64 BL808</a></h1>
<p>TODO</p>
<p>We wish to blink an LED with Nim on Ox64…</p>
<ul>
<li><a href="https://github.com/lupyuen/nuttx-nim#blink-an-led-with-nim">“Blink an LED with Nim”</a></li>
</ul>
<p>But first we need a barebones NuttX LED Driver for Ox64.</p>
<p><em>How to create the NuttX LED Driver?</em></p>
<p>We assume LED is connected to GPIO 29, Pin 21. <a href="https://wiki.pine64.org/wiki/File:Ox64_pinout.png">(See the Pinout)</a></p>
<p>(With a 47 Ohm Resistor, yellow-purple-black-gold)</p>
<p><em>How do we flip a BL808 GPIO High and Low?</em></p>
<p>From BL808 Reference Manual Page 56, “Normal GPIO Output Mode”…</p>
<ul>
<li>
<p>Set reg_gpio_xx_oe (Bit 6) to 1 to enable the GPIO output mode <br>
= (1 &lt;&lt; 6)</p>
</li>
<li>
<p>Set reg_gpio_xx_func_sel (Bits 8 to 12) to 11 to enter the SWGPIO mode <br>
= (11 &lt;&lt; 8)</p>
</li>
<li>
<p>Set reg_gpio_xx_mode (Bits 30 to 31) to 0 to enable the normal output function of I/O <br>
= (0 &lt;&lt; 30)</p>
</li>
<li>
<p>Set reg_gpio_xx_pu (Bit 4) and reg_gpio_xx_pd (Bit 5) to 0 to disable the internal pull-up and pull-down functions <br>
= (0 &lt;&lt; 4)</p>
</li>
<li>
<p>Set the level of I/O pin through reg_gpio_xx_o (Bit 24) <br>
= Either (0 &lt;&lt; 24) Or (1 &lt;&lt; 24)</p>
</li>
</ul>
<p>(GPIO Bit Definitions are below)</p>
<p>Which means…</p>
<ul>
<li>
<p>Set GPIO Output to 0 <br>
= (1 &lt;&lt; 6) | (11 &lt;&lt; 8) | (0 &lt;&lt; 30) | (0 &lt;&lt; 4) | (0 &lt;&lt; 24) <br>
= 0xb40</p>
</li>
<li>
<p>Set GPIO Output to 1 <br>
= (1 &lt;&lt; 6) | (11 &lt;&lt; 8) | (0 &lt;&lt; 30) | (0 &lt;&lt; 4) | (1 &lt;&lt; 24) <br>
= 0x1000b40</p>
</li>
</ul>
<p><em>How to test this?</em></p>
<p>GPIO 29 Base Address <code>gpio_cfg29</code> is 0x20000938.</p>
<p>For testing, we run U-Boot Bootloader Commands to set GPIO 29 to High and Low…</p>
<div class="example-wrap"><pre class="language-bash"><code>## Dump gpio_cfg29 at 0x20000938
$ md 0x20000938 1
20000938: 00400803 ..@.
## Set GPIO Output to 0: (1 &lt;&lt; 6) | (11 &lt;&lt; 8) | (0 &lt;&lt; 30) | (0 &lt;&lt; 4) | (0 &lt;&lt; 24)
## = 0xb40
$ mw 0x20000938 0xb40 1
$ md 0x20000938 1
20000938: 00000b40 @...
## Set GPIO Output to 1: (1 &lt;&lt; 6) | (11 &lt;&lt; 8) | (0 &lt;&lt; 30) | (0 &lt;&lt; 4) | (1 &lt;&lt; 24)
## = 0x1000b40
$ mw 0x20000938 0x1000b40 1
$ md 020000938 1
20000938: 01000b40 @...
</code></pre></div>
<p>And U-Boot switches the LED On and Off correctly yay!</p>
<p><em>How to flip the GPIO in our NuttX LED Driver?</em></p>
<p>This is how we flip the GPIO in our NuttX LED Driver: <a href="https://github.com/lupyuen2/wip-pinephone-nuttx/blob/nim/boards/risc-v/bl808/ox64/src/bl808_userleds.c#L176-L209">bl808_userleds.c</a></p>
<div class="example-wrap"><pre class="language-c"><code>// Switch the LEDs On and Off according to the LED Set
// (Bit 0 = LED 0)
void board_userled_all(uint32_t ledset)
{
_info(&quot;ledset=0x%x\n&quot;, ledset);////
int i;
// For LED 0 to 2...
for (i = 0; i &lt; BOARD_LEDS; i++)
{
// Get the desired state of the LED
bool val = ((ledset &amp; g_led_setmap[i]) != 0);
_info(&quot;led=%d, val=%d\n&quot;, i, val);////
// If this is LED 0...
if (i == 0)
{
// Switch it On or Off?
if (val)
{
// Switch LED 0 (GPIO 29) to On:
// Set gpio_cfg29 to (1 &lt;&lt; 6) | (11 &lt;&lt; 8) | (0 &lt;&lt; 30) | (0 &lt;&lt; 4) | (1 &lt;&lt; 24)
// mw 0x20000938 0x1000b40 1
*(volatile uint32_t *) 0x20000938 = 0x1000b40;
}
else
{
// Switch LED 0 (GPIO 29) to Off:
// Set gpio_cfg29 to (1 &lt;&lt; 6) | (11 &lt;&lt; 8) | (0 &lt;&lt; 30) | (0 &lt;&lt; 4) | (0 &lt;&lt; 24)
// mw 0x20000938 0xb40 1
*(volatile uint32_t *) 0x20000938 = 0xb40;
}
}
////TODO: a64_pio_write(g_led_map[i], (ledset &amp; g_led_setmap[i]) != 0);
}
}
</code></pre></div>
<p>And our LED Driver works OK with Nim: It blinks our LED on Ox64 BL808 SBC!</p>
<ul>
<li>
<p><a href="https://youtube.com/shorts/KCkiXFxBgxQ">Watch the Demo on YouTube</a></p>
</li>
<li>
<p><a href="https://gist.github.com/lupyuen/553c2da4ad5d119468d223e162573e96">See the Log</a></p>
</li>
<li>
<p><a href="https://github.com/lupyuen/nuttx-nim#blink-an-led-with-nim">“Blink an LED with Nim”</a></p>
</li>
</ul>
<p>Later well replace the (awful) code above by the BL808 GPIO Driver. Which well copy from NuttX for BL602.</p>
<p><em>How did we get the GPIO Bit Definitions?</em></p>
<p>From BL808 Reference Manual Page 119…</p>
<div class="example-wrap"><pre class="language-text"><code>4.8.30 gpio_cfg29
Base Address0x20000938
Bits Name Type Reset Description
31:30 reg_gpio_29_mode r/w 0 When GPIO Function Selected to SWGPIO
00 (Output Value Mode): GPIO Output by reg_gpio_x_o
Value
01 (Set/Celar Mode ) :GPIO Output set by reg_gpio_x_set
and clear by reg_gpio_x_clr
10 : SWGPIO Source comes from GPIO DMA (GPIO DMA
Mode), GPIO Output value by gpio_dma_o
11: SWGPIO Source comes from GPIO DMA (GPIO DMA
Mode), GPIO Outout value by gpio_dma_set/gpio_dma_clr
29 RSVD
28 reg_gpio_29_i r 0
27 RSVD
26 reg_gpio_29_clr w1p 0 When SWGPIO @ Set/Clear Mode
Set this bit will clear GPIO output value to 0,when set/clr at
the same time, only set take effect
25 reg_gpio_29_set w1p 0 When SWGPIO @ Set/Clear Mode
Set this bit will set GPIO output value to 1,when set/clr at
the same time, only set take effect
24 reg_gpio_29_o r/w 0 When SWGPIO @ Output Value Mode
00 : GPIO Value changes according to this value
01 : GPIO Value Set by this register and clr by clr_reg
23 RSVD
22 reg_gpio_29_int_mask r/w 1 mask interrupt (1)
21 gpio_29_int_stat r 0 interrupt status
20 reg_gpio_29_int_clr r/w 0 clear interrupt
19:16 reg_gpio_29_int_mode_set r/w 0 0000 : sync falling edge trigger
0001 : sync rising edge trigger
0010 : sync low level trigger
0011 : sync high level trigger
01xx : sync rising &amp; falling edge trigger
1000 : async falling edge trigger
1001 : async rising edge trigger
1010 : async low level trigger
1011 : async high level trigger
15:13 RSVD
12:8 reg_gpio_29_func_sel r/w 5hB GPIO Function Select (Default : SW-GPIO)
7 RSVD
6 reg_gpio_29_oe r/w 0 Register Controlled GPIO Output Enable (Used when GPIO
Function select to Register Control GPIO)
5 reg_gpio_29_pd r/w 0 GPIO Pull Down Control
4 reg_gpio_29_pu r/w 0 GPIO Pull Up Control
3:2 reg_gpio_29_drv r/w 0 GPIO Driving Control
1 reg_gpio_29_smt r/w 1 GPIO SMT Control
0 reg_gpio_29_ie r/w 0 GPIO Input Enable
</code></pre></div><h1 id="whats-next"><a href="#whats-next">17 Whats Next</a></h1>
<h1 id="whats-next"><a href="#whats-next">16 Whats Next</a></h1>
<p>TODO</p>
<p>Many Thanks to my <a href="https://github.com/sponsors/lupyuen"><strong>GitHub Sponsors</strong></a> (and the awesome NuttX Community) for supporting my work! This article wouldnt have been possible without your support.</p>
<ul>
@ -1364,9 +1174,9 @@ Function select to Register Control GPIO)
</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/nim.md"><strong>lupyuen.github.io/src/nim.md</strong></a></p>
<h1 id="appendix-build-nuttx-for-qemu"><a href="#appendix-build-nuttx-for-qemu">18 Appendix: Build NuttX for QEMU</a></h1>
<h1 id="appendix-build-nuttx-for-qemu"><a href="#appendix-build-nuttx-for-qemu">17 Appendix: Build NuttX for QEMU</a></h1>
<p>TODO</p>
<h1 id="appendix-build-nuttx-for-ox64"><a href="#appendix-build-nuttx-for-ox64">19 Appendix: Build NuttX for Ox64</a></h1>
<h1 id="appendix-build-nuttx-for-ox64"><a href="#appendix-build-nuttx-for-ox64">18 Appendix: Build NuttX for Ox64</a></h1>
<p>TODO: <a href="https://github.com/lupyuen/nuttx-nim/releases/tag/ox64-1">ox64-1</a></p>