callwyat / mplab-extension

Build, Program, and Debug MPLAB Projects from the comfort of VS Code
Other
21 stars 9 forks source link

Programming & Debugging Using PICKit4 #1

Closed geocheats2 closed 1 year ago

geocheats2 commented 1 year ago

I am trying to programm/debug a project using pickit4 to no success

launch.json { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "mplabx", "request": "launch", "name": "MPLABX Debug", "program": "${workspaceFolder}/", "stopOnEntry": true, "preLaunchTask": "MPLABX Build", "postDebugTask": "MPLABX Clean" }, { "type": "mplabx", "request": "launch", "name": "MPLABX Debug", "program": "${workspaceFolder}/", "stopOnEntry": true, "preLaunchTask": "MPLABX Build" } ] }

tasks.json { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "MPLABX Build", "type": "mplabx", "task": "build", "projectFolder": "${workspaceFolder}/", "configuration": "default", "problemMatcher": [ { "base": "$xc", "fileLocation": [ "relative", "${workspaceFolder}/" ], } ], "group": { "kind": "build", "isDefault": true } },{ "label": "MPLABX Clean", "type": "mplabx", "task": "clean", "projectFolder": "${workspaceFolder}/", "configuration": "default", "problemMatcher": [ { "base": "$xc", "fileLocation": [ "relative", "${workspaceFolder}/" ], } ], "group": { "kind": "build", "isDefault": true } } ] }

configurations.xml

`<?xml version="1.0" encoding="UTF-8"?>

mcc_generated_files/mcc.h mcc_generated_files/clock.h mcc_generated_files/system.h mcc_generated_files/interrupt_manager.h mcc_generated_files/traps.h mcc_generated_files/spi2.h mcc_generated_files/spi1.h mcc_generated_files/uart3.h mcc_generated_files/uart2.h mcc_generated_files/uart5.h mcc_generated_files/uart4.h mcc_generated_files/ext_int.h mcc_generated_files/uart1.h mcc_generated_files/pin_manager.h mcc_generated_files/rtcc.h mcc_generated_files/tmr2.h mcc_generated_files/tmr1.h mcc_generated_files/adc1.h mcc_generated_files/i2c1.h mcc_generated_files/tmr3.h mcc_generated_files/oc2.h mcc_generated_files/oc1.h mcc_generated_files/tmr4.h mcc_generated_files/tmr5.h Sleep.h main.h Accel.h modem.h Ultrasonic.h spiFlash.h Terminal.h crc16.h vl53l1_ULD/platform/vl53l1_platform.h vl53l1_ULD/platform/vl53l1_types.h vl53l1_ULD/core/VL53L1X_api.h vl53l1_ULD/core/VL53L1X_calibration.h rak3172.h p24FJ512GA606.gld vl53l1_ULD/core/VL53L1X_api.c vl53l1_ULD/core/VL53L1X_calibration.c mcc_generated_files/mcc.c mcc_generated_files/clock.c mcc_generated_files/system.c mcc_generated_files/interrupt_manager.c mcc_generated_files/traps.c mcc_generated_files/spi2.c mcc_generated_files/spi1.c mcc_generated_files/uart3.c mcc_generated_files/uart2.c mcc_generated_files/uart5.c mcc_generated_files/uart4.c mcc_generated_files/ext_int.c mcc_generated_files/uart1.c mcc_generated_files/pin_manager.c mcc_generated_files/rtcc.c mcc_generated_files/tmr2.c mcc_generated_files/tmr1.c mcc_generated_files/adc1.c mcc_generated_files/i2c1.c mcc_generated_files/oc1.c mcc_generated_files/oc2.c mcc_generated_files/tmr3.c mcc_generated_files/tmr4.c mcc_generated_files/tmr5.c vl53l1_ULD/platform/vl53l1_platform.c Sleep.c Accel.c Ultrasonic.c spiFlash.c crc16.c Terminal.c main.c modem.c rak3172.c Makefile MyConfig.mc3 . Makefile localhost PIC24FJ512GA606 pk4hybrid XC16 1.36 3 false false false false false false false false

`

On hitting F5 i get an error Failed to connect to target device

debug console `

Device PIC24FJ512GA606 set communication.activationmode nohv

set communication.interface.jtag 2wire

set debugoptions.debug-startup Run

set debugoptions.reset-behaviour Main

set debugoptions.simultaneous.debug false

set debugoptions.useswbreakpoints false

set freeze.timers false

set memories.aux false

set memories.bootflash true

set memories.configurationmemory true

set memories.configurationmemory2 true

set memories.dataflash true

set memories.eeprom true

set memories.exclude.configurationmemory true

set memories.flashdata true

set memories.id true

set memories.programmemory true

set memories.programmemory.ranges 0-55eff

set poweroptions.powerenable true

set programmerToGoImageName IoTcmp_HW_V2_ptg

`

Do you have any idea what i am doing wrong?

callwyat commented 1 year ago

Hi! Currently, the extension supports debugging but not programming. To program MPLAB is still needed. Can you program the chip from MPLAB? The PICKIT4 also has a feature to enable quicker setup times, but it can keep MPLAB from releasing the PICKIT4. Replugging the PICKIT4 will solve that issue.

