lupyuen.org/articles/porting-apache-mynewt-os-to-gigadevice-gd32-vf103-on-risc-v.html

1088 lines
No EOL
75 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="/_static/css/banner-styles.css?v=bsmaklHF" />
<link rel="stylesheet" type="text/css" href="/_static/css/iconochive.css?v=qtvMKcIJ" />
<link rel="canonical" href="https://lupyuen.org/articles/porting-apache-mynewt-os-to-gigadevice-gd32-vf103-on-risc-v.html" />
<!-- End Wayback Rewrite JS Include -->
<title data-rh="true">Porting Apache Mynewt OS to GigaDevice GD32 VF103 on RISC-V | by Lup Yuen Lee 李立源 | The Startup
| Medium</title>
<meta data-rh="true" charset="utf-8" />
<meta data-rh="true" name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1" />
<meta data-rh="true" name="theme-color" content="#000000" />
<meta data-rh="true" property="og:type" content="article" />
<meta data-rh="true" property="article:published_time" content="2020-09-30T23:24:44.836Z" />
<meta data-rh="true" name="title"
content="Porting Apache Mynewt OS to GigaDevice GD32 VF103 on RISC-V | by Lup Yuen Lee 李立源 | The Startup | Medium" />
<meta data-rh="true" property="og:title" content="Porting Apache Mynewt OS to GigaDevice GD32 VF103 on RISC-V" />
<meta data-rh="true" property="twitter:title" content="Porting Apache Mynewt OS to GigaDevice GD32 VF103 on RISC-V" />
<meta data-rh="true" name="description"
content="Head over to the Seeed online store for embedded gadgets… And youll see a couple of new, ridiculously low-cost development boards based on GigaDevice GD32 VF103 and the RISC-V processor… (The $16…" />
<meta data-rh="true" property="og:description" content="Still in progress but lemme explain why its important…" />
<meta data-rh="true" property="twitter:description"
content="Still in progress but lemme explain why its important…" />
<meta data-rh="true" name="twitter:card" content="summary_large_image" />
<meta data-rh="true" name="twitter:creator" content="@MisterTechBlog" />
<meta data-rh="true" name="author" content="Lup Yuen Lee 李立源" />
<meta data-rh="true" name="robots" content="index,follow,max-image-preview:large" />
<meta data-rh="true" name="referrer" content="unsafe-url" />
<meta data-rh="true" name="twitter:label1" value="Reading time" />
<meta data-rh="true" name="twitter:data1" value="11 min read" />
<meta property="og:image"
content="https://lupyuen.github.io/images/legacy/k1.jpeg">
<!-- 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="../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");
}
a {
color: #77d;
}
</style>
<!-- End scripts/rustdoc-header.html -->
</head>
<body>
<div id="root">
<div class="a b c">
<div class="s">
<article class="meteredContent">
<section class="cx cy cz da aj db dc s"></section><span class="s"></span>
<div>
<div class="t v dd de df dg"></div>
<section class="dh di dj dk dl">
<div class="dm aj">
<div class="figure ct dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k1.jpeg" /></p>
<figcaption><p><em>GigaDevice GD32VF103C-START development board
based on GD32 VF103 microcontroller</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<div>
<h1 id="7a2d"
class="el em en eo b ep eq er es et eu ev ew ex ey ez fa fb fc fd fe ff fg fh fi fj fk">Porting
Apache Mynewt OS to GigaDevice GD32 VF103 on RISC-V</h1>
<div class="fl">
<div class="n fm fn fo fp">
<div class="o n">
<div><a rel="noopener"
href="https://lupyuen.github.io">
<div class="dp fq fr">
<div class="fs n ft o p t fu fv fw fx fy dg"></div>
</div>
</a></div>
<div class="ga aj s">
<div class="n">
<div style="flex:1"><span class="cg b ei ci fk">
<div class="gb n o gc"><span class="cg b ei ci bm gd ge gf gg gh gi fk"><a
class="cm cn av aw ax ay az ba bb bc gj bf gk gl" rel="noopener"
href="https://lupyuen.github.io">Lup
Yuen Lee 李立源</a></span>
</div>
</span></div>
</div><span class="cg b ei ci ej"><span class="cg b ei ci bm gd ge gf gg gh gi ej">
<div><a class="cm cn av aw ax ay az ba bb bc gj bf gk gl" rel="noopener"
href="https://lupyuen.github.io/articles/porting-apache-mynewt-os-to-gigadevice-gd32-vf103-on-risc-v">Oct
29, 2019</a> <!-- -->·
<!-- -->
<!-- -->11
<!-- --> min read<span style="padding-left:4px"></span>
</div>
</span></span>
</div>
</div>
</div>
</div>
</div>
<p id="c3d8"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><em
class="ip">Still in progress but lemme explain why its important…</em></p>
<p id="b2f6"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Head over
to the <a
href="https://www.seeedstudio.com/catalogsearch/result/?cat=&amp;q=gd32vf103"
class="cm iq" rel="noopener nofollow">Seeed online store</a> for embedded gadgets… And youll see
a couple of new, ridiculously low-cost development boards based on <a
href="https://www.gigadevice.com/products/microcontrollers/gd32/risc-v/"
class="cm iq" rel="noopener nofollow"><strong class="ht ir">GigaDevice GD32
VF103</strong></a><strong class="ht ir"> </strong>and the <a
href="https://en.wikipedia.org/wiki/RISC-V"
class="cm iq" rel="noopener nofollow"><strong class="ht ir">RISC-V processor</strong></a></p>
<div class="figure it iu iv iw ix dm cz da paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k2.png" /></p>
<figcaption><p><em>New, ridiculously low-cost development boards
based on GigaDevice GD32 VF103 and the RISC-V processor</em></p></figcaption>
</div>
<p id="e787"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><em
class="ip">(The </em><a
href="https://www.seeedstudio.com/SeeedStudio-GD32-RISC-V-kit-with-LCD-p-4303.html"
class="cm iq" rel="noopener nofollow"><em class="ip">$16 bundle at the right</em></a><em
class="ip"> includes a 2.8-inch touchscreen… </em><strong class="ht ir"><em class="ip">Without the
touchscreen its only $7</em></strong><em class="ip">… Which includes </em><strong
class="ht ir"><em class="ip">8 MB of onboard flash memory</em></strong><em class="ip">!)</em></p>
<p id="35dc"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">I expect
a flood of cheap GD32 VF103 RISC-V developer boards coming real soon… Because of its odd connection
to <a
href="https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill"
class="cm iq" rel="noopener nofollow"><strong class="ht ir">STM32 Blue Pill</strong></a>, a
popular and cheap development board based on the Arm processor.</p>
<p id="5b0d"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><em
class="ip">But RISC-V and Arm are completely different CPUs… </em><strong class="ht ir"><em
class="ip">How could the GD32 VF103 be connected to STM32 Blue Pill?</em></strong></p>
<p id="f2af"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Lets
connect the dots…</p>
<p id="a4fd"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">1
<strong class="ht ir">STM32 Blue Pill</strong> is a development board based on a microcontroller
built by STMicroelectronics… <strong class="ht ir">STM32 F103</strong></p>
<p id="7e12"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">2⃣ Yes,
the <strong class="ht ir">STM32 F103</strong> microcontroller contains an <strong class="ht ir">Arm
Cortex-M3 CPU</strong></p>
<p id="8edd"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">3
Whats the name of the new low-cost microcontroller with a <strong class="ht ir">RISC-V
CPU</strong>? <strong class="ht ir">GD32 VF103</strong>… Sounds familiar?</p>
<p id="e2ec"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">4⃣ No
coincidence that <strong class="ht ir">GD32 VF103</strong> sounds similar to <strong
class="ht ir">STM32 F103</strong>… But <strong class="ht ir">their brains are different… RISC-V vs
Arm!</strong></p>
<p id="a9ef"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">5⃣ Has
someone surgically transplanted a <strong class="ht ir">RISC-V Brain</strong> into a <strong
class="ht ir">Blue Pill Body</strong>…?</p>
<p id="bac4"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">It sounds
like a Frankenstein experiment… But this is no Halloween joke, we really have a strange creature
here that <strong class="ht ir">works like Blue Pill but has the brains of a RISC-V
processor!</strong></p>
<p id="1872"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Im
confused myself… But since Im 100% certain well see many more <em class="ip">Frankenstein
103</em>… er… <em class="ip">GD32 VF103</em> creatures around us, I have decided to port the <a
href="https://mynewt.apache.org/" class="cm iq"
rel="noopener nofollow"><strong class="ht ir">Apache Mynewt Embedded OS</strong></a> to harness
the power of this new creature. (So that we can all exploit it for meaningful purposes, like IoT)
</p>
<p id="1090"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Here is
my story so far…</p>
<div class="figure it iu iv iw ix dm cz da paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k3.jpeg" /></p>
<figcaption><p><em>Frankenstein in action: GigaDevice
GD32VF103C-START development board</em></p></figcaption>
</div>
</div>
</div>
</section>
<div class="n p fl jb jc jd" role="separator"><span class="je fz hb jf jg jh"></span><span
class="je fz hb jf jg jh"></span><span class="je fz hb jf jg"></span></div>
<section class="dh di dj dk dl">
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<h1 id="97e9"
class="ji jj en cg jk jl jm hw jn jo jp ia jq jr js jt ju jv jw jx jy jz ka kb kc kd fk">GD32 F103
vs VF103: One extra “V” makes a huge difference!</h1>
<p id="e1fa"
class="hr hs en ht b hu ke hw hx hy kf ia ib ic kg ie if ig kh ii ij ik ki im in io dh fk">
GigaDevice makes two lines of F103 products…</p>
<p id="f0ea"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">1
<strong class="ht ir">GD32 F103</strong> (<strong class="ht ir">without</strong> the “V”) is based
on <strong class="ht ir">Arm</strong>. Its a drop-in replacement for STM32 F103. Forget about this,
we wont be talking about it, since it works exactly like STM32 F103.</p>
<p id="6e3a"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">2
<strong class="ht ir">GD32 VF103</strong> (<strong class="ht ir">with</strong> the “V”) is based on
<strong class="ht ir">RISC-V</strong>. Its not a drop-in replacement for STM32 F103. <em
class="ip">This is the oddly-similar-yet-different gadget that well be discussing here.</em></p>
<p id="af20"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><em
class="ip">Can we have GD32 F103 AND VF103 on the same board?</em></p>
<p id="f303"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Yes we
can! Well see a bizarre example later in the article.</p>
</div>
</div>
</section>
<div class="n p fl jb jc jd" role="separator"><span class="je fz hb jf jg jh"></span><span
class="je fz hb jf jg jh"></span><span class="je fz hb jf jg"></span></div>
<section class="dh di dj dk dl">
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<h1 id="438f"
class="ji jj en cg jk jl jm hw jn jo jp ia jq jr js jt ju jv jw jx jy jz ka kb kc kd fk">STM32 F103
(Blue Pill) vs GigaDevice GD32 VF103</h1>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k4.png" /></p>
<figcaption><p><em>System Architecture: GD32 VF103 (left) vs STM32
F103 (right)</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<p id="83e5"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">When I
first saw the documents for GigaDevices GD32 VF103 I was totally amazed… <em class="ip">What magic
did they use to swap the Arm processor in STM32 F103 (the heart of </em><a
href="https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill"
class="cm iq" rel="noopener nofollow"><em class="ip">Blue Pill</em></a><em class="ip">) to a
RISC-V processor?</em></p>
<p id="f76d"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">The GD32
VF103 looks exactly like the STM32 F103… <strong class="ht ir">same pinouts!</strong></p>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k5.png" /></p>
<figcaption><p><em>Pinouts: GD32 VF103 (left) vs STM32 F103
(right)</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<p id="a2a8"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">But
inside there are differences. The GD32 VF103 supports <strong class="ht ir">USB Host Mode</strong>,
not found in STM32 F103. So we could connect (in theory) a mouse, keyboard and USB drive to GD32
VF103…</p>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k6.png" /></p>
<figcaption><p><em>USB Support: GD32 VF103 (left) vs STM32 F103
(right)</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<p id="9c4d"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">To add to
the confusion, <strong class="ht ir">some features are named differently</strong>… STM32 F103s Low
Power <em class="ip">“Stop Mode”</em> becomes GD32 VF103s <em class="ip">“Deep-Sleep Mode”</em>
</p>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k7.png" /></p>
<figcaption><p><em>Low Power Modes: GD32 VF103 (left) vs STM32
F103 (right)</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<p id="c826"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><strong
class="ht ir">The Memory Maps look similar… But different</strong>. RAM and ROM are still in their
usual slots at <code class="dy kn ko kp kq b">0x2000 0000</code> and <code
class="dy kn ko kp kq b">0x0800 0000</code>, the sizes are the same (20 KB RAM, 64 KB ROM). But
some peripherals are mapped to different addresses… <em class="ip">Dont blindly copy peripheral
addresses!</em></p>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k8.png" /></p>
<figcaption><p><em>Memory Map: GD32 VF103 (left) vs STM32 F103
(right)</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<p id="218f"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">As for
the actual coding, GigaDevice provides a <strong class="ht ir">GD32 VF103 Firmware Library</strong>
that looks somewhat similar to the <strong class="ht ir">STM32 F103 HAL</strong> provided by
STMicroelectronics. Heres a comparison of the coding for Timers…</p>
<div class="figure it iu iv iw ix dm cz da paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k9.png" /></p>
<figcaption><p><em>Timer Code: STM32 F103 (top) vs GD32 VF103
(bottom)</em></p></figcaption>
</div>
<p id="5542"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">
GigaDevice deliberately made <strong class="ht ir">GD32 F103 code look like STM32 F103</strong>,
heres how…</p>
<p id="a052"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Arm
processors always assume that theres an <strong class="ht ir">Interrupt Vector Table</strong> at
the start of the program. (The table also includes the <code
class="dy kn ko kp kq b">Reset_Handler</code> address, at which the program code actually starts.)
</p>
<p id="0260"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">On RISC-V
theres no requirement for the Interrupt Vector Table to be located at the start of the program. But
yet if we look below, the GigaDevice Firmware Library actually <em class="ip">implements the
Interrupt Vector Table at the start of the program…</em> By jumping over the table to <code
class="dy kn ko kp kq b">Reset_Handler</code>!</p>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k10.png" /></p>
<figcaption><p><em>Interrupt Vectors: GD32 VF103 (left and centre)
vs STM32 F103 (right)</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<p id="b241"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">The
sequence of the Interrupt Vectors also looks similar (but not identical).</p>
<p id="c467"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><em
class="ip">Is this blatant copying? Is it really a bad thing?</em></p>
<p id="412c"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">I find it
remarkable that GigaDevice can roll out a RISC-V microcontroller that has everything in Blue Pill
and more… At a lower price! <em class="ip">A RISC-V microcontroller with so many features will
surely face lots of porting hurdles.</em></p>
<p id="886a"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">So Im
glad that GigaDevice made my job easier by making their RISC-V microcontroller work like Blue Pill,
one of the most popular low-cost microcontrollers of the decade. <em class="ip">(</em><a
href="http://www.st.com/web/en/press/p2184"
class="cm iq" rel="noopener nofollow"><em class="ip">Blue Pill / STM32 F103 was released in June
2007</em></a><em class="ip">)</em></p>
<p id="2c19"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">But it
gets confusing and frustrating sometimes… Mynewt OS ported to GD32 VF103 looks like a cross between
the STM32 F103 and SiFive RISC-V ports. And we need to dig deep into the details and find out how
exactly the GD32 VF103 differs from STM32 F103.</p>
</div>
</div>
</section>
<div class="n p fl jb jc jd" role="separator"><span class="je fz hb jf jg jh"></span><span
class="je fz hb jf jg jh"></span><span class="je fz hb jf jg"></span></div>
<section class="dh di dj dk dl">
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<h1 id="42c8"
class="ji jj en cg jk jl jm hw jn jo jp ia jq jr js jt ju jv jw jx jy jz ka kb kc kd fk">Board
Support Package, Microcontroller Package and Compiler Package in Mynewt OS</h1>
<p id="dca9"
class="hr hs en ht b hu ke hw hx hy kf ia ib ic kg ie if ig kh ii ij ik ki im in io dh fk">If you
recall my articles on customising Mynewt OS for the <a class="cm iq" rel="noopener"
href="https://lupyuen.github.io/articles/build-an-nb-iot-gps-tracker-on-stm32-l476-with-apache-mynewt-and-embedded-rust">STM32
L476</a> and <a class="cm iq" rel="noopener"
href="https://lupyuen.github.io/articles/coding-nrf52-with-rust-and-apache-mynewt-on-visual-studio-code">Nordic
nRF52</a> development boards, the <strong class="ht ir">Board Support Package</strong> is the
first place to start for porting Mynewt OS. Heres my <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/hw/bsp/gd32vf103c-start"
class="cm iq" rel="noopener nofollow">Board Support Package</a> for the GigaDevice
GD32VF103C-START development board…</p>
<div class="figure it iu iv iw ix dm cz da paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k11.png" /></p>
<figcaption><p><em>Board Support Package for GD32VF103C-START
board at <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/hw/bsp/gd32vf103c-start"
class="cm iq"
rel="noopener nofollow">https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/hw/bsp/gd32vf103c-start</a>
</em></p></figcaption>
</div>
<p id="3d46"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">The Board
Support Package <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/hw/bsp/gd32vf103c-start/pkg.yml#L30"
class="cm iq" rel="noopener nofollow">refers to</a> a <strong class="ht ir">Microcontroller (MCU)
Package</strong>. This Microcontroller Package is meant to be reused by all boards (Sipeed, Seeed,
…) that are based on the GD32 VF103 microcontroller. Most of the porting work happens inside this
custom <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/hw/mcu/gigadevice/gd32vf103"
class="cm iq" rel="noopener nofollow">Microcontroller Package</a> for GD32 VF103…</p>
<div class="figure it iu iv iw ix dm cz da paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k12.png" /></p>
<figcaption><p><em>Microcontroller Package for GD32VF103 at <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/hw/mcu/gigadevice/gd32vf103"
class="cm iq"
rel="noopener nofollow">https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/hw/mcu/gigadevice/gd32vf103</a>
</em></p></figcaption>
</div>
<p id="901b"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">The <code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/hw/mcu/gigadevice/gd32vf103/src/ext" class="cm iq" rel="noopener nofollow">ext</a></code>
folder inside the Microcontroller Package is important: It contains the official <strong
class="ht ir">GD32 VF103 Firmware Library</strong> distributed by GigaDevice. (<a
href="http://gd32mcu.21ic.com/en/index/classify_id/7"
class="cm iq" rel="noopener nofollow">Click here and look for <em class="ip">“GD32VF103 Firmware
Library”</em></a>)</p>
<div class="figure it iu iv iw ix dm cz da paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k13.png" /></p>
<figcaption><p><em>GD32VF103 Firmware Library at <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/hw/mcu/gigadevice/gd32vf103/src/ext"
class="cm iq"
rel="noopener nofollow">https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/hw/mcu/gigadevice/gd32vf103/src/ext</a>
</em></p></figcaption>
</div>
<p id="5c70"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">The code
in <code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/hw/mcu/gigadevice/gd32vf103/src/hal_system.c" class="cm iq" rel="noopener nofollow">hal_system.c</a></code>,
<code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/hw/mcu/gigadevice/gd32vf103/src/hal_timer.c" class="cm iq" rel="noopener nofollow">hal_timer.c</a></code>,
… are wrappers around the official GD32 VF103 Firmware Library to expose the standard Mynewt HAL
Interface thats common to all microcontrollers. <em class="ip">(Thats why its easy to write a
Mynewt application that runs on multiple microcontrollers.)</em></p>
<p id="4a5d"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">The Board
Support Package also <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/hw/bsp/gd32vf103c-start/bsp.yml#L24"
class="cm iq" rel="noopener nofollow">specifies the compiler</a> that Mynewt should use to build
the Bootloader and Application Firmware Images. Heres the custom <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/compiler/riscv-none-embed"
class="cm iq" rel="noopener nofollow"><strong class="ht ir">Compiler Package</strong></a> that
defines the RISC-V <code class="dy kn ko kp kq b">rv32imac</code> compiler were using (<a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/scripts/install-mac.sh#L106-L125"
class="cm iq" rel="noopener nofollow">downloaded from the GCC xPack website</a>)…</p>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k14.png" /></p>
<figcaption><p><em>Compiler Package for riscv-none-embed at <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/compiler/riscv-none-embed"
class="cm iq"
rel="noopener nofollow">https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/compiler/riscv-none-embed</a>
</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<p id="8549"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><em
class="ip">Isnt it amazing how easily we can switch Mynewt compilers from Arm to RISC-V… Just by
changing one file?</em></p>
</div>
</div>
</section>
<div class="n p fl jb jc jd" role="separator"><span class="je fz hb jf jg jh"></span><span
class="je fz hb jf jg jh"></span><span class="je fz hb jf jg"></span></div>
<section class="dh di dj dk dl">
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<h1 id="9665"
class="ji jj en cg jk jl jm hw jn jo jp ia jq jr js jt ju jv jw jx jy jz ka kb kc kd fk">SiFive
HiFive1 vs GigaDevice GD32 VF103</h1>
<p id="e252"
class="hr hs en ht b hu ke hw hx hy kf ia ib ic kg ie if ig kh ii ij ik ki im in io dh fk">Mynewt
(and Zephyr) has already been ported to a RISC-V development board: <a
href="https://www.sifive.com/boards/hifive1"
class="cm iq" rel="noopener nofollow"><strong class="ht ir">SiFive HiFive1</strong></a> based on
the <a href="https://www.sifive.com/chip-designer#fe310"
class="cm iq" rel="noopener nofollow"><strong class="ht ir">SiFive FE310-G000</strong></a>
microcontroller. So why dont we start with the HiFive1 code (<a
href="https://github.com/apache/mynewt-core/tree/master/hw/bsp/hifive1"
class="cm iq" rel="noopener nofollow">Board Support Package</a> + <a
href="https://github.com/apache/mynewt-core/tree/master/hw/mcu/sifive/fe310"
class="cm iq" rel="noopener nofollow">Microcontroller Package</a>) and tweak it for GD32 VF103?
</p>
<p id="ac0c"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><em
class="ip">Thats how I started… And I quickly ran into problems.</em></p>
<p id="9e97"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Some
RISC-V features work the same way for HiFive1 and GD32 VF103… Like the <code
class="dy kn ko kp kq b">msip</code> register described below (which we use to trigger an
interrupt for context switching)…</p>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k15.png" /></p>
<figcaption><p><em>Porting Mynewt OS code (left) by reconciling
the SiFive specification (centre) and the GD32 VF103 specification (right)</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<p id="45df"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">So in
theory we could reconcile the SiFive FE310 specification with the GD32 VF103 specification… And do
the mapping in code. (Note that the <code class="dy kn ko kp kq b">msip</code> register is mapped to
different addresses on SiFive FE310 and GD32 VF103)</p>
<p id="65a7"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><strong
class="ht ir">But some RISC-V features cant be reconciled</strong>. Below we see that interrupt
handlers are implemented differently for SiFive FE310 and GD32 VF103. And the same Mynewt Kernel
function cant possibly cater for both types of interrupt handlers…</p>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k16.png" /></p>
<figcaption><p><em>Unable to port Mynewt OS code (left) because
the SiFive specification (centre) cant be reconciled with the GD32 VF103 specification (right)
</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<p id="38cf"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><em
class="ip">Why the Irreconcilable Differences? Isnt RISC-V a standard specification?</em></p>
<p id="5409"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Remember
that RISC-V is an <strong class="ht ir">open-source specification</strong>… Which is bound to have
variations in implementation. <em class="ip">(Pointless to create the exact same thing and compete
with others)</em></p>
<p id="eb10"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">The
RISC-V CPU implemented for GigaDevice GD32 VF103 is actually the <a
href="https://github.com/nucleisys/Bumblebee_Core_Doc"
class="cm iq" rel="noopener nofollow"><strong class="ht ir">Nuclei N200 “Bumblebee”
Core</strong></a>, created by another company (Nuclei).</p>
<p id="00ad"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">The
RISC-V Instruction Set is well defined. So no worries about the GCC compiler generating some dubious
code that will crash a RISC-V CPU designed by SiFive or Nuclei.</p>
<p id="b15d"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">The
problem is with things like interrupt handlers: enabling/disabling specific interrupts, setting
interrupt priorities. These are based on memory-mapped registers, which can be implemented
differently by the RISC-V CPU makers.</p>
<p id="ba4a"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">And the
RISC-V CPU makers can implement unique features as well…</p>
<p id="6df4"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">1
SiFive has a <em class="ip">“Claim Interrupt”</em> feature thats unique to them <em
class="ip">(Check the SiFive FE310-G000 </em><a
href="https://sifive.cdn.prismic.io/sifive%2Ffeb6f967-ff96-418f-9af4-a7f3b7fd1dfc_fe310-g000-ds.pdf"
class="cm iq" rel="noopener nofollow"><em class="ip">datasheet</em></a><em class="ip"> and </em><a
href="https://sifive.cdn.prismic.io/sifive%2F500a69f8-af3a-4fd9-927f-10ca77077532_fe310-g000.pdf"
class="cm iq" rel="noopener nofollow"><em class="ip">manual</em></a><em class="ip">)</em></p>
<p id="81f6"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">2
Nuclei implements an interrupt vector system thats similar to Arm/STM32, because their CPU is
supposed to work like Blue Pill on RISC-V <em class="ip">(Check the </em><a
href="https://github.com/nucleisys/Bumblebee_Core_Doc"
class="cm iq" rel="noopener nofollow"><em class="ip">Nuclei N200 “Bumblebee” Core</em></a><em
class="ip"> docs)</em></p>
<p id="d208"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">So
tweaking the SiFive code to make it work for GD32 VF103 will be very difficult… <em class="ip">Might
as well port the code from STM32 F103 to GD32 VF103 since they are somewhat similar!</em> (Which I
did for the <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/hw/mcu/gigadevice/gd32vf103/src/hal_timer.c"
class="cm iq" rel="noopener nofollow">HAL Timer</a> code)</p>
</div>
</div>
</section>
<div class="n p fl jb jc jd" role="separator"><span class="je fz hb jf jg jh"></span><span
class="je fz hb jf jg jh"></span><span class="je fz hb jf jg"></span></div>
<section class="dh di dj dk dl">
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<h1 id="e337"
class="ji jj en cg jk jl jm hw jn jo jp ia jq jr js jt ju jv jw jx jy jz ka kb kc kd fk">Mynewt
Kernel Support for RISC-V</h1>
<p id="1a40"
class="hr hs en ht b hu ke hw hx hy kf ia ib ic kg ie if ig kh ii ij ik ki im in io dh fk">SiFive
HiFive1 was the first and only port of Mynewt to RISC-V. <em class="ip">Who knew that somebody
someday would create a Franken-microcontroller with RISC-V for brains and Blue Pill for the
body?</em></p>
<p id="4922"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">So as
expected we have some portability issues for RISC-V in the Mynewt Kernel… After all, we have seen
that different RISC-V CPUs can implement interrupts wildly differently.</p>
<p id="3026"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Im
making some <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/hw/mcu/gigadevice/gd32vf103/src/os_arch_rv32imac_patch.c"
class="cm iq" rel="noopener nofollow">ugly patches</a> to the RISC-V kernel files below. Hopefully
when Mynewt runs on GD32 VF103, well find a good way to merge my patches.</p>
<div class="figure it iu iv iw ix dm cz da paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k17.png" /></p>
<figcaption><p><em>RISC-V rv32imac Kernel Support at <a
href="https://github.com/apache/mynewt-core/tree/master/kernel/os/src/arch/rv32imac"
class="cm iq"
rel="noopener nofollow">https://github.com/apache/mynewt-core/tree/master/kernel/os/src/arch/rv32imac</a>
</em></p></figcaption>
</div>
</div>
</div>
</section>
<div class="n p fl jb jc jd" role="separator"><span class="je fz hb jf jg jh"></span><span
class="je fz hb jf jg jh"></span><span class="je fz hb jf jg"></span></div>
<section class="dh di dj dk dl">
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<h1 id="0214"
class="ji jj en cg jk jl jm hw jn jo jp ia jq jr js jt ju jv jw jx jy jz ka kb kc kd fk">Flashing
and Debugging with JTAG and OpenOCD</h1>
<p id="23a5"
class="hr hs en ht b hu ke hw hx hy kf ia ib ic kg ie if ig kh ii ij ik ki im in io dh fk">The
ST-Link USB Programmer works really well for flashing and debugging STM32 Blue Pill, even the Nordic
nRF52. <em class="ip">Why not use it for GD32 VF103?</em></p>
<p id="6f3a"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Well
ST-Link runs on the <a
href="https://developer.arm.com/architectures/cpu-architecture/debug-visibility-and-trace/coresight-architecture/serial-wire-debug"
class="cm iq" rel="noopener nofollow">SWD (Serial Wire Debug) protocol</a>, which was created by
Arm and is implemented inside the Arm CPU. Running SWD on RISC-V is simply not possible.</p>
<p id="6907"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Instead,
my GD32VF103C-START board connects directly to my computer via the <a
href="https://en.wikipedia.org/wiki/JTAG" class="cm iq"
rel="noopener nofollow"><strong class="ht ir">JTAG protocol</strong></a> on USB, for flashing and
debugging. (GigaDevice calls this interface <strong class="ht ir">GD-Link</strong>)</p>
<p id="a790"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">When I
connect the board to my computers USB port, something interesting happens…</p>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k18.jpeg" /></p>
<figcaption><p><em>GD32VF103C-START board connected to macOS
</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<p id="aa6b"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">macOS
identifies the RISC-V board as a CMSIS-DAP Adapter thats<em class="ip"> </em>manufactured by<em
class="ip"> “GD32 ARM”! Why would a RISC-V board identify itself as an Arm board?</em></p>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k19.jpeg" /></p>
<figcaption><p><em>GD32VF103C-START board containing GD32 VF103 on
RISC-V (left) and GD32 F103 on Arm (right)</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<p id="ba98"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Thats
because this particular board uses a <strong class="ht ir">Secondary GD32 F103 (Arm)</strong>
microcontroller to serve as the JTAG flashing and debugging controller for the <strong
class="ht ir">Primary GD32 VF103 (RISC-V)</strong> microcontroller! <em class="ip">(Remember that
GigaDevice makes Arm and RISC-V microcontrollers)</em></p>
<p id="6cea"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">
Fortunately the OpenOCD scripts for GD32 VF103 are <a
href="https://github.com/Tencent/TencentOS-tiny/blob/master/doc/14.How_to_build_RISC-V_eclipse_development_environment.md"
class="cm iq" rel="noopener nofollow">published on the TencentOS website</a>. <em
class="ip">(</em><a
href="https://github.com/Tencent/TencentOS-tiny/blob/master/README_en.md"
class="cm iq" rel="noopener nofollow"><em class="ip">TencentOS</em></a><em class="ip"> is a
lightweight embedded OS that talks to Tencent Cloud)</em></p>
<p id="ab96"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Based on
TencentOS OpenOCD scripts, I was able to derive and test successfully the <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/scripts/gd32vf103"
class="cm iq" rel="noopener nofollow">flash scripts</a> and <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/.vscode/launch-gd32vf103.json#L4"
class="cm iq" rel="noopener nofollow">GDB Debugger script</a> for Mynewt OS. The debugger is fully
integrated with Visual Studio Code.</p>
<p id="bcf0"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">The
OpenOCD scripts require a <a
href="https://github.com/riscv-mcu/riscv-openocd"
class="cm iq" rel="noopener nofollow"><strong class="ht ir">fork of OpenOCD that supports
RISC-V</strong></a>. I have <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/scripts/install-mac.sh#L61-L69"
class="cm iq" rel="noopener nofollow">built the RISC-V fork of OpenOCD successfully on macOS</a>
(but not on Windows yet)</p>
<p id="9d0a"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><a
href="https://platformio.org/" class="cm iq"
rel="noopener nofollow"><strong class="ht ir">PlatformIO</strong></a> was a valuable reference for
checking that the Mynewt Bootloader and Application Firmware Builds look correct. <em class="ip">(I
eyeballed the disassembled RISC-V code, check the “References” section below)</em></p>
</div>
</div>
</section>
<div class="n p fl jb jc jd" role="separator"><span class="je fz hb jf jg jh"></span><span
class="je fz hb jf jg jh"></span><span class="je fz hb jf jg"></span></div>
<section class="dh di dj dk dl">
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<h1 id="5523"
class="ji jj en cg jk jl jm hw jn jo jp ia jq jr js jt ju jv jw jx jy jz ka kb kc kd fk">Rust on
RISC-V</h1>
<p id="6a48"
class="hr hs en ht b hu ke hw hx hy kf ia ib ic kg ie if ig kh ii ij ik ki im in io dh fk">My <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/scripts/build-app.sh"
class="cm iq" rel="noopener nofollow">custom Mynewt build scripts</a> have been updated to build
<a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/rust"
class="cm iq" rel="noopener nofollow"><strong class="ht ir">Rust Applications</strong></a> for
hosting on GD32 VF103 (<code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/scripts/build-app.sh#L100-L102" class="cm iq" rel="noopener nofollow">cargo build</a></code>
for target <code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/scripts/build-app.sh#L8-L11" class="cm iq" rel="noopener nofollow">riscv32imac-unknown-none-elf</a></code>).
The Rust source code may be found in the following folders…</p>
<p id="4c0b"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/rust/app" class="cm iq" rel="noopener nofollow">rust/app</a></code>:
Simple Rust Application that polls a temperature sensor by calling <a
href="https://mynewt.apache.org/latest/os/modules/sensor_framework/sensor_framework.html"
class="cm iq" rel="noopener nofollow">Mynewt Sensor Framework</a> <em class="ip">(</em><a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/rust/macros"
class="cm iq" rel="noopener nofollow"><em class="ip">More details</em></a><em class="ip">)</em>
</p>
<p id="246e"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/rust/mynewt" class="cm iq" rel="noopener nofollow">rust/mynewt</a></code>:
Rust Wrappers for Mynewt API <em class="ip">(</em><a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/rust/macros"
class="cm iq" rel="noopener nofollow"><em class="ip">More details</em></a><em class="ip">)</em>
</p>
<p id="f93f"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/rust/macros" class="cm iq" rel="noopener nofollow">rust/macros</a></code>:
Rust Procedural Macros for generating Mynewt Rust Wrappers <em class="ip">(</em><a class="cm iq"
rel="noopener"
href="https://lupyuen.github.io/articles/safer-simpler-embedded-rust-with-apache-mynewt-on-stm32-blue-pill"><em
class="ip">More details</em></a><em class="ip">)</em></p>
<p id="cb62"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">For the
Rust Application Build Log and RISC-V Disassembly, check the <em class="ip">“References”</em>
section below.</p>
<p id="e388"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><strong
class="ht ir">UPDATE 1 Oct 2020</strong>: My <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/scripts/build-app.sh"
class="cm iq" rel="noopener nofollow">custom Mynewt build script</a> needs to be updated for the
latest Rust Compiler…</p>
<p id="9fec"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">1⃣ The
Rust library should be built as a Static Library, not a Dynamic Library. Change <code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/rust/app/Cargo.toml" class="cm iq" rel="noopener nofollow">rust/app/Cargo.toml</a></code>
from…</p>
<pre
class="it iu iv iw ix li lj bv"><span id="a22d" class="fk lk jj en kq b ll lm ln s lo">[lib]<br/>name = &quot;app&quot; # Output will be named `libapp.rlib`<br/>test = false<br/>bench = false</span></pre>
<p id="43ba"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">To…</p>
<pre
class="it iu iv iw ix li lj bv"><span id="47ef" class="fk lk jj en kq b ll lm ln s lo">[lib]<br/>name = &quot;app&quot; # Output will be named `libapp.lib`<br/>test = false<br/>bench = false<br/>crate-type = [&quot;staticlib&quot;]</span></pre>
<p id="9a12"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">2⃣ The
build script needs to link the Static Library instead of the Dynamic Library. Change <code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/scripts/build-app.sh" class="cm iq" rel="noopener nofollow">scripts/build-app.sh</a></code>
from…</p>
<pre
class="it iu iv iw ix li lj bv"><span id="9fc1" class="fk lk jj en kq b ll lm ln s lo"># Location of the compiled Rust app and external libraries. The Rust compiler generates a *.rlib archive for the Rust app and each external Rust library here.</span><span id="b21b" class="fk lk jj en kq b ll lp lq lr ls lt ln s lo">rust_build_dir=$PWD/target/$rust_build_target/$rust_build_profile/deps</span></pre>
<p id="3da6"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">To…</p>
<pre
class="it iu iv iw ix li lj bv"><span id="cc7b" class="fk lk jj en kq b ll lm ln s lo"># Location of the compiled Rust app and external libraries. The Rust compiler generates a *.lib archive for the Rust app and each external Rust library here.</span><span id="396b" class="fk lk jj en kq b ll lp lq lr ls lt ln s lo">rust_build_dir=$PWD/target/$rust_build_target/$rust_build_profile</span></pre>
<p id="6100"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">3⃣ Also
change <code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/scripts/build-app.sh" class="cm iq" rel="noopener nofollow">scripts/build-app.sh</a></code>
from …</p>
<pre
class="it iu iv iw ix li lj bv"><span id="fb23" class="fk lk jj en kq b ll lm ln s lo"># Delete the compiled Rust app to force the Rust build to relink the Rust app. Sometimes there are multiple copies of the compiled app, this deletes all copies.</span><span id="9047" class="fk lk jj en kq b ll lp lq lr ls lt ln s lo">rust_app_build=$rust_build_dir/libapp*.rlib</span></pre>
<p id="55b1"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">To…</p>
<pre
class="it iu iv iw ix li lj bv"><span id="8f32" class="fk lk jj en kq b ll lm ln s lo"># Delete the compiled Rust app to force the Rust build to relink the Rust app.</span><span id="dbce" class="fk lk jj en kq b ll lp lq lr ls lt ln s lo">rust_app_build=$rust_build_dir/libapp.a</span></pre>
<p id="453c"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">4
Finally change <code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/scripts/build-app.sh" class="cm iq" rel="noopener nofollow">scripts/build-app.sh</a></code>
from …</p>
<pre
class="it iu iv iw ix li lj bv"><span id="0d30" class="fk lk jj en kq b ll lm ln s lo"># Extract the object (*.o) files in the compiled Rust output (*.rlib).</span><span id="b8bf" class="fk lk jj en kq b ll lp lq lr ls lt ln s lo">rust_build=$rust_build_dir/*.rlib</span></pre>
<p id="896f"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">To…</p>
<pre
class="it iu iv iw ix li lj bv"><span id="cc08" class="fk lk jj en kq b ll lm ln s lo"># Extract the object (*.o) files in the compiled Rust output.</span><span id="f769" class="fk lk jj en kq b ll lp lq lr ls lt ln s lo">rust_build=$rust_build_dir/libapp.a</span></pre>
<p id="6d26"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">For
reference, compare with the nRF52 version of the build script for PineTime Smart Watch: <code
class="dy kn ko kp kq b"><a href="https://github.com/lupyuen/pinetime-rust-mynewt/blob/master/scripts/build-app.sh" class="cm iq" rel="noopener nofollow">github.com/lupyuen/pinetime-rust-mynewt/scripts/build-app.sh</a></code>
</p>
</div>
</div>
</section>
<div class="n p fl jb jc jd" role="separator"><span class="je fz hb jf jg jh"></span><span
class="je fz hb jf jg jh"></span><span class="je fz hb jf jg"></span></div>
<section class="dh di dj dk dl">
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<h1 id="a524"
class="ji jj en cg jk jl jm hw jn jo jp ia jq jr js jt ju jv jw jx jy jz ka kb kc kd fk">Whats
Next?</h1>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm aj paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/k20.png" /></p>
<figcaption><p><em>Fixing Mynewt context switching on GD32 VF103
with Visual Studio Code Debugger</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<p id="f8a5"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">The
work-in-progress port of Mynewt OS to GD32 VF103 may be found in the <code
class="dy kn ko kp kq b">gd32vf103</code> branch of this repository…</p>
<div class="lv lw lx ly lz ma"><a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103"
target="_blank" rel="noopener nofollow">
<div class="mb n aq">
<div class="mc n md p me mf">
<h2 class="eo b mg mh bm mi ge gf mj gh gi em fk">lupyuen/stm32bluepill-mynewt-sensor</h2>
</div>
<div class="mn s">
<div class="mo s mp mq mr mn ms mt ma"></div>
</div>
</div>
</a></div>
<p id="5e58"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">As shown
in the screen above, the Visual Studio Code debugger now works great with Mynewt OS on GD32 VF103.
The porting work continues…</p>
<p id="d63d"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><em
class="ip">Check this article for updates…</em></p>
<div class="lv lw lx ly lz ma"><a target="_blank" rel="noopener"
href="https://lupyuen.github.io/articles/hey-gd32-vf103-on-risc-v-i-surrender-for-now">
<div class="mb n aq">
<div class="mc n md p me mf">
<h2 class="eo b mg mh bm mi ge gf mj gh gi em fk">Hey GD32 VF103 on RISC-V: I surrender… For
now</h2>
</div>
<div class="mn s">
<div class="mu s mp mq mr mn ms mt ma"></div>
</div>
</div>
</a></div>
<p id="eee1"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><strong
class="ht ir">UPDATE:</strong> Embedded Rust with Mynewt on GD32 VF103 is <em
class="ip">ALIVE</em>! Now combing through the <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103/hw/mcu/gigadevice/gd32vf103"
class="cm iq" rel="noopener nofollow">Microcontroller Package</a> and fixing things…<br /><a
href="https://weibo.com/7285313566/Ie0qBteYP"
class="cm iq" rel="noopener nofollow">微博视频</a></p>
</div>
</div>
<div class="dm aj">
<div class="figure it iu iv iw ix dm">
<p><a href="https://youtu.be/A-4NkT6BUFg">[Watch the video on YouTube]</a></p>
<figcaption><p><em>Embedded Rust with Mynewt on GD32 VF103 is
ALIVE! With Visual Studio Code Debugger</em></p></figcaption>
</div>
</div>
</section>
<div class="n p fl jb jc jd" role="separator"><span class="je fz hb jf jg jh"></span><span
class="je fz hb jf jg jh"></span><span class="je fz hb jf jg"></span></div>
<section class="dh di dj dk dl">
<div class="n p">
<div class="ab ac ae af ag ek ai aj">
<h1 id="bcae"
class="ji jj en cg jk jl jm hw jn jo jp ia jq jr js jt ju jv jw jx jy jz ka kb kc kd fk">References
</h1>
<p id="49db"
class="hr hs en ht b hu ke hw hx hy kf ia ib ic kg ie if ig kh ii ij ik ki im in io dh fk"><strong
class="ht ir">GigaDevice GD32 VF103</strong> documents and firmware library may be found
here…<br /><code
class="dy kn ko kp kq b"><a href="http://gd32mcu.21ic.com/en/" class="cm iq" rel="noopener nofollow">http://gd32mcu.21ic.com/en/</a></code>
</p>
<p id="dbe8"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">Useful
documents and code from the above link…</p>
<ol class="">
<li id="eb06"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io mw mx my fk">
<strong class="ht ir">GD32VF103 User Manual”</strong></li>
<li id="324b"
class="hr hs en ht b hu mz hw hx hy na ia ib ic nb ie if ig nc ii ij ik nd im in io mw mx my fk">
<strong class="ht ir">GD32VF103 Datasheet”</strong></li>
<li id="de5e"
class="hr hs en ht b hu mz hw hx hy na ia ib ic nb ie if ig nc ii ij ik nd im in io mw mx my fk">
<strong class="ht ir">GD32VF103 Firmware Library”</strong></li>
<li id="b318"
class="hr hs en ht b hu mz hw hx hy na ia ib ic nb ie if ig nc ii ij ik nd im in io mw mx my fk">
<strong class="ht ir">“GD-Link Adapter User Manual”</strong></li>
</ol>
<p id="45fc"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk"><strong
class="ht ir">Nuclei N200 “Bumblebee” Core</strong> (the RISC-V CPU for GD32 VF103) documents may
be found here…<br /><code
class="dy kn ko kp kq b"><a href="https://github.com/nucleisys/Bumblebee_Core_Doc" class="cm iq" rel="noopener nofollow">https://github.com/nucleisys/Bumblebee_Core_Doc</a></code>
</p>
<p id="ff1d"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io dh fk">The
following logs were recorded during the building and flashing of the Bootloader and Application
Firmware Images…</p>
<ol class="">
<li id="b673"
class="hr hs en ht b hu hv hw hx hy hz ia ib ic id ie if ig ih ii ij ik il im in io mw mx my fk">
<a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/logs/build-bootloader.log"
class="cm iq" rel="noopener nofollow">Bootloader Build Log</a></li>
<li id="6f39"
class="hr hs en ht b hu mz hw hx hy na ia ib ic nb ie if ig nc ii ij ik nd im in io mw mx my fk">
<a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/logs/build-application.log"
class="cm iq" rel="noopener nofollow">Application Build Log</a> (includes Rust)</li>
<li id="bffb"
class="hr hs en ht b hu mz hw hx hy na ia ib ic nb ie if ig nc ii ij ik nd im in io mw mx my fk">
<a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/logs/image.log"
class="cm iq" rel="noopener nofollow">Image Application Log</a></li>
<li id="e8bd"
class="hr hs en ht b hu mz hw hx hy na ia ib ic nb ie if ig nc ii ij ik nd im in io mw mx my fk">
<a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/logs/load-bootloader.log"
class="cm iq" rel="noopener nofollow">Flash Bootloader Log</a></li>
<li id="80c1"
class="hr hs en ht b hu mz hw hx hy na ia ib ic nb ie if ig nc ii ij ik nd im in io mw mx my fk">
<a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/logs/load-application.log"
class="cm iq" rel="noopener nofollow">Flash Application Log</a></li>
<li id="2c6d"
class="hr hs en ht b hu mz hw hx hy na ia ib ic nb ie if ig nc ii ij ik nd im in io mw mx my fk">
<a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/logs/boot_stub.elf.lst"
class="cm iq" rel="noopener nofollow">Bootloader RISC-V Disassembly</a></li>
<li id="845d"
class="hr hs en ht b hu mz hw hx hy na ia ib ic nb ie if ig nc ii ij ik nd im in io mw mx my fk">
<a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/logs/boot_stub.elf.map"
class="cm iq" rel="noopener nofollow">Bootloader Linker Map</a></li>
<li id="c628"
class="hr hs en ht b hu mz hw hx hy na ia ib ic nb ie if ig nc ii ij ik nd im in io mw mx my fk">
<a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/logs/my_sensor_app.elf.lst"
class="cm iq" rel="noopener nofollow">Application RISC-V Disassembly</a> (includes Rust)</li>
<li id="d4f8"
class="hr hs en ht b hu mz hw hx hy na ia ib ic nb ie if ig nc ii ij ik nd im in io mw mx my fk">
<a href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/gd32vf103/logs/my_sensor_app.elf.map"
class="cm iq" rel="noopener nofollow">Application Linker Map</a> (includes Rust)</li>
</ol>
</div>
</div>
</section>
</div>
</article>
</div>
</div>
</div>
<ul>
<li>
<p><a href="https://github.com/sponsors/lupyuen">Sponsor me a coffee</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>
</body>
</html>
<!--
FILE ARCHIVED ON 00:54:03 Nov 25, 2020 AND RETRIEVED FROM THE
INTERNET ARCHIVE ON 23:09:57 Feb 22, 2021.
JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.
ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
SECTION 108(a)(3)).
-->
<!--
playback timings (ms):
loaddict: 131.085
exclusion.robots.policy: 0.373
exclusion.robots: 0.386
CDXLines.iter: 36.431 (3)
captures_list: 381.075
esindex: 0.013
load_resource: 384.912
LoadShardBlock: 336.551 (3)
PetaboxLoader3.datanode: 333.147 (5)
PetaboxLoader3.resolve: 74.736
RedisCDXSource: 0.776
-->