Shop OBEX P1 Docs P2 Docs Learn Events
How to do a demo showing run is from EEPROM vs RAM? Open terminal after start run? — Parallax Forums

How to do a demo showing run is from EEPROM vs RAM? Open terminal after start run?

John KauffmanJohn Kauffman Posts: 653
edited 2014-01-22 10:41 in Propeller 1
Just as a simple demo, no programming objective:

How can I show if a program is running from EEPROM or RAM, i.e. it was started by SIDE F10 or F11? Is there something I can put in Print() that indicates the source?

Second, If my program has a print() and I want to run it then I normally hit F8 - run with terminal.
If I accidentally hit F10 load to RAM and run then I have to start terminal by hand. But when I do nothing appears on terminal. (Program runs fine w/ test to terminal with F8).
Same with F11 Load to EEPROM and run - can't get terminal to display text.

Thanks.

Comments

  • T ChapT Chap Posts: 4,223
    edited 2014-01-21 16:21
    On launch, have a method to read a value from an eeprom location(lower 32k) Next write that same location with a value ie 255 When you f11 the value you wrote gets nuked. So a test on launch for 255 tells you if you have previously done f11.
  • SRLMSRLM Posts: 5,045
    edited 2014-01-21 22:00
    There isn't anything built in that will indicate this. PropGCC propeller-load has a variable patcher that you could use to patch a variable on EEPROM load (and not RAM load), but that's outside the SIDE environment. You could also write an EEPROM I2C object that reads the EEPROM code section and compares that to the code section in memory, but that's a bunch of work for something small.

    Here's a thought: I believe that the PropGCC loader will only write the bytes that are actually used. I believe it also writes 0's to HUB RAM before RAM load. So, if that holds, you can (with a single one off program) write a non-zero value to EEPROM. Then your program can simply check that location in HUB RAM on run. If it's 0 then it's RAM loaded, if it's != 0 then it's EEPROM loaded. It's sort of the opposite side of the coin that T Chap proposed.

    My guess to your second question is either that the print came and went before you opened the terminal (so it's output is lost forever), or opening the terminal toggles the reset line (which wipes the program in RAM). For the former, try adding a large delay (10-20seconds) before the print to give you time to open the terminal. For the second, try loading to EEPROM.
  • jazzedjazzed Posts: 11,803
    edited 2014-01-22 08:47
    Just as a simple demo, no programming objective:

    How can I show if a program is running from EEPROM or RAM, i.e. it was started by SIDE F10 or F11? Is there something I can put in Print() that indicates the source?

    F10 programs RAM. F11 programs EEPROM. At power up, the program in EEPROM will run.

    The only way to distinguish if the program is running from EEPROM or by RAM load is to have a global variable that is initialized to one value programmed in EEPROM and initialize to another value when programmed by RAM load. Display the contents at startup for example to find out.
    Second, If my program has a print() and I want to run it then I normally hit F8 - run with terminal.
    If I accidentally hit F10 load to RAM and run then I have to start terminal by hand. But when I do nothing appears on terminal. (Program runs fine w/ test to terminal with F8).
    Same with F11 Load to EEPROM and run - can't get terminal to display text.

    Thanks.

    Please post the example code you are using.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-01-22 10:22
    Another way to look at it is this: all programs run from RAM. If the RAM content (excluding variable values) of the program that's running is identical to the same content in EEPROM, you might as well stipulate that the program was loaded from EEPROM, whether or not that was really the case. Including a simple I2C routine to read and compare RAM and EEPROM contents would be enough to give you the information, assuming C code is structured in memory the same as Spin -- i.e. with the volatile stuff in high memory.

    If this is a common need, it might be nice to have the compiler compute a hash for every program and save it in a known location. That way you would not have to read more than, say, 16 bytes of RAM and EEPROM to provide a test of content identity.

    -Phil
  • John KauffmanJohn Kauffman Posts: 653
    edited 2014-01-22 10:41
    Thanks for help - I like the tricks. Need is only to do a demo to students so they can actually see what I am saying.

    PhiPi: good point for me to make. It is not running from EEPROM, it is loading from EEPROM

    I've settled on an alternative that lacks elegance but can be understood after a couple lessons of BASIC person coming to PRop C
    Project "DemoFromRAM" is always loaded to RAM and run - blinks red led on pin 15
    Project "DemoFrom EEPROM" is always loaded to EEPROM and run - blinks green led on pin 10
    By running in different combinations of first.second and observe after power off and reset, the story is pretty clear.

    I'm moving start terminal problem to another thread
Sign In or Register to comment.