Shop OBEX P1 Docs P2 Docs Learn Events
Propeller reprogramming itself (what am I doing wrong?) — Parallax Forums

Propeller reprogramming itself (what am I doing wrong?)

Bobb FwedBobb Fwed Posts: 1,119
edited 2014-10-02 11:49 in Propeller 1
I have a program in memory, formatted like this:
DAT '' Program to Program...

prog_size               LONG    64 ' bytes -- 16 longs
var_size                LONG    28 ' bytes -- 7 longs
prog                    LONG    $00b4_c404,$6fdb_1000,$4000_6400,$1800_6800
                        LONG    $3000_0200,$0800_0000,$3703_3dd6,$1c38_113d
                        LONG    $d61c_3703,$3dd4_1c38,$113d_d418,$35c0_3701
                        LONG    $e23f_91ec,$2337_033d,$d447_0470,$3200_0000
                                                                                                        
                        LONG    0,0,0,0  ' var space
                        LONG    0,0,0,0  ' var space
                        LONG    0,0,0,0  ' include this at the end -- for overrun memory purposes
This is a very simple program that just blinks an LED. A VAR block is included just for testing purposes

I then have a function that copies that from its space in the DAT block to address 0 in the EEPROM, then reboots:
PRI self_program | i, v

  REPEAT i FROM 0 TO ((prog_size + var_size) >> 2) + 1
    bytemove(@v, MEM.read(@prog + (i << 2), 4), 4)
    MEM.write(i << 2, @v, 4)


  DEBUG.str(string("Rebooting soon...",$D))


  ' this is here so I can verify the code got copied
  REPEAT i FROM 0 TO (prog_size + var_size) >> 2 + 1
    bytemove(@v, MEM.read(i << 2, 4), 4)
    DEBUG.hex(v, 8)
    IF (i // 4 == 3)
      DEBUG.nl
    ELSE
      DEBUG.tx(" ")


  waitcnt(clkfreq << 3 + cnt)
  
  REBOOT
(I know it's not as optimized as it should be...I haven't got to that stage yet)

The read memory (in that final verification loop) looks perfect, but then it reboots and nothing happens. And yes, the "new" program works when I program it directly to the Propeller (should I post that code too).
So what am I doing wrong?

Comments

  • RaymanRayman Posts: 14,807
    edited 2014-10-02 11:09
    Could you use the Prop tool to create a "binary" image that you could use in place of your data in DAT section using the file command?
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2014-10-02 11:12
    Rayman wrote: »
    Could you use the Prop tool to create a "binary" image that you could use in place of your data in DAT section using the file command?

    Well, the reason it is like that, is because the program is actually going to be "downloaded" and stored before it's programmed, so it kind of has to be stored like this. I was just circumventing the downloading portion of the program to simplify it while I'm troubleshooting the issue.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-10-02 11:39
    You have an endian problem. The bytes in each long should be swapped. Or could define them as bytes and keep the same order. The first line of code should look like this:
    BYTE    $00, $b4, $c4, $04, $6f, $db, $10, $00, $40, $00, $64, $00, $18, $00, $68, $00
    
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2014-10-02 11:44
    Dave Hein wrote: »
    You have an endian problem. The bytes in each long should be swapped. Or could define them as bytes and keep the same order. The first line of code should look like this:
    BYTE    $00, $b4, $c4, $04, $6f, $db, $10, $00, $40, $00, $64, $00, $18, $00, $68, $00
    

    Endianness was my best theory as to why it wasn't working. I'll try this fix. Thanks.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2014-10-02 11:49
    And that worked. Thanks. I knew it was probably something simple.
Sign In or Register to comment.