MPLAB snap to atmega328pb program and debugWIRE

Go To Last Post
120 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you using the IPE by any chance? The IPE will reset fuses unless you have them in the hex file..

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

April 11, 2019                                                  File: SNAP Test Notes

Micro Chip SNAP Programmer testing with AVR Mega328P:

Testbed: 

Arduino Nano with a M328P, 5V,  16 MHz Ext Xtal.

A few LEDs and PB Switches attached.

 

Step #1:

Use Studio to program Nano to flash an LED at 1 Hz, using 16 MHz external Xtal.

Studio:  Atmel Studio 7.0.1645  (Programmer: AVR ISP mkII)

File:  Nano Breadboard LED Test V1.bas    ---> .hex

Fuses:

Ext: 0xFF, High: 0xD9, Low: 0xD6

Ext. Full Swing Crystal, Div by 8 disabled.

Micro runs as expected, at 16 MHz, flashes an LED at 1 Hz via ISR.

Close out  Studio.

 

Step #2:

Use MPLab X IDE to load the same pre-compiled .hex file into the same Nano.

MPLab X IDE Version: 5.15

Open Project fails, (Presumably because it isn't a C program)

So instead use: Import Hex/Elf (Prebuilt) File, which is what I'm trying to do anyways.

Select the SNAP programmer from the HW Tool box.

In the top left box, select the hex file.

The hex file shows up in the top right box, (Source).

The Lower right box has 3 tabs: Output, Program Memory, Configuration Bits.

The Config bits are all RED, and the clock says Int RC Osc 8 MHz..., and the Div8 is SET.

Press the little "Read Configuration Bits" button, the top one of the stack, to PRESUMABLY read / upload the current Fuse settings.

Nothing happens.

The Config bits box remains all red, and it doesn't upload the micro's current Fuse settings.

The lower box settings are: Memory: Configuration Bit, Format: Read Only.

 

 

Oh well, I just want to burn a .hex file, (without any embedded Fuse data).

It appears that the only "Burn a hex file" option I can see is the button on the upper bar that says:

"Make and Program Device Main Project", with the green download to device arrow.

 

Note: I don't want to "MAKE" the project, I JUST want to download a pre-compiled .Hex file!!!

And I can't seem to be able to upload my current Config Bits (Fuses)...

And in the Conf Bits view, lower right box, "Read Only" is the only pull-down option available.

I can't seem to edit / change the Fuse settings.

OH well, try the burn, perhaps it will just write the .hex file, and not mess with the Fuses:

Error Failed to launch debug session using debugWire.

 Note: I DON'T want to debug, I JUST want to burn a .hex file!!!

Screenshot taken.

 

So, two options here, first try:

Say no, I don't want to use ISP to enable debugWire.  --> Get: Programming did not complete.

Now do the same, but say Yes, use ISP to enable debugWire:

Get "Please toggle power on the target device", OK, done.

Get the same Failed to launch debug session using debugWire: message.

 

So, perhaps the issue is the Arduino Nano's Reset\ line hardware?

Unfortunately the same sequence occurs with a custom PCB with a M328PB chip and only a 10K pull-up on the Reset\ line.

So it doesn't seem that the Arduino Nano HW Reset\ line is likely an issue.

The original program and Fuse settings were untouched by the above process.

 

The programming box says:  Change communications interface to ISP in the project properties to read or write configuration bits.

Snapshot taken. Project Properties box.

 

Since the Project Properties box doesn't have a "Communications" pull-down, go look in the Manage Config sub-box.  Nope.

So try clicking on the SNAP in the Project Properties Categories box:

Then in Options Category select Communications.

See that debugWire is the currently selected version, so change it to ISP via the pull-down.

BUT: The "OK" button is grayed out. 

So HOW does one make the Comm mode ISP???

Screenshot: Comm ISP Mode

 

 

 

OK, try again:

File / Project Properties / Now in the Categories Box try "Loading"

Good, there is an option to "Load this .hex file instead of or dist/default/....

So, select my pre-compiled Nano Breadboard LED Test V1.hex file.

Click "Add loadable file"

Screenshot: Load this hex file instead.

 

 

 

Again: there are grayed out "OK" and "Apply" buttons, so HOW does one make one's selection take effect?

Very frustrating.

Apparently using MPLab X IDE V5.15 and the SNAP programmer to simply burn a pre-compiled hex file is a non-trivial process.

It would appear that I can almost get there..., but not quite.

.........................................................................................................

So, let's switch gears and try to simply burn a pre-compiled hex file using MPLab X IPE, (instead of the IDE, used above).

MPLAB X IPE V5.15

Close out the IDE and run the IPE.

It sees the SNAP programmer and shows this in the Tools box.

Select the hex file, and get a message that the file was loaded successfully, (into the IPE, not yet into the micro).

Screenshot: IPE Hex file loaded.

 

 

 

Press the Connect button by the Tool/SNAP, and it connects, and says:

Application version.....0.14.230

Target voltage detected.

 

In left column, Memory, Manual select:   Deselect Configuration Memory.

 

Press the Program button, and:

Error.  Failed to connect to device using ISP.

Screenshot: IPE ISP failed.

 

 

What?  With the IDE it wouldn't / couldn't use the debugWire mode.

Now with the IPE it can't connect with the ISP mode...

So, click YES to enable ISP and one is in an infinite loop with the same pop up asking if one wants to use ISP...

Click No to get out of the error pop up box loop.

 

Of course the left column, Settings, shows that the "Communications settings for AVR or SAM devices" is already set to ISP at 0.1 MHz.

Screenshot IPE ISP already set

Why, BTW, does the "output" tell me that the configuration memory will be programmed, when the Config Memory ISN'T selected in the Memory options????

Screenshot: IPE Memory selection

 

 

So, in the past I could at least burn a pre-compiled hex file, although the MPLab X reset the Fuses to use the internal RC Osc with the div by 8 enabled.

(And yes, I am sure that was happening, as I went through the process, resetting the Fuses with Studio, several times...)

 

Today I haven't quite hit on the right sequence with either the IDE or the IPE to burn the pre-compiled hex file.

 

The hex file was created by my Bascom compiler.  It is a simple hex file for a simple LED flasher.  There are no embedded Fuse settings, eeprom data, elf files, or anything else.  Studio 7 and my AVR ISP mkII burn the hex file, (and all of my other hex files over the past years), just fine.

 

I find this incredibly frustrating...

I purchased a couple of SNAP programmers so that I could give one away and not risk the individual damaging my AVR ISP mkII, and so that the individual could use the "easy/simple" MPLAB X IPE interface to simply download pre-compiled hex files, instead of using the full Atmel Studio and my mkII.

 

I consider this endeavor a total failure.  I spent several days on this a few weeks ago, and I've spent several hours on this today, all without success.

 

Perhaps I'm missing something simple, and burning a M328P or M328PB with a canned hex file is doable.  If that's the case then I will apparently need some incredibly detailed hand-holding to walk me through the process.

 

Engineering Tech Notice #36, linked to above by mraardvark would not seem to be applicable in this particular case, as I am attempting to program plain old M328P and M328PB, which use ISP, and not UPDI, PDI, or TPI interfaces.

 

Having now vented, let me say that I am appreciative of your interest in replicating / solving this issue.  I appreciate any further  guidance in the right direction.  

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, so one more image.

Not sure why after posting the above, I get the Unable to send eMail, Contact Site Admin messages.

 

Not, obviously, related to the issue within this Thread, but indicative that clearly a little more work on the web site is still indicated.

 

JC

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not sure why after posting the above, I get the Unable to send eMail, Contact Site Admin messages.

We are all getting that and not getting any emails notifications for a bout 2 days now.

I don't want to "MAKE" the project, I JUST want to download a pre-compiled .Hex file!!!

Now, now let's watch the blood pressure.....cheeky I have downloaded the latest MPLABX and have the pickit4 on the bench ready to try things out but maybe not for now, I have enough blood pressure rising stuff with my piano lessons.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you get to make it work? (with the Arduino Nano) Mine arrived yesterday; and I would like to see if it works with a Nano? Did you have to Desolder the capacitor in the Board, or not? I was planing of uninstalling Windows and start using Linux; to exclusively use MPLAB for both AVR and SAMD21 development.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A Nano will never work with debugWIRE unless you disconnect the DTR capacitor and replace the 1k0 RESET pullup resistor with 10k (or remove entirely)

 

A genuine Uno has a proper 10k pullup and a RESET-EN solder-bridge.   Cut the bridge with a Stanley knife.

Follow the instructions from AS7.0 or MPLABX.

 

You can make/break with a soldering iron as required i.e. to restore Bootloader / enable debugWIRE.

 

The SNAP should work ok with correct debugWIRE schematic.   

Likewise,   ATMEL-ICE, PicKit4, Dragon, ...

 

ASk if you have a problem.

 

David.

 

p.s. if you are determined to use a Nano,   cut track(s) with sharp knife or mini-drill.    It is easier to restore by hand-wiring a patch than to move SMD components.

Last Edited: Wed. Aug 7, 2019 - 05:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your early reply @david.prentice.

A Nano will never work with debugWIRE unless you disconnect the DTR capacitor and replace the 1k0 RESET pullup resistor with 10k (or remove entirely)

I have 3 Nano's, and  plan to use 1 as a development board. I have already done the aforementioned setup in this one. I will consider an Arduino Uno too.

 

Besides this tweak, I wonder if I'll need to do any workaround in my PC, especially considering a will be focusing in a Linux enviroment; and reading a few of the forum posts, it seems some have had trouble with it.

 

I'm currently at my workplace and it's noon here; so anything intended will be done this afternoon.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have 3 Nanos,   I would remove the capacitor and 1k pullup on one Nano.   Enable debugWIRE.   Never restore as a Nano.

 

I find Uno format easier for development.   You can even buy XMINI-328P or XMINI-328PB.

 

If you need a small Target pcb,   after develop/debug on a Uno then just burn the working HEX on the Nano.

 

David.

 

You need MPLABX v5.25.    AS7.0 does not support SNAP.

Last Edited: Wed. Aug 7, 2019 - 05:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Thanks for your discussion/help so far!

I have spent some hours now to use Snap to debug/program an ATmega328P device (minimal HW) with MPLAB X IDE v5.20 and Windows 7, and it finally works.

Programming and fuse read/write with ICP is ok and debugging with debugWire, too.

Maybe this is not new for the forum but I miss the success post in the ongoing discussion.

I updated to MPLAB X IDE v5.25 and got the same results.

Regards Gustav, Vienna 

 

Last Edited: Mon. Oct 7, 2019 - 07:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found this table too.  However the instructions for the MPLAB Snap state for "pin 6 - Do Not Connect"

The MPLAB Snap seems to have no instruction on correct connection but only references to the PICkit 4.

This does not really help because there seems (in print at least) that the 8 pins on the 2 units do not have 1-1 match.

 MPLAB Snap

Pin 6 - Do not connect

Pin 7 - not used

Pin 8 - not used

 

I would be nice to see a direct connection diagram.  I might even get the 20 TQFP/QFN Atmega328 and the atmega2560 with a bootloader on them.

So only one worked.

In the meantime I pray that Dr.Google will eventually help

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I read carefully a few topics but still have error message : 

Data transmission failed. Error code -10121 returned while trying to receive USB data.

A communication error with the debug tool has occurred. The tool will be reset and should re-enumerate shortly.
Connection Failed.

I'm using snap connect to either nano or atmega2560 boards thru ISP connector. I have connected following schema in previous thread.

Version of MPLAB is 5.35.

The only thing that I did not do : remove r48 from snap. Do I really need to do it (knowing that i'm not in  UPDI ....) nor in debugwiore but in ISP¨in MPLAB as well.

 

thank you for your help.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you used (or tried to use) the Snap with a PIC target device first?

(In the past this has been known to shake out some cobwebs and make it work for AVRs too.)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No I haven't tried that.

With the ATmega328 I am confused about the with the connections to the SNAP.

The info I see says to use the table for the PIC4.  With AVRs that table uses pin 6 of the snap but elsewhere there is documentation that states not to use pin 6.

 

I did have success using an Arduino Pro-Mini to put the bootloader onto an ATmega328 QFN32, but only one so far

 

I'll have see about getting a PIC device and trying that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well you don't need to actually have a PIC device - just try to program one and the debugger has to switch from AVR mode to PIC mode.  After the failed attempt, switch back to an AVR.

 

If I remember correctly, SPI is on 4, 5 and 7; and debugWIRE on 6.

To successfully debug you will need to wire all of these, and Vcc+GND

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Thanks for that.  I worked.

 

Now I just have to be more careful with the OFN package so in future I don't get solder bridging between adjacent pins.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I too had a difficult time getting MPLAB X IDE v5.40 to use a Snap to program an ATMega328. Key steps were first setting up the Snap to target a PIC device (no actual PIC device needed, just get it to try to read the device ID while no device is connected), then set the target device to ATMega328, and set the Project Properties / Snap / Communication / Interface to ISE and the Speed (MHz) to 0.4 MHz. I have some more detailed notes if anyone is curious.

 

Now I'd like to know if it's possible to program and debug an ATMega328 using Snap and Atmel Studio 7.0. I can build OK, but how do I set up Atmel Studio to program and debug the ATMega328?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The most important step is connecting all 6 wires on the 3x2 ISP header to your SNAP.

I strongly advise making a proper adapter with a 6-way ribbon cable..

 

Update AS7.0 to current version.

Update Packs to current version.

 

Select SNAP and ISP.   Check that you can read Signature in Device Programming via the 3x2 ISP header.

 

Select SNAP and debugWIRE for your project.

Build and debug in the normal way.

 

When done,  start a Debug session but exit with "Disable debugWIRE and Close"

 

If you have a problem,  take notes on paper.

Then type up your notes to show the (numbered) steps that you took.

 

Then you will get accurate answers.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks! I just installed Atmel Studio 7.0 a few days ago. It seems the CMSIS pack was not included in the installation, so AS didn't know how to talk to the Snap. After installing that pack, restarting AS, and setting the communication method to debugWIRE, I could program and debug my ATmega328 target board.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

So the SNAP now works with Atmel Studio?

 

I'm updating AS7 as we speak!

 

Been trying to figure out MPLab for the last few days but it's a mess.

 

Also hi!

Pages