Shop Learn
Loading code from external eeprom — Parallax Forums

Loading code from external eeprom

Can I read code being ran in a cog and write it to eeprom? Can I then read that code and write it to a cog and run it? I am out of code space on my P1 project.

My thinking is I have a cog running my RGB Panel with several diff display types. I would think I could remove all but 1, program the prop, read the compiled code from that cog and wright it to an external eeprom. I could do this for each subroutine. I could then load the code by reading it from the eeprom and putting it into a cog then start that cog. Can I do this if all the sub-routines have the same "Pub Name" and use the same variables when I read and send to eeprom?

Not clear on how to read the code from the cog or how to start that code after the code was copied to it though. I think I seen some one do this before in the forum but can not find it.


  • Perhaps you might want to write, which programming system you use. Propeller Tool?
    Is conditional compilation a possible approach?

  • Cluso99Cluso99 Posts: 17,955

    It is possible to save and load a cogs code to eeprom but it’s not straightforward and it’s different depending on the software language used.

    There are a few tricks we can use to free up hub memory though. Once a cog is loaded from hub, unless you need to reload a cog, that space can then be used for buffers.

    If your problem is cog space, then you can use overlays where you load a routine from hub and execute it in cog. You could expand this to loading from eeprom instead but of course would be much slower.

    You need to tell us a lot more so we can help.

  • Its just a P1 running spin "the ADC cog has Pasym code for the extra speed" and no, conditional compilation would not help but was an idea I was thinking about as well. The project is running but I just do not like the sledge hammer system I am using with the 2nd rom boot for the user settings interface. No one but ME knows it boots off an external rom for the user settings then back to the displays after all the user options like setting the clock and colors are saved. The user settings are saved to the upper part on the main rom for the display and ADC displays right now. It is bugging me, looking for more options that would be more graceful I guess you would call it. Its more of an OCD thing. It would be great if I could leave 1 display in the main code and swap it out with the other layouts when the display mode is changed. Its just a music RGB display I did that has 5.1 DTS input unlike off the shelf units that are stereo only. I think some one swapped out code in a cog before but I could not find any posts on it. The 2 rom system is working it just feels like a clunky work around.

  • The EEPROM driver that's part of FemtoBasic (sdspiFemto.spin) can read or write an arbitrary block of data to/from any size EEPROM that uses I2C and a 16 bit address. It can handle larger EEPROMs by treating them as several consecutive EEPROMs (like a 128K or 256K EEPROM). It can also "boot" from a portion of an EEPROM given a starting address and a size. This behaves just like the ROM boot loader in that it reads in the program, then starts up the ROM Spin interpreter on the new program.

  • Cluso99Cluso99 Posts: 17,955

    I think what you’re looking for is the thread that Dr_Acula wrote about coglets where he could arbitrarily load a cog from SD. Perhaps a search for this might turn up the thread.

  • msrobotsmsrobots Posts: 3,459

    There is some neat trick with spin. The image in the lower 32K is exactly what is loaded into the HUB.

    So if you have a some Variable in a DAT section say

    mysetting LONG 12345

    and you use your I2C object and write 5678 into @mysetting (the address of mysetting in HUB) as address into the EEPROM, it will overwrite exactly the value 12345 and the next time it boots from EEPROM your Variable mysetting will contain 5678.

    That is neat insofar that you do not need any code to 'load' settings, you just 'save' them at the right place in the EEPROM and they are preset when you boot.



  • KC8DKTKC8DKT Posts: 76
    edited 2021-08-11 23:31

    Thank you all so much, I have options for a cleaner setup it would seem then the 2 rom setup. Will check out the Femoto and the posts. THANKS EVERY ONE big time. This was driving me crazy, it just does not feel right leaving it this way. I know its nit picky on my part but it drives me nuts and I had to find a cleaner solution before starting the PCB layout. Thanks again for all the info.

Sign In or Register to comment.