Executable Spin Files?
Circuitbuilder9
Posts: 85
Hey everyone,
I wanted to load (by EEPROM) on my propeller quickstart a program without including it in an object block, but rather execute it by turning it into a binary file, and then get the propeller to download and execute it on a mSD. However, I'm not sure how to do that, if it can be done at all. Help?
Thanks
p.s. - the program that i want executed is below
Blink.spin
I wanted to load (by EEPROM) on my propeller quickstart a program without including it in an object block, but rather execute it by turning it into a binary file, and then get the propeller to download and execute it on a mSD. However, I'm not sure how to do that, if it can be done at all. Help?
Thanks
p.s. - the program that i want executed is below
Blink.spin
spin
201B
Comments
If all you want to do is blink an LED, it's much easier to just do that as part of your program. What are you really trying to do?
Going back to the program stored in EEPROM can simply be done by doing a software-reset. If I remember right this is described somewhere in http://propeller.wikispaces.com but I could also search for it when I'm back home.
But for easy programs there is another solution which does not stop your loader program.
For such small programs you can also load a bin into a buffer start it there with a COGNEW, not leaving your main program! Have a look: http://forums.parallax.com/showthread.php?143182-Spinneret-need-more-Space&p=1135658&viewfull=1#post1135658
But as I already stated in that thread, this buffer has to be big enough to hold the bin PLUS the main stack that is needed by this loaded program!
It's also possible to pass parameters into this bin-program. If you need that let me know and I'll search for an example.
Mr. Green, for clarification, i wanted to use the blinking program as a proof of concept. I wanted to see if it was possible.
So how would you start? load the spin program you want to execute from the SD into a .bin, then.............
I've tried a few times, but do not know how to go from there.
I suggest you get copies of FemtoBasic (for the sdspiFemto.spin and fsrwFemto.spin files) and DongleBasic (to play with) from the Object Exchange. You'll have to edit BB_Definitions.spin to specify which I/O pins you've got for your SD card, then recompile the whole thing (DongleBasic.spin) using the Propeller Tool. Look at the documentation for the SPIN statement which will execute a file from the SD card.
DongleBasic uses a slightly different arrangement of the I/O drivers than FemtoBasic and it's easier to just take the relevant files (sdspiFemto.spin and fsrwFemto.spin) from FemtoBasic and incorporate them into your program than taking the equivalent files from DongleBasic. With these files, you also get methods to read and write data files from SD cards and to read and write data to EEPROMs.
FemtoBasic has been used to run a kiosk to run one of several demo / game programs for the Propeller from an SD card using a TV monitor and keyboard to select the demo program.
Thanks!!
I am using a parallax quickstart's EEPROM, so, do i set the upper_eeprom variable to $4000 instead of $8000?
When i boot the Blink program mentioned earlier, nothing happened.
Most QuickStarts have 64K EEPROMs.
You can check using the program attached to post #24 here. (Only use it to check your EEPROM size, the rest of the program is very buggy.)
Here's what i have so far:
ExecuteSD.spin
The first repeat will read in 32 byte chunks, but it always stores the 32 bytes in the same memory location.
The second repeat is never ending and always copies the same 32 bytes to the same address of EEPROM.
What you'd need is to have one single repeat loop
read from file
write the chunk to EEPROM
wait until EEPROM is done
But I also don't understand why you would copy the program to EEPROM if you have the SD-card. You can also start bin-files from SD card!
Try, try again....
You'd simply open the file and then call this function - that's it!
PS: This is a modified version, which allows to pass a COG-ID of a COG that should NOT be stopped by bootSDcard. I used it to run a timer which would reboot the propeller after a while.
Here is the code for that timer:
Simply start it with a COGNEW where the second parameter contains the seconds to run. If no additional COG needs to survive, simply pass 8 to the bootSDcard.
Andy
But still no effect.
MagIO2:
i probably should have asked this earlier, because this was my purpose of intention.
Can i see some code on how you are supposed to do that?
I don't get the idea of starting a "watchcog" and then shut it down. What's the purpose of that?
To sum it all up, i want to build a program that executes a spin program on an SD, directly from the SD. So, in context of the program (Blink), i need the parent program to execute "Blink" from the SD. However, i do not know how.
ExecuteSD.spin
The changes I did make the loop more flexible, as your bin file size can be any size. In your code you limited it to 500 bytes. Now it reads as many bytes as there are in the file. On the other hand if reading in junks, there is no need to have a 1000 byte buffer.
For running a bin directly from SD just have a look at Aribas example!
I don't know what your watchdog in ExecuteSD is really good for?! The watch I posted is a little timer which counts seconds. If the number of seconds is equal to the parameter with which the watch has been started, it's resetting the propeller. This piece of code is copied from a small OS where I can run any bin and I can limit the runtime. This was nice for running demos just for a while and then returning to the OS which is the program loaded into EEPROM.
But be aware, this watch only works together with my version of fsrwFemto/sdspiFemto, as the original versions would stop any COG except the COGs needed to load the bin. After loading the bin a new SPIN interpreter is started and the remaining running COGs (except the new interpreter COG) are stopped as well.
I deleted the watchcog method and added MagIO2's repeat loop.
However, this is getting frustrating. There is no result to the LCD or the Blink program on the SD. The method is supposed to say on the LCD that the program is loading from the EEPROM before actually loading the EEPROM (to see that the statements actually went through).
But, no avail.
Help!!
ExecuteSD.spin
j should be initialized with 32, otherwise it won't enter the loop at all:
j := 32
instead of
j := 0
I don't know your LCD driver. Is it starting a COG to send data to the LCD? In that case there might be a problem when bootEEPROM stops this COG to early. Simply wait for half a second before calling bootEEPROM.
Do you think that the sdspi program is stopping my cog before it can be executed?
If so, how do i prevent that?
Then you should see the message at least for 5 sec. But when calling bootEEPROM the backlight will be switched off again, as the COG which drives the backlight pin will be stopped.
I didn't start the sd.start method as Ariba posted a few posts ago.
So, i ended up getting the message on the SD.....
BUT:
No blinking lights from the bin file!!!
Help?
I opened the b1.bin file from the sd, and it opened a spin program with nothing written on it.
BUT, i downloaded the file on a binary viewer, and there was code written on it as it was compiled to a bin file previously.....
I am very confused on why this isn't working. Previously, i thought i was doing something wrong with the code, but when i saw your posts, i was doing everything correctly. The problem lies in the bin file...... but i don't know what.
I've more recently coded a touchscreen version that has the files as icons on the screen and it is also based on Kye's driver.
The main program is KyeDos3_TV and the comments at the beginning show the steps needed to get this working. There are a number of objects commented out, like the driver for a 20x4 LCD screen, but they have been left in to show how this can work with a number of displays. I had it working sending data to the VGA display, to the 20x4 LCD screen and to the serial port as that was a flexible way of debugging. Comment out the things you don't need.
Maybe you can find something useful in this?
I am using a mSD.
I tried executing the program again, but i'm not getting any blinking from the Blink bin program on the mSD. Can someone tell me what's wrong with my code?
ExecuteSD.spin
There's another routine in fsrwFemto that will directly boot from the SD card (bootSDcard).
Here's the code from FemtoBasic that gets the file name into a buffer, mounts the SD card, opens the file, and boots the new program:
How are you getting the binary file and how are you putting it on the SD card?
You could also add some debug messages inside of the loop.
I'd not expect that you see "booting..." and you'll definitely not see "done" because bootEEPROM will stop all the COGs not needed for loading from EEPROM.
Why exactly don't you switch to Aribas code which loads the bin from SD directly?
I actually had another program made (ExecuteSD 3) that uses Ariba's example. However, the mSD wouldn't boot even though the "booting...." message showed up on my LCD.
My mSD is set up like so:
DO -> wire directly to pin 2
SCLK -> wire directly to pin 3
DI -> wire direclty to pin 4
CS -> wire directly to pin 5
am i supposed to include pull-up resistors? That thought just came to me.
@Mike Green - sorry for being confusing, but i just wanted to load the sd file to eeprom, then boot from the file that was downloaded to eeprom as a means of proof of concept.
Oh, and by the way, this is how i put the Blink program to the sd:
1. F8
2. save as .bin file (i called it b1.bin) under binary file type
3. saved to mSD
There is no other file on the mSD, just the Blink binary.
ExecuteSD3.spin
Re the program, can you post the full program ie the objects as well, just to double check the order of the pins is correct?