CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with #ORG

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Andrea
Guest







Problem with #ORG
PostPosted: Mon May 05, 2008 2:20 am     Reply with quote

Hi everyone,

I've got a problem with an #ORG instruction.
I'm trying to insert the CCS bootloader in my code program but...
Every time I reserve space in ROM using the #ORG directive, the space it's correctly reserved but, in the address 0x00000, where everything starts, there's not a jump to the main program but the compiler puts there the code of an interrupt.
This doesn't allow the machine to start properly.

I'm using the latest version of 4.069 and the microcontroller is the PIC18F6722.

Any idea?
Thanks
Ttelmah
Guest







PostPosted: Mon May 05, 2008 2:38 am     Reply with quote

Look at the bootloader examples. Look at the use of the #build instruction.

Best Wishes
Guest








PostPosted: Mon May 05, 2008 2:54 am     Reply with quote

Ttelmah wrote:
Look at the bootloader examples. Look at the use of the #build instruction.

Best Wishes


I've made in the same way but during compilation something goes wrong with the 0x00000 address.
Matro
Guest







PostPosted: Mon May 05, 2008 3:58 am     Reply with quote

Post a small compilable code that demonstrates the problem with all preprocessor directives and fuses.

Matro
Guest








PostPosted: Mon May 05, 2008 4:16 am     Reply with quote

Matro wrote:
Post a small compilable code that demonstrates the problem with all preprocessor directives and fuses.

Matro



Here is the main.h and following the bootloader directives


***********MAIN.H

#include <18F6722.h>

#device *=16
#device ICD=TRUE
#device adc=8

#OPT 9

#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
enabled
#FUSES NOIESO //Internal External Switch Over mode disabled

#FUSES CCP2C1

#FUSES WDT //Watch Dog Timer
#FUSES WDT32768 //Watch Dog Timer uses 1:32768 Postscale
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV27 //Brownout reset at 2.7V
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES DEBUG //Debug mode for use with ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration registers write not protected
#FUSES NOWRTB //Boot block not write protected
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOLPT1OSC //Timer1 configured for higher power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES BBSIZ1K //1K words Boot Block size

#use delay(clock = 20000000, RESTART_WDT)
#use rs232(baud=57600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,restart_wdt)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3,restart_wdt,force_hw)



*********BOOTLOADER.H

#define FIRMWARE_UPGRADE_VECTOR 0 // Bootloader at Start of memory
#define MAX_UPGRADE_AREA (0x500) // Space required by bootloader
#define MIN_FIRMWARE_UPGRADE_MEMORY_AREA (0x20) // Start of bootloder code
#define MAX_FIRMWARE_UPGRADE_MEMORY_AREA (MAX_UPGRADE_AREA-1) // End of bootloder code
#define APPLICATION_RESET_VECTOR 0x500 // New RESET Vector
#define APPLICATION_ISR_VECTOR 0x508 // New Interrupt Vector

#define LOADER_END MAX_UPGRADE_AREA -1
#define LOADER_ADDR MIN_FIRMWARE_UPGRADE_MEMORY_AREA

#build(reset=APPLICATION_RESET_VECTOR, interrupt=APPLICATION_ISR_VECTOR)

#define BUFFER_LEN_LOD 64

int buffidx;
char buffer[BUFFER_LEN_LOD];

#define ACKLOD 0x06
#define XON 0x11
#define XOFF 0x13

#SEPARATE
unsigned int atoi_b16(char *s);

#ORG LOADER_ADDR, LOADER_END auto=0 default


