I saw a reference in an article to a small simple cheap mp3 shield for Arduino and it seemed like a fun and interesting idea. The shield incorporates an SD card holder, and in fact is only slightly larger than a micro SD card in a 16 pin DIP format. I found that I could buy a couple on ebay for £5.
Tuesday, 10 November 2020
Arduino MP3 Shield
Tuesday, 13 October 2020
More Jongo Music
Objective
It is nearly two months since my last post. Mostly tech time over that period has been spent looking at Jongo music. The multiroom music server MuSe and album player aMuSe control what music is played on an mpd music server. The sound is sent to a Jongo using bluetooth and distributed amongst other Jongos using caskeid - a bespoke Jongo program which shares and synchronises sound.
For some reason the bluetooth connection is not very reliable. It could be that the RPi bluetooth device or configuration has issues or the Jongo firmware/hardware is not good enough. For whatever reason it is not always possible to use our web applications to play music and sometimes the system cannot be restarted, evening by rebooting the Jongo and RPI.
There isn't much you can do to monitor control bluetooth devices. On RPi bluetoothctl allows you to check the status of connections, but it doesn't always allow you to see, diagnose or correct problems. There is a python bluetooth module (pybluez) but only has similar capabilities. Jongos can tell you very little about their bluetooth connections.
Consequently I decided to look again at setting up Jongos using the wireless interface. If using the Pure app Pure Connect to control Jongos you are using wireless and can play multiple Jongos in synchronisation. We don't have any specific documentation telling us how Pure Connect controls Jongos but we would like to achieve something similar.
Jongo Access
Our first task is to be able to access Jongos reliably. Jongos setup a random port for wireless communication and keep the same number until rebooted. The only way to find this port number is to use ssdp.discovery but an ssdp.discovery dialog takes about 30s and it is inconvenient to wait that long for each access. Ellis Percival has provided a python upnp library which provides ssdp / upnp functions. His github page also provides a great tutorial on using the library to interrogate / control devices interactively with ipython. I wrote a simple program jongoPorts.py which runs a discover once a minute and stores results in a file. All other programs just need to read the file contents to be able to access each jongo. I also wrote a program jongocheck.py which looks out for any port changes or devices appearing / disappearing so that if testing goes wrong I can check whether device or network access issue occured.
I have been unhappy with VirginMedia wireless coverage for some time (in particular interference from the microwave) and recently purchased a cheap and cheerful router with, hopefully, a better wifi range. Jongos only work at 2.4GHz so I setup a new 2.4GHz network and made sure that all Jongos are on that segment with DHCP allocated fixed IP addresses. We now have our hardware and network configured and monitored to increase reliability.
Packet Capture for Reverse Engineering
Pure have discontinued their Jongo range and it never really caught on (Sonos captured the market) so there is very limited information available on how Jongos work. The Pure Connect (PC) app does a pretty good job at allowing you to play albums or stream radio stations. We have previously been able to instruct a Jongo to play a URL (song, album or radio stream). However I wasn't able to work out how PC controls multiple Jongos in synchronisation.
I wrote a short python program which interrogates Jongos to find what they are doing. This can be set up to run and provide frequent upates with the Bash watch command. It shows us that we add an extra Jongo to PC, it synchronises to the first one using an RTSP stream as shown in the picture below where device Jon was running and Job was added as a second synchronised device.
It is difficult to guess the commands which PC issued to set this up so we need to capture them. I used wireshark to monitor the wireless network 192.168.0.0/24 but it only shows ssdp multicast packets. It doesn't show any http packets, possibly because the packets are WPA encrypted when they circulate the network. The subject appears to get quite complicated. Firstly, the interface has to be in "monitor" mode not "promiscuous" mode. Secondly, Windows does not support monitor mode and nor does the RPi built in wireless adapter. Eventually I found that my WiPi wireless adapter does support monitor mode. A utility airmon-ng allows you to set the adapter into monitor mode and it does show lots of information - for example you can see all devices attached to the neighbours wifi networks. However it still didn't allow wireshark-linux to show me http dialogs.
Close to despair, I made a breakthrough when I found fiddler which does http packet capture and allows you to look at packets in a variety of formats. Much more significantly it allows you to set up a proxy for wireless devices on the network. I set up my Windows computer on the wireless 2.4GHz network and setup Fiddler with port 8888 as a proxy. I then told fiddler to configure itself for Windows and to decode https traffic. I setup an old ipad on the 2.4GHz network and setup Windows port 8888 as a manual proxy. Fiddle now showed all traffic through my windows computer including all ipad http traffic.
I captured Jongo related packets using fiddler, they are all xml formatted and they work with the upnp protocol. It was very easy to see how Jongos achieve synchronisation. The original Jongo (Jon in our example above) starts music with a SyncPlay command, it also creates a unique session id with CreateSession. When you add another Jongo in the PureConnect client it issues a GetSession command to determine the session id. It then tells Jon to AddUnitToSession for the second Jongo (Job). Command RemoveUnitFromSession is used to stop playing on the second Jongo. Fiddler organises the output so it is simple to understand as shown below.
Using Synchronised Wifi
Friday, 21 August 2020
ESP32 + Joy-IT touch screen
Intro
As I have said a number of times before Elektor is a great place to find introductory projects. The January/February 2020 edition contains an article on attaching a Joy-IT touch screen to an ESP32. The example provides a very neat interface to the Elektor Weather Station project and shows what it is capable of. The system makes use of littlevGL an application by Gabor Kiss-Valose which does all the graphics and touch screen heavy lifting. It works on linux and other platforms as well as ESP32 and appears to be coming a popular/standard product. To make life simple I purchased the Joy-IT touch screen from Elektor and also, after a false start, purchased an ESP32 devkitC from eBay.
Installation
The Arduino IDE is used for this project. After connecting and testing board connectivity with a blink program (set LED to GPIO 2) I needed to set up the ESP32_eSPI software and littlevgl and configure them. There are 10 wires used in the interface, including power and SPI, so it isn't too complicated. The Elektor article comes with the required libraries and configuration files as a download. This made it easy to setup, I copied libraries and configuration files across as appropriate. In addition to TFT and LVGL libraries, other libraries are included for MQTT, json and CRC32.
Testing
There is a basic TFT test in the TFT_eSPI examples so I compiled/uploaded and it displayed pretty colours and text.
I then took the Elektor Weather Station Example, set the "demo" flag and compiled it. Very impressively out comes the Weather Station screen, complete with touch screen capability and demo data .
Conclusion
Friday, 7 August 2020
Bare Metal RPI: Dealing with files
Intro
It is over a month since my last entry on bare metal programming. At the time I was struggling to work out how to implement file access. My programs could use terminal input/output and libraries, we had made a start on coding replacement for OS calls in syscalls.c. This allows us to write programs which don't have storage requirements but this tends to limit application to mathematical type calculations, or perhaps text based games.
Searching through github for RPi bare metal sdcard i/o programs yields a few possibilities. Chan has written FatFs, a filesystem module for small embedded systems, including ARM. John Cronin has written an RPI second stage bootloader which contains FatFs. It uses file access to load a program from disk, rather than having to set up a kernel.img file for each test. I found it a little difficult to understand how to apply this. Finally I settled on Marco Maccaferri's rpi bare metal repository. Not only does he implement fileio but also has frame buffer and USB functions. I decided to concentrate on Maccasoft initially.
Maccasoft investigation
Maccasoft separates FatFs into a directory and implements RPI specific functions in a file emmc.c. In fact he has done a grand job in setting up a kernel folder containing sub-folders for USB, FatFs and drivers for frame buffer, HDMI console, png images, Simple DirectMedia graphics, audio, GPIO and compression. This is really what we are aiming for, a bare metal kernel, not dependent on linux, which allows us to write programs using a variety of drivers.
I started by testing the "template" application Maccasoft provided. I ran make on the kernel folder, then make on the template folder and copied the resulting kernel.img to SDcard. I connected an HDMI screen and a USB keyboard and booted. Very impressively I get a low-res screen showing messages, the ability to type in and the ability to move the cursor around the screen.
Optimistically I then ran make on the "abbaye des morts" game. I had to change "uint" variables to "unsigned int" but compilation was successful and I copied the image to SD card. The game is excellent, a properly playable platform game with graphics and sound. Marco has come up with a very good product.Maccasoft File Access
At this stage I had made no further progress on file i/o as maccasoft doesn't seem to use fles although the template app does mount the SD card. I looked at John Cronin's github and I was able to get it to read and write files in the root directory.
I then realised that Maccasoft has a reasonably complete syscalls.c with open/close/read/write functions implemented so I should be able to use standard fopen/fclose/fread/fwrite functions to use the SD card.
This proved to be the case we can open/close/read/write files in the root directory using standard C functions. This is a big step forward for us.
Bootloader integration
David Welch's bootloader is indispensible for loading and testing new versions of programs. It expects application programs to be loaded at 0x8000 and is itself loaded at 0x200000. Maccasoft link script does load at 0x8000 and uses the space above for heap. When we try to load a Maccasoft kernel.img using the bootloader it works fine. This is great, we now have file access and a bootloader.
UART stdin/stdout
Maccasoft sets up a framebuffer to allow writing to an HDMI screen and configures USB for a keyboard input. In fact I much prefer using a putty console for stdio. I take my previous termio program and add uart_get and uart_put to main.c. This is straightforward. Now I add a function uart_init() and put all uart functions in uart.c so that I have added them to the kernel. This also works fine.
Looking at syscalls.c we notice that the file pointers 0,1 and 2 which refer to stdin, stdout, stderr respectively are excluded from processing in _write and _read. I add code to _write so that uart_putc or uart_puts is called if fp=1. Now putchar, puts and printf all use UART output by default and I have a properly working stdout device. This is great progress.
I have so far struggled to work out the details to make _read work for both character and string input so stdin is not fully working, but I wont worry about this for the moment as I can use uart_gets and ssprintf for stdin functions.
Summary
We have made great progress using Maccasoft's work. We have working file access, standard output and (almost) standard input. We have a working boot loader and a separate "kernel" to implement standard functions and drivers. This gives us the capability to write a variety of standalone applications. Maccasoft also provides us with a frame buffer, USB devices, audio, image processing and GPIO controls if we want them.
In fact I did try out USB drivers a bit further. RPI mouse, USB stick and Ethernet interfaces are all correctly detected. However Marco hasn't needed to progress them further. You could read a file sector or an ethernet frame but would have to write the higher levels yourself. There is some discussion on the RPI forum. Rene Stange wrote the USPI RPI bare metal drivers and has gone further in his Circle C++ bare metal OS project.
Tuesday, 30 June 2020
Bare Metal program test
The bare metal programs we previously had working were re-organised so that the initial program (notmain.c) sets up uart i/o. It calls a function jmain.c, which is intentionally not called main to avoid the compiler misinterpreting it. jmain.c contains our program code with printf statements replaced by uart_puts to output strings to the serial terminal.
use sprintf(buffer,.......); printf(buffer); if variable values need to be output for uart_puts convesion
use gets(buffer); sscanf(buffer,.....) for input so uart_gets can be added on conversion.
Monday, 15 June 2020
Bare Metal C - libraries
Introduction
C runtime
Library stubs
Test Program
Saturday, 13 June 2020
FreeRTOS Tutorial
Background
Task Creation
xTaskCreate(functionName, label, stacksize, priority, handle);
For example:
xTaskCreate(flashRedLed,"Flash",100, NULL,1,redHandle);
When compiled and uploaded the LED blinks. Each of the programs functions can be added in a similar manner and will work independently. You can simply copy and paste working functions and FreeRTOS will take care of them.
.... do something ....
Passing Information between tasks
Queues can be grouped into queuesets so that tasks can easily process information from a number of queues.
Synchronising Tasks
Semaphores prevent tasks conflicting for shared resources by flagging when they are in use.
Mutex semaphores allow a single task to control a specific resource.
Summary
Tuesday, 9 June 2020
RPi Bare Metal C - Hello World
Background
On 8-bit processors such as PIC or Atmega you are very close. A processor chip has a data sheet which you can use to see how you place instructions in memory so they will execute. You add your own peripheral devices and are responsible for programming them.
Programming in assembler is a mugs game but in fact only a tiny amount of standard assembler code is required. Once the C environment is setup and you have a cross comiler to hand, you can write C programs without an OS.
Environment
Our focus is to compile an appropriate program, name it kernel.img and place it on an SD card so that it will execute.
Blinking LEDs
GPIO header details need to be included in the program to provide appropriate addresses for controlling the GPIO sub-system. Finally GPIO16 is configured, enabled and set to 0/1 causing the LED to blink.
Hello World
It is a small extra job to read input from the terminal session and echo characters out to the screen. We can now do terminal I/O, another huge step forward.
Bootloader
Saturday, 6 June 2020
Linux AV
Thursday, 28 May 2020
Linux FrameBuffer
Installation
I plugged it in to an RPi 2B and installed the driver software. I run RPi servers headless and I was pleasantly suprised to see that the RPi console startup messages are displayed. It looks nice but isn't useful as the screen / characters are very small and I don't have the ability to type in to the console or login.
Display Text
To send output to a terminal it is easiest to do if the device is logged in. Using raspi-config we can tell linux to login to the console as pi at startup. We can now easily display messages, e.g.:
echo ‘Hello little screen’ > /dev/tty1
To clear the screen or display text at specific positions we use control characters. I have a fondness for these from my DEC PDP-11 programming days when a DEC VT100 was considered an excellent screen and I used it extensively. I can clear the screen with:
echo -e '\e[2J\e[1;1H' > /dev/tty1
Images and videos
It is surprisingly simple to play videos on the frame buffer with vlc:vlc starwars.avi > /dev/fb0
VLC can actually display images such as:
vlc AtTheBeach.jpg /dev/fb0
As everything is a file in linux I can take a screen snapshot with:
cat /dev/fb0 > screenshot.raw
and then redisplay it later with:
cat screenshot.raw > /dev/fb0
However the best way to display images is to install the package fbi (framebuffer image) which gives you lots of image capabilities.
C Programs using the Framebuffer
Lvgl
Friday, 15 May 2020
Google Arts and Culture
For some galleries, mainly in London, I have my own set of pictures, descriptons and opinions in my slideshow app. It is interesting to visit these galleries in GAC and look at see which exhibits they highlight.
For the galleries I visit most often, Tate Britain and the National Gallery, GAC provides a street view virtual tour which includes stops at particular works. The descriptions provided on these works are somewhat superficial but they also contain links to other works on the same theme, with similar subjects, by the same artist etc. Linked works may be at other galleries, which can then be explored as well.
Thursday, 14 May 2020
MSGEQ7 Graphic Equalizer with OLED Display
I tried it out with a Neopixel display and a small OLED screen.

