Microchip MPLAB X – Link Error: region is full / section overlaps section

While trying to compile some code on MPLAB X I came across this link error, stating that my #pragma config bits were full or sections of them were overlapping other sections.

/Applications/microchip/xc16/v1.11/bin/bin/../bin/elf-ld: Link Error: region FOSC is full (dist/default/production/can_to_serial.production.elf section __FOSC)
/Applications/microchip/xc16/v1.11/bin/bin/../bin/elf-ld: Link Error: region FWDT is full (dist/default/production/can_to_serial.production.elf section __FWDT)
/Applications/microchip/xc16/v1.11/bin/bin/../bin/elf-ld: Link Error: region FBORPOR is full (dist/default/production/can_to_serial.production.elf section __FBORPOR)
/Applications/microchip/xc16/v1.11/bin/bin/../bin/elf-ld: Link Error: section .config_MCLRE%10 [f80004   -> f80005  ] overlaps section __FWDT [f80004   -> f80005  ]
/Applications/microchip/xc16/v1.11/bin/bin/../bin/elf-ld: Link Error: section .config_WDT%11 [f80002   -> f80003  ] overlaps section __FOSC [f80002   -> f80003  ]
/Applications/microchip/xc16/v1.11/bin/bin/../bin/elf-ld: Link terminated due to previous error(s).
make[2]: *** [dist/default/production/can_to_serial.production.hex] Error 255
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 1s)

After some time scratching my head I realised the issue was that configuration bits were being set twice. Simply I had to remove them. I also moved all configuration bits to a separate header which is only included in the main c source file to avoid future issues.

Code causing the error:

main.c
#include 
#include 
#include 

// FOSC
#pragma config FPR = XT_PLL4            // Primary Oscillator Mode (XT w/PLL 4x)
#pragma config FOS = PRI                // Oscillator Source (Primary Oscillator)
#pragma config FCKSMEN = CSW_FSCM_OFF   // Clock Switching and Monitor (Sw Disabled, Mon Disabled)

// FWDT
#pragma config FWPSB = WDTPSB_16        // WDT Prescaler B (1:16)
#pragma config FWPSA = WDTPSA_512       // WDT Prescaler A (1:512)
#pragma config WDT = WDT_OFF            // Watchdog Timer (Disabled)

// FBORPOR
#pragma config FPWRT = PWRT_64          // POR Timer Value (64ms)
#pragma config BODENV = BORV20          // Brown Out Voltage (Reserved)
#pragma config BOREN = PBOR_ON          // PBOR Enable (Enabled)
#pragma config LPOL = PWMxL_ACT_HI      // Low-side PWM Output Polarity (Active High)
#pragma config HPOL = PWMxH_ACT_HI      // High-side PWM Output Polarity (Active High)
#pragma config PWMPIN = RST_IOPIN       // PWM Output Pin Reset (Control with PORT/TRIS regs)
#pragma config MCLRE = MCLR_DIS         // Master Clear Enable (Disabled)

// FGS
#pragma config GWRP = GWRP_OFF          // General Code Segment Write Protect (Disabled)
#pragma config GCP = CODE_PROT_OFF      // General Segment Code Protection (Disabled)

// FICD
#pragma config ICS = ICS_PGD            // Comm Channel Select (Use PGC/EMUC and PGD/EMUD)

// Configuration settings
_FOSC(CSW_FSCM_OFF & FRC_PLL16); // Fosc=16x7.5MHz, Fcy=30MHz
_FWDT(WDT_OFF);                  // Watchdog timer off
_FBORPOR(MCLR_DIS);              // Disable reset pin

