-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use -xmode to switch PICkit4 and SNAP application modes #1596
Conversation
It looks like it isn't going to be all that easy to get mode switching to work for |
One way is to ship this as a separate utility along with avrdude without integrating into avrdude, if it is a bit difficult to integrate into existing avrdude source codes. Let's also hear from @stefanrueger and @dl8dtl. |
@mcuee try this project: When the project is loaded you can click the green arrows to switch mode: |
Thanks Wireshark
@mcuee I managed to implement |
@stefanrueger I'd like to hear what you would consider the neatest way to trigger the PIC/AVR mode switching from stk500v2.c. Now that the base functionality of this PR is up and running, this would be the next step.
|
It isn't clear to me why a user option is needed. If the user requests an operation in these programmers for which they need to be in AVR mode, would it not make sense to query which mode they are in, memorise the mode in an appropriate I am sure I have overlooked (or don't know) a crucial problem on the way. |
I will try this PR later this evening. Now I know how to switch to PIC mode using MPLAB X IDE 6.15. And your libusb example code works fine to switch from PIC mode to AVR mode. |
You mentioned that PICKit 4 and SNAP can not program the AVR EB chips in AVR mode and MPLAB X IDE uses PIC mode for that purpose. Is this confirmed? If that is the case, we may have to block them and print a warning message for now. |
@mcuee read this post. It appears that PK4/SNAP can program AVR-EBs, but only in PIC mode using MPLAB X https://www.avrfreaks.net/s/topic/a5C3l000000UkyzEAC/t193040
Ideally, yes. But it may just be a firmware update away from working in AVR mode as well. |
If the user requests an operation in these programmers for which they need to be in AVR mode, would it not make sense to query which mode they are in, memorise the mode in an appropriate PDATA(pgm)->... component, switch to (presumably) AVR mode, do the operation(s) and then in the end switch to the memorised mode the programmer was in, if needed. @stefanrueger There are good reasons why one wants to switch modes explicitly. First, this is a rather niche issue that only deals with two official programmers, and one of them has been discontinued. After a switch, the programmer restarts and reenumerates. Avrdude would have to start over again after the switch, and this is something I don't want to deal with for now; hence returning -1 after the switch. And if the programmer is in PIC mode, there are good reasons why you want to keep it in AVR mode. It's quicker, since the programmer doesn't have to switch modes all the time, and you can use it as a USB to serial adapter because it shows up as a serial port. But if you borrowed someone's programmer that originally was in PIC mode, you would probably like to switch it back before returning it. And having to install MPLAB plus a PIC compiler and create an empty project just to switch back is just dumb. So it's IMO much better to have -xmode where the user can do whatever he or she wants. And I forgot to mention. MPLAB really struggles with switching modes sometimes. Sometimes it works, while others you have to restart MPLAB to get it to do the switch. Just having a utility that can do this that's not MPLAB is a good thing. |
Could that be packed into the programmer's open() function? Don't we now have code that can figure out when a device re-enumerates? And the switching back to PIC could be put into the close function(), not? Having an option makes it necessary to document it; users won't know the option exists and wouldn't know the procedures, so AVRDUDE would need to tell them that the programmer is in pic mode and they need to call avrdude again with some option and then again, to do the work and then again to put it into PIC mode. And somehow it would be much slicker if AVRDUDE did all that on its own accord... |
Yes, feel free! I'm leaving for Christmas holiday tomorrow and will be away for a little more than a week. I'm planning to bring my computer + some hardware, but I have limited time to spend on this PR. However, I can see if I can spend some time in the evenings to do a little testing with the SNAP and PICkit4. Automatic switching would be nice, but I think it's important to also be able to explicitly set a mode, so the user can utilize features like the USB-UART interface the programmer provides in AVR mode. |
I will agree with this one. MPLAB X IDE is really troublesome to use for switching the mode. |
Now this PR is actually working very well (switching from AVR mode to PIC mode and then from PIC mode to AVR mode). Tested under Windows 11 with PICKit 4 in JTAG mode. Well done!
|
Another thing I should look into is to see how the -xmode performs when the SNAP or PICkit4 is in bootloader mode. When in bootloader mode, they have a different PID, so it's easy to detect. However, I doubt -xmode will work, because I'm pretty sure they would require a different command. But this can be fixed in a separate PR. If the programmer is in bootloader mode, it means that it's either in FW upgrade mode or something is wrong with it.
Thanks! |
Mode switching (PIC <->AVR) is working well for Microchip SNAP as well.
|
OK, looks like a good enhancement. Thanks for tackling this problem, @MCUdude! |
Time is still very limited, but I think this PR is soon ready for review.
|
still need to figure out how to actually trigger the mode switch form stk500v2.c
Thanks for another review! |
Resolves issue #1027
If you have a PICkit4 or an MPLAB SNAP that happens to be in PIC mode, it has to be switched to AVR mode before Avrdude can communicate with it. However, with this PR, Avrdude can now do the switching. Use
-xmode=avr
to perform the switch. This is important because it has been reported over at the Avrfreaks forums that the latest MPLAB X doesn't do the switch when programming AVRs. It stays in "PIC mode" and speaks a protocol similar (or identical) to the PICkit5, which Avrdude currently doesn't support.TODO:
-xmode=pic
to switch back to PIC mode.pickit4_isp
andsnap_isp