Assigning linkerfile to project

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
arco
Posts: 312
Joined: 15 Apr 2008 13:54
Location: The Netherlands

Assigning linkerfile to project

#1 Post by arco » 10 Jun 2013 22:20

How do I assign a linkerfile (.mlk) to a project? I need different setups for different situations. (for instance with bootloader)
With the Microchip compilers you can choose the linkerfile(s) you need manually.
Now I have to edit the file everytime, annoying and prone to errors...

Also it's difficult to assign fixed location constants to program memory for use with bootloader.
If I use this code, the compiler strips out the value because it's never used: (It IS used, but in the bootloaded firmware)

Code: Select all

Const MyVar As Word[1] = (0x1234) Org 0x800
Also modifying the linker file doesn't work. The linker seems to ignore or doesn't understand multiple <ROM>...</ROM> entries in the linkerfile.

Code: Select all

        <ROM>
                <MIN_ADDR>0x000</MIN_ADDR>
                <MAX_ADDR>0x7FF</MAX_ADDR>
        </ROM>

        <ROM>
                <MIN_ADDR>0x802</MIN_ADDR>
                <MAX_ADDR>0x2abf7</MAX_ADDR>
        </ROM>
How can I keep the compiler from using certain program memory locations?
Regards,

Peter.

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Assigning linkerfile to project

#2 Post by dejan.odabasic » 11 Jun 2013 15:57

Hello,

Locate the files(.mlk .mbas) that are related to your chip(in ..compiler\Defs\ folder), duplicate the files - add '_bootloader' to the files name.
Now when you open the compiler you should be able to see your chip in MCU Device Name drop down list.
Then you can change the (.mlk) file according to your needs.

I'm not sure I understood what you tried to do with const MyVar, but you can make optimizer include that constant by adding dummy line:

Code: Select all

if(MyVar == 0){}
Depending on your bootloader implementation(if bootloader skips it's own addresses), declaring dummy array could solve your problem.
You can use absolute directive to position the array at desired address.

Best regards.

arco
Posts: 312
Joined: 15 Apr 2008 13:54
Location: The Netherlands

Re: Assigning linkerfile to project

#3 Post by arco » 13 Jun 2013 03:06

Thank you for your explanation. I made a new linkerfile now...
I have one other question. I'm rewriting the Microchip C code bootloader to Mikrobasic, and have a problem.

The bootloader resides in flash area 0x400 to 0xBFF. The bootloaded firmware is loaded from 0xC04 and upwards.
During the bootloading of the firmware I receive the resetvector (address of main() ) of the user firmware.
This pointer is stored by the bootloader. At startup, when the bootloader times out, I need to jump to the userfirmware main() routine.
I don't see if it's possible to do this with GOTO because that doesn't seem to accept an address, only labels...
Or is there another way to accomplish this?
Regards,

Peter.

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Assigning linkerfile to project

#4 Post by dejan.odabasic » 13 Jun 2013 07:59

Hello,

Please take a look at Bootloader project which is available in mikroBasic Examples folder.
..compiler\Examples\Other\USB HID Bootloader\Projects\PIC24FJ\

In Config.mbas>ConfigMem() function you can see how blootloader and program addresses are configured, so when the StartProgram() function is called program starts execution.

Code: Select all

SetOrg(StartProgram, 0xC04 )
...
sub procedure StartProgram()
  ' nops to accomodate MCU reset vector size.
  asm nop end asm
end sub
Best regards.

arco
Posts: 312
Joined: 15 Apr 2008 13:54
Location: The Netherlands

Re: Assigning linkerfile to project

#5 Post by arco » 13 Jun 2013 10:08

Thank you,

I didn't know/find SetOrg, that works. But I only seem to be able to make a call, not a goto (like in the C30 compiler is possible)
I know it will work this way, but it's not very nice making a call which you never return from...
(The user firmware is now handled as one big subroutine this way, I would rather make a 'clean' jump)

Would this be a proper solution? This should push the new vector on the stack and jump cleanly to it:

Code: Select all

Dim UserAddr As Longword
...
UserAddr = 0x00000C04
...
...
sub procedure StartProgram()
  W6 = LoWord(UserAddr)
  W7 = HiWord(UserAddr)
  asm
    pop.d W4
    push.d W6
  end asm
end sub
Regards,

Peter.

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”