It looks like Programer To Go may be turn on in your configuration. That will need to be off to debug.

geocheats2 commented 1 year ago

When using mplab i can program and debug. Thanks, i disabled programmer to go and i did manage to get into debug mode, Do you have any pointers i could use to try and help with the development process of the programming part??

geocheats2 commented 1 year ago

On debug Console i get the following

The following memory area(s) will be programmed: program memory: start address = 0x0, end address = 0x147ff program memory: start address = 0x2a000, end address = 0x2a7ff configuration memory

Programming/Verify complete Program succeeded.

Run

So i guess that by entering debug mode the device does get programmed, it just enters debug mode after that?

geocheats2 commented 1 year ago

I only managed to get into debug mode once

geocheats2 commented 1 year ago

set programoptions.pgcresistor.value 4.7

set programoptions.pgdconfig none

set programoptions.pgdresistor.value 4.7

set programoptions.pgmentry.voltage low

set programoptions.pgmspeed Med

set programoptions.preservedataflash false

set programoptions.preserveeeprom false

set programoptions.preserveprogramrange false

set programoptions.preserveuserid false

set programoptions.program.otpconfig false

set programoptions.programcalmem false

set programoptions.programuserotp false

set programoptions.testmodeentrymethod VDDFirst

set ptgProgramImage false

set ptgSendImage false

set toolpack.updateoptions toolpack.updateoptions.specifictoolpack

set toolpack.updateoptions.packversion 1.10.1305

set voltagevalue 3.25

HwTool PICKit4

That is the output of the debug console

Also because my ts abilities are not the best i am trying to build a script that uses the included mplab_ipe cmd tool to programm the device

The command to use it is :

C:/Program Files/Microchip/MPLABX/v6.00/sys/java/zulu8.54.0.21-ca-fx-jre8.0.292-win_x64/bin/java.exe -jar ../../mplab_platform/mplab_ipe/ipecmd.jar -TPPK4 -P24FJ512GA606 -M -OL -F"file_location/file.hex"

I opted to use the included JRE

You can always find the available parameters of the cmd tool at

C:/Program Files/Microchip/MPLABX/v6.00/docs/Readme for IPECMD.htm

geocheats2 commented 1 year ago

So i just made a scipt and added it to the task.json with a depends option on MPLABX Build and by running this new task i get the complile from your extension and the programm using the mplab cmd option

tasks.json

{ // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format 
    "version": "2.0.0",
    "tasks": [
        {
            "label": "MPLABX Build",
            "type": "mplabx",
            "task": "build",
            "projectFolder": "${workspaceFolder}/",
            "configuration": "default",
            "problemMatcher": [
                {
                    "base": "$xc",
                    "fileLocation": [
                        "relative",
                        "${workspaceFolder}/"
                    ]
                }
            ],
            "group": "build"
        },
        {
            "label": "MPLABX Programm",
            "type": "shell",
            "command": "${workspaceFolder}/programmer-george.bat",
            "windows": {
                "command": "${workspaceFolder}/programmer-george.bat"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always",
                "panel": "new"
            },
            "dependsOn": [
                "MPLABX Build"
            ],
            "problemMatcher": []
        }
    ]
}
callwyat commented 1 year ago

I’m glad disabling Programer-To-Go got it to work!

You did leave a comment that it only worked once, are you still having that problem?

Great work on figuring out how to use the MPLAB IPE to program the device! I have been struggling with which route to go down for programming. IPE could be used, but it is an optional component so I can’t rely on it all the time. The MPLAB MDB, which is used for debugging does support programming, but there is a bug on macOS that holds the reset line after programming.

I’ll probably end up with some solution that includes both methods were the MDB is used for Windows and Linux machines, and the IPE is used for macOS. Which makes testing harder.

I have been idle on this project for a bit, but this is motivating me work on it again 😊

geocheats2 commented 1 year ago

So to make the debug work i have to close mplab disconnect the PicKit4 from usb and connect it again, it seems that mplab even closed? it manages somehow to lock the pickit but it seems to work about 30-40% of the time, if i can help you with any logs feel free to point them to me. George

geocheats2 commented 1 year ago

Output of the debug with error message "Failed to connect to target device"

Device PIC24FJ512GA606 set communication.activationmode nohv set communication.interface.jtag 2wire set debugoptions.debug-startup Run set debugoptions.reset-behaviour Main set debugoptions.simultaneous.debug false set debugoptions.useswbreakpoints false set freeze.timers false set memories.aux false set memories.bootflash true set memories.configurationmemory true set memories.configurationmemory2 true set memories.dataflash true set memories.eeprom true set memories.exclude.configurationmemory true set memories.flashdata true set memories.id true set memories.programmemory true set memories.programmemory.ranges 0-0xd4ff set poweroptions.powerenable false set programmerToGoImageName IoTcmp_HW_V2_ptg

if i manage to successfully enter into debug mode again i will post the successful message

bryanlieblick commented 1 year ago

I also am not able to enter debug using PICkit4 and v0.1.2. See the debug log below, using MacOS.

Any recommendations on next steps to debug this?

