Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 18, 2024, 06:47:21 18:47


Login with username, password and session length


Pages: [1]
Print
Author Topic: Code Offset using C18 and Mplab 8  (Read 7513 times)
0 Members and 1 Guest are viewing this topic.
odessa
Newbie
*
Offline Offline

Posts: 21

Thank You
-Given: 101
-Receive: 16


« on: February 05, 2013, 10:34:15 22:34 »

Hi,

    I'm using a Pic 18f14k50 which can use a bootloader, using Mplab X / XC8 you can specify a code offset (0x1000) so as to not overwrite the bootloader. I looked for the same option in C18 but couldn't find it. I could re-write the code to work in XC8 but wondered if anyone knew if it was possible to do in C18 / Mplab 8 ?

Any help appreciated

 Smiley
Logged
xpress_embedo
Active Member
***
Offline Offline

Posts: 173

Thank You
-Given: 122
-Receive: 254


« Reply #1 on: February 06, 2013, 02:22:32 02:22 »

In c18 compiler we normally use this when dealing with interrupt.

#pragma code vector=0x008

Did you remember that.
Try to use it to shift your code, so that boot loader doesnt gest affected.

I did not remember the syntax but thinks it must work
Logged
xpress_embedo
Active Member
***
Offline Offline

Posts: 173

Thank You
-Given: 122
-Receive: 254


« Reply #2 on: February 06, 2013, 05:15:55 05:15 »



Suppose you want to place your main at some location

do likr this
#pragma code main=0x50

Suppose you want to place a function uart_write to a place
then do before its definition like this

#pragma code uart_write=0x300

Hope this will help
Logged
Xwing
Active Member
***
Offline Offline

Posts: 208

Thank You
-Given: 576
-Receive: 1529



« Reply #3 on: February 06, 2013, 06:59:33 06:59 »

Code relocate with C18


Code:
#define BOOT

#ifdef BOOT
#warning "With bootloader"
 extern void _startup (void);        //  startup at 0x1000
 #pragma code _RESET_INTERRUPT_VECTOR = 0x001000
 void _reset (void)
  {
    _asm goto _startup _endasm
  }
 #pragma code _HIGH_INTERRUPT_VECTOR = 0x001008
 void interrupt_at_high_vector(void)
  {
_asm GOTO ISRgest _endasm
  }
#else
 #warning "Without bootloader"
 #pragma code high_vector=0x08
 void interrupt_at_high_vector(void)
  {
_asm GOTO ISRgest _endasm
  }
#endif
Logged
cranor
Newbie
*
Offline Offline

Posts: 18

Thank You
-Given: 10
-Receive: 10


« Reply #4 on: February 06, 2013, 09:56:45 09:56 »

Solutions given above are only for interrupt redirection.
"#pragma code main=0x50" will only tell the compiler to put main entry point @ 0x50, but it doesn't tell the linker to not put code before 0x50 (To prevent any error, you can however force a fill with NOPs).

The best way with C18 is to use linker files with start addresses of code section depending on bootloader size and add this file to your project.

In reality, you must have two linker files :
 - one for the bootloader which reserves the code area up to 0xFFF for example
 - one for the application which restricts the application's code area to 0x1000 and up

Then, you can redirect the interrupt vectors to 0x1000 + original vector addresses.

Replace 0xFFF and 0x1000 to adapt these values to your bootloader size. If I am not wrong, these are default values in demonstration applications given by Microchip.
Logged
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #5 on: February 06, 2013, 03:36:08 15:36 »

Linker scripts is the best way to do it.

Also be careful.  I don't work with the 18 series that much but with the 24,33, and PIC32 series you have to be careful of the interrupt vectors as they can't be moved and can be overwritten when you put a new bootloader in... OR can't be updated when you change your application.  One way around this is to use a jump table that resides in a known/fixed location in the application space (which is pointed at by the vectors) this allows you move your interrupt handlers in the application space at the cost of a few cycles of latency (for jump table lookup) when you have an interrupt event.
Logged
odessa
Newbie
*
Offline Offline

Posts: 21

Thank You
-Given: 101
-Receive: 16


« Reply #6 on: February 06, 2013, 08:08:38 20:08 »

That's great guys, thanks for your help. I've modded the linker script and included it in my project and it seems to work fine. Im not using any interrupts so I should be safe.

Much Appreciated Smiley
Logged
cranor
Newbie
*
Offline Offline

Posts: 18

Thank You
-Given: 10
-Receive: 10


« Reply #7 on: February 07, 2013, 01:46:16 13:46 »

Happy that it helped you.

PS : Have you tried XC compilers ? It produces code with better optimization..
Logged
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #8 on: February 07, 2013, 06:01:07 18:01 »

I don't know about you but the xc8 compiler with the pic18 is a piece of junk.  It has a lot of problems related to bad documentation, and incomplete merging of the Hi-Tech C and C18 compilers.  I've lost a lot of time sorting through those issues it's not nearly as clean as the xc16 or xc32
Logged
odessa
Newbie
*
Offline Offline

Posts: 21

Thank You
-Given: 101
-Receive: 16


« Reply #9 on: February 07, 2013, 07:06:14 19:06 »

Happy that it helped you.

PS : Have you tried XC compilers ? It produces code with better optimization..

Yes, I have and I actually quite like it.

I would have used it as setting the code offset is really easy in XC8, it's just I didn't want to have to re-write the whole project.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC