module for using ICD debuggers - mplabicd.bas

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
Jerry Messina
Swordfish Developer
Posts: 1245
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

module for using ICD debuggers - mplabicd.bas

Post by Jerry Messina » Thu Oct 02, 2014 3:29 pm

I thought I had posted this before, but if I did I can't seem to find it...

The wiki entry In-Circuit Debugging (ICD) with MPLAB describes the basic steps for using one of the hardware debuggers (PICKit2/3, ICD3, or RealIce) with Swordfish and MPLAB.
This module is an extension to that which takes care of the settings for all the devices supported by Swordfish (as of MPLAB 8.92)

Here's an example of how you would use it in your main program module

Code: Select all

device = 18F26K22

// set the option to enable use of an ICD debugger
// include this before all others 
#option MPLAB_ICD = true
include mplabicd.bas
Here's the module, which can be placed in your UserLibrary folder
mplabicd.bas

Code: Select all

//
//------------------------------------------------------------------------------
// Name    : mplabicd.bas
// Author  : Jerry Messina
// Date    : 10/4/2014
// Version : 1.3
// Notes   :
//   MPLAB ICD settings
// ver 1.1
//  - correct entries for 18F13K22, 18F14K22, 18F13K50, 18F14K50
// ver 1.2
//  - add new K50 and 18FxxJ94 family
//  - device list from MPLAB 8.92
// ver 1.3
//  - correct WDTEN list (devices were missing)
//------------------------------------------------------------------------------
//
module mplabicd

//
// to use ICD, set '#option MPLAB_ICD = true' in the main program module
// before you include this file
//

// set default (ICD not used)
#option MPLAB_ICD = false

#if IsOption(MPLAB_ICD) and (MPLAB_ICD = true)

//
// By default, high priority interrupts use the hardware shadow registers for
// context saving the WREG, STATUS, and BSR registers, and low priority interrupts
// save them using software. The hardware shadow registers can get corrupted when
// placing a breakpoint inside an ISR.
// You can force the compiler to perform software context saving in software for both
// high and low interrupts rather than using hardware shadow registers by using the
// ISR_SHADOW option:
//      #option ISR_SHADOW = false
// This disables all hardware shadow register context saving and lets you use
// breakpoints in an ISR
// NOTE: since this changes the way isr's work, it is up to the user to set this option
//
'#option ISR_SHADOW = false
#if IsOption(ISR_SHADOW) and (ISR_SHADOW = false)
  #warning "disabling hardware shadow registers"
#endif

//
// ICD resources (device dependant)
// most devices require program memory space to hold a debug executive
// pretty much all devices require 12 bytes of ram at the top of memory, so we'll just
// set it as a default. devices that don't require any ram can set it to 0
//
#variable ICD_RAM = $0c

// device list from MPLAB 8.92 (240 devices)
// standard 18F devices (108 devices)
#if _device in (18F242, 18F248, 18F252, 18F258, 18F442, 18F448, 18F452, 18F458)
  #define ICD_ROM = $240
#elseif _device in (18F1220, 18F1230, 18F1320, 18F1330)
  #define ICD_ROM = $1c0
#elseif _device in (18F2220, 18F2221, 18F2320, 18F2321, 18F2331, 18F2410, 18F2420, 18F2423)
  #define ICD_ROM = $240
#elseif _device in (18F2431, 18F2439, 18F2450, 18F2455, 18F2458, 18F2480, 18F2510, 18F2520)
  #define ICD_ROM = $240
#elseif _device in (18F2523, 18F2539, 18F2550, 18F2553, 18F2580)
  #define ICD_ROM = $240
#elseif _device in (18F2515, 18F2525, 18F2585, 18F2610, 18F2620, 18F2680, 18F2682, 18F2685)
  #define ICD_ROM = $280
#elseif _device in (18F4220, 18F4221, 18F4320, 18F4321, 18F4331, 18F4410, 18F4420, 18F4423)
  #define ICD_ROM = $240
#elseif _device in (18F4431, 18F4439, 18F4450, 18F4455, 18F4458, 18F4480, 18F4510, 18F4520)
  #define ICD_ROM = $240
#elseif _device in (18F4523, 18F4539, 18F4550, 18F4553, 18F4580)
  #define ICD_ROM = $240
#elseif _device in (18F4515, 18F4525, 18F4585, 18F4610, 18F4620, 18F4680, 18F4682, 18F4685)
  #define ICD_ROM = $280
#elseif _device in (18F6310, 18F6390, 18F6393, 18F6410, 18F6490, 18F6493)
  #define ICD_ROM = $240
#elseif _device in (18F6520, 18F6525, 18F6527, 18F6585, 18F6620, 18F6621, 18F6622, 18F6627)
  #define ICD_ROM = $280
