Shop OBEX P1 Docs P2 Docs Learn Events
Program a Propeller with the Spinneret — Parallax Forums

Program a Propeller with the Spinneret

Mike GMike G Posts: 2,702
edited 2011-06-27 17:28 in Accessories
I just got this working so I though I would go ahead and publish what I did. Plus my wife has a list of stuff for me to do... She's not happy at all about my weekend break through, go figure!

I created a .NET console application that uploads a Propeller binary to the Spinneret and saves the file in the uploads folder. That's where this demo starts... the file has already been uploaded.

From there it's pretty easy. Well, easy is relative, I could not have done it without solid code from Chip and Kye. It took me a couple of days to figure it out! I'm not the sharpest tool in the shed.
  • Copy the PropellerLoader methods to the top level object.
  • Start up Kye's FAT driver
  • Grab the first 10 bytes of the binary file and copy the bytes to memory. Bytes 8 and 9 contain the number of bytes we'll load into the second Propeller.
  • Reset the file pointer
  • Run the Connect method in Chip's PropellerLoader with a small change to the Communicate method

Byte count is coming from the 10 bytes we wrote to memory from the binary upload. Then, instead of reading the binary file from a RAM buffer, read the source bytes directly from the SD card. That's about it. Now we can program a Propeller attached to the Spinneret.
    'send long count
    ByteCount := byte[CodePtr][8] | byte[CodePtr][9] << 8
    BitsOut(ByteCount >> 2, 32)

    'send bytes
    repeat ByteCount
      'BitsOut(byte[CodePtr++], 8) 
      BitsOut(SDCard.readByte, 8)

Edit:
Spinneret Pin 24 - RESn on the target Prop
Spinneret Pin 25 - P31 on the target Prop
Spinneret Pin 26 - P30 on the target Prop

You could use Spinneret serial port PINs 30 and 31 to program the target Propeller.

Comments

  • jazzedjazzed Posts: 11,803
    edited 2011-06-27 15:23
    Mike G wrote: »
    I just got this working so I though I would go ahead and publish what I did. Plus my wife has a list of stuff for me to do... She's not happy at all about my weekend break through, go figure!

    I created a .NET console application that uploads a Propeller binary to the Spinneret and saves the file in the uploads folder. That's where this demo starts... the file has already been uploaded.

    Hi Mike.

    Sounds like you've had a blast with this.

    Where is your .net app?
    Thanks.
  • Mike GMike G Posts: 2,702
    edited 2011-06-27 17:28
    Jazzed C# attached. MultiSocket is my project name, hence MuiltiSocketUpload is the name of the .NET solution.

    I can't remember if I published the SPIN method counterpart; a little verbose.
    PRI Firmware(id) | rxBytes, bytesRead, packetSize, i, j
    
      packetSize := 0
      
      ifnot(strcomp(Request.GetMethod(id), String("PUT")))
        return
    
      pst.char(13)
      pst.char(13)  
      pst.str(@rxdata)
      pst.char(13)
    
      bytefill(@rxdata, 0, RxTx_BUFFER)
      
      pst.str(string(13, "Send Greeting"))
      StringSend(id, string("Hello from Spinneret!",13,10))
      'pause(10)
    
      
      pst.str(string(13, "Wait for username"))
      repeat
        packetSize := Socket.rxTCP(id, @rxdata)
        pause(200)
        if(packetSize > 0)
          quit
      pst.str(string(13, "Username received"))
      pst.char(13)
      pst.str(@rxdata)
      StringSend(id, string("OK",13,10))
      bytefill(@rxdata, 0, RxTx_BUFFER)
    
    
      pst.str(string(13, "Wait for filename"))
      repeat
        packetSize := Socket.rxTCP(id, @rxdata)
        pause(200)
        if(packetSize > 0)
          quit
      pst.str(string(13, "Filename received"))
      pst.char(13)
      pst.str(@rxdata)
      bytemove(@binFile, @rxdata, strsize(@rxdata) #> 12)
      StringSend(id, string("OK",13,10))
      bytefill(@rxdata, 0, RxTx_BUFFER)
    
    
      pst.str(string(13, "Get file size"))
      repeat
        packetSize := Socket.rxTCP(id, @rxdata)
        pause(200)
        if(packetSize > 0)
          quit
      pst.str(string(13, "File size received"))
      StringSend(id, string("OK"))
      rxBytes := str.ToInteger(@rxdata)
      bytefill(@rxdata, 0, RxTx_BUFFER)
      pst.str(string("rxBytes: "))
      pst.dec(rxBytes)
      pst.char(13)
      bytefill(@rxdata, 0, RxTx_BUFFER)
    
      pst.str(string(13, "change directory"))
      SDCard.changeDirectory(@approot) 
      SDCard.changeDirectory(@uploadfolder)
       
      pst.str(string(13, "File Exists?"))
      if(FileExists(@binFile))
        pst.str(string(13, "YES File Exists - DELETE"))
        SDCard.deleteEntry(@binFile)
    
      pst.str(string(13, "Create file"))
      SDCard.newFile(@binFile)
       
      pst.str(string(13, "Open file"))
      SDCard.openFile(@binFile, "w")
    
      
      pst.str(string(13, "File Upload in process"))
         
      repeat while rxBytes > 0
        packetSize := Socket.rxTCP(id, @rxdata)
        if(packetSize > 0)
    
          'end :=  str.MatchPattern(@rxdata, @hashboundary, 0, true)
          'if(end == -1)
            SDCard.writeData(@rxdata, packetSize)
            StringSend(id, string("OK",13,10))
    
          rxBytes := rxBytes - packetSize
          pst.str(string(13, "Bytes Left: "))
          pst.dec(rxBytes)
          
          if(rxBytes == 0)
            StringSend(id, string("DONE",13,10))
            
          pause(200)
          i := 0
        else
          i++
          pause(200) 
        if(i > 100)
          quit    
    
    
      pst.str(string(13, "loops     : "))
      pst.dec(j)
      pst.str(string(13, "rxBytes   : "))
      pst.dec(rxBytes)
      
      'pst.str(string(13, "Close file", 13))
      SDCard.closeFile
      
      SDCard.changeDirectory(@approot)
      bytemove(@binFile, string("filename.bin"), strsize(@rxdata) #> 12)
      
      return
    

    EDIT: Downloaders, make sure you point to your Spinneret URL :)
Sign In or Register to comment.