SpenceKonde / megaTinyCore

Arduino core for the tinyAVR 0/1/2-series - Ones's digit 2,4,5,7 (pincount, 8,14,20,24), tens digit 0, 1, or 2 (featureset), preceded by flash in kb. Library maintainers: porting help available!
Other
551 stars 142 forks source link

attiny 412 programming: UPDI initialization failed. #545

Closed phil-barrett closed 2 years ago

phil-barrett commented 2 years ago

Arduino 1.8.15, Win 10, megaTinyCore 2.4.2 installed via board manager. Windows board manager shows the USB port for the programmer.

Programmer Selected: SerialUPDI with serial 4.7K or diode 230400 baud Programmer is CH340, first version. 470 ohm resistor on UPDI pin. diode between TX and RX. I don't know how to verify my serial programmer works correctly. I verified that the diode orientation is correct. It does pass the "loopback" test without the diode. If it's a bug in my programmer, not sure how to figure it out. Any help greatly appreciated. Target board is my own design. Works with Atmel ICE. Error trace back from Arduino: (sorry for the crappy formatting, Arduino IDE kinda sucks.)

cmd /C "C:\Users\philba\AppData\Local\Arduino15\packages\DxCore\tools\avr-gcc\7.3.0-atmel3.6.1-azduino4b/bin/avr-nm" --numeric-sort --line-numbers --demangle --print-size --format=s "C:\Users\philba\AppData\Local\Temp\arduino_build_642728/Blink.ino.elf" > "C:\Users\philba\AppData\Local\Temp\arduino_build_642728/Blink.ino.map" "C:\Users\philba\AppData\Local\Arduino15\packages\DxCore\tools\avr-gcc\7.3.0-atmel3.6.1-azduino4b/bin/avr-size" -A "C:\Users\philba\AppData\Local\Temp\arduino_build_642728/Blink.ino.elf" Sketch uses 632 bytes (15%) of program storage space. Maximum is 4096 bytes. Global variables use 10 bytes (3%) of dynamic memory, leaving 246 bytes for local variables. Maximum is 256 bytes. C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\tools\python3\3.7.2-post1/python3 -u C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2/tools/prog.py -t uart -u COM5 -b 230400 -d attiny412 --fuses 2:0x02 6:0x04 8:0x00 -fC:\Users\philba\AppData\Local\Temp\arduino_build_642728/Blink.ino.hex -a write SerialUPDI UPDI programming for Arduino using a serial adapter Based on pymcuprog, with significant modifications By Quentin Bolsee and Spence Konde Version 1.2.0 - June 2021 Using serial port COM5 at 230400 baud. Target: attiny412 Set fuses: ['2:0x02', '6:0x04', '8:0x00'] Action: write File: C:\Users\philba\AppData\Local\Temp\arduino_build_642728/Blink.ino.hex Traceback (most recent call last): File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2/tools/prog.py", line 282, in main() File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2/tools/prog.py", line 131, in main return_code = pymcuprog_basic(args, fuses_dict) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2/tools/prog.py", line 198, in pymcuprog_basic args_start) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\pymcuprog_main.py", line 544, in _start_session backend.start_session(sessionconfig) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\backend.py", line 362, in start_session sessionconfig.interface_speed) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\programmer.py", line 83, in setup_device options=self.options) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\nvm.py", line 42, in get_nvm_access_provider accessprovider = NvmAccessProviderSerial(transport, device_info, baud=frequency) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\nvmserialupdi.py", line 53, in init self.avr = UpdiApplication(port, baud, self.dut) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\serialupdi\application.py", line 79, in init datalink.init_datalink() File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\serialupdi\link.py", line 44, in init_datalink raise PymcuprogError("UPDI initialisation failed") pymcuprog.pymcuprog_errors.PymcuprogError: UPDI initialisation failed pymcuprog.pymcuprog_errors.PymcuprogError: UPDI initialisation failed

SpenceKonde commented 2 years ago

