Propeller C - Propeller Activity Board - Execute code from SD
BlueOkiris
Posts: 4
Hello. I have heard that you can execute code on the PAB from an SD card, but after hours of scouring the internet from general ideas to very specific ideas, I have turned up with nothing. In one of the learning tutorials, the sd data one I believe, it mentions doing this later, but I never could find it. I also found that you could take byte code and cast it to a function pointer which I attempted to do here.
Thank you.
sd_mount(DO, CLK, DI, CS); FILE* fp = fopen("run.bin", "r"); int size = 0; char c; while(fread(c, 1, 1, fp) != 0) { size++; } fclose(fp); char code[size]; fp = fopen("run.bin", "r"); for(int i = 0; i < size; i++) { fread(c, 1, 1, fp); code[i] = c; } fclose(fp); ((void*)code)();but failed to compile for obvious reasons. So now I ask for help from you, people of the forums. Please help me execute code from the sd card in the board.
Thank you.
Comments
Some of the Forth systems for the Propeller have provisions for running small "snippets" of Forth code from an SD card file.
What do you want to accomplish with this capability? Note that it's not impossible, just hard. The byte codes don't use relative addressing, so the code snippets have to be compiled for specific memory locations and the various library routines references have to be in the same locations when the code is written to the SD card as when it executes.
startup(); gameMenu1(); processSelection(); rungame1();
would become
startup(); game1Menu(); *game2Menu(); processSelection(); rungame1(); *rungame2();
So it would startup and go through each added game in a menu, then process what you chose to run the added run method..
If this makes it easier to help me, please reply.
Thanks!
PS: I have already made something similar with arduino, but am trying to improve upon it with a more powerful microcontroller.
It was featured on hackaday, here is a link: http://hackaday.com/2014/08/01/
It is the second build on this page.
Spinix: here
Sphinx: here
(Note that Sphinx includes a Spin compiler/assembler that runs completely on the Propeller.
Cluso's OS: here
I've also used FemtoBasic as a program controller. It will automatically load and execute a Basic program from an SD card which can, in turn, load and execute a binary program (like a compiled C program) from the SD card that replaces FemtoBasic. Like the above, if that program exits by causing a reset, FemtoBasic can be restarted from the EEPROM to again decide what program should be executed next. This was used to control a kiosk that would give a menu to the user to select from one of several demonstration programs written in Spin (but could have been in C).
Theoretically, all you have to do is open the project manager pane "pain for spin lovers" and choose ACTIVITYBOARD-SDXMMC and XMMC External Flash Code .... The attached picture shows the settings.
In practice, Simple Libraries do not use XMMC because in the current incarnation with propellergcc release_1_0 because of the "simple" aspects of multi-core usage (not so simple multi-core which is not really the target audience of the Learn program is possible of course with PASM files I.E. fdserial.h, .cogc drivers, and propeller pthreads).
There is a bug in the windows RC1 package where the loader doesn't work correctly for sending files to the SD Card. It would be necessary to replace your windows C:/Program Files (x86)/SimpleIDE/propeller-gcc/bin/propeller-load.exe with this one working windows propeller-load.exe. Mac and Linux packages should work as is.
You can find readers like these for just a couple dollars on eBay or places like Banggood.
Once you have your SD card connected to your PC, you can just copy the file like you would other computer files.
The example I had seen was with the "Programming the KittyBot" Learn project .
learn.parallax.com/tutorials/robot/activitybot/kittybot/programming-kittybot
The Hydra board has a slot for RAM expansion cards so it would be interesting to see how that was done and if the idea could be ported to another board.
Parallax sells another memory card using serial RAMs and serial flash memories which is supported by the C libraries.
Cluso99 sells a Propeller board with a built-in 64K byte RAM intended mostly for running a Z80/CPM emulator. It uses most of the Propeller's I/O pins to drive the RAM as fast as possible, but does provide for an SD card for emulating floppy and hard disks for CPM. It can either use a serial console or use those same pins for video text output and a PS/2 keyboard.