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

[solved] USB Bootloader -> program loaded not reliable
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
spilz



Joined: 30 Jan 2012
Posts: 220

View user's profile Send private message

[solved] USB Bootloader -> program loaded not reliable
PostPosted: Wed Dec 07, 2016 12:21 pm     Reply with quote

Solution :

there is an error in ex_usb_bootloader file :

at the end of the file, it should be :
Code:
#int_global
 void isr(void)
 {
    jump_to_isr(APPLICATION_ISR);
 }


instead of :
Code:
#int_default
 void isr(void)
 {
    jump_to_isr(APPLICATION_ISR);
 }


thanks to Ttelmah to have found it, and to PCM programmer to help us.


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

Hello,

After having issue on different part of a project, using 18F47J53, it appear that it maybe comes from the bootloader :(
i get the same issue with 18F2550 and bootloader

https://www.ccsinfo.com/forum/viewtopic.php?t=55706
https://www.ccsinfo.com/forum/viewtopic.php?t=55734

But I don't understand what is wrong in my bootloader.

I use the "ex_usb_bootloader.c"
I modified the "ex_usb_common.h" by adding :
Code:
#define USB_HW_GENERIC_18F47J53

Code:
#if defined(USB_HW_GENERIC_18F47J53)
   #include <18F47J53.h>

   #fuses NOWDT
   #fuses NOXINST

   //4Mhz clock configured for USB operation and 48MHz CPU operation
   #fuses HSPLL
   #fuses PLLEN
   #fuses PLL1
   #fuses NOCPUDIV
   #use delay(clock=48MHz, USB_FULL)


   #DEFINE LED1   PIN_B2
   #define LED2   PIN_D4
   #define LED3   PIN_B2
   #define LEDS_OFF()   LED_OFF(LED1); LED_OFF(LED2); LED_OFF(LED3)
   #define BUTTON_PRESSED() (!input(PIN_B3))

   // #define PIN_USB_SENSE   PIN_A3

   #define __NO_UART__

   #define HW_ADC_PORTS    sAN0|sAN1|sAN2
   #define HW_ADC_CHANNEL  0
   #define HW_ADC_CONFIG   ADC_CLOCK_INTERNAL

   #byte OSCTUNE = 0xF9B
   #bit PLLEN=OSCTUNE.6

   #define HW_INIT() LED_ON(LED1);  PLLEN=TRUE; delay_ms(50)
#endif


I added to my program :
Code:
#include "usb_bootloader.h"


I'm able to load the program to the chip.

With a basic program, it works well.
With the same program and a big array declared, it does not work properly.
(cf https://www.ccsinfo.com/forum/viewtopic.php?t=55734)

When I load directly the program (without #include "usb_bootloader.h")
it works well (test during 1 hour without issue).

What can do that ?

Is there a way to directly load the program to the same place as with bootloader, without using the bootloader ?
Its maybe the place in ROM that is not well done in the compiler.

Thanks for your help

regards


Last edited by spilz on Mon Dec 12, 2016 2:54 am; edited 4 times in total
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Dec 07, 2016 3:55 pm     Reply with quote

OK, I don't use that PIC or a bootloader but I am confident the CCS bootloader does function 100%.
1st I'd go back to using the CCS supplied bootloader and get it working.

One item that must be followed is that BOTH the bootloader and the program MUST have identical 'fuses'. While obvious, it is overlooked, just search for 'bootloader problems' here....

2nd Yes you can 'burn' both the bootloader AND program if you want. Again search the forum, it's been answered before....

Since you say IF you burn the PIC with your program it runs fine, THEN there is 'something' wrong with your modified bootloader.
I suspect it might be a 'fuses' issue though without seeing both programs I can't say for sure.

also...

#define HW_ADC_CONFIG ADC_CLOCK_INTERNAL

ADC_CLOCK_INTERNAL is generally used for sleeping PICs, you should check the datasheet for valid use of it.


Jay
spilz



Joined: 30 Jan 2012
Posts: 220

View user's profile Send private message

PostPosted: Wed Dec 07, 2016 5:08 pm     Reply with quote

thanks for your reply,

I check it again, I'm using the same fuses on both

I tried to remove #define HW_ADC_CONFIG ADC_CLOCK_INTERNAL but it change Nothing

My idea was not really to burn bootloader and program at the same time, but but Something like only a "goto APPLICATION_START" instead of the bootloader and the program.

if I try it :
- it works well -> the issue comes from the bootloader software
- it does not work -> the issue comes from the compiler which does not works properly to compile the program not at start memory (it's a little confusing with my bad English, sorry for that).

Are you OK with this logic ?
spilz



Joined: 30 Jan 2012
Posts: 220

View user's profile Send private message

PostPosted: Wed Dec 07, 2016 5:50 pm     Reply with quote

I burnt bootloader and program at the same time, using in bootloader
Code:
#fuse NONE
and adding
Code:
#IMPORT (FILE=ex_usb_bootloader_small.HEX,HEX, RANGE=0:LOADER_SIZE-1)
to the program

-> exactly the same issue :(
spilz



Joined: 30 Jan 2012
Posts: 220

View user's profile Send private message

PostPosted: Thu Dec 08, 2016 2:44 am     Reply with quote

I get the same issue with a PIC18F2550 :(

I guess I'm doing something wrong with bootloader ...
I use it for 3 years and thought it worked well ...

what I did :

test without bootloader works OK :
Code:

 #include <18F2550.h>
 #device ADC=16

 #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
 #use delay(clock=48000000)

 #define LED_R_pin                      pin_D7 

 #define LED_R(x)                       output_bit(LED_R_pin,x)
     

 int DISPLAY [1024];

 int32 TIMER0_Seconde = 0;
 #INT_TIMER0
 void  TIMER0_isr(void)
 {
    set_timer0(18661);         // 1s overflow
    TIMER0_Seconde++;
 }

 void blink(){
    LED_R(1);
    delay_ms(100);
    LED_R(0);
    delay_ms(100);
 }


 int sequence_B_state = -1;
 int32 sequence_B_Seconde_last = 0;
 void sequence_B(void){
    int32 delta = 0;
    int32 TIMER0_Seconde_loc;

    disable_interrupts(GLOBAL);
    TIMER0_Seconde_loc = TIMER0_Seconde;
    enable_interrupts(GLOBAL);

     
    if(TIMER0_Seconde_loc<sequence_B_Seconde_last)
       sequence_B_Seconde_last = TIMER0_Seconde_loc;
     
    delta = (TIMER0_Seconde_loc-sequence_B_Seconde_last);
     
    if(delta >= 7){
       blink();
       sequence_B_Seconde_last = TIMER0_Seconde_loc;
    }
 }

 void main() {
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);      //1,4 s overflow
     
     
    LED_R(0);
   
    enable_interrupts(INT_TIMER0);
    enable_interrupts(GLOBAL);
         
    sequence_B_state = 1;
     
    while(true){
       sequence_B();
    }
    reset_cpu();
 }


test WITH bootloader -> issue :

USB BOOTLOADER :

I copy "ex_usb_bootloader.c", "ex_usb_common.h", "usb_booloader.h" to a local folder. I rename them by adding '_' at the end of the name.

I modify "ex_usb_bootloader_.c" like this :
Code:
#include <ex_usb_common_.h>
...
#include "usb_bootloader_.h"


I modify "ex_usb_common_.h" by adding :
Code:
#define USB_HW_CCS_PIC18F2550

Code:
#if defined(USB_HW_CCS_PIC18F2550)
   #include <18F2550>
   #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
   #use delay(clock=48000000)

   #define LED1 PIN_B7
   #define LED2 PIN_B7
   #define LED3 PIN_B7
   #define LEDS_OFF() LED_OFF(LED1);LED_OFF(LED2);LED_OFF(LED3)
   #define BUTTON_PRESSED() !input(PIN_C0)

   #define HW_ADC_CONFIG   ADC_CLOCK_INTERNAL
   #define HW_ADC_CHANNEL 0
   #define HW_ADC_PORTS AN0

   #define HW_INIT() setup_adc_ports(HW_ADC_PORTS)
#endif


and I burn it using pickit2.

PROGRAM :
Code:

 #include <18F2550.h>
 #device ADC=16

#include <usb_bootloader_.h>

 #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
 #use delay(clock=48000000)

 #define LED_R_pin                      pin_D7 

 #define LED_R(x)                       output_bit(LED_R_pin,x)
     

 int DISPLAY [1024];

 int32 TIMER0_Seconde = 0;
 #INT_TIMER0
 void  TIMER0_isr(void)
 {
    set_timer0(18661);         // 1s overflow
    TIMER0_Seconde++;
 }

 void blink(){
    LED_R(1);
    delay_ms(100);
    LED_R(0);
    delay_ms(100);
 }


 int sequence_B_state = -1;
 int32 sequence_B_Seconde_last = 0;
 void sequence_B(void){
    int32 delta = 0;
    int32 TIMER0_Seconde_loc;

    disable_interrupts(GLOBAL);
    TIMER0_Seconde_loc = TIMER0_Seconde;
    enable_interrupts(GLOBAL);

     
    if(TIMER0_Seconde_loc<sequence_B_Seconde_last)
       sequence_B_Seconde_last = TIMER0_Seconde_loc;
     
    delta = (TIMER0_Seconde_loc-sequence_B_Seconde_last);
     
    if(delta >= 7){
       blink();
       sequence_B_Seconde_last = TIMER0_Seconde_loc;
    }
 }

 void main() {
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);      //1,4 s overflow
     
     
    LED_R(0);
   
    enable_interrupts(INT_TIMER0);
    enable_interrupts(GLOBAL);
         
    sequence_B_state = 1;
     
    while(true){
       sequence_B();
    }
    reset_cpu();
 }


the program is loaded but it does not work properly

What is wrong in my method ?

someone can test it with its own bootloader ?


Last edited by spilz on Thu Dec 08, 2016 3:24 am; edited 2 times in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Thu Dec 08, 2016 2:52 am     Reply with quote

The obvious thing is that LOADER_SIZE may not be set correctly.

If you modify the bootloader, you have to compile it, look at how large it actually is, then set the loader_size to be at the next page boundary in the chip memory above that size. Then use that figure in both the loader and the main code.
It's common when people change the loader and don't do this, to have all sorts of problems as then the main code will overwrite/erase part of the loader (or fail to erase - see below)......

The chip you have is awkward in this regard, since it only supports erases on 1024 byte blocks. Even a one byte increase in the size of the loader, if it takes you across a 1024 byte page boundary, then means a whole KB of ROM extra has to be reserved. If this isn't done, then the bottom part of the memory can't be erased, so the code will not program properly.

CCS's example usb bootloader, as the first thing it does, reads the size of the erase block (getenv("FLASH_ERASE_SIZE)), and then uses this to establish 'where' the LOADER_END needs to be, based upon the 'LOADER_SIZE' define. If you have increased the size of the bootloader, and have not increased 'LOADER_SIZE' to correctly match this, then you will have problems.....
spilz



Joined: 30 Jan 2012
Posts: 220

View user's profile Send private message

PostPosted: Thu Dec 08, 2016 3:23 am     Reply with quote

Thanks for your reply Ttelmah,

Actually I didn't change the bootloader, just create the part for using 18F2550 or 18F47J53 in ex_usb_common_.h (ex_usb_common.h copied in local).

I checked the hex files,
bootloader go until 0x1810, and has just 8 byte in 0x2000,
program file (using bootloader) has nothing before 0x2000.

So it looks ok for me, isn't it ?
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Dec 08, 2016 8:38 am     Reply with quote

You should really go back to 'square one'. Basic Troubleshooting101...

Use the original, unmodified CCS bootloader and use a '1Hz LED ' program to confirm that your PIC works 100%.

Then use the CCS bootloader and your program, test to confirm that works...

Then use your 'modified' bootloader and the 1Hz program, confirm that works.

Then use your modified bootloader and 'real' program, test.

Without seeing 100% of the code, I still bet 'something' you did is causing the problem.

Jay
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Thu Dec 08, 2016 8:48 am     Reply with quote

Sometimes some of the major support code "under the hood" in the compiler will change, and that can have an impact on compiled code size. Even though you haven't modified the CCS bootloader, you should really do as Ttelmah has recommended: compile the bootloader and see how much code it uses, and whether that size still complies with the size set aside in the bootloader.

If everything you say is true, that's the place to look for issues.
spilz



Joined: 30 Jan 2012
Posts: 220

View user's profile Send private message

PostPosted: Thu Dec 08, 2016 2:50 pm     Reply with quote

@newguy :

I'm using the original bootloader,
I just select the good chip (18F2550 instead of 18F4550) and select the good pin for leds and button, because I don't have a 18F4550 board.

18F2550 and 18F4550 are almost the same pin, 4550 has just more pins.

I compile the bootloader for 18F4550 and 18F2550, they have the same size : they use 0x1820 bytes.

so :
Code:
#define LOADER_SIZE (0x2000)
-> it's OK, isn't it?


@temtronic :

-original, unmodified CCS bootloader and use a '1Hz LED ' program
-> OK

-my program directly burn (no bootloader) with big array
-> blink every 7s
-> OK

-original, unmodified CCS bootloader and my program (with big array)
-> randum blinking ~2/3s
-> NOT OK

any idea ?

I can send files if someone need them to try it.

thanks for your help
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 08, 2016 5:38 pm     Reply with quote

What program are you using to download your application program (7s)
to the 18F2550 bootloader ?
spilz



Joined: 30 Jan 2012
Posts: 220

View user's profile Send private message

PostPosted: Thu Dec 08, 2016 5:58 pm     Reply with quote

the same as for 1Hz blink :

ccsbootloader.exe

I tryed Siow.exe too, but same issue :(

transfert seems ok

actually I get the same issue when I burn bootloader and program at the same time, so I don't think it comes from transfert.

Can someone try to just load my program (with big array) by bootloader (what ever the board, just to try) and see if he get it working ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 08, 2016 6:16 pm     Reply with quote

I found it on the CCS download page.
http://www.ccsinfo.com/downloads.php
The readme.txt file says it's a command line program, but there is a GUI
version apparently.

What version are you using ? Are you using it as a command line
program ? If so, post your command line. If you are using the GUI
version, can you post a link to it ?

In other words, I'm trying to duplicate your environment. You need to
give more details.
spilz



Joined: 30 Jan 2012
Posts: 220

View user's profile Send private message

PostPosted: Thu Dec 08, 2016 6:27 pm     Reply with quote

I'm using command line :
Code:
ccsbootloader PORT=COM8 BAUD=9600 DEBUGT=debug.txt test7s.hex


Are you able to reproduce the issue by loading the program through bootloader ?

I get the same issue on different boards (18F2550 and 18F47J53)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 08, 2016 6:35 pm     Reply with quote

I'll work on it later this evening.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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