Design
Hardware: I initially intended to use a NodeMCU ESP8266, but the software library appears not to support ESP8266, so I moved to an Arduino nano. Neopixel and 0.96" OLED displays were used.Input: Initially PC line out used for testing, L and R channel signals were combined. Final solution needed to work on hi-fi using RCA or Digital audio Jongo output.
Software: Nico Hood's MSGEQ7 is principal Arduino library providing the necessary functionality.
Output: Initially console output used to understand MSGEQ7 values, then dots, then bars were used for each channel.
Circuit
Nico Hood provides a lovely informal circuit diagram for the MSGEQ7.
Testing
Wednesday, 22 April 2020
Floureon IPCAM
My current application requirement is to provide a nightime garden webcam to look for activity, particularly from foxes. I need to record video when motion is detected in the picture so that it can be looked at the next day. I have a Raspberry pi noir webcam which isn't being terribly useful for this purpose although it did previously carry out great service as a puppy cam in our kitchen.
As the supplied CamHi software doesn't have the functions we require (in particular motion based recording), it is necessary to find other ways to access the webcam via its network interface. A very helpful open source site ispyconnect provides details of URLs which can be used to access webcams. We know our ip address 192.168.0.175 and user/password admin:admin.
To take a snapshot from the camera we can use a chrome URL:
http://admin:admin@192.168.0.175/snap.jpg
To stream a video from the camera we can Open a network stream in vlc with:
rtsp://admin:admin@192.168.0.175/1/h264major
The video can be streamed at a lower resolution with:
rtsp://admin:admin@192.168.0.175/2/h264major
For the picamera we have previously used linux motion software very successfully to process a video stream and record only when motion is detected. We can utilise the stream coming from the webcam by specifying in motion.conf configuration file netcam_url the rtsp streaming address. Once we restart the motion service (on RPi pi34) we can view camera output at http://pi34:8081.
I am quite keen to be able to be able to control pan/tilt from linux or PC. I found that I can login to its network interface http://192.168.0.175.
In addition to showing the camera view it allows me to use pan and tilt. "Left and right", "up and down" buttons cause the camera to scan throughout its range. You can view two streams, full detail (1280x720) or smaller (640x352). There are 8 preset positions you can setup.
The settings tab is informative, allowing you to see/set many more features on the camera (e.g. turn IR on / off). The network page includes settings for ONVIF, which is already on at port 8080. This should allow me to use a general purpose ONVIF client to control the camera. ispyconnect has a suitable client Agent DVR which I could install on Windows.
After a little experimentation I was able to setup the camera in ispy Agent UI and see the camera. It also gives me a device service URL http://192.168.0.175:8080/onvif/devices . Using Ispy PTZ controls are a bit better.
I was now ready to try out the solution. It turns out, quite reasonably, that infra red light reflects well off glass (which is designed to let optical wavelengths through) so attempts at a setup inside were not successful. As the weather is good I took the IPCAM outside and set it up in the garden. Using the web interface I set the IR leds on continuously. I setup linux motion software to record when movement is detected. I set the sensitivity quite high to capture small changes, and I did capture various moths / insects whizzing by, but I did also see the fox doing his/her evening walk across the garden just before midnight. The motion software worked well, it only recorded about 5 minutes video overnight so it isn't onerous to look through the recording.
Tuesday, 21 April 2020
Pi-Lite
The board is simply a set of 14x9 monochrome LEDs which can be used to display images or scrolling text. It is connected to the RPi using a serial UART and just needs to be plugged straight in to the RPi or 4 pin TX, RX, 5V and GND connections. LEDs are controlled by an ATmega328 chip on the board which accepts commands input from the serial port and changes the displays accordingly. You can program individual pixels, bars, or download a 14x9 pixel image using commands. By default information downloaded is treated as text characters and scrolls across the display as a message, which you can speed up or slow down.
To try out the board you start up minicom, a simple terminal emulator. Any text you type in is displayed on the Pi_lite as scrolling text. It makes more sense to control the display using a program and python-serial is a good way of doing this. Matt Hawkins / Ciseco provide some good demos. A stock ticker and weather report would have been fun but their data sources no longer work.
Pi-Lite doesn't have to be connected to an RPi, it works equally well on a PC serial port (with appropriate convertor). Of course you may not be satisfied with the commands provided on the ATmega328 and will probably have already realised this is an Arduino processor. You can modify the inbuilt program using the Arduino IDE to amend the Pi-Lite sketch. Alternatively you can write your own sketch using the Pi-Lite Arduino library to control the display however you want.
Wednesday, 15 April 2020
Tiny Core Linux
Recently we have looked at Linux in a variety of ways. Buildroot has been used to tailor and build a distribution, we have compiled Linux to run on the Atlas board, we have created many different systems on Qemu. Along the way I came across Tiny Core Linux (TCL) which provides a Linux system in 11MB. Kudos to Robert Shingledecker who developed it in 2008 and those who have supported it since then. It has an extensive user manual and an active forum.
Core System
The simplest variant of TCL is called Core. This comprises two files a recent linux kernel (5.4.3) and core.gz a compressed file system. It is available as an ISO. I could quickly boot from the iso file in Qemu and bring up a small system. It looks like linux, feels like linux and quacks like linux.
PiCore
A version of the system has been provided to run on RPi. I simply copied the iso to an SD card and booted on my RPI 1B. It comes complete with network access and SSH. Initially I connected a screen and keyboard but it was soon reliable enough to run headless.
TinyCore
The next step is to setup a windows manager FLWM (fast light windows manager) so that we have a working X system. Again we have a small amount of software. Using X under Qemu was a bit of a pain and I don't want to use an RPi like this so I installed on Roy's old laptop. A 2GB partition is vast overkill for a system which is now about 50MB but it enabled me to run some variants.
Linux Structure
The irresistable attraction of a tiny system is that it is small enough to have a crack at understanding the overall makeup of linux. The TCL manual was a big help as it describes the boot process initiated by the kernel which lays out the file system, sets up devices and hands over to init which is part of busybox. Init provides utilities for all the processes running on the system and makes requests to the kernel where necessary. Applications / programs can be added as necessary but aren't essential for a running system. TCL minimises the ones provided by default but has a good variety of extensions available for download and install.
So we really just have the kernel, Busybox binaries, some libraries and a few start up scripts which make up our system. As the icing on the cake Busybox has a link to Fabrice Ballards, linux in a browser running busybox.
Monday, 6 April 2020
Atlas - Kernel Build
Following success with Rocketboards WS1 tutorial enabling me to write a C program running under linux in two way communication with an FPGA program I was excited by the prospect of WS2.
WS2 describes how to build a preloader (as before) build u-boot and build a kernel. I was able to build the preloader and build u-boot but kernel build dates from about 2015 and not all the sources are still available. The installation is very technical and I wasn't able to adapt it for myself.
Digikey
Robert Nelson, a modern day hero at Digikey has published, and kept upto date, a sequence of instructions to build u-boot and linux then create a bootable SDcard. The instructions explain how to:
- Install the Linaro ARM cross compiler
- Obtain and compile u-boot
- obtain and build kernel
- Obtain Debian 10.3 root filesystem
- SD card creation.
Sunday, 29 March 2020
Building Linux Images
Buildroot
I have often wondered what it takes to start up linux. As I delve further into the Atlas tutorials I will understand it better. I believe yocto is the hardcore build environment but buildroot is a simpler substitute which, unsurprisingly, runs on linux.
A tool called vagrant makes it ridiculously easy to setup buildroot. As explained in a short tutorial by Dzone you simply download a vagrant configuration file and run vagrant to startup a VirtualBox ubuntu VM configured for buildroot. It works a dream.
I followed the second part of the Dzone tutorial to create a simple i386 linux including openssh.
This builds all necessary software and creates two output files, a kernel image (bzImage) and a file system (rootfs.ext2)
Qemu
Armed with these two files we can bring up linux. We don't have a specific hardware processer in mind for this OS so it makes sense to bring it up in a virtual machine. Qemu is the workhorse for linux VMs and initially I installed qemu on my buildroot VM. I can bring up linux and sign on to the console or ssh from the buildroot VM. The linux I have built is very simple. It is absolutely perfect to know that we have everything we need for a working linux system.
It doesn't make a lot of sense to run a qemu linux VM under VirtualBox ubuntu linux. Qemu is available for Windows so I moved my two files across to my PC and installed Qemu for windows. The batch file to start up qemu has a different format to the linux script but after a bit of trial and error I could start my qemu VM in Windows. Establishing the network under windows took a little care, I had to enable openssh server in Windows so that ssh communication from qemu to windows was possible.
RPI image
Clearly buildroot can create images for real hardware and I would like one for my trusty old RPI model 1B. Buildroot makes this childs play by giving you a default configuration for various RPI models. Within buildroot I simply ran "make raspberrypi_defconfig" and then "make" . The result was an image that I could burn to an SD card using Balena Etcher. I booted it up and I have a simple RPI build. This is excellent.
Qemu RPI
Rather than create SD cards for RPIs I would like to have an Qemu RPI VM working under Windows. Alistair Chapman has provided a little blog showing how to do this. It isn't a buildroot cutdown but a full RPI-buster-lite image. The real RPI kernel needs some tweaking to run under windows but Dhruv Vras has provided suitable kernels for each Raspbian release. With a tailored kernel and a standard Raspbian image you can startup a Qemu VM.
In fact it is slightly more complicated than suggested to get the build to work, a couple of files need editing to make the image work and I followed instructions in wiki helpfully provided by Dhruv. Awesome, I now have an RPI VM working under Windows10 without VirtualBox.
Conclusion
It is very educational to build linux systems yourself to gain a feel for what software you need and what hardware components it uses.
Monday, 23 March 2020
Atlas Workshop WS1
Introduction
The DE0-nano-SoC documentation provided some great tutorials to get started with FPGA, HPS and then establish links between them. I can see that there is a lot more to find out about the device, software and working environment.
My efforts with the Golden Hardware Reference Design (GHRD) were eventually successful and the hard work involved was centred around choosing the right versions of software to match the tutorials.
I learned quite a bit through this process of trial and error, in particular Quartus and EDS version 15 (c.2016) are preferred where possible. If there are bugs, version 16.1 may be more appropriate. Version 18.1 is my newer favoured release but doesn't include suitable EDS/DS-5 capabilities as they have become chargeable.
Rocketboards.org provides a set of three workshops for familiarisation and they seem to go down a considerable depth into the internals of the product. I am reasonably happy that I understand enough about FPGAs for my current purposes, I can compile and load a design using my own verilog or Altera IP modules. However the Linux environment and FPGA-HPS bridges are mysterious.
The WS1 course materials provide an excellent overview of documentation available / required. The format is a slide deck so there isn't much detail included but technical areas are summarised. The Cyclone V boot process is covered in some detail and forms the basis for the four labs within the workshop.
Preparation
In preparation for lab activities we download an SD card image which contains linux and course files. The card is tailored for Atlas / DE0 and assumes that Quartus 15.1.2 is used. Once the image is unzipped and burned to card using BalenaEtcher it can be booted. This is excellent as I now have a known source for an SD card image which is tailored for my board.
We have a general WS1-IntroToSoc folder and device specific hps_isw_handoff, DE0_NANO_SOC.sof, soc_system.sopcinfo.
LAB 1 Generating and compiling the preloader
When you boot the Atlas board from SDcard a very small BootROM program loads the preloader into on-chip memory. The preloaders job is to setup the FGPA, define HPS I/O and memory and then copy the Linux bootloader into DDR memory which allows the HPS to boot in the usual manner, load the OS etc.
Our first task is to generate a Board Support Package (BSP) which will define various hardware details relating to the FPGA design and HPS interface. We have a pre-generated QSYS design, whose details are provideed in hps_isw_handoff/soc_system_hps_0. We create a new BSP using the Altera BSP Editor tool, give it a copy of the design and generate a BSP.
The BSP folder contains source code, preloader settings and a Makefile to build the Preloader.
We now run make to compile the preloader and create a image file preloader-mkpimage.bin.
Finally we use the Altera Boot Disk Utility to copy the file to the correct partition on the SDcard so that the Boot Rom program will read it in and execute it.
Inserting the SDcard into the Atlas board we see the preloader booting up the system. This is great progress but the system doesn't do a lot at this stage so we reset to the original preloader for now.
The lab is very instructive in showing the files required produced and the steps needed to generate a preloader. We don't need to understand more detail as the design provides details and the BSP Editor interprets them to generate a preloader.
LAB 2 Verifying Hardware with System Console
Quite a short lab showing you how to use the System Console which looks to be hugely powerful. It allows you see and set values within the FPGA. Our FPGA demo design runs a Fast Fourier Transform in hardware and sends the results back to HPS. Using the system console you can provide values to the FPGA, run the algorithm and using scripts, capture and display output.
It requires a far better understanding of the hardware than I have currently so I don't expect to use it in practice.
LAB 3 Bare Metal FFT app
A bare metal C program is provided for us and our mission is to run it.
The file soc_system.sopcinfo which was given to us contains information about the FPGA memory layout. Using sopc-create-header-files utility a number of headers are created from .sopcinfo which are required by our C program.
Now run make to use the provided Makefile to compile our bare metal program fft.bin.
C the executable across to the SDcard FAT partition which is mounted on our PC.
We now boot the SDcard and type "stop" to get to a u-boot prompt.
Commands are used to:
load the FPGA program
configure HPS-to-FPGA bridges
load the bare metal application into memory
run the application
See the output, Hello world followed by FFT inputs and outputs.
Finally we automate the load of the bare metal application. This is (intentionally) partially successful, when our application runs it only prints hello world. This is because we haven't configured or started the FPGA and bridges.
The tutorial covers a lot of ground. Although I am unlikely to write bare metal programs it is wonderful to set up a working example so that we can see what a program does without an operating system there to help it.
LAB 4 Linux FFT Application
After the complexities of the previous labs this one is quite easy.
The fft app is compiled in EDS and copied to the SDcard.
We can then run the fft program on Atlas linux.
The linux configuration includes a lighttpd web server which can be used to specify input parameters and graph the output from the FFT.
It is deceptively simple as the C program looks complex and has a lot of code concerned with sending fft values to the FPGA, controlling it and reading back results before formatting them for the web server.
Tuesday, 10 March 2020
Atlas - First designs
Introduction
My First FPGA
This is a good project to familiarise yourself with Quartus. A simple counter is implemented in verilog and a schematic created integrating the counter with a clock and a multiplexor. A button input is used to control the speed of LED output pattern flashing.
The tutorial clearly shows you how to use a number of Quartus features without introducing more complexity than necessary.
My First HPS
The purpose of this tutorial is to allow you to compile and run a C program on the linux system.
A cross-compiler is required and should be provided following a successful install as described in the getting started guide.
Initially my Altera toolchain didn't work so I installed arm-linux-gnueabihf-gcc under wsl and compiled / copied it across to atlas_sockit using winscp.
It wasn't particularly informative but good preparation for the combined FPGA-HPS test.
For further tutorials it was important that the compiler works as expected and I could use EDS (Embedded development software). Generally I am using v18.1 software but licensing has changed so EDS isn't included. I installed Quartus and EDS v16.1, the last release including EDS, and this worked exactly as expected.
My First HPS-FPGA
The third tutorial guides you to create a QSYS design based on the GHRD (Golden Hardware Reference Design) which includes a PIO module for the LEDs. An interface between FPGA and HPS is configured so LEDs can be controlled from a linux program.
An HPS C program is written to map the appropriate memory locations so that the C program can use them. It is quite complex and I couldn't write it from scratch.
Once we have loaded the FPGA image and copied the compiled C program to Linux we can run the program and control LEDs. This is a leap forward in using these devices.
I am not convinced I will go far along this route. I don't want to spend too much time writing C programs.
Again software was a bit of an issue but once I standardised on Quartus / EDS 16.1 I could follow the tutorial easily.
Compiling Hardware Design
Having completed basic tutorials I wanted to compile the Golden Hardware Reference Design (GHRD) as this would provide me with a template for using all the FPGA components. It also seemed to provide a way to build an SD card image. Instructions were simple, an intricate Makefile script is provided to create a Quartus project, build it and add all the necessary files for an SD card image. Unfortunately they didn't work well.
Eventually I was able to compile the GHRD and download it to Atlas. It required me to start the creation process on Quartus web edition 15.0 + EDS, then continue in Quartus 16.1 and finalise/download in Quartus 18.1.
I am pleased that I have a "working" reference design and I did learn quite a lot along the way but it wasn't enjoyable.



























