Jump to content
hollie

Boostc 1.7 Bootloader Support

Recommended Posts

Hello,

 

does the BoostC 1.7 support inserting specific code at certain memory locations?

 

In C2C-plus, one could do:

 

#pragma RESERVE_ADDR_0 clrf 0x3 
#pragma RESERVE_ADDR_1 movlw 0x00 
#pragma RESERVE_ADDR_2 movwf 0xA 
#pragma RESERVE_ADDR_3 goto start__code

 

What is the equivalent code that is supported by BoostC 1.7? Do I need to add the opcodes with a #pragma DATA statement?

 

Thanks in advance,

Hollie.

Share this post


Link to post
Share on other sites

hollie,

 

Currently in BoostC the nearest equivalent is #pragma DATA.

 

Unfortunately this does mean that you will have to enter the opcodes directy :(

 

 

Regards

Dave

Share this post


Link to post
Share on other sites

Hi Dave,

 

Ok, no problem. Actually I'm just switching from quite some year of assembly PIC programming, so those few opcodes won't hurt. :(

 

Thanks for your swift reply.

 

Kind regards,

Hollie.

Share this post


Link to post
Share on other sites

Hollie,

 

Something else to consider, when you used #pragma DATA it currently doesn't reserve the memory. If it clashes with code place ment you will get a warning.

 

Program memory is allocated from the bottom up, so make sure that you put your code high in memory.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Dave,

 

aha, this could be a problem.

 

The bootloader I use requires 4 specially crafted opcodes starting at locations 0x00 - 0x03. (I believe most bootloaders do, since they need to have a way to intervene in the 'boot process' of the PIC).

 

So you mean that there is no way to put a specific opcode at 0x00?

 

I already tried with assembly code also, but the compiler doesn't understand the org 0x00 statement.

 

Are there any other options to obtain the same result?

 

Kind regards,

Hollie.

Edited by hollie

Share this post


Link to post
Share on other sites

Hollie,

 

Some bootloaders do load high ( I don't know which ones).

 

Also the plan this that you will be able to specified the first location used by code, thereby shifting everything up in memory, allowing a boot loader to be slipped in.

 

Hopefully this will be in before the next release :(

 

Regards

Dave

Share this post


Link to post
Share on other sites

Hello Dave,

 

the bootloader I use does load high (I'm using the Tiny PIC bootloader). However, in order to be able to be launched after reset, the first 4 words from the original PIC program are moved to a location in high memory and are being replaced by a jump to the bootloader code.

 

This causes a paging problem with 16F devices when the original 'goto main' is not preceded by a correct 'pagesel'. Since it is placed in high memory, the goto fails.

 

I'll settle with modifying the asm file by hand for now and I'll be looking forward to the next version of the BoostC :(

 

Another possible solution for this problem (instead of shifting the entire code as you mention) would be to allow the #pragma DATA to actually reserve a certain memory location, or to interpret the 'org' statement in inline assembly code.

 

Anyway, thanks for the information.

 

Regards,

Hollie.

Edited by hollie

Share this post


Link to post
Share on other sites
...the bootloader I use does load high (I'm using the Tiny PIC bootloader). However, in order to be able to be launched after reset, the first 4 words from the original PIC program are moved to a location in high memory and are being replaced by a jump to the bootloader code.

 

This causes a paging problem with 16F devices when the original 'goto main' is not preceded by a correct 'pagesel'. Since it is placed in high memory, the goto fails.

 

Hi Hollie,

 

What you are describing is a bootloader bug. I have a roll your own bootloader which places the users reset vector contents into high memory. When the bootloader passes control to the application program it jumps to code immediately prior to the users remapped reset vector in high memory. This code resets the page select bits to their reset defaults and then flows into the reset vector code. The users code will then run unmodified which means you do not need to add the "bootloader fixup" you have described.

 

Rgds, Andrew

Share this post


Link to post
Share on other sites

Hello Andrew,

 

indeed, this is a better solution. I'll look into the source of the bootloader I use and make the required changes.

 

Thanks for your input.

 

Kind regards,

Hollie.

Share this post


Link to post
Share on other sites

Hi Hollie,

Maybe you could do all of us a big favor and shed some light into the bootloader topic.

I was looking for a bootloader that works as universal as possible and support 16F877 and 18F8720. Found it, it's the one you also use: Tiny Pic Bootloader at http://www.ac.ugal.ro/staff/ckiku/software/picbootloader.htm

 

Would you please walk me through the following steps:

 

PIC 16F877

 

1. I need to modify the file tinybld16f.asm.

 

original file:

radix DEC

LIST P=16F876A, F=INHX8M ; change also: Configure->SelectDevice from Mplab

xtal EQU 20000000 ; you may also want to change: _HS_OSC _XT_OSC

baud EQU 115200 ; standard TinyBld baud rates: 115200 or 19200

; The above 3 lines can be changed and buid a bootloader for the desired frequency and PIC type

_______________________________

 

my modified file:

radix DEC

LIST P=16F877A, F=INHX8M ; (do I need to adjust the INHX8M?)

xtal EQU 20000000 ; 20 MHz is what I have

baud EQU 115200 ; 115200 is OK for me

 

 

Are there any other changes necessary in the tinybld16f.asm file?

As far as I understand, I need to build this file for 16F877A, although I use a 16F877. (On the Website it says, Tiny PIC bootloader was reported to work with 16F877.)

 

2. Next step would be to open MPLAB, change the target to PIC16F877A, open my modified tinybld16f.asm and project/quickbuild tinybld16f.asm. Then I enable my Picstart plus programmer, stick the 16F877 in and press the build button.

 

3. Now the big step: Using C2C compiler, apparently, we need to add the 4 lines to our main file (let's call it MAIN) in order to keep the bootloader working:

#pragma RESERVE_ADDR_0 clrf 0x3

#pragma RESERVE_ADDR_1 movlw 0x00

#pragma RESERVE_ADDR_2 movwf 0xA

#pragma RESERVE_ADDR_3 goto start__code

 

Now where exactly does this code go? First lines after the initial remark lines?

Right before / after any of these lines (taken from Interface to CompactFlash for PIC16F877 sample on the Picant site)?

 

#include <system.h>

#include "serial.h"

#include "compactflash.h"

#pragma CLOCK_FREQ 20000000

void main()

{.....

 

4. Compile, debug using C2C compiler. Result: MAIN.asm

Then build MAIN.ASM in MPLAB, result will be MAIN.hex

 

5. I re-insert the PIC, connect the serial cable via Max323 level converter chip to my PC and the PIC, then start tinybldWin.exe on my PC.

 

6. Next, I connect power to the PIC or reset it. If the settings are OK (Baudrate, COM port), tinybldWin.exe should detect the PIC, right?

 

7. Then I browse for "MAIN.hex" and press the Writeflash button

 

8. That should be it, right? After the next change of MAIN, I can loop directly to 4, I suppose?

 

So much for 16F877 and C2C compiler.

________________________________________

 

What about 18F8720 and BoostC?

 

Apparently, as you posted, one will have to make some changes in the source code of Tiny PIC Bootloader, as Andrew (Asmallri) suggests:

"What you are describing is a bootloader bug. I have a roll your own bootloader which places the users reset vector contents into high memory. When the bootloader passes control to the application program it jumps to code immediately prior to the users remapped reset vector in high memory. This code resets the page select bits to their reset defaults and then flows into the reset vector code. The users code will then run unmodified which means you do not need to add the "bootloader fixup" you have described. "

 

What exactly would I have to do to implement these changes?

 

Hollie, I would appreciate your help very much.

 

Best regards,

 

Hendrik

Share this post


Link to post
Share on other sites

If you are using an 877 then do not specify an 877A. I am surprised the 877 is supposed to work with the tiny bootloader as I thought the mechanism for writing to program memory was different between the 877 and 877A.

 

You can keep the INX8 format

 

The rest of your description sounds about right but I have not used this bootloader.

 

Here are the changes to fix the bootloader. If you do this you can skip step 3. Once you have done this no changes are required to BoostC.

 

Disclaimer: I have not tried this mod with the Tiny Bootloader because I do not use it. However this is the code I use in the same position in my bootloader.

 

I have shown the lines added

 

; Add the following line

#define fix_up max_flash-101 ; 101 word in size

#define prima_adresa max_flash-100 ; 100 word in size <--- ADD BEFORE THIS LINE

 

; the following two lines have been added

ORG fix_up

clrf PCLATH ; set correct page for reset

ORG prima_adresa ; <------- ADD BEFORE THIS LINE

nop

nop

; ......

 

; change the following from this:

goto prima_adresa

; to this

goto fix_up

Share this post


Link to post
Share on other sites

The last post was how to fix the tiny boot loader code for a 16F87x processor. Here is the code to fix the 18F processor version

 

#define fix_up max_flash-206 ;103 words

#define first_address max_flash-200 ;100 words

 

ORG fix_up

clrf BSR

clrf PCLATH ; set correct page for reset

clrf PCLATU

; here we flow into the previous reset vector

ORG first_address

 

change from this:

bra first_address

to this

bra fix_up

Share this post


Link to post
Share on other sites

Hi Andrew,

I appreciate your quick answer.

For PIC16F877 and C2C compiler, I found a working solution yesterday. (I'll still have to work on BoostC and use your suggestions.)

 

1. I need to modify the file tinybld16f.asm.

 

original file:

radix DEC

LIST P=16F876A, F=INHX8M ; change also: Configure->SelectDevice from Mplab

xtal EQU 20000000 ; you may also want to change: _HS_OSC _XT_OSC

baud EQU 115200 ; standard TinyBld baud rates: 115200 or 19200

; The above 3 lines can be changed and buid a bootloader for the desired frequency and PIC type

_______________________________

 

my modified file:

radix DEC

LIST P=16F877, F=INHX8M ; (enter 16F877, not 16F877A)

xtal EQU 20000000 ; 20 MHz is what I have

baud EQU 115200 ; 115200 is OK for me

 

 

1a.

Modify tiny PIC bootloader's file

 

in line 26 to 30

replace

___________________________________

 

IFDEF __16F873A

#include "p16f873A.inc"

IdTypePIC = 0x32

#define max_flash 0x1000

ENDIF

___________________________________

 

 

with

 

___________________________________

 

IFDEF __16F877

#include "p16f877.inc"

IdTypePIC = 0x32

#define max_flash 0x1000

ENDIF

___________________________________

 

 

2. Next step would be to open MPLAB, change the target to PIC16F877 (not: 877A!), open your modified tinybld16f.asm and project/quickbuild tinybld16f.asm. Then enable your Picstart plus programmer, stick the 16F877 in and press the build button.

 

3. Now the big step: Using C2C compiler, you need to add the 4 lines to your main file (let's call it MAIN) in order to keep the bootloader working:

#pragma RESERVE_ADDR_0 clrf 0x3

#pragma RESERVE_ADDR_1 movlw 0x00

#pragma RESERVE_ADDR_2 movwf 0xA

#pragma RESERVE_ADDR_3 goto start__code

 

This code goes right before the following lines:

#include "system.h"

#pragma CLOCK_FREQ 20000000

 

4. Compile, debug using C2C compiler. Result: MAIN.asm

Then build MAIN.ASM in MPLAB, result will be MAIN.hex

 

5. Re-insert the PIC, connect the serial cable via Max323 level converter chip to my PC and the PIC, then start tinybldWin.exe on your PC.

 

6. Browse for "MAIN.hex" and press the Writeflash button

 

7. Next, as long as TinyPICbootloader is searching for the PIC, quickly connect power to the PIC or reset it. If the settings are OK (Baudrate, COM port), tinybldWin.exe will detect the PIC. It says something like: "PIC16F873A/4A found", although it's an 877.

 

7a. After downloading, the PIC resets itself and starts with the new program.

 

8. That's it! After the next change of MAIN, you can loop directly to 4.

 

 

It WORKS and I can recommend using this bootloader to everybody. It takes away a lot of hassle from PIC programming.

(This is for Pic Tiny bootloader, tiny Pic bootloader.)

 

Regards,

Hendrik

Share this post


Link to post
Share on other sites

Hello all,

 

I can confirm that the fix as described by asmallri works fine with the BoostC compiler. The compiler generates in the first four instruction words a jump to the main code. If the main code is not in bank 0, then the compiler will generate the required bank selection code. Clearing the PCLATH in the bootlader before rolling into the four instruction words makes sure that the PC points to the correct bank for the goto.

 

So basically, when you are using the BoostC compiler, you don't need to insert asm statements any more for the bootloader to work.

 

Kind regards,

Hollie.

Share this post


Link to post
Share on other sites
Hello all,

 

I can confirm that the fix as described by asmallri works fine with the BoostC compiler. The compiler generates in the first four instruction words a jump to the main code. If the main code is not in bank 0, then the compiler will generate the required bank selection code. Clearing the PCLATH in the bootlader before rolling into the four instruction words makes sure that the PC points to the correct bank for the goto.

 

So basically, when you are using the BoostC compiler, you don't need to insert asm statements any more for the bootloader to work.

 

Kind regards,

Hollie.

 

I don't understand this, which probably isn't surprising since I just started using PIC's :-)

 

I disassemble my .hex file generated with BoostC, and I see:

 

org 0

goto Main

 

At the very beginning. Good, this is what Tinybld wants. I assume from hollie's comment above that if my Main() wasn't in bank zero, then the compiler would insert the necessary bank change instructions (to set PCLATH e.g.). So if Tinybld executed the first four instructions that the compiler generated and Main() wasn't in bank zero, then the first four instructions would include the PCLATH mod and everything works fine.

 

But, given that Tinybld is loaded high, and that it includes goto's in that high bank, I assume that PCLATH gets set to point at the high bank while Tinybld is running. So if the compiler doesn't fix this (e.g. the first instruction at ORG 0 is just Goto Main), why does Tinybld ever work?

 

To put it differently, it seems to me that Tinybld should either always work (because it doesn't mess with PCLATH, and so as long as the compiler does the right thing in the first four instructions including bank instructions if necessary it works), or it should never work if Main() is in bank zero (because Tinybld always jumps within the high bank, which points PCLATH at the high bank, and the compiler can't know that and so doesn't zero out PCLATH but rather just short jumps assuming it is in bank zero).

 

I hope this makes some sense, it is a bit late at night for me :-)

Share this post


Link to post
Share on other sites
I don't understand this, which probably isn't surprising since I just started using PIC's :-)

 

I disassemble my .hex file generated with BoostC, and I see:

 

org 0

goto Main

 

What you have listed works for a power on reset but not if you do a long jump (goto) 0x0000 (for example you may want your application to reset the CPU). In this case the page registers are no necesarily correctly set. This is also true of multiple other registers but these will not cause your application to go off into the never never.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...