chipKIT® Development Platform

Inspired by Arduino™

Changing configuration bits in MPIDE

Created Tue, 29 Apr 2014 03:35:57 +0000 by rpanebi1


rpanebi1

Tue, 29 Apr 2014 03:35:57 +0000

HI,

Does anyone know how to change the configuration bits that MPIDE will load onto my board when the board has a PIC32MX795F512L on it. When I import my MPIDE hex file into MPLAB the configuration bits are read only so unless there is a way to override this (suggestions WELCOME under the consideration I have a hex file from MPIDE) I am in trouble :X. I know for a fact this set of configurations works for my chip.

#pragma config FSRSSEL = PRIORITY_7 // SRS Select (SRS Priority 7) #pragma config FMIIEN = ON // Ethernet RMII/MII Enable (MII Enabled) #pragma config FETHIO = ON // Ethernet I/O Pin Select (Default Ethernet I/O) #pragma config FCANIO = ON // CAN I/O Pin Select (Default CAN I/O) #pragma config FUSBIDIO = ON // USB USID Selection (Controlled by the USB Module) #pragma config FVBUSONIO = ON // USB VBUS ON Selection (Controlled by USB Module)

// DEVCFG2 #pragma config FPLLIDIV = DIV_10 // PLL Input Divider (10x Divider) #pragma config FPLLMUL = MUL_20 // PLL Multiplier (20x Multiplier) #pragma config UPLLIDIV = DIV_12 // USB PLL Input Divider (12x Divider) #pragma config UPLLEN = OFF // USB PLL Enable (Disabled and Bypassed) #pragma config FPLLODIV = DIV_256 // System PLL Output Clock Divider (PLL Divide by 256)

// DEVCFG1 #pragma config FNOSC = PRIPLL // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL)) #pragma config FSOSCEN = ON // Secondary Oscillator Enable (Enabled) #pragma config IESO = ON // Internal/External Switch Over (Enabled) #pragma config POSCMOD = OFF // Primary Oscillator Configuration (Primary osc disabled) #pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled) #pragma config FPBDIV = DIV_8 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/8) #pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled) #pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576) #pragma config FWDTEN = ON // Watchdog Timer Enable (WDT Enabled)

// DEVCFG0 #pragma config DEBUG = OFF // Background Debugger Enable (Debugger is disabled) #pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select (ICE EMUC2/EMUD2 pins shared with PGC2/PGD2) #pragma config PWP = OFF // Program Flash Write Protect (Disable) #pragma config BWP = OFF // Boot Flash Write Protect bit (Protection Disabled) #pragma config CP = OFF // Code Protect (Protection Disabled)

but MPIDE does not use these ! So I must change them to these ! Thanks for any help.


EmbeddedMan

Tue, 29 Apr 2014 04:28:00 +0000

The easiest way to do it would probably be to edit the config bits in the bootloader source, then rebuild the bootloader for your board and re-program it. The bootloader project can be found here :[url] https://github.com/chipKIT32/PIC32-avrdude-bootloader [/url]

Now, that may not work out for you if you're not using a bootloader. In that case, there should be a way to add those config bits into your sketch so that it builds with the config bits set (as you want them) in the resulting hex file, so that when you program it they will be programmed too. I've never done this, but I'll bet Keith would have some good ideas how.

*Brian


rpanebi1

Tue, 29 Apr 2014 04:41:56 +0000

I assume there is hard coded configuration bits inside the MPIDE framework specifically for the PIC32MX795F512L. When I compile a hex file from my MPIDE sketch with the nobootloader linker, I cannot seem to edit the configuration bits for that sketch in MPLAB. There's definitely config bits put into the sketch for the PIC32MX795F512L. I must find that file! Otherwise I'll need to add all the config bit definitions for every future sketch (but knowing if that could be done too would be great nonetheless :)


majenko

Tue, 29 Apr 2014 07:52:12 +0000

They're hard coded in the linker script.


rpanebi1

Tue, 29 Apr 2014 11:34:41 +0000

Are you referring to something like...

C:\Users\Rob\Desktop\Senior Design\MPIDE\mpide-0023-windows-20140121-test\mpide-0023-windows-20140121-test\hardware\pic32\compiler\pic32-tools\pic32mx\lib\ldscripts where there is a bunch of elf32pic32.XX files

or

C:\Users\Rob\Desktop\Senior Design\MPIDE\mpide-0023-windows-20140121-test\mpide-0023-windows-20140121-test\hardware\pic32\cores\pic32 where there is for example chipKIT-application-32MX795F512-nobootloader.ld

