If you know anything about microcontrollers you most likely know that blinking a LED on the microcontroller development board is what we call a hello-world program for other technologies. Over the years I have done this exercise 10 times or more using different microcontrollers and boards. Once the board-specifics, compiler configurations, flashing firmware are all figured out, one can take a faster pace but without this first steps one can not do anything with the microcontroller at all. And for sure each microcontroller offers its unique challenges. Today I have spent the better part of the day figuring out how to get started with the N76 on Linux.
I have an interest in Value Line Gadgets like the ones mass produced in China. Until about fall 2018 many of these have been equipped with STM8 chips or equivalents. Today if you order such a component it is a pretty safe bet that the STM8 has been replaced by the pin compatible Nuvoton N76E003AT20. Many argue that this has to do with costs per unit but I can not say for sure. Couple of weeks ago I have found a fantastic site by Jay Carlson. THE AMAZING $1 MICROCONTROLLER goes into all details on 21 different microcontrollers in that segment including pros, cons, tooling, etc. To me it was the most impressive work I have seen in all 2018 by far! Of course he covers the Nuvoton N76.
Big chip manufacturers often provide proprietary IDEs, frameworks and such but in the case of cheap mass market chips they often go with Keil or IAR. I can not say anything against these tools but they are Windows only and as a Maker I prefer Linux and Open Source tools. We have the small device C compiler SDCC that supports the 8051 architecture of the N76. Nuvoton offers the NuMicro ICP software for uploading the firmware. The NuMicro is also a Windows tool but it almost works on Linux using wine. Compared to the STM8 the Linux & Open Source tooling is far from optimal but I stay positive and look forward to better Linux support in the future.
Enough said, lets look into microcontroller hardware! I use the Nuvoton NuLink programmer (red component in the photo above) and a N76E003 development board (blue component).
One of the challenges I faced today with this new board was that unlike other development boards the one for N76 has the onboard LED connected via jumper J2. J2 is missing in this version and I had to solder in a bridge for J2 before the onboard LED could be used.
The nu-link programmer is connected to the laptop via USB. For it to work on Arch Linux I had to add the “/etc/udev/rules.d/88-nulink.rules” file with config:
Now, lets look into some code!
Here the simple blink sample gpio.c:
The rest of the code is my quick & dirty port of Nuvoton’s sample for Keil. So far I ported only the parts I needed for this blink sample. Here you can find this hack including Makefile.
Running NuMicro on Linux using wine overall is at best a strange experience. The software can not be used without mouse so no-way for automation! And the mouse does only work 30% of the time. If the mouse is not working I have to close NuMicro and restart it. If the mouse is working then flashing the firmware works reliable.
Like I said before I hope for better Linux tooling to support flashing the N76 from the command line. Something as good as for example stm8flash for the STM8s. Till then I hope somebody comes up with a better way of using the NuMicro on Linux by fine tuning wine or using Docker…
Don’t get me wrong, if I was using the N76 professionally, I would follow Jay’s suggestion to buy a Windows laptop and a Keil license. For writing some small programs in my spare time this will do for now.
I hope this post is helpful to you.
All the best, Mark