Reply
Posts: 10
Registered: ‎06-26-2017
Accepted Solution

Writing bootloader in bank 0 and 3 (C8051f120)

Hello,

I'm curently writing a bootloader. For particular reasons, I have to put my bootloader at the very beginning of the flash memory and at the very end (right before the security bytes) (following the AN533 document). But unforutnately my code doesn't want to fit like I would like it to do.

I manage to put it at the beginning of the bank 0 and at the end of the bank 1.

I manage to put the beginning in bank 0 most of the end at the end of bank 3, but some instructions are copied in the bank 1. I tried to tweak my linker but couldn't get it working.

Does anyone has ever done this before?

 

Thanks in advance.

Posts: 8,132
Registered: ‎08-13-2003

Re: Writing bootloader in bank 0 and 3 (C8051f120)

I manage to put the beginning in bank 0 most of the end at the end of bank 3, but some instructions are copied in the bank 1. I tried to tweak my linker but couldn't get it working.

 

I have not used bank switching for a long time (after the ARM prices came down I consider '51 jobs requiring bank switching automatic transfers to ARM) but i tend to recall that there are some very unique things that will not bank switch and thus you get the "copy to bank1"

erik
Posts: 3,092
Registered: ‎02-07-2002

Re: Writing bootloader in bank 0 and 3 (C8051f120)

I would not attack such a problem with telling the compiler to do bank switching. Instead I would compile as if I was using (the beginning of) bank 0 and (the end of) bank 1. This way the compiler does not need to know about any bank switching. Then load the bank 1 code into bank 3 and make sure you switch to bank 3 as early as possible.

 

For the application you use the rest of bank 0 and the real bank 1, also without bank switching. You use the banks to easily switch between the bootloader and the actual application and still have a large code space.

Posts: 10
Registered: ‎06-26-2017

Re: Writing bootloader in bank 0 and 3 (C8051f120)

I tried your solution @vanmierlo: compile for bank 1 as usual and then flash it to bank 3.

But unfortunately it still doesn't work when I put it in bank3 but it does when in bank1.

After a small investigation I found out that my instruction "PSBANK=0x33" in my main was contained in bank1 (or considered). This instruction is the first to be executed, right after variable declaration, so I cannot go around this and the value will be set back to 0x31.

My idea was then to put it in the STARTUP.A51 file but the sfr registers are not defined in this file so I cannot use this instruction "mov PSBANK, #33h".

 

Do you have any idea where or how to force my bank switching at the earliest of my program.

 

Sebastien

Posts: 10
Registered: ‎06-26-2017

Re: Writing bootloader in bank 0 and 3 (C8051f120)

Ok,

 

I found a way to do it. I added a few instructions right before the first long jump instruction.

I attached the file for more informations.

Here is whart I added:

        LJMP    BANKSELECTION
        CSEG    AT    150H
        BANKSELECTION:    MOV    0B1H,    #33h

 

If you have an other "proper way" to do it post it anyway I will try it.

 

Thanks,

Sebastien

Posts: 1
Registered: ‎06-27-2017

C8051f120 Examples

I am new for C805F120. Please send some examples for C8051F120 to me.

 

I am using P0 to P6 to control , write and read the Digital singal.

 

Thanks

Posts: 2,308
Registered: ‎10-14-2014

Re: C8051f120 Examples

@tombearlin

You could get some example if you install the Silicon Lab IDE here.

WeiguoLu
Posts: 3,092
Registered: ‎02-07-2002

Re: Writing bootloader in bank 0 and 3 (C8051f120)


Sebastieng wrote:

        LJMP    BANKSELECTION
        CSEG    AT    150H
        BANKSELECTION:    MOV    0B1H,    #33h

 


Why do you insert an extra jump? Why not place that MOV at the top of STARTUP1? Is the STARTUP1 segment already placed in bank 1?

Instead of 0B1H you could create an EQU for it first and use that so it describes what you're doing here.

Posts: 10
Registered: ‎06-26-2017

Re: Writing bootloader in bank 0 and 3 (C8051f120)


vanmierlo wrote:

 

Why do you insert an extra jump? Why not place that MOV at the top of STARTUP1? Is the STARTUP1 segment already placed in bank 1?

Instead of 0B1H you could create an EQU for it first and use that so it describes what you're doing here.


 

STARTUP1 is already in bank1. This is why I make sure the switch bank operation is in bank0.

Good point I added the definition for PSBANK.

 

Thanks.

Sebastien

Posts: 3,092
Registered: ‎02-07-2002

Re: Writing bootloader in bank 0 and 3 (C8051f120)

Come to think of it, you could also exchange bank 1 and 3 to eleviate the problem. The bootloader then uses bank 1 and needs nothing special. You can switch to bank 3 (from code in bank 0) just before you jump to the application. Instead of bank 3 you can also use bank 2 if you need the last flash pages as well.