Helpful ReplyHot!dsPIC33FJ32MC304 problems debugging with PicKit3?

Page: 123 > Showing page 1 of 3
Author
twelve12pm
Overseer
  • Total Posts : 320
  • Reward points : 0
  • Joined: 2012/04/09 17:27:24
  • Location: 0
  • Status: offline
2018/05/07 07:04:26 (permalink)
0

dsPIC33FJ32MC304 problems debugging with PicKit3?

Does dsPIC33FJ32MC304 support debugging (single-stepping, placing breakpoints, etc.) with PicKit3?
 
It seems I am able to use the PicKit3 as a programmer to program a release executable -- which is NOT working -- and I am NOT able to use the PicKit3 as a debugger to program a debug executable and do any debugging. I get all sorts of errors and weird behavior that seem to suggest a failure to communicate with the device.
 
Sometimes we can erase the device but I have a feeling the PicKit does not actually check if the device is erased or not. It only reports that it erased successfully. Sometimes it is stuck on "PICkit3 detected. Connecting to PICkit3..." and it never gets anywhere. The PicKit3 status light is red. Sometimes it tries to program but comes back saying the infamous "The following memory regions failed to program correctly: Program Memory Address: 00000000 Expected Value: 00001303 Received Value: 00000000 Programming failed"
 
Connections to the device:
 
PicKit pin 1 MCLR is connected to device pin 18 MCLR. It is pulled up to the board's VCC through a 4.7k ohm resistor.
 
PicKit pin 2 VCC is connected to the board's VCC (3.3v)
 
PicKit pin 3 GND is connected to the board's GND
 
PicKit pin 4 PGED is connected to the device pin 21 PGED1
 
PicKit pin 5 PGEC is connected to the device pin 22 PGEC1
 
PicKit pin 6 LVP is not connected at all.
 
Other than the 4.7k ohm pull-up on MCLR, there are no other resistors, capacitors, diodes, or anything else, on the MCLR, PGED, PGEC lines.
 
There is no external clock or oscillator. Pins 30/OSC1 and 31/OSC2 are not connected to anything. We intend to startup with the internal 7.37 MHz FRC and during software initialization switch to 40 MHz Fcy/Fp using this code:
 

  // Use internal 7.37 MHz FRC with PLL to achieve:
  // 40 MHz CPU clock (Fcy)
  // 40 MHz Peripheral clock (Fp)
  CLKDIVbits.FRCDIV = 0; // Internal Fast RC oscillator divide by 1 (7.37 MHz)
  CLKDIVbits.PLLPRE = 1; // N1 PLL prescaler = 3 (divide input clock of 7.37 MHz by 3 to give 2.463 MHz)
  CLKDIVbits.PLLPOST = 0; // N2 PLL postscaler = 2 (divide 160.12 MHz by 2 to give 80.05 MHz Fosc = 40 MHz Fcy and 40 MHz Fp)
  PLLFBDbits.PLLDIV = 63; // M PLL multiplier = 65 (multiply 2.463 MHz by 65 to give 160.12 MHz)

  // Wait for new clock to stabilize
  while (OSCCONbits.OSWEN) {
  }

 
But I believe we never get that far because we can't seem to put the code in the device.
 
This is a new custom board. Tool version: MPLAB IDE 8.90.
 
Configuration bits:
 

// Register FBS (0xf80000):
// - Boot Segment may be written
// - No Boot program Flash segment
_FBS(BWRP_WRPROTECT_OFF & BSS_NO_BOOT_CODE)


// Register FGS (0xf80004):
// - User program memory is not write-protected
// - User program memory is not code-protected
_FGS(GWRP_OFF & GCP_OFF)


// Register FOSCSEL (0xf80006):
// - FNOSC_FRC Internal Fast RC (FRC)
// - IESO_OFF Start-up device with user-selected oscillator source
_FOSCSEL(FNOSC_FRC & IESO_OFF)


// Register FOSC (0xf80008):
// - Primary oscillator disabled (using internal FRC)
// - OSC2 pin is general purpose I/O
// - Peripheral Pin Select: Allow multiple reconfigurations
// - Clock switching is enabled, Fail-Safe Clock Monitor is disabled
_FOSC(POSCMD_NONE & OSCIOFNC_ON & IOL1WAY_OFF & FCKSM_CSECMD)


// Register FWDT (0xf8000a):
// - Watchdog Timer enabled/disabled by user software
_FWDT(FWDTEN_OFF)


// Register FPOR (0xf8000c):
// - POR Timer Disabled (no delay at power up)
// - I2C mapped to SDA1/SCL1 pins
// - PWM module low side output pins have active-high output polarity
// - PWM module high side output pins have active-high output polarity
// - PWM module pins controlled by PORT register at device Reset
_FPOR(FPWRT_PWR128 & ALTI2C_OFF & LPOL_ON & HPOL_ON & PWMPIN_ON)


