lipeesh
Joined: 06 Jul 2007 Posts: 5 Location: bangalore
|
Problem facing with PIC18F258 Boot_Loader. |
Posted: Fri Jul 06, 2007 4:55 am |
|
|
Hi All,
Am a new member to this forum. Am using PCWH Compiler Version 3.241
Am trying to use Boot Loader 'ex_bootloader.c' ,provided by the PCWH Compiler with PIC18F258 Device.
This bootloader is designed to detect pin B5 low on reset. It will then use the RS232 link to download a new program.Otherwise the application program is started.
Changes made to the code:
Changed the device from 18f452 to 18F258, modified the clock to 40Mhz with baudrate 9600.
Compiled and flashed the program into the chip successfully. Loaded the application (ex_bootload.c) .Hex file through Siow (file/open file).
Problem Situation:
Am getting the acknowledgement for each of the hex lines (application has 25 hex lines) but the application is not running!!!!!!!!!!!!!!!!
Question:
What could be the problem? whether the code is not writing to the program memory or my seetings (address/configuration) had went wrong?
Please advise me,if anyone knows.
Am putting my Boot_Loader Code as well as Application Code below.
thax n regards
Lipeesh
//////////////////////////Boot_Loader_Code//////////////////////////////
/////////////////////////ex_bootloader.c//////////////////////////////////
#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#elif defined(__PCH__)
#include <18F258.h>
#FUSES NOWDT //Watch Dog Timer
#FUSES WDT16 //Watch Dog Timer uses 1:8 Postscale
#FUSES H4 //High speed osc with HW enabled 4X PLL
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV27 //Brownout reset at 2.7V
#FUSES NOPUT //No Power Up Timer
#FUSES CPD //EE protection
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES WRTB //Boot block not write protected
#FUSES CPB //No Boot Block code protection
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES EBTRB //Boot block not protected from table reads
#use delay(clock=40000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
// #fuses H4,NOWDT,NOPROTECT,NOLVP
// #use delay(clock=20000000)
// #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#endif
#define _bootloader
#include <bootloader.h>
#include <loader.c>
#if defined(__PCM__)
#org LOADER_END+1,LOADER_END+10
#elif defined(__PCH__)
#org LOADER_END+2,LOADER_END+20
#endif
void application(void)
{
while(TRUE);
}
#if defined(__PCH__)
#org 0x40,0x7F
#else
#org 0x20,0x3F
#endif
void main(void)
{
if(!input(PIN_B5))
{
putc(0x72);
load_program();
}
putc(0x54);
application();
}
#ORG default
#int_global
void isr(void) {
jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}
///////////////////loader.c//////////////////////////////////////////////////
#ifndef LOADER_END
#define LOADER_END getenv("PROGRAM_MEMORY")-1
#if defined(__PCM__)
#define LOADER_SIZE 0x17F
#elif defined(__PCH__)
#define LOADER_SIZE 0x3FF
#endif
#endif
#define LOADER_ADDR LOADER_END-LOADER_SIZE
#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+10, 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[32];
while (!done) // 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;
// 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 defined(__PCM__) // PIC16 uses word addresses
addr /= 2;
#endif
// If the line type is 1, then data is done being sent
if (line_type == 1) {
done = TRUE;
#if defined(__PCM__)
} else if ((addr <LOADER_ADDR> LOADER_END) && addr < 0x2000){
#elif defined(__PCH__)
} else if ((addr <LOADER_ADDR> LOADER_END) && addr < 0x300000){
#endif
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> getenv("FLASH_WRITE_SIZE")
#if defined(__PCM__)
if ((addr!=next_addr)&&(addr&(getenv("FLASH_ERASE_SIZE")-1)!=0))
#else
if ((addr!=next_addr)&&(addr&(getenv("FLASH_ERASE_SIZE")/2-1)!=0))
#endif
ERASE_PROGRAM_EEPROM(addr);
next_addr = addr + 1;
#endif
WRITE_PROGRAM_MEMORY(addr, data, count);
//delay_ms(1000);
}
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>= 'A')
result = 16*result + (*s) - 'A' + 10;
else
result = 16*result + (*s) - '0';
}
return(result);
}
#ORG default
#ORG LOADER_ADDR, LOADER_ADDR+9
void load_program(void)
{
real_load_program();
}
///////////////////////bootloader.h////////////////////////////////////////
#if defined(__PCM__)
#define LOADER_END 0x1FF
#define LOADER_SIZE 0x1BF
#elif defined(__PCH__)
#define LOADER_END 0x4FF
#define LOADER_SIZE 0x3FF
#endif
#ifndef _bootloader
#if defined(__PCM__)
#build(reset=LOADER_END+1, interrupt=LOADER_END+5)
#elif defined(__PCH__)
#build(reset=LOADER_END+2, interrupt=LOADER_END+8)
#endif
#org 0, LOADER_END {}
#endif
///////////////////////////Application_Code///////////////////////////////
//////////////////////////ex_bootload.c///////////////////////////////////
#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#elif defined(__PCH__)
#include <18F258.h>
#FUSES NOWDT //Watch Dog Timer
#FUSES WDT16 //Watch Dog Timer uses 1:8 Postscale
#FUSES H4 //High speed osc with HW enabled 4X PLL
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV27 //Brownout reset at 2.7V
#FUSES NOPUT //No Power Up Timer
#FUSES CPD //EE protection
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES WRTB //Boot block not write protected
#FUSES CPB //No Boot Block code protection
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES EBTRB //Boot block not protected from table reads
#use delay(clock=40000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
//#fuses HS,NOWDT,NOPROTECT,NOLVP
//#use delay(clock=40000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#endif
#include <bootloader.h>
void main(void) {
int i=0;
printf("\r\nApplication program version 1.00 \r\n");
while(TRUE)
printf("%u ",++i);
} _________________ lipeesh |
|