Shop OBEX P1 Docs P2 Docs Learn Events
Writing a Spin binary to EEPROM — Parallax Forums

Writing a Spin binary to EEPROM

David BetzDavid Betz Posts: 14,516
edited 2014-03-15 06:43 in Propeller 1
If I want to write a Spin binary file as output by OpenSpin or the Propeller Tool to EEPROM, do I have to write the entire 32K or can I stop writing after the end of the .binary file? In other words, if the .binary file is 8K can I just overwrite the first 8K of EEPROM and leave the rest as-is or do I need to fill the remainder of the first 32K with zeros?

Comments

  • msrobotsmsrobots Posts: 3,709
    edited 2014-03-15 03:36
    It depends how you will write the eeprom.

    When loading eeprom with PropTool (and propeller bootloader) you have to write all 32k and need a correct checksum.

    once in the eeprom the checksum does not matter.

    If you have some loader already running on the prop it can write just needed bytes to the eeprom and leave the rest as is.

    Enjoy!

    Mike
  • David BetzDavid Betz Posts: 14,516
    edited 2014-03-15 05:07
    msrobots wrote: »
    It depends how you will write the eeprom.

    When loading eeprom with PropTool (and propeller bootloader) you have to write all 32k and need a correct checksum.

    once in the eeprom the checksum does not matter.

    If you have some loader already running on the prop it can write just needed bytes to the eeprom and leave the rest as is.

    Enjoy!

    Mike
    Thanks. That's what I was doing but it wasn't working. Turns out it was stupidity on my part. I was trying to write 512 bytes at a time to the EEPROM but you can't write more than 128 bytes at a time. Now it's working.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-03-15 06:16
    I think you have to zero out the VAR area and write the initial stack frame of $FFF9FFFF, $FFF9FFFF.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-03-15 06:43
    Dave Hein wrote: »
    I think you have to zero out the VAR area and write the initial stack frame of $FFF9FFFF, $FFF9FFFF.
    Thanks for reminding me. I'm planning to use this code to start the program once I load it into hub memory. As indicated by the comment, it is stolen from sdspiFemto.spin.
    CON
    
      ' program preamble
      PREAMBLE0 = $0000
      PREAMBLE1 = $0004
      PREAMBLE2 = $0008
      PREAMBLE3 = $000c
    
    '' Adapted from code in sdspiFemto.spin
    '' After reading is finished for a boot, the stack marker is added below dbase
    '' and memory is cleared between that and vbase (the end of the loaded program).
    '' Memory beyond the stack marker is not cleared.  Note that if ioNoStore is set,
    '' we go through the motions, but don't actually change memory or the clock.
    
    DAT
                            rdlong  t1,#PREAMBLE2
                            shr     t1,#16             ' Get dbase value
                            sub     t1,#4
                            wrlong  StackMark,t1       ' Place stack marker at dbase
                            sub     t1,#4
                            wrlong  StackMark,t1
                            rdlong  t2,#PREAMBLE2      ' Get vbase value
                            and     t2,WordMask
                            sub     t1,t2
                            shr     t1,#2         wz   ' Compute number of longs between
    :zeroIt         if_nz   wrlong  zero,t2            '  vbase and below stack marker
                    if_nz   add     t2,#4
                    if_nz   djnz    t1,#:zeroIt        ' Zero that space (if any)
                            rdlong  t1,#PREAMBLE0
                            cmp     t1,SaveClkFreq wz  ' Is the clock frequency the same?
                            rdlong  t1,#PREAMBLE1
                            and     t1,#$FF            ' Is the clock mode the same also?
                    if_ne   jmp     #:changeClock
                            cmp     t1,SaveClkMode wz  ' If both same, just go start COG
                    if_e    jmp     #:justStartUp
    :changeClock            and     t1,#$F8            ' Force use of RCFAST clock while
                            clkset  t1                 '  letting requested clock start
                            mov     t1,time_xtal
    :startupDelay           djnz    t1,#:startupDelay  ' Allow 20ms@20MHz for xtal/pll to settle
                            rdlong  t1,#PREAMBLE1
                            and     t1,#$FF            ' Then switch to selected clock
                            clkset  t1
    :justStartUp            cogid   t1
                            or      t1, interpreter
                            coginit t1
    
    StackMark               long    $FFF9FFFF               ' Two of these mark the base of the stack
    interpreter             long    ($0004 << 16) | ($F004 << 2) | %0000
    WordMask                long    $0000FFFF
    time_xtal               long    20 * 20000 / 4 / 1      ' 20ms (@20MHz, 1 inst/loop)
    SaveClkFreq             long    0                       ' Initial clock frequency (clkfreqVal)
    SaveClkMode             long    0                       ' Initial clock mode value (clksetVal)
    
Sign In or Register to comment.