Starting Tiny OS Development With HiFive1

Hello everyone, I was wondering if I could get some advice from the SiFive community.

I just purchased a HiFive1 with the intention of learning to develop for that and possibly create a tiny OS for it. I have no experience with this level of programming but I’m willing to do it for the fun of it and adventure.

My goal is bootstrap a mini operating system for me to create all sorts of apps and tools for me to use to create other things such as graphics and sound programs.

Do you have any advice for me in this endeavor?

Mind that the HiFive1 has only 16kB of RAM for data (although there is plenty of flash). That doesn’t leave much in terms of OS abstraction, certainly not with a 32-bit processor. And certainly not if you want to do sound and graphics.

When I said “Tiny” meant along the lines of a 16-Bit OS such as Windows 3.1 … I know that sound and graphics WOULD be limited. Thats kind of the point. I want to see what I can do in a really tiny space. I will learn a great deal about optimization and memory management along with everything thats involved in bootstrapping an OS. At first my OS will probably not even have graphics. However I do want to build in that direction.

This is not Windows 3.1 ballpark, computers had 640kB RAM by then, more like home computers like the MSX1 and other 80’s 8-bit computers.

If that’s your challenge that’s great, don’t mean to discourage you :slight_smile:

(using RISC-V as essentially a 16-bit processor is a kind of interesting idea, you could get away with storing pointers as 16 bit)

However you’re in the territory of early Apple ][, Commodore 16 etc, which had some pretty powerful software. Better, because you have practically unlimited code size available in flash. And much more compact and powerful machine code.

Someone really needs to pull the flash-programming code out of OpenOCD and make a library from it. Then you could use the top 8 MB (or more) of flash as a file system. Maybe do software data paging :wink: (aka overlays)

1 Like

You can also use a few GPIO lines to connect the board to a SPI SRAM chip, but it’ll be slower to access.

Yeah, seems you can get 1 MB for a couple of bucks.

https://www.digikey.com/product-detail/en/microchip-technology/23LC1024-I-SN/23LC1024-I-SN-ND/3543084

There are 2 MB ones for not much more, but minimum order I immediately found is for 400 of them.

The next step up would be a Raspberry Pi Zero with 512 MB for $5. It comes with a free ARM management CPU. Or, if you want something you can actually buy, a NanoPi Neo. Nice peripherals :slight_smile:

Oh wow, I never realized, so it would be possible to write the flash from the board itself?
(I suppose so, switching to raw SPI mode while running from memory, which must be exactly what OpenOCD does, thinking about it)

Overlays and manual paging, that sure brings back some memories.

Nah it must be faster than using the host for storage over serial :slight_smile:

Exactly. OpenOCD puts some SPI-writing code into SRAM and then runs it. There’s no reason any other program can’t do that too, it’s just the hassle of copying that code into SRAM temporarily (and making sure it’s PI or else simply linked for that address). Or you could just link it in SRAM as a kind of initialised globals that happens to be instructions, if you don’t mind the wasted space.

I’ve been hoping someone will do this for about the last 18 months, so I don’t have to do it :slight_smile: Copious spare time, and all that.

This is something that any self-respecting FORTH for the HiFive1 should be doing hint hint

1 Like

i actually did this for a customer. (code that runs in RAM and writes FLASH.) Megan describes the fespi driver in this post from way back when:

i was also able to run TINY BASIC on the HiFive1, but still trying to figure out how to modify it to allow me to do GPIO twiddling.

2 Likes

Note those are 1Mb (ie 128k) but still not too bad. I did come across a post on some Arduino bulletin board about a 6502 emulator that reads and writes to SPI ram (using the onboard ram as a cache) that I was interested in getting running on my HiFive, but alas other priorities and all that.

2 Likes

These answers while really cool and interesting are much much more than I need. Here are the actionable steps I think I should probably take based off of what was posted:

  1. Learn the basics of Arduino and try to learn about writing an OS there, then run that on RISC-V
  2. I need to learn fundamental stuff about how to approach writing an OS at all. I don’t have a computer science background.
  3. I found a video on youtube where a guy is showing how to write an OS (called Chibi OS) on an Arduino. Maybe try that.
  4. Writing a 16bit app on RISC-V seems possible. Thumbsup.
  5. I wish programmers were willing to keep it simple and stupid when explaining things but I think its hard to de-abstract heavily abstracted topics. Takes more effort.

Thanks for all of your input. I’ll get cracking this weekend.