Is that diode a schotky? If not, a 4.7k resistor will work better - I could never make it work with a silicon diode. Most ch340 adapters have a resistor in series with the TX pin so if yours does, try without the 470 ohm resistor (which is not in any way required for serial UPDI - all we need is at least 470-1k total between the two, and I keep starting to think I need to lower the value of the series resistor for general use.


Spence Konde Azzy’S Electronics

New products! Check them out at tindie.com/stores/DrAzzy GitHub: github.com/SpenceKonde ATTinyCore: Arduino support for almost every ATTiny microcontroller Contact: @.***

On Tue, Nov 9, 2021, 03:05 phil-barrett @.***> wrote:

Arduino 1.8.15, Win 10, megaTinyCore 2.4.2 installed via board manager.

Programmer Selected: SerialUPDI with serial 4.7K or diode 230400 baud Programmer is CH340, first version. 470 ohm resistor on UPDI pin. diode between TX and RX. I don't know how to verify my serial programmer works correctly. I verified that the diode orientation is correct. It does pass the "loopback" test without the diode. Target board is my own design. Works with Atmel ICE. Error trace back from Arduino: (sorry for the crappy formatting, Arduino IDE kinda sucks.)

cmd /C "C:\Users\philba\AppData\Local\Arduino15\packages\DxCore\tools\avr-gcc\7.3.0-atmel3.6.1-azduino4b/bin/avr-nm" --numeric-sort --line-numbers --demangle --print-size --format=s "C:\Users\philba\AppData\Local\Temp\arduino_build_642728/Blink.ino.elf" > "C:\Users\philba\AppData\Local\Temp\arduino_build_642728/Blink.ino.map" "C:\Users\philba\AppData\Local\Arduino15\packages\DxCore\tools\avr-gcc\7.3.0-atmel3.6.1-azduino4b/bin/avr-size" -A "C:\Users\philba\AppData\Local\Temp\arduino_build_642728/Blink.ino.elf" Sketch uses 632 bytes (15%) of program storage space. Maximum is 4096 bytes. Global variables use 10 bytes (3%) of dynamic memory, leaving 246 bytes for local variables. Maximum is 256 bytes. C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\tools\python3\3.7.2-post1/python3 -u C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2/tools/prog.py -t uart -u COM5 -b 230400 -d attiny412 --fuses 2:0x02 6:0x04 8:0x00 -fC:\Users\philba\AppData\Local\Temp\arduino_build_642728/Blink.ino.hex -a write SerialUPDI UPDI programming for Arduino using a serial adapter Based on pymcuprog, with significant modifications By Quentin Bolsee and Spence Konde Version 1.2.0 - June 2021 Using serial port COM5 at 230400 baud. Target: attiny412 Set fuses: ['2:0x02', '6:0x04', '8:0x00'] Action: write File: C:\Users\philba\AppData\Local\Temp\arduino_build_642728/Blink.ino.hex Traceback (most recent call last): File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2/tools/prog.py", line 282, in main() File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2/tools/prog.py", line 131, in main return_code = pymcuprog_basic(args, fuses_dict) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2/tools/prog.py", line 198, in pymcuprog_basic args_start) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\pymcuprog_main.py", line 544, in _start_session backend.start_session(sessionconfig) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\backend.py", line 362, in start_session sessionconfig.interface_speed) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\programmer.py", line 83, in setup_device options=self.options) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\nvm.py", line 42, in get_nvm_access_provider accessprovider = NvmAccessProviderSerial(transport, device_info, baud=frequency) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\nvmserialupdi.py", line 53, in init self.avr = UpdiApplication(port, baud, self.dut) File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\serialupdi\application.py", line 79, in init datalink.init_datalink() File "C:\Users\philba\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.4.2\tools\libs\pymcuprog\serialupdi\link.py", line 44, in init_datalink raise PymcuprogError("UPDI initialisation failed") pymcuprog.pymcuprog_errors.PymcuprogError: UPDI initialisation failed pymcuprog.pymcuprog_errors.PymcuprogError: UPDI initialisation failed

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/SpenceKonde/megaTinyCore/issues/545, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTXEW26GOPTTXBWDUMHGVTULDI53ANCNFSM5HUTYJNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

phil-barrett commented 2 years ago

It was a 1N4148 like the UPDI docs call out. But, that isn't a schottky by the way. It's just a fast switching silicon diode. I do have some real schottky diodes I could use. But, it sounds like the 4.7K resistors works so I'll go with that. Put it between RX and TX on the serial adapter, right?

Yeah, my CH340 adapter has a 1.5K R on TX

Thanks for getting back to me. I know you've got lots on your plate and appreciate your attention.

SpenceKonde commented 2 years ago

ARGHHHHH which document still has the wrong partnumber? I thought I went through and fixed that everywhere when I realized I'd screwed up on the part number....

On Tue, Nov 9, 2021 at 5:06 PM phil-barrett @.***> wrote:

