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

Application uses bootloader #fuses settings

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



Joined: 16 Sep 2011
Posts: 10

View user's profile Send private message

Application uses bootloader #fuses settings
PostPosted: Fri Sep 16, 2011 4:37 am     Reply with quote

Hi

I'm using a PIC18F46J50, CCS V4.119 with a 12MHz crystal.

I am using a slightly modified version of the CCS USB bootloader to program the PIC with my application code. The bootloader has the following #fuses/#use statements set:
Code:

#include <18F46J50.h>
#fuses HSPLL,NOWDT,NOPROTECT,PLL3,CPUDIV2,NOT1DIG,NOIESO
#use delay(clock=6000000)
 

The application code that is loaded into the PIC using the bootloader has different fuse settings as follows:
Code:

#include "18F46J50.h"
#fuses HS,WDT,NOPROTECT,NOIESO,NOT1DIG
#use delay(clock=12000000, RESTART_WDT)

I am finding that the application code ignores its fuse settings and uses the bootloader fuse settings instead thereby making the application code run at the wrong speed.

Any ideas what I can do to force it to use the application fuse settings? Or is there something else I am doing wrong?

Many thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri Sep 16, 2011 7:26 am     Reply with quote

Most bootloaders, _don't_ program the fuses.
Think about it for a moment. The bootloader _must_ know how fast the chip is running, so if the fuses were changed by the bootloader, it would then stop working, making it pointless.
You need to reprogram your bootloader to use the same fuses as your final code, and write this into the chip with a programmer....

Best Wishes
rightbak



Joined: 16 Sep 2011
Posts: 10

View user's profile Send private message

PostPosted: Mon Sep 19, 2011 6:32 am     Reply with quote

Many thanks for your reply
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Aug 07, 2012 4:00 am     Reply with quote

hey!
I have the same problem, I want to use bootloader, but in normal mode, I need to have a low consumption to save battery, so I want to use internal clock with no pll.

Is it possible to have a bootloader which forces the fuses for it at the start of the program, and an other part at the beginning of the "normal application" which force the fuse for it ?

I'm not sure to be clear, sorry for my bad english.

Spliz
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Aug 07, 2012 6:51 am     Reply with quote

No.
The fuses in application, and bootloader _must_ normally be be the same.
However remember that on most modern chips, you can change the clock rate independant of the fuses. So (for instance), many chips allow selection of a clock from the timer oscillator, or the internal RC, or the fuse programmed default.
So you don't change the fuses, just use the setup_oscillator command to change the selected oscillator.

Best Wishes
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Aug 07, 2012 8:55 am     Reply with quote

it's a 18F2550
I know how to use setup_oscillator() to change internal clock speed, but I don't know how to switch from quartz to internal clock.
and what about write_configuration_memory() ?

I had
Code:
int data[6] = {0x24,0x0E,0x3E,0x1E,0x00,0x03};
write_configuration_memory(data,6);

at the beginning of the bootloader,
like this whatever is changed by the program after, when the pic restart, the fuses are still right for bootloader.
But I didn't find the good way to change the configuration in the program load.
How the compiler know when the clock change, for delay for example ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Aug 07, 2012 11:28 am     Reply with quote

If you do this, you risk killing your chip.
The flash memory has limited write life.

Look at the settings for 'setup_oscillator'. However have to ask what you are using the 2550 for?. If you want USB, then you _must_ (not optional), have a quartz oscillator running at 4,6,8,12,16,20, or 24MHz.

setup_oscillator(OSC_4MHZ | OSC_INTRC);

switches to the internal 4MHz oscillator.

Best Wishes
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Thu Aug 09, 2012 2:05 pm     Reply with quote

hey

thanks Ttelmah, it's exactly what i was looking for, I didn't know
" | OSC_INTRC "

is there something to go back to HS or HSPLL ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Thu Aug 09, 2012 2:10 pm     Reply with quote

setup_oscillator(OSC_NORMAL);

Puts you back to the fuse selected oscillator.

Best Wishes
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Thu Aug 09, 2012 2:12 pm     Reply with quote

thanks a lot Smile
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Aug 10, 2012 1:23 am     Reply with quote

Read the datasheet!

Oscillator section. There's a lot of cool stuff in there...
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Fri Aug 10, 2012 1:49 am     Reply with quote

I did, I understand it, but I don't know where I can find the syntax for the compiler. Often I know what I want to do, but I don't know how to do it with the ccs compiler
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Aug 10, 2012 2:03 am     Reply with quote

spilz wrote:
I did, I understand it, but I don't know where I can find the syntax for the compiler. Often I know what I want to do, but I don't know how to do it with the ccs compiler


You can always look in the corresponding .H file for the PIC you're using...

It's in the CCS installdir.

For example, 18F46j11.h will be the starting place for using that PIC.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Fri Aug 10, 2012 2:10 am     Reply with quote

I will Smile
thanks
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