Near the first directory ^, I thought the settings were in the file (for example my paerticular pic32) C:\Users\Rob\Desktop\Senior Design\MPIDE\mpide-0023-windows-20140121-test\mpide-0023-windows-20140121-test\hardware\pic32\compiler\pic32-tools\pic32mx\lib\proc\32MX795F512L\configuration.data

But editing a value a 'CSetting' in that didnt seem to change the config bit when I opened the corresponding sketch in MPLAB and look under the read only config bits.

Any more insight and guidance on the issue? Perhaps if someone could give me an example of how to change one configuration setting in these files from X -> Y? Thanks guys.


majenko

Tue, 29 Apr 2014 11:38:38 +0000

They are in chipKIT-application-32MX795F512-nobootloader.ld:

SECTIONS
{
  .config_BFC02FF0 : {
    LONG(0x3AFFFFFF)
  } > config3
  .config_BFC02FF4 : {
    LONG(0xFFF879D9)
  } > config2
  .config_BFC02FF8 : {
    LONG(0xFF6ACD5B)
  } > config1
  .config_BFC02FFC : {
    LONG(0x7FFFFFF7)
  } > config0
}

Those for LONG(...) hex numbers are the flag settings. The best way I have found of generating those numbers is from within MPLAB-X - go to the Configuration Settings window, set the settings you want, then copy the hex numbers it gives you into those variables.


EmbeddedMan

Tue, 29 Apr 2014 13:30:51 +0000

I wonder if there wouldn't be a simple way we could allow folks to change the config bits from within a sketch. Obviously this gives the normal chipKIT user a good chance to shoot themselves in the foot (since they can brick their board if they set the bits wrong) but for more advanced users, it might be really nice.

*Brian


majenko

Tue, 29 Apr 2014 14:21:04 +0000

It would only be doable for non-bootloader situations, and they're not going to be bricking the bootloader as the bootloader doesn't exist.


EmbeddedMan

Tue, 29 Apr 2014 16:25:45 +0000

Right - I was thinking only of bootloader situations. Why can't we have AVRDUDE re-program the config bits? Is it hard-coded to ignore those addresses in the HEX file?

*Brian


rpanebi1

Tue, 29 Apr 2014 17:18:53 +0000

So changing this worked great !

SECTIONS > config3 .config_BFC02FF4 : { LONG(0xFFF879D9) } > config2 .config_BFC02FF8 : { LONG(0xFF6ACD5B) } > config1 .config_BFC02FFC : { LONG(0x7FFFFFF7) } > config0

This loads the settings .... [attachment=0]Capture.PNG[/attachment]

Now this works on my cerebot board great and when I probe the board which has a sketch on that is simply

main() {

digitalWrite(0,HIGH); //flash LED digitalWrite(0,LOW);

}

I clock the LED at 480Khz.

Now I want to replicate this on my custom board which has an external crystal instead of an oscillator like the cerebot (same frequency though). BUT no matter how many different combinations of config settings i change on my board, I cannot
get the same output of 480kHz, only 48 Khz. Right now I suspect there being something funky with my crystal so can someone inform me what config settings NEED to be change (based on the photo) to have the internal crystal on my custom board act like what the oscillator is to the cerebot (basically replicate behavior if that wasnt clear).

Also, assuming my crystal should work , should the cerebot settings work on my custom board (to get the LED flashing at 480kHz) that is? There is clearly a problem though because the settings don't work and the LED doesn't go on with these specific config settings. (I have to change FNOSC but then changing any of the DIV_ or MUL_ settings do nothing and leave me at 48Khz. So it seems PLL seems to not be working?


rpanebi1

Wed, 30 Apr 2014 00:18:31 +0000

I have figured out there is a problem with using the PLL in the chip. Perhaps due to either the layout of the board or there needs to be capacitors put somewhere.


Ian Billing

Mon, 12 May 2014 11:34:41 +0000

I see from majenko's reply that the config bits can be accessed and edited from within the linker script at chipKIT-application-32MX795F512-nobootloader.ld, which is great but does this apply if one is using the bootloader and a sketch written in mpide?

I ask because I am unable to get results from changing the config bits there and because I see the "nobootloader" part of the filename.


majenko

Mon, 12 May 2014 12:11:09 +0000

The config bits are embedded in the bootloader. While it may be possible to re-program the config bits on an installed system using a PK3, it's not something I have ever attempted. Best to compile a new bootloader image with the new config bits in it and install that.


Ian Billing

Mon, 12 May 2014 12:59:10 +0000

Thanks majenko - I'll try that