It was a 1N4148 like the UPDI docs call out. But, that isn't a schottky by the way. It's just a fast switching silicon diode. I do have some real schottky diodes I could use. But, it sounds like the 4.7K resistors works so I'll go with that. Put it between RX and TX on the serial adapter, right?

Thanks for getting back to me. I know you've got lots on your plate and appreciate your attention.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SpenceKonde/megaTinyCore/issues/545#issuecomment-964588994, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTXEW2Z32S2LVCAOSQ7OY3ULGLMVANCNFSM5HUTYJNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

--


Spence Konde Azzy’S Electronics

New products! Check them out at tindie.com/stores/DrAzzy GitHub: github.com/SpenceKonde ATTinyCore https://github.com/SpenceKonde/ATTinyCore: Arduino support for all pre-2016 tinyAVR with >2k flash! megaTinyCore https://github.com/SpenceKonde/megaTinyCore: Arduino support for all post-2016 tinyAVR parts! DxCore https://github.com/SpenceKonde/DxCore: Arduino support for the AVR Dx-series parts, the latest and greatest from Microchip! Contact: @.***

phil-barrett commented 2 years ago

It's here.

Tell you what, once I get it working with the resistor, I will try out a schottky diode and let you know.

SpenceKonde commented 2 years ago

Thanks - fixed. If you have a 'scope, it is much easier to debug - generally the cause of programming problems is that the balance of "pulling line high" and "pulling line low" is wrong and either the serial adapter isn't able to pull the updi line low enough for the target to recognize a low, or the target isn't able to pull it low enough for the adapter to recognize a high - both of which are very easy to see on a scope, and in successful communication you see the line going to a different voltage as the "low" depending on which side it comes from.

