|
|
View previous topic :: View next topic |
Author |
Message |
art
Joined: 21 May 2015 Posts: 181
|
EX_USB_BOOTLOADER.C |
Posted: Sun Dec 25, 2016 9:30 am |
|
|
Hi,
I've just compiled the EX_USB_BOOTLOADER.C, but it shows message Error 71 "usb bootloader.c" Line 339(1,2): Out of ROM, A segment or the program is too large load_program. Hope someone can explain to me. What should I do ?
Code: |
#include <ex_usb_common.h>
/*
Configure, then load the bootloader definitions
*/
#define _bootloader
#include "usb_bootloader.h"
// Includes all USB code and interrupts, as well as the CDC API
#include <usb_cdc.h>
#define ROM_BLOCK_INVALID -1
int32 rom_block_start = ROM_BLOCK_INVALID;
#if defined(__PCD__)
#define EEPROM_ERASE_SIZE getenv("FLASH_ERASE_SIZE")/2
#else
#define EEPROM_ERASE_SIZE getenv("FLASH_ERASE_SIZE")
#endif
int8 rom_block[EEPROM_ERASE_SIZE];
// see rom_w() documentation. performs the flushing
void rom_w_flush(void)
{
if (rom_block_start != ROM_BLOCK_INVALID)
{
#if !defined(__PCD__)
erase_program_eeprom(rom_block_start); //erase entire block
#else
erase_program_memory(rom_block_start);
#endif
write_program_memory(rom_block_start, rom_block, sizeof(rom_block)); //write modified block
rom_block_start = ROM_BLOCK_INVALID;
}
}
// see rom_w() documentation. performs the writing
void rom_w_block(int32 location, char *src, int16 size)
{
int32 block_start;
int16 i,num;
block_start = location & (~((int32)EEPROM_ERASE_SIZE-1));
i = location - block_start;
while (size)
{
if (block_start != rom_block_start)
{
rom_w_flush();
rom_block_start = block_start;
read_program_memory(block_start, rom_block, sizeof(rom_block)); //read entire block to ram buffer
}
if (size>(EEPROM_ERASE_SIZE-i)) {num=EEPROM_ERASE_SIZE-i;} else {num=size;}
memcpy(&rom_block[i], src, num); //modify ram buffer
src += num;
block_start += EEPROM_ERASE_SIZE;
i = 0;
size -= num;
}
}
// Write to Flash ROM.
//
// location - flash program memory address
// src - pointer to data to write
// size - number of bytes to write to flash
//
// Here is the sequence of events:
// 1.) Goes to the beginning of the first erase block for this address
// 2.) Reads n records to ram, where n is the PIC's flash erase size
// 3.) Erases block in flash
// 4.) Modifies block in RAM
// 5.) Writes changed block back to FLASH. Writes in chunks defined by PIC's flash write size
// 6.) Goes back to step1 if there is still more data to be written
void rom_w(int32 location, char *src, int16 size)
{
rom_w_block(location, src, size);
rom_w_flush();
}
#define BUFFER_LEN_LOD 64
#define ACKLOD 0x06
#define XON 0x11
#define XOFF 0x13
// Convert two hex characters to a int8
unsigned int8 atoi_b16(char *s)
{
char c;
unsigned int8 result = 0;
int i;
for (i=0; i<2; i++,s++)
{
c = *s;
if (c >= 'A')
result = 16*result + c - 'A' + 10;
else
result = 16*result + c - '0';
}
return(result);
}
void load_program(void)
{
int1 do_ACKLOD, done=FALSE;
int8 checksum, line_type;
int16 l_addr,h_addr=0;
int8 to;
int32 addr;
int8 dataidx, i, count;
int8 data[32];
int buffidx;
char buffer[BUFFER_LEN_LOD];
#if defined(__PCD__)
unsigned int32 address_erase;
for(address_erase=APPLICATION_START;address_erase<APPLICATION_END-EEPROM_ERASE_SIZE+1;address_erase+=EEPROM_ERASE_SIZE)
erase_program_memory(address_erase);
#endif
while (!done) // Loop until the entire program is downloaded
{
usb_task();
if (!usb_cdc_kbhit())
continue;
buffidx = 0; // Read into the buffer until 0x0D ('\r') is received or the buffer is full
to = 250; //250 milliseconds
do
{
if (!usb_cdc_kbhit())
{
delay_ms(1);
usb_task();
to--;
if (!to)
break;
}
else
to = 250;
i = usb_cdc_getc();
buffer[buffidx++] = i;
} while ( (i != 0x0D) && (i != 0x0A) && (buffidx <= BUFFER_LEN_LOD) );
if (!to)
continue;
usb_cdc_putc(XOFF); // Suspend sender
do_ACKLOD = TRUE;
// Only process data blocks that start with ':'
if (buffer[0] == ':')
{
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
{
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]);
#if defined(__PCD__)
addr = (make32(h_addr,l_addr)/2);
#else
addr = make32(h_addr,l_addr);
#endif
// If the line type is 1, then data is done being sent
if (line_type == 1)
done = TRUE;
else if (line_type == 4)
h_addr = make16(atoi_b16(&buffer[9]), atoi_b16(&buffer[11]));
else if ((line_type == 0) && (addr >= (int32)APPLICATION_START) && (addr < ((int32)APPLICATION_END)))
{
// 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[dataidx++]=atoi_b16(&buffer[i]);
#if !defined(__PCD__)
rom_w_block(addr, data, count);
#else
write_program_memory(addr, data, count);
addr += count;
read_program_memory(addr, data, count);
#endif
}
}
}
if(do_ACKLOD)
usb_cdc_putc(ACKLOD);
usb_cdc_putc(XON);
}
#if !defined(__PCD__)
rom_w_flush();
#endif
while(!usb_cdc_put_buffer_free())
uart_task();
usb_cdc_putc(ACKLOD);
usb_cdc_putc(XON);
delay_ms(2000); //give time for packet to flush
reset_cpu();
}
void main(void)
{
HW_INIT();
//we use a button as an event to determine if we should start the USB CDC
//bootloader. if button is not pressed then goto the application, else if
//button is pressed then do the bootloader.
if(BUTTON_PRESSED())
{
usb_init_cs();
while(!usb_enumerated())
{
// necessary for polling function to work
#ifdef USB_ISR_POLLING
usb_task();
#endif
}
LED_ON(LED3);
load_program();
}
#asm
goto APPLICATION_START
#endasm
}
#int_default
void isr(void)
{
jump_to_isr(APPLICATION_ISR);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 25, 2016 10:36 am |
|
|
What is your PIC ? |
|
|
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Sun Dec 25, 2016 11:02 am |
|
|
Pic18f4550 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 25, 2016 11:23 am |
|
|
1. What's your compiler version ?
2. Did you un-comment the line for 18F4550 in ex_usb_common.h
as shown below in bold ? (and make sure all other PICs are commented out).
Quote: |
////// Begin User Configuration
#define USB_HW_CCS_PIC18F4550 //CCS PIC18F4550 USB Development kit
//#define USB_HW_CCS_PIC18F45K50 //CCS PIC18F45K50 USB Development kit
//#define USB_HW_CCS_E3 //CCS E3 Mini development kit. 18F14K50 with 12Mhz crystal.
//#define USB_HW_CCS_16F1459 //CCS Rapid USB devleopment kit. 16F1459 with no oscillator
//#define USB_HW_CCS_PIC24F //CCS 24FJ256GB206 USB Development kit
//#define USB_HW_CCS_PIC33EP //CCS PIC24 USB Development kit, PIC replaced with a 33EP256MU806
//#define USB_HW_CCS_USBN9604 //CCS National USBN9604 USB development kit (external USB peripheral)
//#define USB_HW_MCHP_18F14K50 //Microchip low-pin count USB development kit (PIC18F14K50) |
|
|
|
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Sun Dec 25, 2016 4:38 pm |
|
|
1) compiler Version 5.008
2)Yes, I did un-comment the line for 18F4550 in ex_usb_common.h |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 25, 2016 6:24 pm |
|
|
I installed vs. 5.008 and was able to get it compile by editing the
usb_bootloader.h file in the Drivers sub-directory. I changed
the loader size as shown in bold below.
Quote: |
#define LOADER_START (0)
#define LOADER_SIZE (0x1900) // Was 0x1800 |
I don't guarantee this works. I didn't test the code. I just got it to compile. |
|
|
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Sun Dec 25, 2016 6:37 pm |
|
|
I've change it to 0x1900 but it still give the same error.
Error 71 "usb bootloader.c" Line 339(1,2): Out of ROM, A segment or the program is too large load_program
Seg 0008E-017FE,01F0 left, need 00276
Seg 01800-0180E,000C left, need 00276
Seg 01810-07FFE,67F0 left, need 00276
Seg 00000-00006,0004 left, need 00276
Seg 00008-0008C,0000 left, need 00276
Code: |
#define LOADER_START (0)
#define LOADER_SIZE (0x1900)//original 0x1800
#if defined(__USB_87J50__)
#define APPLICATION_END (getenv("PROGRAM_MEMORY")-9) //configuration bits
#elif defined(__PCD__)
#define APPLICATION_END (getenv("PROGRAM_MEMORY")-2)
#else
#define APPLICATION_END (getenv("PROGRAM_MEMORY")-1)
#endif
#if defined(__PCM__)
#define LOADER_END (LOADER_SIZE+0x40-1)
#elif defined(__PCH__)
#define FLASH_SIZE getenv("FLASH_ERASE_SIZE")
#if (((LOADER_SIZE) % FLASH_SIZE) == 0 ) //IF LOADER_SIZE is even flash boundary
#define LOADER_END (LOADER_SIZE-1)
#else //ELSE, goto next even boundary
#define LOADER_END (((LOADER_SIZE)+FLASH_SIZE-((LOADER_SIZE)%FLASH_SIZE))-1)
#endif
#elif defined(__PCD__)
#define FLASH_SIZE getenv("FLASH_ERASE_SIZE")/2
#if (((LOADER_START+LOADER_SIZE) % FLASH_SIZE) == 0)
#define LOADER_END (LOADER_START+LOADER_SIZE-1)
#else
#define LOADER_END (LOADER_START+(LOADER_SIZE+FLASH_SIZE-((LOADER_SIZE)%FLASH_SIZE))-1)
#endif
#else
#error PCM, PCH, and PCD only supported
#endif
#define APPLICATION_START (LOADER_END+1)
#if defined(__PCH__)
#define APPLICATION_ISR (APPLICATION_START+8)
#elif defined(__PCM__)
#define APPLICATION_ISR (APPLICATION_START+4)
#elif defined(__PCD__)
#define APPLICATION_ISR (APPLICATION_START+4)
#endif
//// --- end configuration --- ////////////////////////////////////////////
#ifdef _bootloader
// bootloader won't use interrupts, instead it will poll USB IF
#define USB_ISR_POLLING
/*
Provide an empty application, so if you load this .HEX file into the pic
without an application this will prevent the pic from executing unknown code.
*/
#org APPLICATION_START,APPLICATION_START+0xF
void BlankApplication(void)
{
while(TRUE);
}
//we need to prevent the loader from using application space
#if (APPLICATION_END > 0x10000)
#org APPLICATION_START+0x10, 0xFFFF {}
#if (APPLICATION_END > 0x20000)
#org 0x10000, 0x1FFFF {}
#org 0x20000, APPLICATION_END {}
#else
#org 0x10000, APPLICATION_END {}
#endif
#else
#org APPLICATION_START+0x10, APPLICATION_END {}
#endif
#define USB_CONFIG_PID 0x0034
#define USB_STRINGS_OVERWRITTEN
char USB_STRING_DESC_OFFSET[]={0,4,12};
// Here is where the "CCS" Manufacturer string and "SERIAL DEMO" are stored.
// Strings are saved as unicode.
// These strings are mostly only displayed during the add hardware wizard.
// Once the operating system drivers have been installed it will usually display
// the name from the drivers .INF.
char const USB_STRING_DESC[]={
//string 0
4, //length of string index
0x03, //USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
0x09,0x04, //Microsoft Defined for US-English
//string 1 - manufacturer
8, //length of string index
0x03, //USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
'C',0,
'C',0,
'S',0,
//string 2 - product
30, //length of string index
0x03, //USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
'C',0,
'D',0,
'C',0,
' ',0,
'B',0,
'o',0,
'o',0,
't',0,
'l',0,
'o',0,
'a',0,
'd',0,
'e',0,
'r',0
};
#endif //_bootloader
#ifndef _bootloader
//in the application, this moves the reset and isr vector out of the bootload
//space. it then reserves the loader space from being used by the application.
#build(reset=APPLICATION_START, interrupt=APPLICATION_ISR)
#org 0, LOADER_END {}
#endif
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 25, 2016 7:24 pm |
|
|
I'm running vs. 5.008 with your posted program.
I don't know, try a larger size. Try 0x1F00. See what happens. |
|
|
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Sun Dec 25, 2016 7:52 pm |
|
|
I've tried...but the result still the same.
However when I skip the #int_default , it can be compile.
what does #int_default means?
Code: |
//#int_default
void isr(void)
{
jump_to_isr(APPLICATION_ISR);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 25, 2016 8:09 pm |
|
|
Oh, that's one thing I forgot. Ttelmah explained in this thread
http://www.ccsinfo.com/forum/viewtopic.php?t=55739&start=35
that it really should be #int_global. I edited your program and
changed it to this:
Quote: |
#int_global
void isr(void)
{
jump_to_isr(APPLICATION_ISR);
}
|
Try that and see if it works. |
|
|
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Sun Dec 25, 2016 8:32 pm |
|
|
I've change it to #int_global..... but when i compiled, error message appear.
Error 71 "usb bootloader.c" Line 339(1,2): Out of ROM, A segment or the program is too large MAIN
Seg 0001E-017FE,005C left, need 00068
Seg 01800-0180E,000C left, need 00068
Seg 01810-07FFE,67F0 left, need 00068
Seg 00000-00006,0004 left, need 00068
Seg 00008-0008C,0000 left, need 00068 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 25, 2016 8:44 pm |
|
|
I don't know the reason. I'm compiling with vs. 5.008. I made only
the changes that I mentioned. It compiles OK for me:
Quote: | Executing: "C:\Program files\Picc\CCSC.exe" +FH "PCH_Test.c" +DF +LY -T -A +M -Z +Y=9 +EA #__buildcount__="0" #__18F4550=TRUE
Memory usage: ROM=19% RAM=23% - 30%
0 Errors, 0 Warnings.
Build Successful.
Loaded C:\Program Files\PICC\Projects\PCH_Test\PCH_Test.cof.
BUILD SUCCEEDED: Sun Dec 25 18:44:31 2016 |
|
|
|
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Sun Dec 25, 2016 8:50 pm |
|
|
Dear PCM,
Could you paste your EX_USB_BOOTLOADER.C and USB_BOOTLOADER.H code here. Maybe I can check if there is any differences. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 25, 2016 8:53 pm |
|
|
We're not supposed to do that, according to the forum rules which are in
the first thread at the top of the forum. I don't want to break the rules. |
|
|
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Sun Dec 25, 2016 11:21 pm |
|
|
I really hope someone can confirm that the EX_USB_BOOTLOADER.C and USB_BOOTLOADER.H that i have is same with the latest version. Hope it can work. |
|
|
|
|
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
|