Differences between bootloader and pickit

General questions about Firewing...

Re: Differences between bootloader and pickit

Postby Jerry Messina » Sat Aug 15, 2015 12:09 pm

Glad you got it all working.

The OSCTUN value shown in that example code is just a placeholder number. You might find you have to tweak things some.

For the 24HJ128GP502 the FRC internal osc is 7.3728MHz. That's a good number for UART baudrates, but bad for CAN as you usually want a number divisable by 8 or 10 depending on how you set up the CAN Tq calculations.

To adjust FOSC closer to a nice round 8MHz value we have: 8MHz - 7.3728MHz = 0.6272MHz adjustment needed
Each bit of OSCTUN adjusts it about 0.375% (0.0276MHz): OSCTUN = 0.6272/0.0276 = 22.6, so pick either 22 or 23

setting OSCTUN = 22 -> 7.3728 + (22 * 0.0276) = 7.3728 + 0.6072 = 7.98MHz
or OSCTUN = 23 -> 7.3728 + (23 * 0.0276) = 7.3728 + 0.6348 = 7.98MHz = 8.0076MHz

Now, changing the OSCTUN value is going to give you a different set of calculations for the PLL (and the UART baud rate, too)

Here's an excel spreadsheet that you can use to help calculate the PLL M, N1 and N2 settings:
http://www.leobodnar.com/dsPIC33%20PLL%20settings.xls

It's a little confusing at first... remember that the PLL register settings don't get programmed directly with the M, N1, and N2 values.
If you happen to have mplabx there's a handy ECAN Bit Rate Calculator plugin that lets you put in all the above and helps calculate the various ECAN register settings.

After going through all that, keep in mind that none of the FOSC and OSCTUN numbers above are exact (and they can change), but it should get you in the ballpark.
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Re: Differences between bootloader and pickit

Postby Coccoliso » Sat Aug 15, 2015 12:33 pm

Hi Jerry,
always fast and precise, thanks for the clarification .. at least now I understand the mess that I created uncomment the line :D
User avatar
Coccoliso
 
Posts: 177
Joined: Sat Sep 27, 2014 10:02 am

Re: Differences between bootloader and pickit

Postby Coccoliso » Wed Aug 19, 2015 11:03 am

Hi,
HELP!
So, I will try to explain as best as possible and swear not to be under the influence of hallucinogens :lol: .
I use Pickit2 to program FW PIC24 R2 board using the macro of Jerry ( viewtopic.php?f=12&t=216#p1215 ) and setting the clock with SetSysClock () as the first instruction of the main.
If I program directly with the FW pickit (for example with the program I2C hardware) nothing works as expected (and do not set even ports and I always read 0).
But the strange thing is this, if by pickit GUI read the contents of the PIC and reprogram FW (READ and then WRITE immediately) magically the program runs like a dream :o .
The main difference is that the hex generated by the compiler (which lacks the config) is large a ten Ks while the program read and rewritten is large 480K.
The question is :
1) what is missing in the source ?
2) how can I force the compiler to generate a hex that features the first load ?
:roll:
User avatar
Coccoliso
 
Posts: 177
Joined: Sat Sep 27, 2014 10:02 am

Re: Differences between bootloader and pickit

Postby Jerry Messina » Wed Aug 19, 2015 1:35 pm

I'm not sure I follow 100% of what you're trying, so let's review.

When you compile using the Firewing Toolsuite, the default settings assume that you're building for the FW loader,
and the loader takes care of the config settings for you (they're built into the bootloader.. you don't reprogram them).

If you take that hex file and program the chip using the PICkit2 it won't work as there are no config settings in the project hex file.
You can see this if you take a look at the output .c or .lst files. If you have config settings they'll show in the .c file like this:
Code: Select all
// configuration fuses...
_FWDT(FWDTEN_OFF)

note: to tell the IDE that you want it to produce a .C file, create a zero-byte file in the Firewing folder named 'imc.token'.
Then, in the Firewing IDE set the checkbox 'View | Compile and Program Options.. | Compiler tab | Keep all working files'


If you want to compile for complete standalone operation where there is no bootloader and you program the chip using the PK2, you'll have to add config settings to your main program file like in that link, something like:
Code: Select all
#if (_device = 24HJ128GP502)
config FOSCSEL = {FNOSC_FRCPLL, IESO_OFF}
config FOSC = {FCKSM_CSECMD, OSCIOFNC_OFF, POSCMD_NONE, IOL1WAY_OFF}    // OSC2 output on (pin 10)
config FWDT = {WDTPOST_PS256, WDTPRE_PR128, WINDIS_OFF, FWDTEN_OFF}
config FPOR = {FPWRT_PWR128, ALTI2C_OFF}
#endif

You'll have to make the correct selections for your hardware, and also add code to your program to do things like setup the clock, IO pins, etc. You should be able to see these config settings in the .c file. If you don't, something's not quite right.

One thing that is missing from the above is the FICD setting, and that may be one of the problems since the chip defaults to having the JTAG interface enabled:
Code: Select all
_FICD(ICS_PGD1 & JTAGEN_OFF)

I forgot about that one since on my system it's handled by the mplabicd.bas file so that I can do hardware debugging.

As far as the difference in the hex file sizes, when you read the chip using the PK2 it reads the entire chip contents so you get a large file. The compiler only generates a hex file containing what's actually used so it's a lot smaller. Maybe one of the config settings is getting changed when you read and re-write the chip using the GUI app, and that's why it works.

