Microchip USB Hid Bootloader & Swordfish

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
RangerBob
Posts: 152
Joined: Thu May 31, 2007 8:52 am
Location: Beds, UK

Microchip USB Hid Bootloader & Swordfish

Post by RangerBob » Fri Jan 22, 2010 11:21 am

Hello All,

Just posting some information in case anyone else encounters this type of problem whilst trying to use the Microchip USB HID Bootloader.

I've been using said bootloader for my latest project, using a 18F4550 and after a while started noticing odd behavior from Swordfish. For example, the program seemed to be working OK, but I could not get USBCDC to work. When I added a single DecToStr command to start using the LCD, the program would start exhibiting undefined behavior and crash badly.

After chasing what I thought was a compiler bug in DecToStr for a while (including having to buy a new copy of Swordfish thanks to our IT dept losing the original copy!), completely reinstalling Swordfish, and then on a blank machine, I was still completely stumped.

Anyway, thinking back I recalled having undefined behavior on the 18F87J50, using the HID Bootloader. It would seem that the HID Bootloader leaves a register(s) in a state that Swordfish does not expect for the 18f4550 as well; as such I have expanded my "ClearRegisters.bas" and am posting it here in case anyone else needs it. I have no idea which register is the problem one, so I just reset all that I dare to their default states.

Always place the file at the top of your includes list.

Hope this helps someone!

Code: Select all

{
*****************************************************************************
*  Name    : ClearRegisters.BAS                                             *
*  Author  : Nathan Herbert                                                 *
*  Notice  :  													            *
*          : All Rights Reserved                                            *
*  Date    : 22/01/2010                                                     *
*  Version : 2.0                                                            *
*  Notes   : Use with Microchip HID bootloader  to ensure correct operation *
*          : of main program                                                *
*****************************************************************************
}
Module ClearRegisters

#if _device = 18F87J50

	TBLPTR	= %00000000
	TABLAT	= %00000000
	INTCON	= %00000000
	INTCON2 = %11111111
	INTCON3 = %11000000
	TMR0H	= %00000000
	T0CON	= %11111111
	CM1CON	= %00011111
	CM2CON	= %00011111
	ODCON1	= %00000000
	ODCON2	= %00000000
	T1CON	= %00000000
	ODCON3	= %00000000
	TMR2	= %00000000
	T2CON	= %00000000
	IPR3	= %11111111
	PIR3	= %00000000
	PIE3	= %00000000
	IPR2	= %11111111
	PIR2	= %00000000
	PIE2	= %00000000
	IPR1	= %11111111
	PIR1	= %00000000
	PIE1	= %00000000
	UCON 	= %00000000
	UEIR	= %00000000
	UIR		= %00000000
	UCFG	= %00000000
	UEIE	= %00000000
	UIE		= %00000000

#endif
	
#if _device = 18F4550	

   UIR 		= %00000000
   UIE 		= %00000000
   UEIR 	= %00000000
   UEIE 	= %00000000
   UCON 	= %00000000
   UADDR 	= %00000000
   UCFG 	= %00000000
   UEP0 	= %00000000
   UEP1 	= %00000000
   UEP2 	= %00000000
   UEP3 	= %00000000
   UEP4 	= %00000000
   UEP5 	= %00000000
   UEP6 	= %00000000
   UEP7 	= %00000000
   UEP8 	= %00000000
   UEP9 	= %00000000
   UEP10 	= %00000000
   UEP11 	= %00000000
   UEP12 	= %00000000
   UEP13 	= %00000000
   UEP14 	= %00000000
   UEP15 	= %00000000
   PIE1 	= %00000000
   PIR1 	= %00000000
   IPR1 	= %11111111
   PIE2 	= %00000000
   PIR2 	= %00000000
   IPR2 	= %11111111
   WDTCON  	= %00000000
   HLVDCON  = %00000101
   BSR  	= %00000000
   INTCON3  = %11000000
   INTCON2 	= %11111111
   INTCON  	= %00000000
   TABLAT 	= %00000000
   TBLPTR 	= %00000000
   TBLPTRL 	= %00000000
   TBLPTRH 	= %00000000
   TBLPTRU 	= %00000000

#endif

Post Reply