A $9 Introduction to the RISC-V Future of Computing

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this little thing here is the same shape as a Raspberry Pi and it's actually just a breakout board for this little guy here a $9 risk 5 single board computer the milk 5 Duo is a $9 single board computer it runs Linux has 64 Megs of RAM and a Micro SD card slot in this little tiny package that's so small I can't even show it on camera because I don't have a macro lens has an onboard camera connector it can do encoding of video has on board 100 megabit ethernet and uh yeah what else could you ask for from a $9 single board computer so today I'm going to play with this and understand the risk five architecture why risk 5 could be the future of computing and how you can get started with this little tiny $9 single board computer so let's get started with this adventure so in case you haven't heard of risk 5 before it's an instruction set architecture which competes against things like x86 or the arm instruction set essentially that's a specific for the machine language of a processor originally designed by UC Berkeley risk 5 was designed to be an open and royaltyfree platform for people to build on the document isn't particularly long and the instruction set is not particularly complex but it's an extremely wellth out and well-designed architecture and all of the design decisions and design logic is included in the document unlike something like arm so it's growing in popularity with a number of niches due to its royalty-free nature and the ability for anyone to produce chip or implementations of the architecture I'm very excited to play with it so come along and try it with me so this little thing is so small that here is a US Quarter to compare it against they also sent a breakout board this has a USB hub and ethernet and ethernet comes directly off of this board so this board actually has 100 megabit ethernet built in but it doesn't have magnetics and doesn't have a connector so you need like a MAG Jack and then they also sent along this little tiny camera I don't know if this gives you a sense of scale for this thing so this chip in this board is essentially um designed for security cameras so it has like h264 Hardware en code it has the camera interface and has 100 Mega ethernet so that's what it's designed for but they've packaged it in this nice development board so this looks just like a Raspberry Pi form factor so we've got ethernet which is Hunter mag um USB 2 there's a USB 2 Hub here and then it picks up some Pogo pads on the board and then this is where the actual Dev board itself mounts here there's no micro SD because that's actually on this board itself see what we got here wow this thing is Tiny okay here it is so we got USBC this actually acts as a USBC Gadget so when you plug it into your computer it shows up as a USB ethernet adapter and you can SSH into the Linux system on here some passives and the one chip so everything is done by this one chip so I got my tiny little dual board I got a really tiny micro SD card and we're going to image this thing and Boot It Up at Linux so coming over here to their docs page so we probably need official image which is this guy so got the image on the SD card this this tiny little thing it's in here plug it into my computer now over USB and it should show up as an ethernet adapter which is magical so it's not as simple as it seems so I have to click update browse let me pick from a list available USB AR this go ahead don't know why Windows can't figure that out on its own but Windows is kind of stupid we've got automatic IP address that's good milk V okay we are in SL root we have a file system um do we have a GCC we don't have GCC um what bins do we have so we have busy box and um yeah not a whole lot else we have IP so e zero has no carrier USB has the rnis adapter so we're connected also I should note it blinks and there's a script built in that does This Blink so let's take a look at that script and see what it looks like okay so this is what does the blink so we're using bin sh we're using GPI 440 that's another neat thing about this all of the peripherals on this chip are exported through Linux etel uh CFS API so there are device nodes in the cyfs file system to access all of the hardware in this thing and the website has some really good documentation on how to access all these files and what they're named so you can get to the gpio the pwm generators the Spy bu ice gidy all that kind of stuff through the usual Linux interfaces um that are designed for this kind of thing it's pretty quite impressive to me that it's documented and working to this level on a essentially a new board a new platform like this I've set up a Linux environment on Debian that has the risk 564 compiler RV 64 and I'm going to use that environment to compile some test programs for this and then copy them over with SSH so it should be relatively simple let's see if we can get the blinking trick to work with the program we write and C ourselves then we take a look at what the risk 5 assembly looks like for that same program so just to make sure our tool chain works at all I have just a basic hello world and I'm going to go ahead and build that so I copied my test file over with SCP and let's run it so there we go hello from risk 5 how nice I did have to tell GCC to link as a static binary so some of the libraries I was trying to dynamically pull in were not on this little guy here which is pretty normal for embedded stuff so if I knew what libraries were on it I could know what I have to statically link but I just statically link the whole binary and it's a tiny binary so that's not a big deal and uh it runs great so let's see if we can figure out how to emulate the Blinky program but in C cuz I'm familiar with c and uh seems like a good test so it's blinking out in Morse code the message on top hello from risk 5 and it's doing it by writing to those device files in Cy class gpio I went a little bit overboard but uh it was a fun night of programming coming over to the computer here's what the code for that moris code test looks like so it's kind of a long file cuz I wrote it all one file but uh top we have IO functions so we're writing to the Cy class GPO so we have to write the direction to out and if that fails that means it hasn't been exported yet which means it's reserved for the kernel so we call export on it and then we set the direction again set Direction to out then we can open the value file and we can write a zero to it to actually write the gpio we just have to write the literal one or zero and F flush to make sure it gets applied so that's pretty simple I have all the uh the times based on the official Morse code spec from Wikipedia because Wikipedia is obviously the uh clear Source on this Morse code itself is kind of brilliant it's sort of like Huffman coding but before Huffman coding was a thing and uh so you make a kind of a tree of if you do a DOT or a dash or did what uh what letter it could be and so the shortest letter is an e which is just a dip by itself then from there you can either add a DA on the end or a did on the end and you can just kind of make a a tree of what everything is represented that tree using this string here where it's literally dots and dashes and then I can check for the end of the string with a null because null terminated then I have a pointer array that's a pointer of tables to the A through Z 0 through 9 so to print a single letter it's a Char if it's a space we do a long sleep and if it's not then we have to look up what array we need to find from the pattern table and um so if it's a zero through 9 we have to find the index at the End plus 26 it's an A through Z or with a case masked out we have to get the letter and otherwise it's invalid and we don't print anything and then we print out out the string we're printing which is the literal string from the table like dot dot dash and then we just go through the array turn on the pin wait either the DI time or the dot time turn back off and then wait the space for the next letter and then we keep going until we reach the null Terminator and then we wait for the end of letter delay and then the Morse function is pretty simple it takes in the string pointer it just goes through every element in the array and prints it and then go to the next letter St we've seen the code let's see how much different risk 5 assembly is from say x86 that we're all familiar with I mean you're probably not familiar with x86 assembly but if you were they're going to look drastically different so as you may have noticed up here I actually compiled this for five different languages all of them 64-bit so we have AMD 64 AR Arch 64 which is arm MIP 64 power PC 64 and risk 564 so let's find void Morris and all of these guys that's Morse letter there's Morse so an x86 you can see here so this is the address in memory this is the bite so this is the value in memory and this is what the assembly decodes to so this stuff is just setting up a stack frame for our function so we have instructions of variable lengths that one has one bite this one has three bytes that one has two this one has five in case you're curious the uh longest instruction in x86 is 15 bytes so in that case that's a call instruction and it's not even going that far it's going to 13 F2 you'll notice that uh these are register names here x86 likes to name them so RBX is the base pointer RDI is the destination register EDI is extended Di and RDI is long di I don't know why they chose R for that but R means it's 64bit e means it's 32bit and nothing means it's 16bit also fun fact 16-bit instructions are still a thing in x86 because we have to have backwards compatibility back to the 7 right these nice little annotations here show us where branches go so in this case the pop is well the J here is taking us down to the pop so the pop is unwinding the stack frame for the r and these are relatively short instructions but the call can be quite long so an AR 64 we again find void Morse and this time we have much longer instruction words so in arm 64-bit every instruction is 32 bits wide so I like this EX 86 thing where we have variable numbers of byes always 64-bit and that makes design in the processor a lot easier because you can guarantee things like how long the instruction decode has to be the instruction decode does couldn't potentially have like to straddle a page or something like that it's it's simpler from an implementation perspective so all of this work just to set up a stack frame so it's not as efficient as x86 was um this one for some reason doesn't want to show the nice uh jumps I don't know why this this version of GCC doesn't but again it's relatively simple we're going through a loop we have some instructions so BL is branch and Link jumping to Morris letter so BL means we're going to come back here because we're linking with the link register uh CBN Z does a compare with zero and branch and that takes us to risk 5 so risk 5 can have either a 16bit or a 32-bit instruction but other than those two lengths it's not variable so the front end only has to deal with these two possible cases and not like x86 you could have any number of bytes from 1 to 15 so This Is Us setting up our stack frame so we're changing this deck pointer uh storing the return address so beak Z so Branch equal to zero so basically here we're loading in the value the string points to and checking if it's equal to zero which will skip the loop because if you remember in our code we're saying while it's not equal to zero so while the character is not null so this is loading the character and then if it's equal to zero we do a jump down here to the end and then we do the loop and then again in the loop we check to see if we're zero and jump back up so like arm we have these Branch compare instructions so this is where we highlight a bit of a big difference between the different instruction sets and how they handle testing and branching so one of the most fundamental things about an architecture is how it handles memory access branching jumping and math because those are basically the fundamental things of computer programming accessing our data in memory doing arithmetic on it we can basically boil down every math operation into its most basic form and also control flow where the program code should execute and what path it should take so the Intel x86 way of doing it probably dates back to some very old processors and how things used to be done in the olden days essentially back then you would have a condition flag that had a couple of bits that were like the state of the processor and traditionally these were n z v and C so n is if the output was negative Z is if it's zero V is if there was a signed overflow and C is the carry flag which means there was an unsigned overflow some processors didn't have the vbit um Power PC has a positive bit and a negative bit that are separate so they have positive negative zero and carry basically processors have Flags like this you can do Logic on so in x86 you do test and you compare some register value or some memory value and then you Branch based on the results the test so first you have to take your value and test it and that sets the condition bits and then you can say Branch if not equal Branch if equal jump if equal whatever whatever your control flow is going to do based on your test arm does it a bit differently so in arm the testing is done in the instruction but it can only compare to zero so with x86 you can compare two numbers and say who's greater who's less whatever in arm you say is it greater than Z equal to Z less than zero and those are basically your only options uh greater than equal to those those kind of combinations so in arm what you do is you take the two numbers you want to compare and you subtract them and then you say was it positive was it negative branch of positive branch of negative branch of zero so since we're counting a null we can just load that value directly in and say Branch if not zero or Branch if zero and so that's a pretty efficient way of doing it we don't have to do a test the way power PC does it is they use flag bits similar to Intel but they always set them at the end of the instruction so if you do for example do an add you can say add Dot and the dot means whatever the result is update the condition bits based on that output so if we add two numbers together and the result was positive we'll set the positive bit we'll clear the zero bit that kind of thing and then power PC also has this neat trick where it has eight different condition registers and you can do Boolean arithmetic around the different condition registers so it's very common to store Boolean values in condition flag bits and kind of use them as extra registers which is pretty neat and I don't think any other system does the eight condition registers like power PC does and risk five takes a similar approach to arm where the comparison happens in the instruction so you don't need a separate test instruction and you don't have condition bits at all the instruction reads a value and it says Branch if not equal Branch if positive Branch if negative Etc like that so you have to do a subtract first just like arm and that's pretty much the solution that most of the risk architectures have come to except for power PC Al so myps does it the same way nips was largely a Pioneer in this having only 34 instructions they don't have room for a test instruction so in case you're curious and you want to read any of this assembly yourself I've created a Hub repository link down below also link to my blog post about this and that'll have all of the assembly and the example code I've used if you want to dig into it and read it yourself so with this board having the full-on computing power of Linux you might think it doesn't have the io of a more embedded microcontroller like Raspberry Pi Pico but in fact that's not true so in addition to the gpio that I've already shown it has a number of Hardware pwm generators it has five uarts if you want to do Sero it has Hardware spy including Linux uh spy support it has three i squ c buses also integrated with Linux um it has two analog inputs which are 1.8 volts but the little board has resistor dividers to take in 3.3 volts and it also has SDI which is capable of being used for Wi-Fi and includes the drivers for that on board as well so next up I want to play with ethernet so these little pins on the side our ethernet so we have a TX differential pair RX differential pair and a ground and they need magnetics to work you can't just hook this straight up to an Ethernet line the FI transceiver is on board but we just need magnetics normally that would be a MAG Jack so like this is a MAG Jack so inside the Jack there's the pulse Transformers you need if you're not using RJ45 you can put a pulse Transformer on the board or if you have like a multi-way RJ45 connector you can put pulse Transformers on the board so this breakup board has the pulse Transformers in the Jack and it has these Pogo pins that can pick up the five ethernet lines um it also has the USB chip that picks up the two USB data lines the power from the headers so we get five USB or four USB T ports there's also a bunch of extra pads here for extra functionality that's not included by default so up here we have the diodes and the power supply and inductor You' need to build a Poe Supply so the parts for this are in the schematic which is freely available um there's also space for a number of other transceiver chips here including a spy buus can transceiver and rs40 5 transceiver that uses one of the ID uarts as well as some spy flash memory so an assortment of good stuff on this board that's not populated what is populated is USBC power uart USB and ethernet but I want to use the USB as the gadget so I can continue to use my SSH method to connect to it so I taped over the pads on the back for USB and I'm just going to set this down in here and tape it so I don't have to solder pins on cuz I have another project where I want to use this as is so I don't want to get solder in all these holes just yet seems to be sturdy so we're holding down those Pogo pads now I just need to bring in Ethernet and USBC there we go so I got it set up for ethernet and let's see what we get I need a little bit of help here so Mr Sherlock had uh had to come join me so if I just run IPA what do I get so we're up and we got an address beautiful but what we don't have is IPv6 so what do we say when we don't have IPv6 we build the kernel ourself so I got the shirt on today so here on GitHub they have the entire repository needed to build the SD card image this includes everything in the image so we've got Linux we've got uboot uh free artos they have an option for that as well build route everything is here oh I'm I lost my help no more help anymore so they are suggesting Ubuntu 20.04 and I chose to use buntu like distribute pre-compiled risk 5 compilers for Linux the make image version is designed for runtu 20s libraries so with Ubuntu 22 it needs a newer version of lib SSL so I just replaced that version of make image with the version from uboot tools from the Ubuntu package all good so at this point I could run menu config and change IPv6 to enable and recompile the kernel and eventually we had the message gen image successful then I can uh flash that on my micro SD card and go from there so I got my custom Linux kernel on this SD card and let's go oh wow look at that so I got my ipv4 got my IPv6 got my link local and I got a link local here so now can I ping six [Applause] Google okay so that worked so we connected to an HTTP site over IPv6 on Port 80 because remember we don't have TLS so we can't do TLs but it did make an IPv6 connection to the outside world and it succeeded so if I were to write my own app that did whatever protocol I want to do I could write that using IPv6 on this board and that's really magical to me so now that it works I committed my changes to GitHub and sent them a pull request saying ipv4 is Legacy so I decided to try testing USB as well which meant I had to solder pins on so it's currently running a USB flash drive and this is a USB zigby dongle I had on hand it should show up as a serial Port if it has a driver for it of course I had to connect over ethernet since I can't use the USB Gadget when I'm using USB host but that's expected with only one USB controller so over here in putty so sda1 2 and 3 that is my flash drive other cool things you can see the Spy Dev shows up so there's two spy buses and they both show up with Linux byy devices there's five uarts and they all five show up here what does not show up is the uart for that zigby dongle so I'm guessing that that would be another kernel compile thing to enable that driver on this minimal Linux build it's the only Hardware left to test is the camera in case you're curious about the camera module which is currently selling selling for $350 $3.50 it is a Galaxy Core GC 2083 resolution 1920 x 1080 and uh I can do that 30 frames per second comes with example software for the board that streams it over rtsp and that's what I'm using now to collect it so if you want to build your own security camera this is a pretty cheap option so that ends my tour of the milk 5 or milk V Duo the $9 risk 5 single board computer I'm not sure if you know this about me but I actually have a degree in computer engineering so writing programs in assembly and optimizing them is kind of my jam and so my professional experience includes things like writing and debugging and optimizing at the assembly level code and arm and power PC and so I've written high integrity boot code for some systems in power PC assembly I've done math optimization of complex math functions down the assembly level or optimizing C Level and that's something I really enjoy and so working with risk 5 has given me a true enjoyment for computer architecture again something I don't see a whole lot in the world and so as I work with more architectures I get really sad that x86 that we ended up on because it's honestly the the worst to work with myips is incredibly clean and optimized but um almost too small it pushes too much work on the compiler the goal with myips was to push clocks as high as possible and make the processor as simple as possible and that worked to a point but eventually high performance Computing surpassed it and so if I wanted to work on Nipps today I would basically be buying like an old SGI workstation like an onyx or indie or Indigo or something like that which isn't really modern on the power PC side it's technically a risk or reduced instruction set architecture but with about 600 instructions it's it's getting up there in terms of what uh you can count as reduced I really enjoy working with power PC as well it's an excellent architecture to play with um and you can clearly tell it's been designed for hyper performance Computing and so I wanted to play with one of those at home my option would basically be buy like an IBM power 9 or power 10 which would be wildly expensive there is one company that makes power PC workstations but they're also not cheap with risk 5 I got the $9 board I can do architecture learning assembly that kind of thing on a wellth thought out well-designed architecture that's not the bottom like myips it's it's designed for high performance and expandable and I really like that risk 5 there are also of course higher-end boards in this $9 board uh this particular company also has uh two different Raspberry Pi form factor boards with higher-end processors and they're working on coming out with a full-on 64 car workstation so maybe someday I'll be able to afford one of those but uh for now I've got this guy and uh so great to see you all if you want to buy one of these I have links in the description where you can get them you do have to pay for shipping from Asia uh I am doing a groupx as well over on my Kofi so Link in the description for my Kofi and in my store there you'll find some of these boards that I bought myself and I'm reselling just to help out shipping for Americans if you're outside of America it's probably easier to buy direct from them uh if you want to talk to me about anything head to uh my Discord server link down in the description for that as well uh thanks for coming and as always I'll see you on the next adventure next project for this board I got a beautiful box from crane that includes 12 old used audio parts so stay tuned to see that
Info
Channel: apalrd's adventures
Views: 316,288
Rating: undefined out of 5
Keywords:
Id: z-GoLDQHYsE
Channel Id: undefined
Length: 26min 34sec (1594 seconds)
Published: Mon Oct 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.