XC32 program does not work

This forum handles questions and discussions concerning Microchip’s 32-bit compilers, assemblers, linkers and related tools for PIC32 MCUs.

XC32 program does not work

Postby ogremage » Sun Apr 30, 2017 9:13 pm

Again, I'm facing this issue. I've got PIC32MX534F064H and a very basic led blinking program:

Code: Select all
//#include <p32xxxx.h> // for C32
#include <xc.h> // for XC32

#pragma config FPLLIDIV = DIV_2 // PLL Input Divider
#pragma config FPLLMUL = MUL_20 // PLL Multiplier
#pragma config UPLLIDIV = DIV_2 // USB PLL Input Divider (POSC = 8 Mhz, USB must be supplied with 4 Mhz)
#pragma config UPLLEN = ON // USB PLL Enabled
#pragma config FPLLODIV = DIV_1 // System PLL Output Clock Divider

#pragma config FNOSC = PRIPLL // Oscillator Selection - primary OSC w/Pll (XT+,HS+,EC+PLL)
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (KLO was off)
#pragma config IESO = OFF // Internal/External Switch-over
#pragma config POSCMOD = HS // Primary Oscillator Configuration - HS osc mode

#pragma config OSCIOFNC = OFF // CLKO Output signal active on the OSCO Pin
#pragma config FPBDIV = DIV_2 // Peripheral Clock divisor
#pragma config FCKSM = CSDCMD // Clock Switching & Monitor Selection - Clk Switch enable, FSCM disable

#pragma config WDTPS = PS1 // Watchdog Timer Postscale - 1:1
#pragma config FWDTEN = OFF // Watchdog Timer Enable

#pragma config CP = OFF // Code Protect
#pragma config BWP = OFF // Boot Flash Write Protect
#pragma config PWP = OFF // Program Flash Write Protect
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select
#pragma config DEBUG = ON // Background Debugger Enable

int main ( void )
{
    TRISDbits.TRISD6 = 0; // LED 1
    TRISGbits.TRISG6 = 0; // LED 2

    while (1) {
        LATDbits.LATD6 = 1;
        LATGbits.LATG6 = 0;
    }
}


It runs successfully when is compiled with C32 compiler and goes into an endless reboot cycle, when is compiled with XC32. I didn't change anything in both compilers' settings. But there must be a subtle difference between them that affects my program. Or it's just a pure black magic.
I certainly can go along with an older C32, but I want to test Harmony framework, and it supports only XC32, as far as I know. Btw, when I load a sample harmony project (CDC), MCU doesn't go into reboot, but it just ignores my code and always fires both LEDs, even if I force them to be off in the program.

MplabX version: 3.60
XC32 version: 1.43
ogremage
 
Posts: 4
Joined: Sun Apr 30, 2017 9:05 pm
PIC experience: Professional 1+ years with MCHP products

Re: XC32 program does not work

Postby ric » Sun Apr 30, 2017 9:26 pm

I don't know if this is your problem, but you should NOT write to the DEBUG bit yourself. Let the tools manage it.

Code: Select all
#pragma config DEBUG = ON // Background Debugger Enable
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: XC32 program does not work

Postby ogremage » Sun Apr 30, 2017 9:50 pm

Nope, still the same.
ogremage
 
Posts: 4
Joined: Sun Apr 30, 2017 9:05 pm
PIC experience: Professional 1+ years with MCHP products

Re: XC32 program does not work

Postby AussieSusan » Mon May 01, 2017 3:55 am

Are you compiling for release or debug?
Are you keeping the programmer connected?
Have you allowed the programmer to release the \MCLR\ line (or is the programmer keeping the device in reset)?
How do you know that it is an endless reboot cycle?
Susan
AussieSusan
Verified identity
 
Posts: 173
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: XC32 program does not work

Postby ogremage » Mon May 01, 2017 6:04 am

I don't know whether it's release or debug :D
It was easy to figure it out in old Mplab, but in MplabX it's not so obvious. But I find hex file under `production` folder, so I think it's release.
I'm using a bootloader from `mikroElektronika`, because it's their dev-board. So it's identified as a USB device in my PC, and when I upload a bad program, I hear an endless sequence of Windows' usb attachment/removal sound: *tu-dum*.

Btw, there's another branch of this topic on Microchip's forum: www.microchip.com/forums/m988992.aspx
ogremage
 
Posts: 4
Joined: Sun Apr 30, 2017 9:05 pm
PIC experience: Professional 1+ years with MCHP products

Re: XC32 program does not work

Postby vloki » Mon May 01, 2017 11:12 am

ogremage wrote:It was easy to figure it out in old Mplab, but in MplabX it's not so obvious. But I find hex file under `production` folder, so I think it's release.
I'm using a bootloader from `mikroElektronika`, because it's their dev-board.

I think with MPLABX it is more easy and obvious to build in release or debug mode.
Click the drop down menu at the build tools in the main toolbar...
http://microchipdeveloper.com/mplabx:file-menu

Are you sure that you fulfill all the additional requirements for the bootloader?
Are there any examples from mikroElectronica to set up a project suitable for their bootloader with xc compiler?
I you use a bootloader you possibly should right click on the top node of the project you wish to build
(this is the "chip" icon in the project tree) and select "Export Hex" from the popup menu.
vloki
Verified identity
 
Posts: 186
Joined: Wed May 28, 2014 8:42 am
Location: Germany
PIC experience: Professional 5+ years with MCHP products

Re: XC32 program does not work

Postby ogremage » Mon May 01, 2017 7:38 pm

I'm starting to think that I have MplabX version from parallel universe :D
I didn't find any signs of either debug or release build and didn't find "Export hex" menu.
Nevertheless, the problem is now solved. I've just used PICkit3 instead of bootloader :)
Still it's a mystery for me, why it works with C32 and can not with XC32 (did C32 have special linker file?), but that doesn't matter anymore.
ogremage
 
Posts: 4
Joined: Sun Apr 30, 2017 9:05 pm
PIC experience: Professional 1+ years with MCHP products


Return to MPLAB XC32

Who is online

Users browsing this forum: No registered users and 1 guest

cron