Bootloader For 18F4520


Closed Thread
Results 1 to 37 of 37

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default

    Hi Charles. Thanks for the post. Can you elaborate on this?

    I was pretty sure that Bootloader and Secutity don't go together.

    Ioannis

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I don't know about all the others, but the 18F series lets you modify FLASH at run-time. You have to first erase a block, (8-64 bytes, depending on your chip type - and you have to start at a block boundary) with the ERASECODE command. After erasure, you can write whatever you want.
    I did this in several versions or "levels". This is the lowest level.

    The following to allow the bootloader to run (or not) depending on a program variable. If you set PROTECT and called PatchLoader, the bootloader will not run. If in the program, you set PROTECT = 0, and run it, the bootloader will again work.

    It should be noted that this was used with PBP 250a and an 18F8722 and MCLOADER.

    PBP2.50a could not access the upper half of the big chips (>64K) memory using READCODE,WRITECODE or ERASECODE, so I had to modify PBPPPIC18.LIB to include a new SYSTEM variable called UPMEM. The library modification set TBLPTRU to UPMEM at the beginning of these 3 routines, and cleared UPMEM at the end (so as not to screw up PBP). By setting UPMEM to 1, I could read the upper half of memory (and by setting it to 0x30, you can set/read the configuration registers). You will see that I need to set upmem before each operation to get to that upper half of FLASH. You wouldn't have to deal with that in a smaller chip.

    I have done quite a bit of this, let me know if you need any more help.


    Code:
    PatchLoader:
    
              UPMEM = 0
          
             ERASECODE $0
           
             WRITECODE $0,$EFE0          ; Change the initial jump vector
             WRITECODE $2,$F0FF          ; 0X1FFC0
     
             WRITECODE $4,$FFFF
             WRITECODE $6,$FFFF
           
             for xx = $8 TO $3E STEP 2    ; Do the rest of the block
             WRITECODE XX,$FFFF
             NEXT Xx
             
             PAUSE 100
             
             PROTECT = 1
             GOSUB PROTECT_UNPROTECT 
    
             RETURN
    
    
    PROTECT_UNPROTECT:
    
             UPMEM = 1     
             ERASECODE $FFC0
            
             UPMEM = 1 
             WRITECODE $FFC0,$6B08
             UPMEM = 1 
             WRITECODE $FFC2,$0000
             UPMEM = 1 
             WRITECODE $FFC4,$0000
             UPMEM = 1 
             WRITECODE $FFC6,$0000
             UPMEM = 1 
             WRITECODE $FFC8,$3F08
             UPMEM = 1 
             WRITECODE $FFCA,$D7FB
             
           if PROTECT = 0 THEN        
                 UPMEM = 1 
                 WRITECODE $FFCC,$EF82
                 UPMEM = 1 
                 WRITECODE $FFCE,$F0FE    ; JUMP TO 1FD04
           ELSE  
                 UPMEM = 1 
                 WRITECODE $FFCC,$EF78
                 UPMEM = 1 
                 WRITECODE $FFCE,$F0FE    ; JUMP TO 1fcF0
           ENDIF
            
           FOR XX = $FFD0 TO $FFFE STEP 2
                 UPMEM = 1 
                 WRITECODE XX,$FFFF
           NEXT XX
             
             RETURN
    
    REPROTECT:
             UPMEM = 1
             READCODE $FFCC,X
               IF X = $82 THEN
                HSEROUT [13,10,10,"Reprotecting Loader",13,10]
                PROTECT = 1
                GOSUB PROTECT_UNPROTECT
               ENDIF 
              RETURN  
              
    GetTypeLoader:
             READCODE 0,TypeLoader
             RETURN
    Charles Linquist

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default

    Many thanks for the post.

    I will do some testing.

    Ioannis

  4. #4
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default

    it looks like Mecanique wont support the 18f4520 as they never got back to
    me.
    Did anyone get the boot loaded from Mecanique ?
    Just really want to know


    Regards
    Isaac

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by isaac View Post
    it looks like Mecanique wont support the 18f4520 as they never got back to
    me.
    Did anyone get the boot loaded from Mecanique ?
    Just really want to know


    Regards
    Isaac
    OK, I originally posted away from my computer. My MCS has the 18F4520_20.hex file in it. I have MCS version 3.0.0.5. Which version do you have?

    I have just tried the 18F2520_20.hex file, and got it to work. (I don't have a 18F4520 to try).

    You should be able to update MCS over the internet. Not sure if that would update your .hex files, but I don't see why not.

  6. #6
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default Bootloader For 18F4520

    Thanks for the info Walter

    My MCS dont have the 18F4520_20.hex file in it. I have MCS version 3.0.0.5

    nor the 18F2520_20.hex file

    i did the update MCS over the internet but it dont update the loader .hex files, but I don't see why
    Attached Images Attached Images  

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default

    Which version of PBP you have? Its the PBP that matters.

    Ioannis

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    MCS reads from the PBP directory for chips.
    What version of PBP do you have?
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. PIC18F4680 bootloader
    By vinyl_theif in forum General
    Replies: 1
    Last Post: - 29th January 2009, 18:45
  2. 18F4550 Bootloader enter via eeprom setting
    By bradb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd November 2008, 00:51
  3. USBDemo with Bootloader
    By vacpress in forum USB
    Replies: 4
    Last Post: - 25th January 2007, 23:29
  4. Bootloader Problems
    By rossfree in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th February 2005, 18:51
  5. Replies: 3
    Last Post: - 26th January 2005, 14:41

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts