PDA

View Full Version : 18F4550 programming failed using PICkit4 while verifying "User ID memory"



Demon
- 26th April 2023, 01:50
Any idea what it's crying about?

9365

I had to slow the programming speed to SLOW or else I'd get speeding errors.

Program, configuration and EEdata memory seem to verify just fine. It looks like it failed at "User ID memory" - whatever that is.

This was programmed 15 years ago; no idea what's on that memory location.

Robert

mpgmike
- 26th April 2023, 01:55
Out of curiosity, did you try the PIC to see if it actually programmed? Usually the "User ID Failed" shows up before it even tries to program. Just asking.

Demon
- 26th April 2023, 02:02
So I tried with a brand new 18F4550, same error:

9366

Demon
- 26th April 2023, 02:04
Out of curiosity, did you try the PIC to see if it actually programmed? Usually the "User ID Failed" shows up before it even tries to program. Just asking.

It says "programming/verify" complete though?

Gotta go feed the dogs. Gonna try with just a blinky program (this is an old program that worked way back when).

Robert

tumbleweed
- 26th April 2023, 12:43
I don't think it's complaining about the UserID area, it's just a poorly arranged display making it look that way.
The UserID is located at 0x200000-0x200007 in that part.

It looks to me that it's complaining about location 0xcc0, which is in program memory.
Try doing an erase and then a blank check.

There's a later toolpack for the 18F devices... maybe try updating it?

Demon
- 26th April 2023, 17:42
Got a new pack, same problem.

9367


It already says ERASIN SUCCESSFUL midway down the pic.

Not sure what to try next. I don't get why I can program a 16F877 without problems.

Gonna gut my program and try to BLINKY, see if that makes a difference.

Robert
:(

Demon
- 26th April 2023, 17:52
Gutted all the USB and interrupt stuff, added just a basic blinky, and it worked.

9368

Demon
- 26th April 2023, 17:57
This is the complete program that failed.

Same OSC speed, same CONFIGs, gutted everything except ALLDIGITAL and ADCON1.


'************************************************* **************************
'* Name : KK 18F4550 C152.pbp *
'* Author : Robert Hedan *
'* Date : Apr 7 2023 *
'* Version : 1.0 *
'* Notes : MICROSOFT FLIGHT SIMULATOR 2023 *
'* Cessna 152 control panel (Asobo) *
'* Hardware : PIC 18F4550, 20mhz crystal *
'* : Lab X1 Experimental Board *
'* Oscillator Jumpers A = 1-2 *
'* B = 1-2 *
'* C = 2-3 *
'* : PICkit4 Programmer v? *
'* Software : PIC Basic Pro v3.0.8.4 *
'* : MicroCode Studio Plus v5.0.0.5 *
'* : MPASM v5.62 *
'* PIC mods : plastic USB connector hot-glued onto top of PIC *
'* : leads soldered directly to top of PIC pins *
'* : two 0.1uF ceramic caps in parallel across VUSB and VSS *
'* : USB VDD is NOT connected *
'* : USB GND is wired to PIC *
'* : D- wired to C4 (pin 23) *
'* : D+ wired to C5 (pin 24) *
'************************************************* **************************

#CONFIG
CONFIG PLLDIV=5, CPUDIV=OSC1_PLL2, USBDIV=2, FOSC=HSPLL_HS
CONFIG PWRT=OFF, BOR=ON, BORV=1, VREGEN=ON, WDT=OFF
CONFIG CCP2MX=ON, PBADEN=OFF, LPT1OSC=OFF, MCLRE=ON
CONFIG STVREN=ON, LVP=OFF, ICPRT=OFF, XINST=OFF
#ENDCONFIG

DEFINE OSC 48

;================================== USB NOTES ==================================
; If you get an ERROR saying these registers are undefined?
; Uncomment the corresponding line in DT_HID260:
; UIE VAR BYTE EXT ; for PBP versions prior to 2.50
; UEIE VAR BYTE EXT
; UIR VAR BYTE EXT
; - DT
;-------------------------------------------------------------------------------
; Before you put the PIC to sleep, you'll need to put the USB module in suspend
; mode UCON.1, which can only be done reliably when unplugged.
;
; This disables the USB voltage regulator and stops the clock to the SIE, which
; will give the lowest current consumption.
;
; The USB routines are not setup to handle a resume.
; So your best bet it probably to connect the +5V from the USB cable to one of
; the INT pins with a pull-down resistor.
;
; When the cable gets plugged in, it will generate an interrupt, at which point
; you would execute an @ RESET to reset the processor and initialize the USB again.
; - DT
;-------------------------------------------------------------------------------
; Enable bits (IE), Interrupt Flags (IF) or Priority bits (IP).
; Don't "mess" with them. That includes GIE and PEIE or GIEL.
; - DT
;-------------------------------------------------------------------------------
; Put the Interrupt definitions before the HID stuff.
; - DT
;-------------------------------------------------------------------------------
; Both USB_INSIZE and USB_OUTSIZE can only be 8,16,32 or 64.
; If you want to send 10-bytes per report, it needs to be 16.
; - DT
;-------------------------------------------------------------------------------
; Each USB status LED is optional, comment them if not used.
; They can be assigned to any pin, and no further action is required.
; - DT
;================================================= ==============================

;--- Setup all digital pins-----------------------------------------------------

INCLUDE "ALLDIGITAL.pbp" ; Set all pins as digital

;--- Initialize ----------------------------------------------------------------
ADCON1 = %00001111 ; A/D Control
' Bit 7, 0 = n/a
' Bit 6, 0 = n/a
' Bit 5, Vref- Source
' 0 = VSS
' 1 = Vref- (AN2)
' Bit 4, Vref+ Source
' 0 = VSS
' 1 = Vref+ (AN3)
' Bit 3-0 1111 = All digital
' 1110 = All digital, AN0 analog
' 1101 = All digital, AN0 & AN1 analog

INTCON2 = %00000000
' Bit 7, 0 = enabled, Pull-up resistors
' Bit 6, 0 = falling edge, B0 interrupt
' Bit 5, 0 = falling edge, B1 interrupt
' Bit 4, 0 = falling edge, B2 interrupt
' Bit 3, 0 = n/a
' Bit 2, 0 = low priority, TMR0 interrupt
' Bit 1, 0 = n/a
' Bit 0, 0 = low priority, Port B on-change

;--- Setup Interrupts ----------------------------------------------------------

INCLUDE "DT_INTS-18.bas" ; Base Interrupt System

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_Handler
endm
INT_CREATE ; Creates the interrupt processor
endasm

;--- Setup USB -----------------------------------------------------------------
INCLUDE "DT_HID260.pbp"

DEFINE USB_VENDORID 6017
DEFINE USB_PRODUCTID 2000
DEFINE USB_VERSION 1
DEFINE USB_VENDORNAME "USBDemon1"
DEFINE USB_PRODUCTNAME "LabX1 Simple"
DEFINE USB_SERIAL "001"
DEFINE USB_INSIZE 16 ; IN report is PIC to PC (8, 16, 32, or 64)
DEFINE USB_OUTSIZE 8 ; OUT report is PC to PIC
DEFINE USB_POLLIN 1 ; Polling times in mS, MIN=1 MAX=10
DEFINE USB_POLLOUT 10

DEFINE USB_LEDPOLARITY 1 ; LED ON State [0 or 1] (default = 1)
DEFINE USB_PLUGGEDLED PORTD,0 ; LED indicates USB is connected
DEFINE USB_TXLED PORTD,1 ; " " data being sent to PC
DEFINE USB_RXLED PORTD,2 ; " " data being received from PC

' Using only 4 bit bus to control LCD
DEFINE LCD_DREG PORTD ' Set LCD data port
DEFINE LCD_DBIT 4 ' Set starting data bit
DEFINE LCD_RSREG PORTE ' Set LCD register select port
DEFINE LCD_RSBIT 0 ' Set LCD register select bit
DEFINE LCD_EREG PORTE ' Set LCD enable port
DEFINE LCD_EBIT 1 ' Set LCD enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 1000 ' Set command delay time in microseconds
DEFINE LCD_DATAUS 50 ' Set data delay time in microseconds

TRISA = %00000000
TRISB = %00000000
TRISC = %00000000
TRISD = %00000000
TRISE = %00000000

LoopCount var byte
UsbReceivedData var byte

GOTO ProgramStart

HandleRX:
UsbReceivedData = 1 ' Set USB data received flag
RETURN

ProgramStart:
FOR LoopCount = 1 TO 8 ' clear USB receive buffer
USBRXBuffer[LoopCount] = 0
NEXT LoopCount

PAUSE 1500 ' wait for PIC and LCD to stabilize
LCDOUT $FE,1,"LabX1 18F4550 USB"

ProgramMain:
IF NOT Plugged THEN ' check if USB is plugged
LCDOUT $FE,$C0,"USB not plugged... "
WHILE NOT Plugged:WEND ' wait until USB is plugged
LCDOUT $FE,$C0," "
ENDIF

@ ON_USBRX_GOSUB _HandleRX ; check if USB data is received

IF UsbReceivedData = 1 THEN

REM Do want you want with data received from USB in this IF statement

LCDOUT $FE,$C0, _ ' display USB data received
bin8 USBRXBuffer[0], ":", bin8 USBRXBuffer[1]

ARRAYWRITE USBTXBuffer, _ ' echo USB data back to PC
[BIN8 USBRXBuffer[0], BIN8 USBRXBuffer[1]]
IF TX_READY THEN GOSUB DoUSBOut

UsbReceivedData = 0 ' Reset USB data received flag
ENDIF

REM Your main process goes here:
REM - check input buttons.
REM - turn LEDs ON/OFF.
REM - communicate with other PICs.
REM - send USB data to PC.

GOTO ProgramMain ' main loop
END

Demon
- 26th April 2023, 18:35
I've narrowed it down to USB logic. I probably have something out of date.

The LCD and blinky on lower bits of Port D work fine.


#CONFIG
CONFIG PLLDIV=5, CPUDIV=OSC1_PLL2, USBDIV=2, FOSC=HSPLL_HS
CONFIG PWRT=OFF, BOR=ON, BORV=1, VREGEN=ON, WDT=OFF
CONFIG CCP2MX=ON, PBADEN=OFF, LPT1OSC=OFF, MCLRE=ON
CONFIG STVREN=ON, LVP=OFF, ICPRT=OFF, XINST=OFF
#ENDCONFIG

DEFINE OSC 48

INCLUDE "ALLDIGITAL.pbp" ; Set all pins as digital
ADCON1 = %00001111 ; A/D Control
INTCON2 = %00000000

' Using only 4 bit bus to control LCD
DEFINE LCD_DREG PORTD ' Set LCD data port
DEFINE LCD_DBIT 4 ' Set starting data bit
DEFINE LCD_RSREG PORTE ' Set LCD register select port
DEFINE LCD_RSBIT 0 ' Set LCD register select bit
DEFINE LCD_EREG PORTE ' Set LCD enable port
DEFINE LCD_EBIT 1 ' Set LCD enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 1000 ' Set command delay time in microseconds
DEFINE LCD_DATAUS 50 ' Set data delay time in microseconds

TRISA = %00000000
TRISB = %00000000
TRISC = %00000000
TRISD = %00000000
TRISE = %00000000

ProgramStart:

PAUSE 1500
LCDOUT $FE,1,"LabX1 18F4550 USB"

ProgramMain:

PORTD = %00001010
PAUSE 500
PORTD = %00000101
PAUSE 500

GOTO ProgramMain
END

Ioannis
- 26th April 2023, 18:37
Is there an option on PickIt 4 to erase the chip before write?

When I had such messages the above solved the problem.

Ioannis

tumbleweed
- 26th April 2023, 19:10
If you look at the messages, when it fails the program end addr is 0xcbf.
It's then not seeing the next addr 0xcc0 as erased... there's still something there.

I think there's a setting to specify the full range and not let the PK4 pick it.

Demon
- 26th April 2023, 23:57
Since I had never paid attention to a command line when I was using my old serial and later USB programmers, I had no clue what I should "verify", so, I verified everything.

9369

Turns out it doesn't like when I verify ID Memory and Configuration Memory.

This is my new command line for the PICkit 4:


-TPPK4 -P$target-device$ -F$hex-filename$ -E -M -OAS0 -OB -OL -OV -YP -YE

Note that I "might" be verifying the Programming and EEData areas a 2nd time for nothing. But hey, I paid for it so I'm using it. :D

9370

Robert
"One happy camper"

P.S.: Here's a copy&paste of the command line parameters available (no idea if you can attach a PDF)

The complete version of Readme for IPECMD.htm can be found in your MPLABX/version number/docs folder.

9371

Demon
- 27th April 2023, 00:01
If you look at the messages, when it fails the program end addr is 0xcbf.
It's then not seeing the next addr 0xcc0 as erased... there's still something there.

I think there's a setting to specify the full range and not let the PK4 pick it.


I had the -E option, so no idea why it didn't want to erase the entire darned thing. It's off by default.

Robert
:shrug:

Demon
- 27th April 2023, 00:07
Programming speed, turns out it doesn't mind running at max speed for this particular PIC:


-TPPK4 -P$target-device$ -F$hex-filename$ -E -M -OAS2 -OB -OL -OV -YP -YE

This runs just fine.

Robert

Demon
- 13th May 2023, 20:55
I still have one bug; 18F4550 programmed by my PK4 run Blinky at 1/2 speed compared to my U2 USB programmer.

- leads on my PK4 are just over 6 inches, with gold pins so they connect directly beside the pin.
- flat cable on my U2 is nearly 3 inches long, and PGC/PGD wires on the breadboard are nearly 3 inches.

I can't find any spec that says EXACTLY what the max length is for the PK4 leads....?

Robert


EDIT: The only reference to lead lengths for the PK4 has a 8pin 6in cable:
https://www.microchip.com/en-us/development-tool/AC102015

tumbleweed
- 13th May 2023, 23:46
FWIW, I use a 6" cable with the PK4 all the time. Cables can cause issues, but I don't think that's your problem here.


I still have one bug; 18F4550 programmed by my PK4 run Blinky at 1/2 speed compared to my U2 USB programmer.
Try programming it with the PK4 and then verifying it with the U2, or vice-versa.

Pay particular attention to CONFIG1L. Unless one of them is changing it (????), I don't see how that is.
Are you overriding the CONFIG settings in the hex file with one of them?

Demon
- 14th May 2023, 07:34
FWIW, I use a 6" cable with the PK4 all the time. Cables can cause issues, but I don't think that's your problem here.


Try programming it with the PK4 and then verifying it with the U2, or vice-versa.

Pay particular attention to CONFIG1L. Unless one of them is changing it (????), I don't see how that is.
Are you overriding the CONFIG settings in the hex file with one of them?


Yeah, I was about to make a new cable, but that cable from Microchip is as long as mine, and they have one even longer.


Good idea about the swapping verify, gonna try tomorrow if wifey lets me in the house. I'm gonna lose a dog in that grass. :D


I'm not changing anything. The only variable I can think of is the options on the command lines. I'm gonna take screen shots of all the U2 settings, then compare that against the PK4.


Going to bed, just finished an "exposé" on HIDmaker FS2 (just comments and observations really), but I tried to be as open an truthful. gonna post about it on a USB thread.

Robert
:)

mpgmike
- 15th May 2023, 05:28
The U2 Programmer has a header button that allows you to set your CONFIG settings. Since your PICkit4 and U2 Programmers yield different Clock speeds, the U2 may be using a different default CONFIG setting than the PICkit4. If you don't specifically define your CONFIGs, you are leaving it up to software to make decisions for you.

Demon
- 16th May 2023, 04:59
This is what my U2 does.

Erase:
9408

Program:
9409

Verify:
9410


These are the settings I have for the PK4:

-TPPK4 -P$target-device$ -F$hex-filename$ -E -M -OAS2 -OB -OL -OV -W -YP -YE


E = Erase Flash Device (there are no options)
M = Program entire device (does not include calibration, same like U2)
OAS2 = Maximum programming speed
OB = Batch mode operation (so the window stays open to check out the results)
OL = Release from RESET NOT SURE ABOUT THIS GUY!
OV = Verify device ID before program in batch mode
W = Power target from tool
YE = Verify EEPROM
YP = Verify Program memory (U2 verifies Code, Calibration, Data, User ID and Configuration)



If anything, the U2 should be waaaaay slower, it verifies more, and the PK4 is supposed to be running at max speed and it's plugged in a SS USB port.

Weird...

Robert

mpgmike
- 16th May 2023, 18:06
You are not selecting "Erase User ID" but have selected "Program User ID". The Programming process only clears bits. If you have bits in your programmed User ID that are set, but that bit is already cleared, programming a 1 will not over-write a 0.