#elseif _device in (18F6628, 18F6680, 18F6720, 18F6722, 18F6723)
  #define ICD_ROM = $280
#elseif _device in (18F8310, 18F8390, 18F8393, 18F8410, 18F8490, 18F8493)
  #define ICD_ROM = $240
#elseif _device in (18F8520, 18F8525, 18F8527, 18F8585, 18F8620, 18F8621, 18F8622, 18F8627)
  #define ICD_ROM = $280
#elseif _device in (18F8628, 18F8680, 18F8720, 18F8722, 18F8723)
  #define ICD_ROM = $280

// J series devices (91 devices)
// these require no program memory, but some of them use ram
#elseif _device in (18F24J10, 18F25J10, 18F44J10, 18F45J10)
  #define ICD_ROM = 0
#elseif _device in (18F24J11, 18F24J50, 18F25J11, 18F25J50, 18F26J11, 18F26J13, 18F26J50, 18F26J53, 18F27J13, 18F27J53)
  #define ICD_ROM = 0
  #variable ICD_RAM = 0
#elseif _device in (18F44J11, 18F44J50, 18F45J11, 18F45J50, 18F46J11, 18F46J13, 18F46J50, 18F46J53, 18F47J13, 18F47J53)
  #define ICD_ROM = 0
  #variable ICD_RAM = 0
#elseif _device in (18F63J11, 18F63J90, 18F64J11, 18F64J90, 18F65J10, 18F65J11, 18F65J15, 18F65J50)
  #define ICD_ROM = 0
#elseif _device in (18F65J90, 18F66J10, 18F66J11, 18F66J15, 18F66J16, 18F66J50, 18F66J55, 18F66J60)
  #define ICD_ROM = 0
#elseif _device in (18F66J65, 18F67J10, 18F67J11, 18F67J50, 18F67J60)
  #define ICD_ROM = 0
#elseif _device in (18F66J90, 18F66J93, 18F67J90, 18F67J93)
  #define ICD_ROM = 0
  #variable ICD_RAM = 0
#elseif _device in (18F83J11, 18F83J90, 18F84J11, 18F84J90, 18F85J10, 18F85J11, 18F85J15, 18F85J50)
  #define ICD_ROM = 0
#elseif _device in (18F85J90, 18F86J10, 18F86J11, 18F86J15, 18F86J16, 18F86J50, 18F86J55, 18F86J60)
  #define ICD_ROM = 0
#elseif _device in (18F86J65, 18F87J10, 18F87J11, 18F87J50, 18F87J60)
  #define ICD_ROM = 0
#elseif _device in (18F86J72, 18F86J90, 18F86J93, 18F87J72, 18F87J90, 18F87J93)
  #define ICD_ROM = 0
  #variable ICD_RAM = 0
#elseif _device in (18F96J60, 18F96J65, 18F97J60)
  #define ICD_ROM = 0
#elseif _device in (18F65J94, 18F85J94, 18F95J94, 18F66J94, 18F86J94, 18F96J94, 18F67J94, 18F87J94, 18F97J94)
  #define ICD_ROM = 0
  #variable ICD_RAM = 0
#elseif _device in (18F66J99, 18F86J99, 18F96J99)
  #warning "support marked preliminary in 892"
  #define ICD_ROM = 0
  #variable ICD_RAM = 0


// K series devices (41 devices)
// many of these require no program memory or ram
#elseif _device in (18F13K22, 18F14K22, 18F13K50, 18F14K50)
  #define ICD_ROM = $200
  #variable ICD_RAM = 0
#elseif _device in (18F23K20, 18F24K20, 18F25K20, 18F43K20, 18F44K20, 18F45K20)
  #define ICD_ROM = $240
#elseif _device in (18F26K20, 18F46K20)
  #define ICD_ROM = $280
#elseif _device in (18F23K22, 18F24K22, 18F25K22, 18F26K22, 18F25K80, 18F26K80, 18F43K22, 18F44K22, 18F45K22, 18F46K22)
   #define ICD_ROM = 0
   #variable ICD_RAM = 0
#elseif _device in (18F45K80, 18F46K80, 18F65K22, 18F65K80, 18F65K90, 18F66K22, 18F66K80, 18F66K90, 18F67K22, 18F67K90)
   #define ICD_ROM = 0
   #variable ICD_RAM = 0
#elseif _device in (18F85K22, 18F85K90, 18F86K22, 18F86K90, 18F87K22, 18F87K90)
   #define ICD_ROM = 0
   #variable ICD_RAM = 0
#elseif _device in (18F24K50, 18F25K50, 18F45K50)
   #define ICD_ROM = 0
   #variable ICD_RAM = 0

#else
  #error "unsupported ICD device"