With the 4.7k resistor, it barely works with a 470 ohm, series resistor which is why I use and recommend the schottky diode. (the series resistor is needed for the simplest jtag2updi programmer from nano, because a lot of those get built with no series resistor of their own and that really shouldn't be connected directly because it's possible in theory for the two to be out of sync and fight over the line.

Just like every other programming issue, the errors you get back are practically useless. All it can see is "Huh, I didn't get the response I expected", just like the STK500 sync error for bootloader uploads. There's no information there, because all it's getting is what character the serial adapter sees. We could do a better job with the debugging messages, as there is one piece of information we do get - we can tell if we're seeing the character we sent... but the code is a bit of a dumpster fire (it's derived from pymcuprog it's agonizing to work with and when I talked about the verbosity of the verbose mode (that's why there isn't a verbose mode available for it - the actual verbose mode drowns you in spurious output) the guy who was the python expert on the project still hadn't accepted that we are't going to be able to merge in changes from pymcuprog anyway

SpenceKonde commented 2 years ago

Attiny3226 support requires 2.4.3 (github) avrdude.conf for uploads through avrdude. Uploads using the recommended upload tool, serialupdi, should be fine

There are two major changes that are half implemented in the core itself totally unrelated to that so it is awkward for me to do a release and I have a ton a documents that refer to 2.4.3 as being the first release with new features, so I would need to find all those and correct them if I built a new branch with the features rolled back to 2.4.2 state and that whole process sucks when one text file is missing 3 entries and we're deep into dev of next versiob because the ide doesn't let you put . I think serialupdi should w


Spence Konde Azzy’S Electronics

New products! Check them out at tindie.com/stores/DrAzzy GitHub: github.com/SpenceKonde ATTinyCore: Arduino support for almost every ATTiny microcontroller Contact: @.***

On Wed, Nov 17, 2021, 14:22 SanFable @.***> wrote:

Hello,

I have similar problem using new Attiny3226 using working arduino nano setup as a jtag2updi (I have bracket and on other attiny it works).

avrdude: AVR Part "attiny3226" not found.

Valid parts are: uc3a0512 = AT32UC3A0512 c128 = AT90CAN128 c32 = AT90CAN32 c64 = AT90CAN64 pwm2 = AT90PWM2 pwm216 = AT90PWM216 ...

Any solution?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SpenceKonde/megaTinyCore/issues/545#issuecomment-971899137, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTXEW5XER26EW2BOJLL4S3UMP6G3ANCNFSM5HUTYJNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

SpenceKonde commented 2 years ago

worth noting that 2.5.0 (formerly 2.4.3) is coming out VERY soon.

SpenceKonde commented 2 years ago

No comments from OP in over a week. Closing under assumption that this is resolved.

dejavu1987 commented 1 year ago

Well I have tried using an smd switching diode and a the resistor of 1k and my CH340 adapter to program my first ATTiny424, and it worked without a hitch, I tried twice and worked like a charm.

Tx --------- |<|-----/------/\/\/\-------- UPDI
Rx ----------------/             1k

Now today a month later I tried literally same Hardware, same sketch, and same config, and it is not working anymore. Did anything change in the library, I can still see the same version in the terminal tho Version 1.2.3 - Jan 2022.

Really confused. I am getting same pymcuprog.pymcuprog_errors.PymcuprogError: UPDI initialisation failed

I have recorded a video which is on youtube which shows that the configs look similar too.

Using serial port /dev/cu.usbserial-210 at 230400 baud.
Delaying next op after each page write command by 1.0ms (-wd).
Target: attiny424
Set fuses: ['0:0b00000000', '2:0x02', '6:0x04', '7:0x00', '8:0x00']

Here is the video https://www.youtube.com/shorts/w51bsm1D_dc I have changed resistance value from 100Ohm, 1k and 4k7 but none made any difference.

full error stack trace:

Traceback (most recent call last):
  File "/Users/anilmaharjan/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.5/tools/prog.py", line 286, in <module>
    main()
  File "/Users/anilmaharjan/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.5/tools/prog.py", line 128, in main
    return_code = pymcuprog_basic(args, fuses_dict)
  File "/Users/anilmaharjan/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.5/tools/prog.py", line 199, in pymcuprog_basic
    status = pymcu._start_session(backend,
  File "/Users/anilmaharjan/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.5/tools/libs/pymcuprog/pymcuprog_main.py", line 545, in _start_session
    backend.start_session(sessionconfig)
  File "/Users/anilmaharjan/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.5/tools/libs/pymcuprog/backend.py", line 359, in start_session
    self.programmer.setup_device(
  File "/Users/anilmaharjan/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.5/tools/libs/pymcuprog/programmer.py", line 78, in setup_device
    self.device_model = get_nvm_access_provider(self.transport,
  File "/Users/anilmaharjan/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.5/tools/libs/pymcuprog/nvm.py", line 42, in get_nvm_access_provider
    accessprovider = NvmAccessProviderSerial(transport, device_info, baud=frequency, options=options)
  File "/Users/anilmaharjan/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.5/tools/libs/pymcuprog/nvmserialupdi.py", line 54, in __init__
    self.avr = UpdiApplication(port, baud, self.dut)
  File "/Users/anilmaharjan/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.5/tools/libs/pymcuprog/serialupdi/application.py", line 79, in __init__
    datalink.init_datalink()
  File "/Users/anilmaharjan/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.5/tools/libs/pymcuprog/serialupdi/link.py", line 44, in init_datalink
    raise PymcuprogError("UPDI initialisation failed")
pymcuprog.pymcuprog_errors.PymcuprogError: UPDI initialisation failed
Failed programming: uploading error: exit status 1
SpenceKonde commented 1 year ago

drop the resistor back to 220 ohms or so and it should work on a CH340, I use those all the time without issue,

dejavu1987 commented 1 year ago

Okay realised, my CH340 had Tx and Rx in reverse. Woked both with 1k and 330 res. In addition, I was using another board where UPDI pin was connected with a .1uF cap to the ground for some reason, that was also one reason it did not work.

wholder commented 1 year ago

To barge in on this thread, In an attempt to minimize issues with diode voltage drop, my idea was to use a tri-state buffer (sn74lvc1g125) where the enable pin (active low) is tied to the TX output of a CH340N and the sn74lvc1g125's input pin is tied low. In turn, the output pin of the sn74lvc1g125 is connected to the CH340N's RX pin and then to the UPDI pin on an ATtiny212, like , ilke this: UPDI Buffer 2 However, this does not seem to work... Specifically, the ATtiny212 does not respond to any queries I try sending.

The signal output from the sn74lvc1g125 looke fine on my scope, so I'm not sure what the problem might be. It seems like having a tri-state output from the TX line would be ideal, but I must be missing something. Any thoughts?

Note: I was able to use the diode scheme, but found that I kept getting garbled responses (parity errors, etc.) on the RX line

Leo-Ka commented 1 month ago

I have Attiny1616. Here is my solution: https://github.com/SpenceKonde/megaTinyCore/discussions/713?new_signup=true?new_signup=true#discussioncomment-10117450