// Register FICD (0xf8000e):
// - Communicate on PGC1/EMUC1 and PGD1/EMUD1
// - JTAG is Disabled
_FICD(ICS_PGD1 & JTAGEN_OFF)

 
Any help is appreciated very much.
#1
du00000001
Just Some Member
  • Total Posts : 2075
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 07:23:52 (permalink)
0
Might help if you provide the messages displayed during programming (whether successful or not) with the PICkit3.
 
Basically the dsPIC33FJ32MC304 should be programmable and debuggable with the PICkit - not sure about MPLAB 8.x. (I'm using MPLAB X - no problems other than the occasional user's error.)

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#2
NKurzman
A Guy on the Net
  • Total Posts : 16281
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 07:33:12 (permalink)
0
What version of MPLab?
#3
twelve12pm
Overseer
  • Total Posts : 320
  • Reward points : 0
  • Joined: 2012/04/09 17:27:24
  • Location: 0
  • Status: offline
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 08:09:55 (permalink)
0
NKurzman
What version of MPLab?



I said in my original post: MPLAB IDE 8.90.
 
#4
twelve12pm
Overseer
  • Total Posts : 320
  • Reward points : 0
  • Joined: 2012/04/09 17:27:24
  • Location: 0
  • Status: offline
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 08:12:44 (permalink)
0
du00000001
Might help if you provide the messages displayed during programming (whether successful or not) with the PICkit3.

 
I will soon.
 
Other posts about similar issues suggest that the pull-up on MCLR should not be stronger than 10k. We are changing our 4.7k to a 10k and will try again shortly. 
 
du00000001
Basically the dsPIC33FJ32MC304 should be programmable and debuggable with the PICkit - not sure about MPLAB 8.x. (I'm using MPLAB X - no problems other than the occasional user's error.)



Thank you for confirming that.
 
#5
du00000001
Just Some Member
  • Total Posts : 2075
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 08:18:25 (permalink)
0
The 4k7 might be an issue. The same applies if your wire harness between PICkit3 and the board is too long.
(Please don't ask how long is too long - depends on the wires/cables, wire routing and more. Cutting the wires in half sometimes solves issues.)

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#6
twelve12pm
Overseer
  • Total Posts : 320
  • Reward points : 0
  • Joined: 2012/04/09 17:27:24
  • Location: 0
  • Status: offline
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 08:32:00 (permalink)
0
du00000001
Basically the dsPIC33FJ32MC304 should be programmable and debuggable with the PICkit - not sure about MPLAB 8.x. (I'm using MPLAB X - no problems other than the occasional user's error.)



I should mention that we have been using MPLAB 8.90 for as long as I can remember. We are only using several dsPIC33 and PIC32MX parts that have been fully supported by this version of MPLAB (like this dsPIC33FJ32MC304 part today). To double-check, I looked at the release notes for MPLAB 8.90 and they do state that dsPIC33FJ32MC304 is supported (Green/Yes) for PicKit3 Debug and PicKit3 Programming. I don't see anything in the notes to raise any red flags -- and the reason we chose this device is because it was used in a prior product which means the schematics and most of the software code are already known. I believe today's problem is not caused by the IDE.
 
#7
twelve12pm
Overseer
  • Total Posts : 320
  • Reward points : 0
  • Joined: 2012/04/09 17:27:24
  • Location: 0
  • Status: offline
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 08:33:11 (permalink)
0
du00000001
The 4k7 might be an issue. The same applies if your wire harness between PICkit3 and the board is too long.
(Please don't ask how long is too long - depends on the wires/cables, wire routing and more. Cutting the wires in half sometimes solves issues.)



We are making some changes :-)
 
I'll be back soon to report on the outcome.
 
#8
du00000001
Just Some Member
  • Total Posts : 2075
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 08:55:37 (permalink)
0
If you already had a board with the dsPIC33FJ32MC304, it would be wise to check whether the current "problem board" has changes that would be related to the programming interface (routing, the pullup already identified, but also e.g. buffer capacitors).
Seeing forward to your report...

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#9
twelve12pm
Overseer
  • Total Posts : 320
  • Reward points : 0
  • Joined: 2012/04/09 17:27:24
  • Location: 0
  • Status: offline
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 08:56:59 (permalink)
0
du00000001
Might help if you provide the messages displayed during programming (whether successful or not) with the PICkit3.

 
We changed the MCLR pull-up to 10k ohm.
 
We noticed a problem with the USB cable from the computer to the PicKit3. Shaking the PicKit3 caused it to connect/disconnect from the computer. Changing the USB cable resolved this.
 
We changed the connection from the PicKit3 to the MCU. This is a 6-inch flat cable with good connections on both ends. Once in the board, the signals travel 250 mil from the debug connector to the MCU pins.
 
This is a Debug build configuration. Attempting to program for debugging printed these messages:
 

PICkit 3 detected
Connecting to PICkit 3...
Running self test...
Self test completed
Firmware Suite Version...... 01.28.56
Firmware type......................dsPIC33F/24F/24H
PICkit 3 Connected.
PK3Err0045: You must connect to a target device to use PICkit 3.
Resetting...
Target Detected
Device ID Revision = 00003004
Erasing...
Erase device complete
Programming...
PK3Err0037: Timed out waiting for response from PICkit 3
Programming failed

 
#10
du00000001
Just Some Member
  • Total Posts : 2075
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 09:05:16 (permalink)
0
PK3Err0037: Timed out waiting for response from PICkit 3

 
Seems you still have an issue with the USB. OR the overall computing load on your machine is too high.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#11
Gort2015
Klaatu Barada Nikto
  • Total Posts : 2645
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 09:19:19 (permalink)
0
vcap/vddcore cap. connected?

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#12
twelve12pm
Overseer
  • Total Posts : 320
  • Reward points : 0
  • Joined: 2012/04/09 17:27:24
  • Location: 0
  • Status: offline
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 09:30:45 (permalink)
0
Gort2015
vcap/vddcore cap. connected?



Like this:
 
 

Attached Image(s)

#13
twelve12pm
Overseer
  • Total Posts : 320
  • Reward points : 0
  • Joined: 2012/04/09 17:27:24
  • Location: 0
  • Status: offline
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 10:06:12 (permalink)
0
du00000001
Might help if you provide the messages displayed during programming (whether successful or not) with the PICkit3.

 
We noticed another thing. Suppose we switch from Debug to just Programming. We can load a program and it runs (verified by toggling a GPIO pin to produce a square wave). Attempting to program again (make a change, compile, program) consistently produces:
 
Programming...
Programming failed
 
Until we first Erase Flash Device.
 
I remember, in the past, being able to program and reprogram all day long without having to Erase Flash Device.
#14
du00000001
Just Some Member
  • Total Posts : 2075
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 11:42:24 (permalink)
0
I remember, in the past, being able to program and reprogram all day long without having to Erase Flash Device.

 
Your memory is somewhat imperfect:
Such systems existed (called "emulators"), but required much more hardware than a single Flash microcontroller (at least no PICs of any color).

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#15
twelve12pm
Overseer
  • Total Posts : 320
  • Reward points : 0
  • Joined: 2012/04/09 17:27:24
  • Location: 0
  • Status: offline
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 12:51:24 (permalink)
0
du00000001
I remember, in the past, being able to program and reprogram all day long without having to Erase Flash Device.

 
Your memory is somewhat imperfect:
Such systems existed (called "emulators"), but required much more hardware than a single Flash microcontroller (at least no PICs of any color).




Fair enough. In any event, once we solved various connector/cable issues, we are able to use PicKit3 for Programming only and are able to repeatably Erase Flash Device followed by Program. We are still unable to use PicKit3 for Debugging. I cannot figure out what it is about our setup that prevents that. There is no complicated routing (the MCU PGC/PGD pins are literally right next to the programming connector pins with no vias or other obstacles in the way). We have three boards. We changed the 4.7k ohm resistor to 10k ohm on one of the boards and it made no difference. I can consistently Program both the 4.7k and the 10k ohm boards (but not Debug).
 
The configuration fuses and clock setup code have changed slightly since I first posted.
 
Configuration fuses:
 
 
// Register FBS (0xf80000):
// - Boot Segment may be written
// - No Boot program Flash segment
_FBS(BWRP_WRPROTECT_OFF & BSS_NO_BOOT_CODE)


// Register FGS (0xf80004):
// - User program memory is not write-protected
// - User program memory is not code-protected
_FGS(GWRP_OFF & GCP_OFF)


// Register FOSCSEL (0xf80006):
// - FNOSC_FRC Internal Fast RC (FRC)
// - IESO_OFF Start-up device with user-selected oscillator source
_FOSCSEL(FNOSC_FRC & IESO_OFF)


// Register FOSC (0xf80008):
// - Primary oscillator disabled (using internal FRC)
// - OSC2 pin is general purpose I/O
// - Peripheral Pin Select: Allow multiple reconfigurations
// - Clock switching is enabled, Fail-Safe Clock Monitor is disabled
_FOSC(POSCMD_NONE & OSCIOFNC_ON & IOL1WAY_OFF & FCKSM_CSECMD)


// Register FWDT (0xf8000a):
// - Watchdog Timer enabled/disabled by user software
_FWDT(FWDTEN_OFF)


// Register FPOR (0xf8000c):
// - POR Timer Disabled (no delay at power up)
// - I2C mapped to SDA1/SCL1 pins
// - PWM module low side output pins have active-high output polarity
// - PWM module high side output pins have active-high output polarity
// - PWM module pins controlled by PORT register at device Reset
_FPOR(FPWRT_PWR1 & ALTI2C_OFF & LPOL_ON & HPOL_ON & PWMPIN_ON)


// Register FICD (0xf8000e):
// - Communicate on PGC1/EMUC1 and PGD1/EMUD1
// - JTAG is Disabled
_FICD(ICS_PGD1 & JTAGEN_OFF)

 
In particular we are now using _FOSCSEL(FNOSC_FRC & IESO_OFF) to startup with FRC without PLL.
 
Later we set up the PLL and switch to FRC + PLL as follows:
 
  // Use internal 7.37 MHz FRC with PLL to achieve:
  // 40 MHz CPU clock (Fcy)
  // 40 MHz Peripheral clock (Fp)
  CLKDIVbits.FRCDIV = 0; // Internal Fast RC oscillator divide by 1 (7.37 MHz)
  CLKDIVbits.PLLPRE = 1; // N1 PLL prescaler = 3 (divide input clock of 7.37 MHz by 3 to give 2.463 MHz)
  CLKDIVbits.PLLPOST = 0; // N2 PLL postscaler = 2 (divide 160.12 MHz by 2 to give 80.05 MHz Fosc = 40 MHz Fcy and 40 MHz Fp)
  PLLFBDbits.PLLDIV = 63; // M PLL multiplier = 65 (multiply 2.463 MHz by 65 to give 160.12 MHz)

  // Writing to OSCCON requires using compiler intrinsics
  __builtin_write_OSCCONH(0x01); // NOSC = 1, Fast RC (FRC) oscillator with divide-by-N and PLL (FRCDIVN + PLL)
  __builtin_write_OSCCONL(OSCCON | 0x1); // OSWEN: Oscillator Switch Enable bit

  // Wait for new clock to stabilize
  while (OSCCONbits.OSWEN) {
  }

 
This adds the calls to the compiler intrinsics to write to OSCCON.
 
(Strange observation: I copied the originally posted clock setup code as from a prior product, where it worked without the writes to OSCCON. Was it starting up with FRC+PLL with some default PLL settings and then changing the PLL settings? I thought one must first switch to FRC, then mess with the PLL, then switch back to FRC+PLL. Weird.)
 
Also earlier I played with the POR timer, using various values from none to 128 ms. From another forum post I gathered that it should be none so I returned it to that setting.
 
I'm really not sure what to check next. It's great that we can at least program the silly thing, but there is some new code that I need to breakpoint and verify that registers look okay, etc.
 
Incidentally, what voltages are supposed to be present on MCLR during Debug? Earlier the oscilloscope showed some 10V signal on that line. Does that seem correct?
 
Possibly dumb question: Does the JTAG interface need to be enabled? I.e., currently we have _FICD(ICS_PGD1 & JTAGEN_OFF). Should that be changed to _FICD(ICS_PGD1 & JTAGEN_ON)?
 
#16
du00000001
Just Some Member
  • Total Posts : 2075
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 13:20:24 (permalink)
0
At least in MPLAB X there exists another set of fuse settings that IMHO overwrite the settings compiled when the HEX file is loaded post linking. If such a set exists hat enables another debug interface - - - or if debugging is disabled (another option bit) . . . then you sholdn't wonder . . .

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#17
qɥb
Monolothic Member
  • Total Posts : 3329
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 13:42:58 (permalink)
0

PK3Err0045: You must connect to a target device to use PICkit 3.

This message implies that the connection on the PK3's "VDD" pin is faulty.




This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#18
twelve12pm
Overseer
  • Total Posts : 320
  • Reward points : 0
  • Joined: 2012/04/09 17:27:24
  • Location: 0
  • Status: offline
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 13:43:59 (permalink)
0
du00000001
At least in MPLAB X there exists another set of fuse settings that IMHO overwrite the settings compiled when the HEX file is loaded post linking. If such a set exists hat enables another debug interface - - - or if debugging is disabled (another option bit) . . . then you sholdn't wonder . . .




I checked for that already. :-)
 
In MPLAB 8.90 that is this window (see attached), and as you can see in the image "Configuration bits set in code" is selected and the window is grayed out. If you de-select that check mark, the window turns white and you can play with configuration bits.
 

Attached Image(s)

#19
du00000001
Just Some Member
  • Total Posts : 2075
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: online
Re: dsPIC33FJ32MC304 problems debugging with PicKit3? 2018/05/07 13:53:27 (permalink)
0
In your very first post, JTAGEN is set to OFF!
I doubt that you can expect to debug while it is off :)

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#20
Page: 123 > Showing page 1 of 3
Jump to:
© 2018 APG vNext Commercial Version 4.5