Shop Learn
Propeller C - Propeller Activity Board - Execute code from SD — Parallax Forums

Propeller C - Propeller Activity Board - Execute code from SD

BlueOkirisBlueOkiris Posts: 4
edited 2014-12-06 12:48 in Learn with BlocklyProp
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.
  sd_mount(DO, CLK, DI, CS);  FILE* fp = fopen("run.bin", "r");
  int size = 0;
  char c;
  while(fread(c, 1, 1, fp) != 0) {
  char code[size];
  fp = fopen("run.bin", "r");
  for(int i = 0; i < size; i++) {
    fread(c, 1, 1, fp);
    code[i] = c;
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.


  • Mike GreenMike Green Posts: 23,045
    edited 2014-11-10 11:42
    It looks like you're trying to execute little code "snippets" that you're trying to load in from an SD card. You can't really do that. When you "run" a piece of code using the Propeller C system, it replaces the whole program with what's read in. There are some other programming systems for the Propeller that can run overlays or "code snippets". For example, Spinix and Sphinx are mini- operating systems that can load small programs written in Spin that are designed to not overlay or affect the operating system which remains in memory. Spin is more forgiving of the memory locations of the code and can be relocated more easily than compiled C code.

    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.
  • David BetzDavid Betz Posts: 14,385
    edited 2014-11-10 11:58
    You can use the XMMC memory model and select the SD cache driver. That will allow you to have large amounts of code that will be read in on demand from the SD card. However, the performance of XMM is significantly lower than LMM or CMM and is particularly slow when using the SD cache driver.
  • BlueOkirisBlueOkiris Posts: 4
    edited 2014-11-10 14:31
    Mr. Green and Mr. Betz, thank you for the advice. If you can, I would like you to give me a little more information and some references to read. If you would like to know what I am doing, I am making a sort of retro game console with an LCD. Ii would like it to run code from an sd card that could easily be updated (without someone knowing how to program Propeller C). So a program would add a section of code that lets you pick and run a game like:

    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.


    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:
    It is the second build on this page.
  • BlueOkirisBlueOkiris Posts: 4
    edited 2014-11-10 14:38
    Also, I am not worried to much about performance as this is not but a proof of concept, a learning experience, and fun for me. However, it's one thing to have a delay of a few milliseconds and another to have a delay of seconds..
  • Mike GreenMike Green Posts: 23,045
    edited 2014-11-10 21:58
    Here are some starting points for forum threads on various OS's for the Propeller and an SD card. All are Spin-based although they will execute C programs stored on the SD card ... the C program completely replaces the OS in memory, so it's hard to get back to it ... you can store the OS in EEPROM so it executes automatically if the Propeller is reset. You could leave status information in the EEPROM or on a file on the SD card so the OS can figure out what to do next.

    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).
  • BlueOkirisBlueOkiris Posts: 4
    edited 2014-11-11 04:58
    Thanks. i will check those out and see if i can get them to work.
  • Dave HeinDave Hein Posts: 6,331
    edited 2014-11-11 06:58
    You could use spinix to launch your programs, but I would suggest looking into the LameStation. Since you are interested in running games on the Prop, the LameStation should work well for you.
  • jazzedjazzed Posts: 11,803
    edited 2014-12-06 12:48
    FYI and others here who don't know ...

    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.

    820 x 680 - 87K
  • how do i put the file onto my micro SD card???
  • how do i put the file onto my micro SD card???
    Does your computer have a slot for SD cards? If not you can purchase micro SD card reader like this one.

    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.

  • I thought you could move files to the micro SD Card via SimpleIDE by selecting Program->File to SD Card ? I've done this with sound files and an Activity Board so I would think it should be same in this instance.
    The example I had seen was with the "Programming the KittyBot" Learn project .

    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.
  • Mike GreenMike Green Posts: 23,045
    edited 2017-01-05 18:46
    There's a RAM card for the Hydra that adds a 512K byte RAM, 64K EEPROM, and interface that uses 12 I/O lines to control the RAM card. You can read and write to the first 64K bytes using a random address and several I/O cycles and read and write blocks to the rest of memory using an address counter in the interface. I'm not sure if there's direct support in the C library for this memory scheme. There's some Spin code in the Hydra memory card library showing how it can be used.

    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.
  • Mike Green wrote: »
    Parallax sells another memory card using serial RAMs and serial flash memories which is supported by the C libraries.
    Unfortunately, that board is no longer available.

  • The SPI RAMs and flash memories are really easy to use. I've set up one of each on the little breadboards on the Activity Board and Board of Education. That still leaves some room for other stuff on the breadboard. I've posted code in the ObEx for using them including a simple file system with provisions for storing programs on the flash memory.
Sign In or Register to comment.