int main(){
// ... code continues here

Altered code:

main.c
#include 
#include 
#include "config.h"
#include 

int main(){
// ... code continues here
config.h
// FOSC
#pragma config FPR = XT_PLL4            // Primary Oscillator Mode (XT w/PLL 4x)
#pragma config FOS = PRI                // Oscillator Source (Primary Oscillator)
#pragma config FCKSMEN = CSW_FSCM_OFF   // Clock Switching and Monitor (Sw Disabled, Mon Disabled)

// FWDT
#pragma config FWPSB = WDTPSB_16        // WDT Prescaler B (1:16)
#pragma config FWPSA = WDTPSA_512       // WDT Prescaler A (1:512)
#pragma config WDT = WDT_OFF            // Watchdog Timer (Disabled)

// FBORPOR
#pragma config FPWRT = PWRT_64          // POR Timer Value (64ms)
#pragma config BODENV = BORV20          // Brown Out Voltage (Reserved)
#pragma config BOREN = PBOR_ON          // PBOR Enable (Enabled)
#pragma config LPOL = PWMxL_ACT_HI      // Low-side PWM Output Polarity (Active High)
#pragma config HPOL = PWMxH_ACT_HI      // High-side PWM Output Polarity (Active High)
#pragma config PWMPIN = RST_IOPIN       // PWM Output Pin Reset (Control with PORT/TRIS regs)
#pragma config MCLRE = MCLR_DIS         // Master Clear Enable (Disabled)

// FGS
#pragma config GWRP = GWRP_OFF          // General Code Segment Write Protect (Disabled)
#pragma config GCP = CODE_PROT_OFF      // General Segment Code Protection (Disabled)

// FICD
#pragma config ICS = ICS_PGD            // Comm Channel Select (Use PGC/EMUC and PGD/EMUD)

1 comment to Microchip MPLAB X – Link Error: region is full / section overlaps section

  • Stephen

    Hi

    I eventually took the advice of others on the Microchip forum, and replaced the config “.h” file with a “.c” file.

    There is no way a .c file can be processed twice; doing this helped me a lot.

    So I have one file called “FUSES.c”, and that counts as part of the project “source files”.

    Regards
    Stephen.

    ===
    /**********************************************************************************************************************************

    Project : USB Interrupt Example
    Copyright : S.Bernhoeft 2011
    Filename : FUSES.c
    Function : PIC Configuration fuse settings
    Reference :
    Target : PIC
    Author :
    Created : 22-09-2011
    Version : 0.01

    Revision History
    Ver Date ECR/tag By Change
    0.01 22-09-2011 SB Original

    Notes

    ***********************************************************************************************************************************/

    #include

    #if defined(__PIC24FJ256GB206__)
    // CONFIG3
    /*

    */

    #pragma config WPFP = WPFP255 // Write Protection Flash Page Segment Boundary (Highest Page (same as page 170))
    #pragma config SOSCSEL = SOSC // Secondary Oscillator Power Mode Select (Secondary oscillator is in Default (high drive strength) Oscillator mode)
    #pragma config WUTSEL = LEG // Voltage Regulator Wake-up Time Select (Default regulator start-up time is used)
    #pragma config ALTPMP = ALPMPDIS // Alternate PMP Pin Mapping = default. (N/A to 64-pin devices)
    #pragma config WPDIS = WPDIS // Segment Write Protection Disable (Segmented code protection is disabled)
    #pragma config WPCFG = WPCFGDIS // Write Protect Configuration Page Select (Last page (at the top of program memory) and Flash Configuration Words are not write-protected)
    #pragma config WPEND = WPENDMEM // Segment Write Protection End Page Select (Protected code segment upper boundary is at the last page of program memory; the lower boundary is the code page specified by WPFP)

    // CONFIG2
    #pragma config POSCMOD = HS // Primary Oscillator Select (HS Oscillator mode is selected)
    #pragma config IOL1WAY = OFF // IOLOCK bit can be set and cleared as needed
    #pragma config OSCIOFNC = ON // OSCO Pin Configuration (OSCO/CLKO/RC15 functions as port I/O (RC15))
    #pragma config FCKSM = CSDCMD // Clock Switching and Fail-Safe Clock Monitor (Clock switching and Fail-Safe Clock Monitor are disabled)
    #pragma config FNOSC = PRIPLL // Initial Oscillator Select (Primary Oscillator with PLL module (XTPLL, HSPLL, ECPLL))
    #pragma config PLL96MHZ = ON // 96MHz PLL Startup Select (96 MHz PLL is enabled automatically on start-up)
    #pragma config PLLDIV = DIV2 // 96 MHz PLL Prescaler Select (Oscillator input is divided by 2 (8 MHz input))
    #pragma config IESO = OFF // Internal External Switchover (IESO mode (Two-Speed Start-up) is disabled)

    // CONFIG1
    #pragma config WDTPS = PS32768 // Watchdog Timer Postscaler (1:32,768)
    #pragma config FWPSA = PR128 // WDT Prescaler (Prescaler ratio of 1:128)
    #pragma config WINDIS = OFF // Windowed WDT (Standard Watchdog Timer enabled,(Windowed-mode is disabled))
    #pragma config FWDTEN = OFF // Watchdog Timer (Watchdog Timer is disabled)
    #pragma config ICS = PGx2 // Emulator Pin Placement Select bits (Emulator functions are shared with PGEC2/PGED2)
    #pragma config GWRP = OFF // General Segment Write Protect (Writes to program memory are allowed)
    #pragma config GCP = OFF // General Segment Code Protect (Code protection is disabled)
    #pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled)
    #else
    #error Not a supported hardware platform
    #endif

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>