Getting started with Spinix
jazzed
Posts: 11,803
Did you know that Dave Hein's Spinix090 has a Spin Compiler and Assembler?
Spinix is pretty amazing. Not sure how it is over-looked by this community.
The spinit Spin Compiler compiles *.spn to *.spa spasm (spin byte-code assembly).
The spasm Spin Assembler converts spin byte-code assembly into a spin program.
The spinit *.spn program is limited to one file, but there are several interesting demos.
Spinix090 comes with a fairly complete set of on-line documentation and Unix-like utilities.
Additionally, Spinix can run programs built with the PropellerTool or Propeller-GCC.
Future posts will build on this introduction.
Spinix is pretty amazing. Not sure how it is over-looked by this community.
The spinit Spin Compiler compiles *.spn to *.spa spasm (spin byte-code assembly).
The spasm Spin Assembler converts spin byte-code assembly into a spin program.
The spinit *.spn program is limited to one file, but there are several interesting demos.
Spinix090 comes with a fairly complete set of on-line documentation and Unix-like utilities.
Additionally, Spinix can run programs built with the PropellerTool or Propeller-GCC.
Future posts will build on this introduction.
Comments
To succeed with the Spinix setup below, you will need a few things.
Hardware Requirements:
- Propeller Board with micro SD card slot like the ACTIVITYBOARD (4 pin SD card interface)
- A microSD card and USB adapter (or other PC interface for file transfer)
- USB Cable
- Optional power supply for servo experiments
Software Requirements:
- The Spinix090 Package (latest as of this post). Latest Spinix seems to always get posted here.
- Some kind of Serial terminal program capable of using USB at 115200 bps.
- Propeller-Tool, BSTC, or some kind of loader.
- Optional ANSI terminal program for PC for best experience like Putty. Putty for window here.
- Optional Propeller-GCC
Setup Procedure:
1. Make sure you have required items above. Optional items are nice to have.
2. Unpack the Spinix090 package to your computer.
3. Use Propeller-Tool, BSTC, or other loader to program the Propeller board with Spinix/bootsd.eeprom.
4. Insert SD card to computer, do a quick format as FAT32 (works best with 32KB Allocation size).
5. Reinsert SD card if necessary.
6. Copy Spinix/root/files to the SD Card.
7. Safely remove SD Card and insert in the Propeller board.
8. Start the terminal program for the serial port (for Putty, set Keyboard Backspace Control-H)
9. Reset the Propeller board by pushing the button or power-cycle.
10. Spinix should start with thie prompt "Press any key to start SD pin setup"
On ACTIVITYBOARD:
10.a. Enter DO pin number: 22
10.b. Enter CLK pin number: 23
10.c. Enter DI pin number: 24
10.d. Enter DI pin number: 25
11. Reset the Propeller board again and verfy the Spinix prompt shows something like this:
spinix 0.90 April 8, 2012
/$
12. Enter "ls" to see files, then "ps" to see COG usage.
What do they do?
Use the man program (manual) to find out. The ls program has already been used. Let's see what it does.
That's a man page. Other man pages are available and are in the manpage directory.
The man program can be used from anywhere in the directory structure.
Another way to see the content of a file is by using $ cat.
The cat program concatenates the output of a file to the terminal. This example shows the linefeed utility. In linux and spinix both line-feed and carriage-return are printed. A terminal program like PST interprets both to mean new-line, so "$ linefeed off" tells spinix not to print line-feeds. Of course one can just disable line-feed in PST also.
The cat program has another feature when combined with a pipe command line modifier.
What happened here? We created a new file called test.txt that contains "hello". Using cat > file, sends console text to the file. To stop cat, use CTRL+D.
Why didn't the hello text show up when being typed? Dave?
What is a pipe command line modifier ? Use "$ man shell" to find out. Pipe command line modifiers are built-in to the shell.
There are many such utility commands. Many of them are very familiar to command-line linux users. All /bin utilities are fully documented.
Indeed P2 will have more room ....
Honestly, I started looking at this mainly because of the spasm spin byte-code assembler. It looks like a good intermediate language for other things.
I suspect that all such solutions suffer from the same problem with 32KB of HUB RAM. There are always trade-offs to be made in such a tiny space.
Perhaps some features could be sacrificed?
While TVs and VGAs are interesting, there is a lot that can be done with just a serial embedded solution.
I'm curious, was the spinit compiler designed from scratch?
Thanks,
--Steve
Looking back at the archive files in 2010, it is in Spin, but that was before C and XMM mode came along. If it is running out of space for VGA drivers, one solution might be to port it over to C and run it in XMM mode from an external SPI ram chip. Then you could allocate (say) 8k for cache, some memory for essential things, and still have most of the hub ram left over for a VGA or TV screen buffer.
Many cool possibilities - I'll be following this thread with interest.
With Forth it can be done and it is a nice solution.
Massimo
I think this is a big plus!
Some of the features of spinix could be sacrificed to better fit the 32K of RAM. spinix supports several types of executables, which include relocatable Spin programs that can be run with other programs. I think quite a bit of space could be saved if the relocatable programs were eliminated along with the resident kernel. The shell could be expanded to handle more scripting features, and maybe some of the common apps could be included such as ls and cat.
@Dr_Acula, spinix is written mostly in Spin. There are a few demo programs that are written in C. spinix only knows how to run LMM C programs, but it should be able to run CMM programs also. It shouldn't be too hard to add XMMC programs that run from the SD card. LMM C programs can be written to run in a stand-alone mode or as an app that runs with the resident kernel. The main limitation with C programs is that they are not relocatable like Spin programs, and must be loaded at location 0. However, it is possible to run one C program along with the kernel and additional Spin programs at the same time. hub RAM is the main limitation.
One thing that spinix does with C programs is that it patches in the command-line programs using argc and argv. This works with stand-alone programs and apps, and allows the programs to work like on a real Linux system.
To me the great values here are shell and spinit programming. A shell script can run any program on the sdcard with redirection. That means you get the ability to use much more than 32KB memory for propeller programs without needing XMM support. Having spinit adds to shell power by giving program access to propeller resources. Of course if you only need to read or write pins, then you can make tiny programs to do that.
Having some conditional support in the shell would very useful - that could be traded for command history in a different shell. Fortunately, all the source appears to be in the package, so a shell with different features is certainly possible.
Can spinit and spasm be run in spinsim? It might be a stretch, but could the whole package could run in spinsim?
Thanks
Hi Dave. That works
Running "programs" in addition to "apps" in spinsim would be very useful.
Thanks!
I posted spinix097 to the spinix thread. That version contains some work I did on a VGA driver about a year ago. The driver only supports a 32x15 text display, which is a bit low-res to use for a console. I had done some work on an 80x24 text display, but it uses 2 cogs and requires about 3K of hub RAM.
I hadn't use spinix for a while, so it was kind of fun to play around with it again. For anybody that is familiar with Linux you'll find that spinix has a similar feel to it. I had forgotten how far I had gotten with spinit/spasm. It is quite usable at this point. Probably the next thing to add to it is multiple object support.
Could you give a little description of how to make a pipe-able C program for spinix?
I'd like to do this: $ program < junk.txt
The program should just be able to read and echo junk.txt
I'm able to read something from stdin on spinix by doing getchar() but can't pipe it in.
Is it necessary to build pipe-able spinix programs in lmm mode?
Also, what is the purpose of clkfreq ?
I.E. propeller-load -s -D clkfreq=1347436867 hello1.elf
I've tried building hello1.c, loading, and running without much success with cmm.
Using lmm it seems to work fine.
File redirection requires an interface to the that spinix kernel file driver using the FileDriver struct. I haven't done that yet, but it is on my todo list.
It's good to hear that LMM apps still work. The spinix loader patches a few things into binary image, to set the initial stack value, and provide an exit routine. A few things have changed in the C startup code since I last worked on spinix, so I wasn't sure that LMM apps would still work. The issue with CMM apps is probably due to a difference in the locations that are patched by the loader. I'll look at that when I have a chance.
The value of 1347436867 that is used for the clock frequency is equal to 0x50504143, which represents the ASCII string "CAPP". This is used to tell spinix that the file is a C app. Spin files use the string "SPIN". It was convenient to use the first 4 bytes in the file for this purpose, and the clock frequency isn't needed since it was already set up at boot time.
Thanks for all those details.
If you haven't guessed yet, I'm trying to get the LittleC interpreter to work in Spinix. The CMM binary of the LittleC interpreter has lots of head room without including file-system stuff. The LMM binary won't run on Spinix at all.
I thought the easiest and smallest way to get a usable LittleC program running in Spinix would be to pipe the source program into the interpreter ... maybe not.
Do you have an example CAPP C program that uses Spinix file IO services?
Actually, it would be nice to know what other services Spinix offers and how new services might be added.
Thanks,
--Steve
Each method calls RemoteFunctionCall passing a command number and a pointer to the parameter list. The RemoteFunctionCall method waits for the system file lock to be cleared, and then puts the command number and parameter pointer in the kernel mailbox. It then waits for the function to be complete, and returns a return value. The mailbox location as well as other system information, such as the process table are located at high memory. The locations are defined in sysdefs.spin.
With all that being said, I think the easiest way to run the LittleC interpreter under spinix is to run it as a stand-alone program. You just need to compile it with a clock frequency between 80 MHz and 100 MHz. That's how spinix detects stand-alone programs. If you want to get commands from an file you would need to build LittleC with the standard PropGCC file drivers. From spinix you would then type "littlec junk.txt", and spinix will pass the argument list to the program using argc and argv. You could use the technique that I used in the PropGCC filetest program to open a file and use it as stdin.
EDIT: Look at filetest/filetest.c in the spinix source tree. It is essentially the same as the PropGCC demo program except that it calls a GetConfig program to get the SD pin assignment and a pointer to the current working directory string. It then calls LoadSDDriver, dfs_mount and chdir using the pin assignment and CWD string. I don't think this will work any more because dfs_mount was changed since I wrote this. I'll look into it.
http://www.busybox.net/about.html
I am aware that there are some utilities that are Spinix specific and NOT compatible with the Linux/UNIX file system and the SDcard is a FAT file system. But a great deal of effort has gone into making Busybox a wonderfully small code footprint that offers the most utilities it can for Linux embedded systems. The same approach for Spinix might be a win.
There is also the FreeDos project that might offer more of the kind of utilites that a FAT file system desires.
http://www.busybox.net/downloads/BusyBox.html
Here is the detail listing of BusyBox utilites.
http://www.busybox.net/downloads/BusyBox.html