bootloader that xfers code from I2C into program memory


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: bootloader that xfers code from I2C into program memory

    You get something wrong, probably because my bad English
    Constant BLOCK_SIZE is defined in microchip MPLAB, and doesn't have anything with PBP. So PBP compiler won't be aware of BLOCK_SIZE and will throw an error.
    (And I can't remember where I found it, I think it was used in some PBP lib file)

    [EDIT]BLOCK_SIZE is defined in includes that are located at PBP3\DEVICES. But this is ASM level include as far as I know. It is just added to .lst file after compiling. So compiler isn't aware of this file.[/EDIT]

    But if you use it in ASM, compiler will just forward your ASM line to .LST file. And .LST file will be assembled into ASM and then in HEX file.
    So to be clear(or try to be), BLOCK_SIZE is in assembler include, BlockSize is any variable in PBP preferably in BANKA.
    There is two way, one I used is to move constant to variable in ASM, and other is similar to yours, but you must use EXT to tell PBP compiler that your constant is declared somewhere else, but assembler can reach it.
    That should look like this
    BLOCK_SIZE CON EXT
    BlockSize VAR BYTE
    BlockSize=BLOCK_SIZE
    But then you don't need variable BlockSize, because you can use constant BLOCK_SIZE.
    I didn't try this, I just know what I learned from Darrel's post about EXT.

    To pass variable from main app to bootloader, variable doesn't have to be in any specific bank, it must be at specific address.
    In main app:
    VarAtAdr50 VAR BYTE 50 'This is variable declared at decimal address 50
    ....
    VarAtAdr50=10
    GOTO StartBootloader

    In Bootloader:
    VarAtAdr50 VAR BYTE 50
    If VarAtAdr50=10 THEN ....
    I hope that this clears things, if not can somebody else try to explain it better? Thanks, in advance.
    Last edited by pedja089; - 11th May 2016 at 23:49.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: bootloader that xfers code from I2C into program memory

    Ok pedja089, so to summarize...


    1) Declaring a variable at the same RAM location for BOTH the "bootloader" AND the main program will result in that variable's contents being "preserved" and accessible by the "bootloader".

    MySharedVar1 var byte $40 'assigns the byte variable at RAM location $40 - this line would be included in both the bootloader (prior to compiling/copying) and the main program

    Setting the RAM location doesn't CLEAR the variable, so when it's subsequently set at the same RAM location (again) when the bootloader is started, the contents remain the same (they're preserved).


    2) An ASM level variable (such as BLOCK_SIZE, the value of which is defined in the .INC file for the device) can only be accessed via ASM, but it can be passed to a "preserved" variable like in #1.

    BlockSize var byte $40
    @ MovLW BLOCK_SIZE
    @ MovWF _BlockSize

    This loads the assigned value (from the INCLUDE file) into the designated location for the PBP variable "BlockSize".

    Anything I'm missing here?

  3. #3
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: bootloader that xfers code from I2C into program memory

    1) Yes, but write to that address in RAM can corrupt value(eg CLEAR instruction in bootloader). Be careful.
    2) Yes and No.
    Yes, it can be accessed via ASM. But that isn't ONLY way. Other is via modifier EXT. More about EXT: http://www.picbasic.co.uk/forum/showthread.php?t=3891
    BLOCK_SIZE is constant, not variable. And BlockSize is best to leave to compiler to allocate variable as all other "regular variables", but in BANKA. BlockSize VAR BYTE BANKA.
    I think, but not sure, that is best to leave to compiler to allocate variable. If you access lot to that variable then it should be in BANKA, or to simplify ASM code. And if you must, then you specify location.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: bootloader that xfers code from I2C into program memory

    Without getting into the EXT modifier,

    Yes, I agree - BLOCK_SIZE is a constant, but still treated "like" a variable when passed from one side to the other in this manner. The point here being, it will change and be assigned the value according to the INCLUDE file for the PIC.

    So if I just do:

    BlockSize VAR BYTE BANKA

    in both the bootloader and the main program, will they both allocate to the same RAM location automatically? I know they'll do the same BANK, but the same actual location? Wouldn't I need to specify the same location in BANKA for both to ensure I'm grabbing the same byte from RAM?

    I'm really not so concerned about doing it with BLOCK_SIZE because it IS a constant that I can just declare in my bootloader as 32 - but I'm thinking about other variables that might come in handy to "pass" from the lower program to higher program.
    Last edited by picster; - 12th May 2016 at 23:54. Reason: more

  5. #5
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: bootloader that xfers code from I2C into program memory

    I think that now I understand what you didn't understand about BLOCK_SIZE.
    First main app usually doesn't have to know what is block size. Only if you use FLASH2FLASH bootloader you must know what is block size.
    Bootloader should know what block size is, so you can erase pic page by page.

    Because BLOCK_SIZE is used in internally PBP library for CODE WRITE/ERASE, you MUST compile bootloader for each PIC.
    So there is no need(also there is no way to pass constant at runtime in LIB) to pass BLOCK_SIZE from main app to bootloader app.
    You can't use same HEX for different pic's, for some you can, but for others you can't. Because register map isn't same for all pic.
    So no to take any chance, just compile bootloader for different pics and don't worry about PAGE_SIZE.

    Conclusion is that you can use same code for almost all PICs, but you can't use same HEX. You must compile, extract and edit bootloader HEX for each PIC you want to use.

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: bootloader that xfers code from I2C into program memory

    Agreed - just the bootloader needs it.

    If you're passing OTHER stuff (variables), then you'd want to assign the same location in BOTH files, correct?

  7. #7
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: bootloader that xfers code from I2C into program memory

    Yes. It must be same location and same size.

Similar Threads

  1. Program Code and Program Memory
    By DenFrod in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th February 2007, 15:51
  2. Use internal program memory like DATA memory
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th December 2006, 19:38
  3. using Flash Program Memory ?
    By muskut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th October 2006, 16:17
  4. PIC16F88, Bootloader & I2C Memory
    By digilord in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th December 2005, 16:36
  5. program memory size
    By volcane in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 25th October 2005, 20:45

Members who have read this thread : 1

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