#endif

// constrain ROM and RAM so they are not used by SF
#variable _maxrom = _maxrom - ICD_ROM
#variable _maxram = _maxram - ICD_RAM

//
// wdt must be off for icd
//
// these 127 devices use WDTEN instead of WDT
#if _device in( _
18F13K22, 18F13K50, 18F14K22, 18F14K50, 18F2331,  18F23K20, 18F23K22, 18F2431, _
18F24J10, 18F24J11, 18F24J50, 18F24K20, 18F24K22, 18F24K50, 18F25J10, 18F25J11, _
18F25J50, 18F25K20, 18F25K22, 18F25K50, 18F25K80, 18F26J11, 18F26J13, 18F26J50, _
18F26J53, 18F26K20, 18F26K22, 18F26K80, 18F27J13, 18F27J53, 18F4331,  18F43K20, _
18F43K22, 18F4431,  18F44J10, 18F44J11, 18F44J50, 18F44K20, 18F44K22, 18F45J10, _
18F45J11, 18F45J50, 18F45K20, 18F45K22, 18F45K50, 18F45K80, 18F46J11, 18F46J13, _
18F46J50, 18F46J53, 18F46K20, 18F46K22, 18F46K80, 18F47J13, 18F47J53, 18F63J11, _
18F63J90, 18F64J11, 18F64J90, 18F65J10, 18F65J11, 18F65J15, 18F65J50, 18F65J90, _
18F65J94, 18F65K22, 18F65K80, 18F65K90, 18F66J10, 18F66J11, 18F66J15, 18F66J16, _
18F66J50, 18F66J55, 18F66J90, 18F66J93, 18F66J94, 18F66J99, 18F66K22, 18F66K80, _
18F66K90, 18F67J10, 18F67J11, 18F67J50, 18F67J90, 18F67J93, 18F67J94, 18F67K22, _
18F67K90, 18F83J11, 18F83J90, 18F84J11, 18F84J90, 18F85J10, 18F85J11, 18F85J15, _
18F85J50, 18F85J90, 18F85J94, 18F85K22, 18F85K90, 18F86J10, 18F86J11, 18F86J15, _
18F86J16, 18F86J50, 18F86J55, 18F86J72, 18F86J90, 18F86J93, 18F86J94, 18F86J99, _
18F86K22, 18F86K90, 18F87J10, 18F87J11, 18F87J50, 18F87J72, 18F87J90, 18F87J93, _
18F87J94, 18F87K22, 18F87K90, 18F95J94, 18F96J94, 18F96J99, 18F97J94 _
)
  config WDTEN = off
#else       // assume standard WDT
  config WDT = off
#endif     // _device

// enable debug (not required... this is controlled by mplab)
'config DEBUG = ON
#endif      // MPLAB_ICD = true

end module

EDIT: correct WDTEN list (V1.3)
Attachments
mplabicd.zip
(2.22 KiB) Downloaded 159 times

bitfogav
Registered User
Registered User
Posts: 166
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Re: module for using ICD debuggers - mplabicd.bas

Post by bitfogav » Thu Oct 02, 2014 4:15 pm

Great Module Jerry. I think you will find it within the SFUSBv142 zip :)

Jerry Messina
Swordfish Developer
Posts: 1245
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: module for using ICD debuggers - mplabicd.bas

Post by Jerry Messina » Thu Oct 02, 2014 4:33 pm

Ahhh... THAT's where I put it.

Thanks.

Jerry Messina
Swordfish Developer
Posts: 1245
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: module for using ICD debuggers - mplabicd.bas

Post by Jerry Messina » Sat Oct 04, 2014 2:15 pm

Wouldn't you know it... as soon as I post it I find an error. Some devices were missing from the 'config WDTEN' list.

I corrected the original post and added an updated zip file

Jerry Messina
Swordfish Developer
Posts: 1245
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: module for using ICD debuggers - mplabicd.bas

Post by Jerry Messina » Sun Oct 16, 2016 1:49 pm

Here's an updated version (1.6) that adds support for the K40 and 18LF devices.
The device list should be current for mplabx 3.40

Code: Select all

// ver 1.4
//  - add support for Software Breakpoints (SWBP) and #option MPLAB_ICD_SWBP
//      this must be set by the user to enable the extra reserved resources
// ver 1.5
//  - add support for '_wdt_type' in new device files for WDT/WDTEN support
// ver 1.6
//  - device list from MPLABX 3.40
//  - add support for 18FxxK40 family (requires mplabx)
//  - add support for '_wdt_type = 4' for WDT/WDTE/WDTEN support
//  - add support for 18LF devices
Attachments
mplabicd_v16.zip
(2.82 KiB) Downloaded 131 times

Post Reply