void real_load_program (void)
{
int1 do_ACKLOD, done=FALSE;
int8 checksum, line_type;
int16 l_addr,h_addr=0;
int32 addr;
// #if getenv("FLASH_ERASE_SIZE")>2
// int32 next_addr;
// #endif
int8 dataidx, i, count;
int8 data_boot[32];

while (!done || (counter_timer_boot <= TIMEOUT_BOOT)) // Loop until the entire program is downloaded
{
buffidx = 0; // Read into the buffer until 0x0D ('\r') is received or the buffer is full
do {
buffer[buffidx] = getc();
}
while ( (buffer[buffidx++] != 0x0D) && (buffidx <= BUFFER_LEN_LOD) );

putchar (XOFF); // Suspend sender

do_ACKLOD = TRUE;

counter_timer_boot = 0;

// Only process data blocks that start with ':'
if (buffer[0] == ':')
{
count = atoi_b16 (&buffer[1]); // Get the number of bytes from the buffer
// Get the lower 16 bits of address
l_addr = make16(atoi_b16(&buffer[3]),atoi_b16(&buffer[5]));
line_type = atoi_b16 (&buffer[7]);
addr = make32(h_addr,l_addr);
// If the line type is 1, then data is done being sent
if (line_type == 1)
{
done = TRUE;
}
/*
else if ((addr < LOADER_ADDR || addr > LOADER_END) && addr < 0x2000)
{
#elif defined(__PCH__)
}
*/
else if ((addr < LOADER_ADDR || addr > LOADER_END) && addr < 0x300000)
{
checksum = 0; // Sum the bytes to find the check sum value
for (i=1; i<(buffidx-3); i+=2)
checksum += atoi_b16 (&buffer[i]);
checksum = 0xFF - checksum + 1;

if (checksum != atoi_b16 (&buffer[buffidx-3]))
do_ACKLOD = FALSE;
else
{
if (line_type == 0) {
// Loops through all of the data and stores it in data
// The last 2 bytes are the check sum, hence buffidx-3
for (i = 9,dataidx=0; i < buffidx-3; i += 2)
data_boot[dataidx++]=atoi_b16(&buffer[i]);

// #if getenv("FLASH_ERASE_SIZE") > getenv("FLASH_WRITE_SIZE")
// if ((addr!=next_addr)&&(addr&(getenv("FLASH_ERASE_SIZE")/2-1)!=0))
// erase_program_eeprom(addr);
// next_addr = addr + 1;
// #endif
write_program_memory(addr, data_boot, count);
}
else if (line_type == 4)
h_addr = make16(atoi_b16(&buffer[9]), atoi_b16(&buffer[11]));
}
}
}

if (do_ACKLOD)
putchar (ACKLOD);

putchar(XON);
}

putchar (ACKLOD);
putchar(XON);
// #ifndef _bootloader
reset_cpu();
// #endif
}

unsigned int atoi_b16(char *s) { // Convert two hex characters to a int8
unsigned int result = 0;
int i;

for (i=0; i<2; i++,s++) {
if (*s >= 'A')
result = 16*result + (*s) - 'A' + 10;
else
result = 16*result + (*s) - '0';
}

return(result);
}

#ORG default




**********************
In the main code,



void main()
{

startup_system();


if(!input(PIN_E6))
{
real_load_program ();
}// if(!input(PIN_E6))



while (true)
{
restart_wdt();
etc...


***************************

This is the code, and the problem still remain on the 0x00000 address thet it's not a jump to the main but it's some part of a code involved in interrupt handling!

Thanks for the help
Matro
Guest







PostPosted: Mon May 05, 2008 4:25 am     Reply with quote

The code you just posted is neither small nor compilable.

It generates a huge amount of errors when I copy-paste it.
Post a small code that doesn't generate any compilation error except the one that corresponds to the problem you are encountering.

Matro
Ttelmah
Guest







PostPosted: Mon May 05, 2008 4:35 am     Reply with quote

The 'glaring' thing, is that it is the _main_ that needs the #build relocation, not the bootloader.....
Look again at the examples. ex_bootload.c, shows how the main code has to be relocated. It loads bootloader.h, which without the keyword '_bootloader' defined, relocates the code.

Best Wishes
Guest








PostPosted: Mon May 05, 2008 5:59 am     Reply with quote

Ttelmah wrote:
The 'glaring' thing, is that it is the _main_ that needs the #build relocation, not the bootloader.....
Look again at the examples. ex_bootload.c, shows how the main code has to be relocated. It loads bootloader.h, which without the keyword '_bootloader' defined, relocates the code.

Best Wishes


Ok thanks.
I wiil try in that way and let you know.
I will study morre in deep the code example and then try to recompile.

I will let you know.

If doesn't work, I will then poste a code that make me go crazy.

Smile
Andrea
Guest







PostPosted: Tue May 06, 2008 3:54 pm     Reply with quote

Anonymous wrote:
Ttelmah wrote:
The 'glaring' thing, is that it is the _main_ that needs the #build relocation, not the bootloader.....
Look again at the examples. ex_bootload.c, shows how the main code has to be relocated. It loads bootloader.h, which without the keyword '_bootloader' defined, relocates the code.

Best Wishes


Ok thanks.
I will try in that way and let you know.
I will study more in deep the code example and then try to recompile.

I will let you know.

If doesn't work, I will then post a code that make me go crazy.

Smile



Thanks everybody.
Was my mistake in organize the bootloader and all the directives to reserve space.
Now it's clear what to do.
Just reserve space in my main program (using the bootload.c example to clarify) but previously I have to lad the bootloader alone.
Thanks again
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group