Saturday, 29 January 2022

Sipeed LicheeRV Panel

Intro

The Sipeed LicheeRV 86 Panel is a very exciting product.  It is based on the same LicheeRV D1 board and dock but it includes a 4" touch screen and ethernet connection.  At $72 it is somewhat more expensive than the basic boards but it is much closer to being a self-contained working system.  It works on 5V USB or 12V supply.  The panel comes with a case which protects the board which is attached to its rear side.  In fact it could easily provide the basis for a home automation control.  It is only about the size of a light switch and could easily be wall mounted near a door way to activate room functions.  The only extra needed is a 12V power supply (similar to the one used by low voltage LEDs).


There is plenty of documentation available on the Sipeed BBS and the linux-sunxi community web-site has started to add descriptions.

Installation - Tina


I first installed the Tina WAFT (WebAssembly Framework for Things) image using good instructions which Sipeed provided, translated to English with Google Translate.  A USB cable connected to the USB-C UART port at one end and the PC at the other to provide power and a serial console.  The system boots in about 5 seconds into Maix Linux.  Tina / MaixLinux is a very small IoT (Internet of Things) linux which uses Busybox to provide basic command line tools. The image is only 115MB in size so it is great for small systems. I quickly tried looking at using WAFT but the demo didn't seem to work.  In addition, the panel screen didn't work initially (rapid scrolling of the image) so I moved on Debian.



Installation - Debian


The debain image is somewhat larger.  Initially I chose LicheeRV_Debian_86_480p.7z. It was easy enough to download from mega.nz although it was 1.1G compressed and expands into a 4GB image.
As usual I used PhoenixCard software to burn the image and inserted in the SD card on the back of the panel.  The system boots up without many errors and you can sign on via the serial console (putty) as sipeed or root.

The Panel has an ethernet connection using a rather unusual connector onto the back of the panel which is shown below.  The cable provided has an RJ45 and a barrel connector on one end and circuit board connectors for ethernet (on the left) and power (on the right).  If you want you can use the 12V power connector instead of using USB power input.  With the ethernet connected we can easily signin to the system using ssdh

When the system was booted up the 4 inch screen showed a signon screen scrolling vertically and was unuseable.  I tried all the different images, both Tina and Debian but the screen problem remained.  Eventually I tried over-writing the "fex" partition on the SD card (partition 1) with the fex file for a 720p display.  On booting the system works perfectly.  So the problem was that the downloaded images were for a 480p screen, which is the one which is described in the advert.  However I have a 720p screen which needs a different fex file.  I reported this on the LicheeRV/Nezha Telegram thread and a note will be added to the linux-sunxi community webpage to explain this.
I plugged a screen and keyboard into the HOST USB port and I was then able to signin to Debian.  The screen is 720p x 720p so although it is very small it is very detailed and if you look closely enough it is quite useable.  As a first test I ran HTOP to display system usage.
I wanted to display an image and there weren't any I could find on the system.  I needed to install wget using the apt package manager and could then download an image from my website and display it on the panel.  It looks very clear.

Initially I couldn't get the wireless interface to work on either Debian or Tina.  Once I realised that I am using the 8723ds wireless chip (not the xr829) I retrieved the correct images and wifi networking works fine.

I now have available a lovely RISC-V panel with ethernet / wifi with a small high quality screen. 





  





Thursday, 27 January 2022

Sipeed LicheeRV Dock

 A couple of weeks after I saw the Sipeed LicheeRV advertised and bought one, the LicheeRV Dock became available.  A docking station for the LicheeRV costs about £4.  I ordered a LicheeRV + Dock on 29th December and it was delivered 13th January.  The docking station provides a HDMI connection, a USB port, 40 pin connector and wifi (Realtek 8723DS), so there are many more things you can do with it.

 


Its specification is very similar to the Nezha which came out 6 months ago but it is about 1/3 the price.  This was expected, the Nezha gave people an early look at RISC-V.  The LicheeRV is more of a product.

Documentation for the LicheeRV is now available on the sipeed BBS and it is quite extensive.  Although it is initially in Chinese,  Google Translate does a perfectly acceptable job translating it into English for me.



There are also a number of images available to make installation easier.  Firstly I tried the Debian image and, once I had plugged a screen in on the HDMI port and a keyboard/mouse on the USB port I was ready to go.


It was easy to boot into Debian and use the GUI.  Once I worked out the wifi is RTL8723DS and chosen the right image I could configure the wifi and SSH into the system easily enough.

Similarly Tina is easy to setup.  I downloaded and burned the image for tina hdmi 8723 and booted up.  I was then able to configure wifi details and connect to the network.

The screen is used as a monitor rather than a terminal I think.  When booting it show a 480x480 screen shot in chinese with a date 2021.12.8.  I can display a color bar test but the frame viewer doesn't work for me (yet?).


So for about £20 I have a working RV system with network, HDMI and a choice of Operating Systems.




Tuesday, 25 January 2022

LFS : Linux from Scratch

 Why

Linux installation is straightforward.  For an RPi you just download an image in Windows, burn it on to an SD card, insert the card in RPi with screen, keyboard attached and turn the power on.  Adding network capability is similarly easy, in Raspbian you specify the package name to the apt command and the necessary steps are completed to install dependencies and the requested software.

From other activities I know that setting up partitions and choosing a kernel are also important.  Building a kernel is a matter of ensuring you have all the necessary files and running one long compile job.

The missing part of the picture is the ability to set up all the basic software in files and folders so that the system works.  It turns out that, as expected, there is a lot of work involved.  Thanks to the LFS (Linux from Scratch) project and the PiLFS ( RPi LFS) guide I have been able to successfully build my own minimal system, sign on, add packages etc.    

It is a challenging objective and the LFS team have done an amazing job in making each of the 100 or so tasks understandable so that you can create the Linux system you want.  Even with this  I would have struggled to build my own system.  PiLFS provides a guide to how to implement LFS on a Pi system together with a host configuration containing working build software and two large scripts to automate many of the tasks.  I feel that LFS is awesome and I'm grateful to PiLFS for making it practical to build with my patchy Linux knowledge.

Host System

You need a set of software running on the host system to be able to build linux, the list includes kernel, c compiler, make and various utilities:

bash  binutils  bison  bzip2  coreutils  diffutils  findutils  gawk  GCC  glibc  grep  gzip  Linux-kernel
m4  make  patch  perl  python  sed  tar  texinfo  xz

This isn't a long list bearing in mind the scale of the work we are undertaking.  I use a RPi4 as my host system.  PiLFS provide a RPi image so we can be sure we start with the correct pre-requisites.  We boot RPi with the image and we can start building. 

The first task is to make a new partition as a target for the software which is built.  Following PiLFS suggestion create a new partition (20GB) on the SD card.  All the software will be installed in the root file system; on completion we boot software from the new partition.

Download software and create LFS user

A number of tarballs are downloaded containing sources for software to be installed on our new system.  They are installed in the /sources folder on the new system.  There are also some patch files which will need to be applied.  Software is downloaded from the linux from scratch website which ensures that packages are all at compatible levels.

A userid LFS is setup to carry out compilation tasks for the new system.  Good practice says that root should only be used when necessary, LFS is able to carry out most of the work.

Create Toolchain and utility tools

The first thing we need to do as user lfs is build a toolchain for the new system.  Binutils is created first, it provides a linker and assembler.  Next we compile GCC onto the new system - of course we are using GCC on the host system to do the compilation.  Our task is made easier because both our host and target systems are RPis so GCC is going to work.  A proper cross-compiler would be (even) more challenging.

The remaining toolchain software we need is linux-headers, glibc and libstdc (for c++).  These five builds are quite complex and PiLFS provides a script which automates the process for us.

The script also compiles utilities which will be required on the new system m4, ncurses, bash, coreutils, diffutil, file, findutils, gawk, grep gzip, make, patch, sed, tar, xz. 

Entering Chroot

The chroot command allows us to use the new filesystem we have created with the existing kernel. The chroot environment doesn't have access to the host software.  Before entering chroot we have to setup the virtual filesystem that the kernel uses to manage / communicate with software running in the environment. 

Within chroot, as root user, we create some essential files (/etc/hosts. pwsswd, group) and compile some more tools (gettext, bison, perl, python, texinfo, util-linux).

Building new system software

We are finally ready to do the proper build of all the software on the new system.  There are 73 steps to carry out and PiLFS has simplified the process by putting all the builds into a script for us.
Many hours later the build is finished.

Finale

One of the last tasks is to setup a filesystem table (/etc/fstab) for the target system.  It looks very similar to the host except that the root partition is changed to the one we have just been building.

In our simplified environment we are going to use the same kernel as before - there is no particular advantage in building a new one and we can do it as a separate exercise whenever.  In addition we have been working for many hours to get this far and I want to see if it works... 


it does :):):)

Amazingly we have our own working linux system.  Anything that works has been done by us and anything that doesn't is yet to be installed.  It is very satisfying.  Thanks to the LFS project I know (or can find out by checking the doc) what all the components are, how they are built and what they do.  In particular LFS has an excellent summary of the relevant configuration options used to create the software.

Next Steps

There are a few extras we need to add for a basic working system:
openssh - needed to login from a terminal session, in particular to be able to copy / paste commands.
wget - needed to download packages to extend our system
ntp - RPi has no clock so we need to obtain the time at each system startup.

We can also install other software installs facilitated by LFS or attempt our own installations from github etc.

In conclusion this is a wonderful exercise to help me understand what I am using on a Linux system.







Sunday, 16 January 2022