There are a few errors from the device setup, although MPLAB X seems perfectly content with these options. Could also be irrelevant, as I edited the file to not generate any errors and still was not successful. Happy to provide more information.

However, using @geocheats2 suggestions above I am able to program the device easily from VSCode by adding the build option to tasks.json. Rather than using a separate batch command I have one-liner shell command with a few paths defined in settings.json.

>Device dsPIC33CK256MP506
set communication.activationmode nohv
>set communication.interface.jtag 2wire
>set debugoptions.debug-startup Use system settings
>set debugoptions.reset-behaviour Use system settings
Error: invalid parameter.

>set debugoptions.simultaneous.debug false
Error: invalid parameter.
>set debugoptions.useswbreakpoints false
>set freeze.timers false
>set memories.aux false
>set memories.bootflash true
>set memories.configurationmemory true
>set memories.configurationmemory2 true
>set memories.dataflash true
>set memories.eeprom true
>set memories.exclude.configurationmemory true
>set memories.flashdata true
>set memories.id true
>set memories.programmemory true
>set memories.programmemory.ranges 0-2beff
>set poweroptions.powerenable true
>set programmerToGoImageName dev_dspic33ck_ptg
>set programoptions.donoteraseauxmem false
>set programoptions.eraseb4program true
>set programoptions.ledbrightness 5
>set programoptions.pgcconfig pull down
>set programoptions.pgcresistor.value 4.7
Error: invalid parameter.

>set programoptions.pgdconfig pull down
>set programoptions.pgdresistor.value 4.7
Error: invalid parameter.

>set programoptions.pgmentry.voltage low
>set programoptions.pgmspeed Med
>set programoptions.preservedataflash false
>set programoptions.preserveeeprom false
>set programoptions.preserveprogramrange false
>set programoptions.preserveuserid false
>set programoptions.program.otpconfig false
>set programoptions.programcalmem false
>set programoptions.programuserotp false
>set programoptions.testmodeentrymethod VDDFirst
>set ptgProgramImage false
>set ptgSendImage false
>set toolpack.updateoptions toolpack.updateoptions.specifictoolpack
>set toolpack.updateoptions.packversion 1.13.1519
>set voltagevalue 3.25
>HwTool PICKit4
>

-1
Failed to initialize PICkit 4
*****************************************************
zhang00956 commented 1 year ago

set programoptions.pgcresistor.value 4.7

set programoptions.pgdconfig none

set programoptions.pgdresistor.value 4.7

set programoptions.pgmentry.voltage low

set programoptions.pgmspeed Med

set programoptions.preservedataflash false

set programoptions.preserveeeprom false

set programoptions.preserveprogramrange false

set programoptions.preserveuserid false

set programoptions.program.otpconfig false

set programoptions.programcalmem false

set programoptions.programuserotp false

set programoptions.testmodeentrymethod VDDFirst

set ptgProgramImage false

set ptgSendImage false

set toolpack.updateoptions toolpack.updateoptions.specifictoolpack

set toolpack.updateoptions.packversion 1.10.1305

set voltagevalue 3.25

HwTool PICKit4

That is the output of the debug console

Also because my ts abilities are not the best i am trying to build a script that uses the included mplab_ipe cmd tool to programm the device

The command to use it is :

C:/Program Files/Microchip/MPLABX/v6.00/sys/java/zulu8.54.0.21-ca-fx-jre8.0.292-win_x64/bin/java.exe -jar ../../mplab_platform/mplab_ipe/ipecmd.jar -TPPK4 -P24FJ512GA606 -M -OL -F"file_location/file.hex"

I opted to use the included JRE

You can always find the available parameters of the cmd tool at

C:/Program Files/Microchip/MPLABX/v6.00/docs/Readme for IPECMD.htm

I find use this command will program faster: D:/MPLAB/mplab_platform/mplab_ipe/ipecmd.exe -TPPK4 -P32MZ2048EFH144 -M -OL -F"pic32mz_lunch.X.production.hex" 我发现使用这个烧录命令,烧写速度更快:D:/MPLAB/mplab_platform/mplab_ipe/ipecmd.exe -TPPK4 -P32MZ2048EFH144 -M -OL -F"pic32mz_lunch.X.production.hex"

callwyat commented 1 year ago

I have released a preview version of the app that should fix this issue. Will some of you please update to 0.1.7 and let me know if your 4 Series programmers work?

callwyat commented 1 year ago

You’ll need to open up the extension and select “Switch to Pre-Release“

callwyat commented 1 year ago

Closed due to inactivity, and the problem should be resolved in v0.1.7

bryanlieblick commented 1 year ago

@callwyat I can now use the PicKit4 for debugging with VSCode. I programmed the device and setup a few breakpoints to play around. Thanks for the update!

If you're looking for additional feedback, but the debugger output for the watch window isn't super useful. I can see items I add to the watch window in the Debug Console output, but the Watch window proper has "Out of Scope" for variables that I would expect to be in the current scope. The variable structures aren't properly populated either in these windows.

Lastly, I also experienced some slow response times while stepping through the code as large amounts of data were being dumped to the console (probably related to backtrace full referenced in #6).