lupyuen.org/articles/hey-gd32-vf103-on-risc-v-i-surrender-for-now.html

380 lines
No EOL
25 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/hey-gd32-vf103-on-risc-v-i-surrender-for-now.html" />
<!-- End Wayback Rewrite JS Include -->
<title data-rh="true">Hey GD32 VF103 on RISC-V: I surrender… For now - Lup Yuen Lee 李立源 - 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="2019-11-23T15:55:20.275Z" />
<meta data-rh="true" name="title"
content="Hey GD32 VF103 on RISC-V: I surrender… For now - Lup Yuen Lee 李立源 - Medium" />
<meta data-rh="true" property="og:title" content="Hey GD32 VF103 on RISC-V: I surrender… For now" />
<meta data-rh="true" property="twitter:title" content="Hey GD32 VF103 on RISC-V: I surrender… For now" />
<meta data-rh="true" name="description"
content="I have failed only once… Building a simple IoT Sensor Device on FPGA. The reason for that failure was strongly evident… FPGA Programming is not meant for ordinary mortals! I tucked that project away…" />
<meta data-rh="true" property="og:description"
content="Me vs Tech: I will never admit defeat to Tech because I have too much pride… Or toxic masculinity." />
<meta data-rh="true" property="twitter:description"
content="Me vs Tech: I will never admit defeat to Tech because I have too much pride… Or toxic masculinity." />
<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" />
<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="5 min read" />
<meta property="og:image"
content="https://lupyuen.github.io/images/legacy/h1.png">
<!-- 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">
<article>
<section class="cj ck cl cm ak cn ce n co"></section><span class="r"></span>
<div>
<div class="cp u cq cr cs ct"></div>
<section class="cu cv cw cx cy">
<div class="cz ak">
<div class="figure da cz ak paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/h1.png" /></p>
<figcaption><p><em>“All creatures bow down and surrender to the
mighty GigaDevice GD32 VF103 on RISC-V!”</em></p></figcaption>
</div>
</div>
<div class="n p">
<div class="ac ae af ag ah dz aj ak">
<div>
<div id="a62e" class="ea eb ec bk ed b ee ef eg eh ei ej ek">
<h1 class="ed b ee el ec">Hey GD32 VF103 on RISC-V: I surrender… For now</h1>
</div>
<div class="em">
<div class="n en eo ep eq">
<div class="o n">
<div><a rel="noopener"
href="https://lupyuen.github.io">
<div class="dd er es">
<div class="bs n et o p cp eu ev ew ex ey ct"></div>
</div>
</a></div>
<div class="fa ak r">
<div class="n">
<div style="flex:1"><span class="bj b bk bl bm bn r ec q">
<div class="fb n o fc"><span class="bj dy ds bl di fd fe ff fg fh ec"><a
class="at au av aw ax ay az ba bb bc fi bf bg bh bi" rel="noopener"
href="https://lupyuen.github.io">Lup
Yuen Lee 李立源</a></span>
</div>
</span></div>
</div><span class="bj b bk bl bm bn r bo bp"><span class="bj dy ds bl di fd fe ff fg fh bo">
<div><a class="at au av aw ax ay az ba bb bc fi bf bg bh bi" rel="noopener"
href="https://lupyuen.github.io/articles/hey-gd32-vf103-on-risc-v-i-surrender-for-now">
23 Nov 2019</a> <!-- -->·
<!-- -->
<!-- -->5
<!-- --> min read
</div>
</span></span>
</div>
</div>
</div>
</div>
</div>
<p id="3564" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">Me vs Tech: I will <strong
class="gj gv">never admit defeat to Tech</strong> because I have too much pride… Or toxic
masculinity.</p>
<p id="c041" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu"><em class="gw">I have failed only
once…</em> <a class="at cg gx gy gz ha" target="_blank" rel="noopener"
href="https://web.archive.org/https://medium.com/coinmonks/program-your-first-fpga-with-gowin-gw1n-4-b0d5c22b9fea">Building
a simple IoT Sensor Device on FPGA</a>. The reason for that failure was strongly evident… <em
class="gw">FPGA Programming is not meant for ordinary mortals!</em> I tucked that project away until
we have better open-source graphical FPGA programming tools that can synthesise exactly what I need,
without micromanaging every single LUT <em class="gw">(OK thats an exaggeration)</em></p>
<p id="6481" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu"><strong class="gj gv">Porting
</strong><a href="https://mynewt.apache.org/"
class="at cg gx gy gz ha" target="_blank" rel="noopener nofollow"><strong class="gj gv">Mynewt
OS</strong></a><strong class="gj gv"> to </strong><a
href="https://www.gigadevice.com/products/microcontrollers/gd32/risc-v/"
class="at cg gx gy gz ha" target="_blank" rel="noopener nofollow"><strong class="gj gv">GD32
VF103</strong></a><strong class="gj gv"> on </strong><a
href="https://en.wikipedia.org/wiki/RISC-V"
class="at cg gx gy gz ha" target="_blank" rel="noopener nofollow"><strong
class="gj gv">RISC-V</strong></a><strong class="gj gv"> is my second failure</strong>. <a
class="at cg gx gy gz ha" target="_blank" rel="noopener"
href="https://lupyuen.github.io/articles/porting-apache-mynewt-os-to-gigadevice-gd32-vf103-on-risc-v">As
I have documented earlier</a>, the low level Mynewt OS code was running fine, even Embedded Rust.
But then other issues crept in. Heres what failure looks like…</p>
<div class="figure hc hd he hf hg cz cl cm paragraph-image">
<p><img src="https://lupyuen.github.io/images/legacy/h2.png" /></p>
<figcaption><p><em>History of GitHub commits on the GD32 VF103
port of Mynewt OS. From <a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/commits/gd32vf103"
class="at cg gx gy gz ha" target="_blank"
rel="noopener nofollow">https://github.com/lupyuen/stm32bluepill-mynewt-sensor/commits/gd32vf103</a>
</em></p></figcaption>
</div>
</div>
</div>
</section>
<hr class="hi dy hj hk hl dv hm hn ho hp hq" />
<section class="cu cv cw cx cy">
<div class="n p">
<div class="ac ae af ag ah dz aj ak">
<p><img src="https://lupyuen.github.io/images/legacy/h3.jpeg" /></p>
<p id="1af3" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">1<strong class="gj gv">Too
comfortable with Arm Semihosting, SWD Flashing + Debugging and ST-Link</strong></p>
<p id="34ff" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">After working on RISC-V for a
while, I gotta admit that Arm and STMicroelectronics did a really great job with programming support:
<strong class="gj gv">Flashing and Debugging</strong>!</p>
<p id="33ee" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">I love using <strong
class="gj gv">Arm Semihosting</strong> to display debug messages on OpenOCD! Yes some developers are
annoyed by the slow transfer of debug messages over Semihosting… But I solved it the software way:
Buffering in memory before going a giant dump of debug messages.</p>
<p id="8729" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">I dont like the hassle of
connecting another UART port just to see debug messages. To me, <strong class="gj gv">Embedded
Programming should be Plug and Play</strong>… Just Plug in the ST-Link USB Programmer and start
Playing with the gadget! Lets not subject Embedded Newbies to any extra hassle… <em class="gw">We
should be thankful they are still hanging on!</em></p>
<p id="47e8" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">While experimenting with Nordic
nRF52, I realised theres something magical about the ST-Link USB dongle. Its known as a High Level
Adapter for SWD, because <strong class="gj gv">ST-Link handles the complex SWD protocol
internally</strong> and presents a <strong class="gj gv">simple, high-speed USB interface</strong>
to OpenOCD. <em class="gw">(Thats why I had to use a Raspberry Pi to remove the Flash Protection on
nRF52)</em></p>
<p id="0353" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">So using ST-Link and OpenOCD to
flash and debug any STM32 microcontroller, even Nordic nRF52, are super efficient. Today I still enjoy
rapid iterative development on <a class="at cg gx gy gz ha" target="_blank" rel="noopener"
href="https://lupyuen.github.io/articles/sneak-peek-of-pinetime-smart-watch-and-why-its-perfect-for-teaching-iot"><strong
class="gj gv">PineTime Smart Watch</strong></a> (nRF52)… <em class="gw">Arm Semihosting + SWD +
ST-Link make the perfect workflow for Embedded Developers!</em></p>
<p id="b4eb" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">Now here are my gripes about
RISC-V and GD32 VF103…</p>
<ol class="">
<li id="8a70" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu hr hs ht">Took me a while to
figure out how to <strong class="gj gv">connect OpenOCD to GD32 VF103 via JTAG</strong>. <a
href="https://github.com/Tencent/TencentOS-tiny/blob/master/doc/14.How_to_build_RISC-V_eclipse_development_environment.md"
class="at cg gx gy gz ha" target="_blank" rel="noopener nofollow">Instructions were spotty</a>,
and I had to build a <a
href="https://github.com/riscv-mcu/riscv-openocd"
class="at cg gx gy gz ha" target="_blank" rel="noopener nofollow">special version of OpenOCD just
to support GD32 VF103</a>!</li>
<li id="9d76" class="gh gi ec bk gj b gk hu gm hv go hw gq hx gs hy gu hr hs ht">Building OpenOCD on
macOS to support GD32 VF103 was relatively painless. But <strong class="gj gv">building OpenOCD on
Windows</strong><em class="gw">It really hurts! </em>You can see in the Commit Log above that I
gave up after many failed attempts to build OpenOCD on Windows… Just not worth my time to solve this
tooling issue<em class="gw">. (I think GigaDevice should be the party to solve this and provide the
Windows binaries for OpenOCD!)</em></li>
<li id="11c6" class="gh gi ec bk gj b gk hu gm hv go hw gq hx gs hy gu hr hs ht"><strong
class="gj gv">Flashing over JTAG is slow</strong>. It disrupts my iterative coding workflow. And I
become much less productive. Wished theres some High Level Adapter for JTAG that flashes more
efficiently.</li>
<li id="7555" class="gh gi ec bk gj b gk hu gm hv go hw gq hx gs hy gu hr hs ht"><strong
class="gj gv">Debug output goes… where?</strong> JTAG doesnt expose a debug messaging port like
Arm Semihosting. So I have to use the UART port. Only <a
href="https://www.seeedstudio.com/Sipeed-USB-JTAG-TTL-RISC-V-Debugger-p-2910.html"
class="at cg gx gy gz ha" target="_blank" rel="noopener nofollow">Sipeeds JTAG dongle</a>
includes a UART interface… Are there other JTAG dongles that support this? I doubt so. <em
class="gw">(I gave up while porting the UART driver, which was supposed to make my debugging more
productive)</em></li>
</ol>
</div>
</div>
</section>
<hr class="hi dy hj hk hl dv hm hn ho hp hq" />
<section class="cu cv cw cx cy">
<div class="n p">
<div class="ac ae af ag ah dz aj ak">
<p id="a9f1" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">2<strong class="gj gv">GD32
VF103 is just too different from SiFive FE310-G000</strong></p>
<p id="635d" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">Mynewt (and Zephyr) has already
been ported to a RISC-V development board: <a
href="https://www.sifive.com/boards/hifive1"
class="at cg gx gy gz ha" target="_blank" rel="noopener nofollow"><strong class="gj gv">SiFive
HiFive1</strong></a> based on the <a
href="https://www.sifive.com/chip-designer#fe310"
class="at cg gx gy gz ha" target="_blank" rel="noopener nofollow"><strong class="gj gv">SiFive
FE310-G000</strong></a> microcontroller. So why dont we start with the HiFive1 code and tweak it
for GD32 VF103?</p>
<p id="90c6" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu"><em class="gw">Thats how I
started… And I quickly ran into deep sh… shenanigans.</em></p>
<p id="876a" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu"><strong class="gj gv">GD32 VF103
has too many I/O ports</strong>: UART, I2C, SPI, CAN, USB… Most of them dont exist on SiFive
FE310-G000. Most modern microcontrollers have a huge selection of ports so Im not blaming GigaDevice.
Since GD32 VF103 was inspired by STM32 Blue Pill (F103), it has as many ports as Blue Pill. <em
class="gw">(Thats the reason why I upgraded from Arduino Uno to Blue Pill… Farewell Bit Banging,
Hello Proper Ports!)</em></p>
<p id="9b7f" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">This causes problems when we port
an operating system like Mynewt to GD32 VF103… <strong class="gj gv">We need to build a
driver</strong> for UART, another for I2C, another for SPI, another for CAN, another for USB, …</p>
<p id="0217" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">I gave up while building the UART
driver (so that I could debug GD32 VF103 more productively).</p>
</div>
</div>
</section>
<hr class="hi dy hj hk hl dv hm hn ho hp hq" />
<section class="cu cv cw cx cy">
<div class="n p">
<div class="ac ae af ag ah dz aj ak">
<p id="95a8" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu"><strong class="gj gv">3⃣ GD32
VF103 is also too different from STM32 Blue Pill</strong></p>
<p id="1604" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu"><em class="gw">Since GD32 VF103
was inspired by STM32 Blue Pill, why not copy the driver code from Blue Pill?</em></p>
<p id="b9ff" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">Its not 100% the same.
GigaDevice tried very hard to make them look the same (even the Interrupt Vector Table). But the
architectures are fundamentally different: Arm vs RISC-V.</p>
<p id="3ce7" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">System Constants get renamed,
Peripheral Addresses get shuffled around, … It gets very tiring to reconcile the STM32 Blue Pill docs
with GD32 VF103.</p>
<p id="773d" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">Maybe if I had a whole class of
IoT students, I could assign this as homework. But to me it feels like… <em class="gw">Administrative
Paperwork</em>. Not sure if its worth my time.</p>
</div>
</div>
</section>
<hr class="hi dy hj hk hl dv hm hn ho hp hq" />
<section class="cu cv cw cx cy">
<div class="n p">
<div class="ac ae af ag ah dz aj ak">
<p id="3e6e" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu"><strong class="gj gv">4⃣ Is
there really an urgency to support RISC-V?</strong></p>
<p id="bb7d" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">Reflecting on my <a
class="at cg gx gy gz ha" target="_blank" rel="noopener"
href="https://lupyuen.github.io/articles/porting-apache-mynewt-os-to-gigadevice-gd32-vf103-on-risc-v">earlier
optimism about RISC-V and GD32 VF103</a>… It seemed to be a sure thing that the China-US Trade War
would escalate and the IoT Ecosystem in the East would stop producing Arm chips altogether, and move
on to RISC-V.</p>
<p id="b6a4" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu"><a
href="https://www.theverge.com/2019/10/25/20932096/arm-license-chip-architecture-huawei-trump-trade-ban-uk-us"
class="at cg gx gy gz ha" target="_blank" rel="noopener nofollow"><em class="gw">But thats not
happening any more</em></a><em class="gw">.</em></p>
<p id="c79e" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">I backtracked to first principles
and recalled… <em class="gw">What problem are we solving?</em></p>
<p id="c4bb" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">If we are trying to make sure
that RISC-V boards have a decent operating system like Mynewt (and a proper language like Rust) for
teaching IoT… Maybe thats not so urgent any more. The supply of STM32 Blue Pills and Nordic nRF52
microcontrollers will last for a long while.</p>
<p id="5e74" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">Meanwhile we have <a
class="at cg gx gy gz ha" target="_blank" rel="noopener"
href="https://lupyuen.github.io/articles/sneak-peek-of-pinetime-smart-watch-and-why-its-perfect-for-teaching-iot">$20
smart watches like PineTime</a> running on nRF52 desperately seeking a decent operating system like
Mynewt (and a proper language like Rust) for teaching IoT. <em class="gw">Isnt that an urgent problem
to solve?</em></p>
<p id="d2ed" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">Thus Im waving the White Flag at
RISC-V and GD32 VF103 for now… Retreating to the warm cozy feeling of Arm Semihosting, SWD Flashing +
Debugging and ST-Link… <a class="at cg gx gy gz ha" target="_blank" rel="noopener"
href="https://lupyuen.github.io/articles/building-a-rust-driver-for-pinetimes-touch-controller">As
I hack away productively on the PineTime Smart Watch</a>.</p>
<p id="654c" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu"><em class="gw">No Regrets!</em>
</p>
<p><img src="https://lupyuen.github.io/images/legacy/h4.jpeg" /></p>
</div>
</div>
</section>
<hr class="hi dy hj hk hl dv hm hn ho hp hq" />
<section class="cu cv cw cx cy">
<div class="n p">
<div class="ac ae af ag ah dz aj ak">
<p id="7630" class="gh gi ec bk gj b gk gl gm gn go gp gq gr gs gt gu">The incomplete port of Mynewt OS
to GD32 VF103 on RISC-V is at the <code class="dm hz ia ib ic b">gd32vf103</code> branch of the
repository below. Basic features like task scheduling are working and so is Rust… Just that we have no
drivers for UART, I2C, SPI, CAN, USB, …</p>
<div class="id ie if ig ih ii"><a
href="https://github.com/lupyuen/stm32bluepill-mynewt-sensor/tree/gd32vf103?source=post_page-----d39d0c7b0001----------------------"
rel="noopener nofollow">
<section class="il cl cm ak ce n ar im in io ip iq ir is it iu iv iw ix iy iz ja">
<div class="jb n co p jc jd">
<h2 class="bj je jf bl ec">
<div class="di ij fe ff ik fh">lupyuen/stm32bluepill-mynewt-sensor</div>
</h2>
</div>
<div class="ji r">
<div class="jj r jk jl jm ji jn jo jp"></div>
</div>
</section>
</a></div>
</div>
</div>
</section>
</div>
</article>
</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 16:06:06 Nov 23, 2019 AND RETRIEVED FROM THE
INTERNET ARCHIVE ON 23:05:43 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):
esindex: 0.01
PetaboxLoader3.resolve: 49.455
CDXLines.iter: 29.78 (3)
exclusion.robots.policy: 0.185
RedisCDXSource: 1.889
load_resource: 108.553
captures_list: 250.926
LoadShardBlock: 215.363 (3)
PetaboxLoader3.datanode: 95.794 (4)
exclusion.robots: 0.195
-->