Sipeed LicheeRV

 Back in June 2021, I was fortunate enough to spot that the Sipeed Nezha RISC-V development SBC was on sale.  It is the first Linux RISC-V SBC system for less than $100 and marks the beginning of a new era in home / hobbyist computers.  It is based on the Raspberry Pi form factor and runs Debian Linux.  I have greatly enjoyed getting to know it and particularly using it to write some simple RISC-V assembly programs which I can compile directly using the GCC compiler.

On 24th November I saw on the Sipeed twitter feed that the Lichee RV is for sale.  It uses the same processor as the Nezha but has very few peripherals on board and no GPIO pins.  An SPI connector is used for an LCD screen and there is an SD card holder.  Instead it has an m2 connector which can connect to external devices such as Ethernet, wifi, bluetooth.  It costs $13 as opposed to the Nezha $99 crowdfunder price and doesn't have a limit on the number available.

 I purchased the version with a screen (total $17) on Ali Express and waited in anticipation for it to be delivered.  It arrived in the UK on 4th December and was delivered 16th December so I was one of the first to receive them outside China, certainly an early arrival in Europe.

Initially I wasn't sure what to do with it, my Nezha SD card didn't seem to do anything.  On 24th December O-GL in France and Daniel Maslowski in Germany on Telegram provided me with the information needed.  There is an international download folder on mega.nz and a  set of tutorials on the sipeed forum.


On 4th January I was  lucky enough to look a the Mega.nz site and see that a zip file for an Ubuntu 20.04 build including the LCD had just been uploaded.  It was slightly more complicated to download than the usual images, I had to locate files manually in the correct part of the SD card.  However this meant that the download was 167MB instead of 1.07GB so it was worth the extra work.  Initially the build did nothing but on 5th January someone on Telegram posted a correction to the instructions and the result was that I could get a working Ubuntu Linux with tiny LCD console.


Of course there wasn't a lot I could do with just a screen but I was quickly able to solder on the four pins in the bottom left corner of the board so that I could connect an FTDI cable, allowing me to sign on to a serial console session.
So I now have a working Linux system on a tiny 6cm x 4cm board - a bit similar to the RPi Zero.

I was also able to download Debian and Tina images and create SD cards.  The Sipeed tutorial provides console commands to switch the on board LED on/off using GPIO commands and Iwas able to check that this works.  The basic board doesn't have any networking capability so I had to await my LicheeRV dock before progressing much further.







Saturday, 15 January 2022

Christmas Lights Improvements last year

 For the past few years I have set up music controlled colourful Xmas lights using Lightshow Pi software (LSPi) running on a Raspberry Pi RPi.  LSPi software hasn't changed in the past three years but it still works and support is still available from enthusiastic users, particularly SoftwareArtist.  I started my updates for Xmas early in December 2021 which helped me produce something useful in time for Xmas day.

Last year I ran the music (MPD) and LSPi on the same server.  My RPi server used for this application had a disastrous SD card failure during the year so I needed to reinstall software on my shiny new RPi4 application server (PI41) this December.  Luckily LSPi configuration was backed up and my notes on installation was up to date.  Currently the MPD music player is active on my web server (PI40) along with the web pages to select and play music.  

LSPi Installation is well documented on reddit.  I followed  the instructions, which have been updated for RPi4.  I encountered one error in building "rpi-audio-levels" which the helpful SoftwareArtist on reddit provided a solution for.  Once I updated RPi firmware, LSPi installation worked fine and I was able to test that LSPi on PI40 was controlling GPIO output properly.

The LSPi configuration required for my setup is quite simple.  Music is streamed in from MPD on PI40 and RGB output provided on three GPIO pins.  The sample LSPi configuration file has detailed explanatory comments for all the options but my cutdown file only requires a few.
The most important command is "stream_command_string" which causes LSPi to listen to the music being played on PI40 by MPD.  Clearly MPD needs to be setup with a streaming output on port 8000 to achieve this in mpd.conf






I found by trial and error the pin_modes, pwm_range and attenuate_pct settings to give a pleasing range of colours on the output.  We need to set preshow_configuration to null to avoid a few seconds delay before the lightshow starts.  I was grateful that this solution avoids the syncing problems I have previously experienced with the lights being a secnd or two behind the music.  The current solution is quite impressive, RPi is calculating Fast Fourier Transforms (FFTs) in real time to determine music frequencies and using these to calculate pwm duty cycles.

The second improvement I made this year was to "finalise" my MOSFET setup.  I use MOSFETs to increase the RPI GPIO voltage to 12V and provide the current that MOSFETs need to drive the 5050 LED strip. Previously a breadboard solution provided this facility.  My track record in transferring working breadboard configurations to perfboard has been abysmal so although the circuit is quite straightforward I was very careful to draw out a design, check it, cut wires to length and find the necessary components before I started.  I colour-coded the RGB wires and on completion made sure the wires were tidy then put labels on the connections.  





I am rather proud of the results, it works a treat and I will probably keep the lights setup all year round.