Programming the chip using the PK2 will wipe out the FW loader, so if you ever want to restore it you can use the PK2 to reprogram the loader using the hex file in http://www.firewing.info/downloads/load ... der-r2.zip

Does that make sense, and does it answer your questions? Let me know if that still doesn't work.
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Re: Differences between bootloader and pickit

Postby Coccoliso » Wed Aug 19, 2015 1:53 pm

Thanks Jerry,
a great place to start .. or better restart.. because I began having hallucinations of mystical character.
User avatar
Coccoliso
 
Posts: 177
Joined: Sat Sep 27, 2014 10:02 am

Re: Differences between bootloader and pickit

Postby Coccoliso » Wed Aug 19, 2015 2:46 pm

Hi Jerry,
config word in c source are there
Code: Select all
// configuration fuses...
_FOSCSEL(FNOSC_FRCPLL & IESO_OFF)
_FOSC(FCKSM_CSECMD & IOL1WAY_OFF & OSCIOFNC_OFF & POSCMD_NONE)
_FWDT(FWDTEN_OFF & WDTPOST_PS256 & WDTPRE_PR128 & WINDIS_OFF)
_FPOR(ALTI2C_OFF & FPWRT_PWR128)

but when I load the hex in the gui of pickit2 I will read in yellow
Code: Select all
"Warning: Some configuration words not in hex file. Ensure default values above right are acceptable."

Now I program the PIC not taking care of the message and nothing works.
I read the hex from the PIC and write it and it works.
Please note that I realized of this thing by setting the I2C hardware ( where SDA/SCL are not set properly ) and now testing the FT800 example ( where I had to comment out the line of SD card load because otherwise hang even with this ploy ) .
User avatar
Coccoliso
 
Posts: 177
Joined: Sat Sep 27, 2014 10:02 am

Re: Differences between bootloader and pickit

Postby Coccoliso » Wed Aug 19, 2015 3:10 pm

Hi Jerry,
I watched the PIC24 loader and according to that configuration I modified the source Bas and now the error in the pickit2 gui is gone.
Now it is so:
Code: Select all
#if (_device = 24HJ128GP502)
Config FOSCSEL = {FNOSC_FRCPLL, IESO_OFF}
'           config FOSC = {FCKSM_CSECMD, OSCIOFNC_OFF, POSCMD_NONE, IOL1WAY_OFF}  Original row
Config FOSC = {FCKSM_CSECMD, OSCIOFNC_OFF, POSCMD_NONE, IOL1WAY_OFF, FCKSM_CSDCMD}  ' Modified config
'           config FWDT = {WDTPOST_PS256, WDTPRE_PR128, WINDIS_OFF, FWDTEN_OFF}  Original row
Config FWDT = {WDTPOST_PS256, WINDIS_OFF, FWDTEN_OFF}  ' Modified config
Config FPOR = {FPWRT_PWR128, ALTI2C_OFF}
Config FICD = {ICS_PGD1, JTAGEN_OFF}
Config FGS = {GWRP_OFF}  ' Added config row
Config FSS = {SWRP_WRPROTECT_OFF}  ' Added config row
Config FBS = {BWRP_WRPROTECT_OFF}  ' Added config row
#endif

I still have to do a test to know what happened to working sources!
Now I'd like to know what I've done with these four changes. :lol:
User avatar
Coccoliso
 
Posts: 177
Joined: Sat Sep 27, 2014 10:02 am

Re: Differences between bootloader and pickit

Postby Coccoliso » Wed Aug 19, 2015 4:37 pm

Hi Jerry,
to prevent the loading error of pickit2 gui must use all these config ( without any row it throw the error)
Code: Select all
#if (_device = 24HJ128GP502)
config FOSCSEL = {FNOSC_FRCPLL, IESO_OFF}
config FOSC = {FCKSM_CSECMD, OSCIOFNC_OFF, POSCMD_NONE, IOL1WAY_OFF, FCKSM_CSDCMD} 
config FOSC = {POSCMD_NONE, OSCIOFNC_ON , IOL1WAY_OFF , FCKSM_CSECMD}
config FWDT = {WDTPOST_PS256, WDTPRE_PR128, WINDIS_OFF, FWDTEN_OFF}
config FPOR = {FPWRT_PWR128, ALTI2C_OFF}
config FICD = {ICS_PGD1, JTAGEN_OFF}
config FGS = {GWRP_OFF}
Config FSS = {SWRP_WRPROTECT_OFF}
Config FBS = {BWRP_WRPROTECT_OFF}
#endif

to make it work without reloading the firmware is of primary importance the FCKSM_CSDCMD option in FOSC config line.
User avatar
Coccoliso
 
Posts: 177
Joined: Sat Sep 27, 2014 10:02 am

Re: Differences between bootloader and pickit

Postby Jerry Messina » Wed Aug 19, 2015 4:54 pm

The one that that probably fixed it is
Code: Select all
Config FICD = {ICS_PGD1, JTAGEN_OFF}

The JTAG port is a programming port (like the ICD), and it defaults to ON. That can keep it from working normally.

The others have to do with protection, and I think they all default to off.
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Previous

Return to Questions

Who is online

Users browsing this forum: No registered users and 2 guests

cron

x