callwyat / mplab-extension

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

Programming & Debugging using PKOB4, ICD4 and ICE #3

Closed areiter128 closed 1 year ago

areiter128 commented 1 year ago

Extending Debugger/Programmer-Support

PKOB4

Many of Microchip's Starter Kits, such as the Curiosity Boards, use the on-board version of PICkit4, called Pkob4. They identify as pkob4hybrid. It seems like they are not supported yet?

MPLAB ICD4 (Part Number: DV164045)

One of the most commonly used programmers/debuggers is MPLAB ICD4, which also doesn't seem to be supported. These identify as ICD4Tool

MPLAB ICE4 (Part Number: DV244140)

The latest programmer/debugger released by Microchip is MPLAB ICE4 These identify as ri4hybrid

Please let me know if there is anything I can help with.

callwyat commented 1 year ago

Thanks for submitting these programer names! I haven’t been able find any documentation with all the device names, so I plan to add them as issues are are submitted. I can make a preview release in the next few days that you can test with the hardware you have, or you can fork the repo and test it out yourself. You should just need to add the names to the ‘ confToMdBNames’ dictionary in src/debugAdapter/mdbCommunications.ts:251

areiter128 commented 1 year ago

Great! Thank you. I will go for the Forking-option and will let you know if everything works soon. BTW: Sorry for the delayed reply

areiter128 commented 1 year ago

Seems like ran in to a problem I'm unable to solve. I am building and running a debug session using the simulator. It builds fine but when it tries to start a debug session, I getting an error message, saying "Failure to write program to device". launch.json looks like this:

version": "0.2.0",
        "configurations": [
        {
            "type": "mplabx",
            "request": "launch",
            "name": "MPLABX Debug",
            "program": "${workspaceFolder}/",
            "stopOnEntry": true,
            "preLaunchTask": "MPLABX Build"
        }
    ]

Am I missing something?

areiter128 commented 1 year ago

BTW: I'm using MPLAB X 6.0 and MPLAB X 6.05

callwyat commented 1 year ago

I have not seen that message before when using the simulator. I have seen that issue when working with the PICKIT4. There is an issue related to it “https://github.com/callwyat/mplab-extension/issues/1#issuecomment-1275767457“ I haven’t figured out the cause yet, but suspect it’s related to MPLAB X filling in automatic values that VSLAB doesn’t know how to handle.

Does the test project work inside of MPLAB X?

jasonkelly214 commented 1 year ago

@areiter128 I called mdb.bat directly and saw that in the hwtool list it uses different names. Rather than ICD4Tool it is icd4. Using ICD4Tool would return null, and using icd4 it would connect. Unfortunately I haven't figured out how to build the extension so I can use it. I installed most of the tools but I get lots of errors from various things. I assume I'm missing the relevant dependencies or tools

callwyat commented 1 year ago

Thanks @jasonkelly214 with that info I can now add the ICT4 to the release!

jasonkelly214 commented 1 year ago

ICD4 hopefully :) and no problem!

callwyat commented 1 year ago

Support for the ICD4Tool has been added in version 0.1.3. Please let me know if it doesn’t work as I don’t have a way to test it myself!

jasonkelly214 commented 1 year ago

Awesome! Almost worked, I made a comment on the commit but it should just be flipped:

private confToMdBNames = {
    "pk4hybrid": "PICKit4",
    "ICD4Tool" : "icd4",
    "Simulator": "Sim"
};

https://github.com/callwyat/mplab-extension/commit/b24db05ba2e77bc44f855ad23ba3c87e4881bb20

callwyat commented 1 year ago

Thanks for testing that out! I have applied your recommendation and published it in v0.1.4.

jasonkelly214 commented 1 year ago

I haven't gotten a change to try your build, but when I made the change I ran into some more issues. I think there's a problem with the configuration file because there are a long list of options that get returned as invalid. Perhaps this is a version issue? And/or the newer version 4 devices use different parameter sets? I intend to dig into it a bit more this week if I have time, and I can certainly post the output stream so you can take a look.

jasonkelly214 commented 1 year ago

I updated to newer toolchains, and I removed some of the offending configuration options and now it's somewhat working.

I'm not very experienced with these scripting languages but it seems to me the async call to this.query() to call Program is returning too early...either a timeout, or the return conditions have been met.


/** Sends a command to the Microchip Debugger and returns the whole response
     * @param input The command to send to the debugger
     */
    public async query(input: string, level: ConnectionLevel): Promise<string> {

        if (this.connectionLevel >= level) {
            return this._mdbMutex.runExclusive(() => {
                // Read off any data that may be sitting in the buffer.
                if (this.mdbProcess.stdout?.readableLength ?? 0 > 0) {
                    this.mdbProcess.stdout?.read();
                }

                let result: Promise<string> = this.readResult();
                this._write(input, level);

                return result;
            });
        } else {
            return new Promise<string>((resolve) => {
                this.once(level.toString(), () => {
                    this.query(input, level).then(v => resolve);
                });
            });
        }

const programResult = await this.query(`Program "${path.join(outputFolder, outputFile)}"`, ConnectionLevel.connected);
                    if (programResult.match(/Program succeeded\./) || programResult.match(/Programming\/Verify complete/)) {
                        if (stopOnEntry) {
                            this.emit('stopOnEntry');
                        } else {
                            this.run();
                        }

                        this.connectionLevel = ConnectionLevel.programed;

                    } else {
                        throw new Error('Failure to write program to device');
                    }

Here is the output from the mdb.bat directly image

I also have my project set to half at main, but I didn't get any breakpoints once launched. That would be good to add if possible.

callwyat commented 1 year ago

I have released a preview version of the extension 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

Close due to inactivity, and the issue should be resolve in v0.1.7