spencekonde / avr-guidance Goto Github PK
View Code? Open in Web Editor NEWA guide to best practices when using the Arduino IDE to program AVR microcontrollers
A guide to best practices when using the Arduino IDE to program AVR microcontrollers
I trying to upload a blink sketch to an AVR128DB32 processor.
Using a FTDI board (Robotdyn) witch has a CH340H chip onboard.
Added the diode between Rx and Tx and have a 470R resistor in series with the UPDI line.
Updated the programmers.txt
, boards.txt
and platforms.txt
files in my Arduino15
map and copied the python3 program to the map ../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/python3
.
The full path now is: ../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/python3/python3
This is what is in the tools map:
$ la -l
total 88
-rw-r--r-- 1 User staff 1523 May 18 17:35 ManualPython.md
-rw-r--r-- 1 User staff 26974 May 18 17:35 README.md
drwxr-xr-x 9 User staff 288 Sep 30 13:52 libs
-rw-r--r-- 1 User staff 9258 May 18 17:35 prog.py
drwxr-xr-x 3 User staff 96 Oct 22 12:44 python3
I get these errors uploading the sketch:
Sketch uses 5962 bytes (4%) of program storage space. Maximum is 131072 bytes.
Global variables use 534 bytes (3%) of dynamic memory, leaving 15850 bytes for local variables. Maximum is 16384 bytes.
../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/python3/python3 -u ../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/prog.py -t uart -u /dev/cu.usbserial-1434440 -b 230400 -d avr128db32 --fuses 5:0b11001001 7:0x00 8:0x00 -f../tmp/arduinoBuild/Blink.ino.hex -a write
Arduino <---> pymcuprog bridge by Quentin Bolsee and Spence Konde
Version 1.1.0 - May 2021
Using serial port /dev/cu.usbserial-1434440 at 230400 baud.
Target: avr128db32
Set fuses: ['5:0b11001001', '7:0x00', '8:0x00']
Action: write
File: ../tmp/arduinoBuild/Blink.ino.hex
Traceback (most recent call last):
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/prog.py", line 266, in <module>
main()
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/prog.py", line 121, in main
return_code = pymcuprog_basic(args, fuses_dict)
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/prog.py", line 183, in pymcuprog_basic
status = pymcu._start_session(backend,
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/pymcuprog_main.py", line 549, in _start_session
backend.start_session(sessionconfig)
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/backend.py", line 359, in start_session
self.programmer.setup_device(
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/programmer.py", line 78, in setup_device
self.device_model = get_nvm_access_provider(self.transport,
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/nvm.py", line 42, in get_nvm_access_provider
accessprovider = NvmAccessProviderSerial(transport, device_info, baud=frequency)
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/nvmserialupdi.py", line 53, in __init__
self.avr = UpdiApplication(port, baud, self.dut)
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/serialupdi/application.py", line 79, in __init__
datalink.init_datalink()
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/serialupdi/link.py", line 45, in init_datalink
raise PymcuprogError("UPDI initialisation failed")
pymcuprog.pymcuprog_errors.PymcuprogError: UPDI initialisation failed
pymcuprog.pymcuprog_errors.PymcuprogError: UPDI initialisation failed
With the FTDI adaptor I got from you with the AVR128DB64 board I get these errors:
Global variables use 534 bytes (3%) of dynamic memory, leaving 15850 bytes for local variables. Maximum is 16384 bytes.
../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/python3/python3 -u ../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/prog.py -t uart -u /dev/cu.usbserial-1434440 -b 230400 -d avr128db32 --fuses 5:0b11001001 7:0x00 8:0x00 -f../tmp/arduinoBuild/Blink.ino.hex -a write
Arduino <---> pymcuprog bridge by Quentin Bolsee and Spence Konde
Version 1.1.0 - May 2021
Using serial port /dev/cu.usbserial-1434440 at 230400 baud.
Target: avr128db32
Set fuses: ['5:0b11001001', '7:0x00', '8:0x00']
Action: write
File: ../tmp/arduinoBuild/Blink.ino.hex
pymcuprog.serialupdi.application - ERROR - Hard reset failed.
Traceback (most recent call last):
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/prog.py", line 266, in <module>
main()
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/prog.py", line 121, in main
return_code = pymcuprog_basic(args, fuses_dict)
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/prog.py", line 183, in pymcuprog_basic
status = pymcu._start_session(backend,
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/pymcuprog_main.py", line 549, in _start_session
backend.start_session(sessionconfig)
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/backend.py", line 359, in start_session
self.programmer.setup_device(
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/programmer.py", line 78, in setup_device
self.device_model = get_nvm_access_provider(self.transport,
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/nvm.py", line 42, in get_nvm_access_provider
accessprovider = NvmAccessProviderSerial(transport, device_info, baud=frequency)
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/nvmserialupdi.py", line 56, in __init__
self.avr.read_device_info()
File "../Arduino15/packages/DxCore/hardware/megaavr/1.3.6/tools/libs/pymcuprog/serialupdi/application.py", line 104, in read_device_info
raise RuntimeError("Failed to read device info.")
RuntimeError: Failed to read device info.
RuntimeError: Failed to read device info.
Have I forgotten something?
I have added a 4k7 resistor between the Tx and Rx lines .. and now it works!
But, this (from ../UPDI/jtag2updi.md) is very confusing (to me anyway) as is the naming of this document ;-):
Some tinyAVR and other UPDI-based part breakout boards have an on-board resistor. Sometimes this is a 4.7k one. That is NOT appropriate. I was part of the problem for a while. I think the original mistake came from people conflating the pyupdi resistor with a generally appropriate one. When I started megaTinyCore, my early collaborator was making hardware with a 4.7k resistor; I assumed he was doing it right. While this does work with dedicated programmers, including jtag2updi, it doesn't work with serial UPDIO. It will work with dedicated programmers like jtag2updi, as long as they don't have their own resistor. Suffice to say, for a time it was a very common belief. I use 470 ohms now, but I can't find fault with a design over it not having one at all.
Vcc, Gnd of serial adapter to Vcc, Gnd of target
4.7k resistor between Tx and Rx of adapter (many adapters have built-in 1k, 1.5k, or 2.2k resistor in series with Tx; these should use a proportionally smaller resistor)
For better results, a smaller resistor (that built-in one on most adapters, mentioned above, will do perfectly here) and a small schottky diode (band towards Tx, other end connected to Rx) can be used (use a "small signal diode" - larger general purpose diodes may have properties that make them less suitable for this) The diode substantially widens the tolerances of this programming method, and significantly improves reliability.
My top pick here is the BAT54C,235; it's in a tiny SOT-23 package (it's 2 diodes both weith the "band" towards the pin thats' alone on one side) Why? Because, assuming your serial adapter has the pins on 0.1" header, and TX and RX are next to eachother (both extremely common) the the diode fits right in beteeen them. and with no lead that could later fatigue and break the result is less likely to be damaged by rough handling. Then if I want to more ovbviously mark it as a UPDI programmer, I might cut off the Tx, DTR and CTS pin; always remember that you can get serial adapters for a buck a piece on ebay.
Rx of adapter to UPDI pin of target. A small resistor (under 1k - like the 470 ohm one we generally recommend) in series with this is fine.
Hi, I'd like to ask about the status of HyperUPDI.
I wanted to build a simple shield myself for Arduino Nano to extend jtag2updi with 12V booster and an opto-switch . But then I thought building a full one with a mCPU won't be much more complex. As you write, it'd allow both a pass-through and a buffered operation mode.
One possibility would be to use ATtiny322x, which has 3kb of SRAM. I'm not sure if this would be large enough buffer. If not, it could be extended with a SPI external RAM chip.
Or, shifting the idea yet another level, one could use a Atmel SAM Dx mCPU such as SAMD51J20. It'd have more than plenty of RAM and also has a built in USB interface. But obviously harder to program.
Hi Spence
On the old repository
https://github.com/SpenceKonde/jtag2updi
There is no link to the new improved solution:
https://github.com/SpenceKonde/AVR-Guidance/blob/master/UPDI/jtag2updi.md
Can you add the link?
I have been trying to burn a bootloader into an ATtiny3217 for quite some time now. It does not work. With an unprogrammed, new ATtiny3217, I can burn the bootloader, without an error message, but it does not work, there is no RX communication back from the ATtiny. The UPDI pin was set as reset.
Now I want to burn a bootloader again in the ATtiny3217 with a HV programmer (because the UPDI pin was reset), this doesn't work either.
Here are the settings:
This is the error message when burning the bootloader:
SerialUPDI UPDI programming for Arduino using a serial adapter Based on pymcuprog, with significant modifications By Quentin Bolsee and Spence Konde Version 1.2.3 - Jan 2022 Using serial port COM4 at 57600 baud. Target: attiny3217 Set fuses: ['0:0x00', '1:0x00', '2:0x01', '5:0b11000100', '6:0x04', '7:0x00', '8:0x02'] Action: write File: C:\Users\Albert\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10/bootloaders/hex/optiboot_txyz_all8sec.hex Traceback (most recent call last): File "C:\Users\Albert\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10/tools/prog.py", line 286, in <module> main() File "C:\Users\Albert\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10/tools/prog.py", line 128, in main return_code = pymcuprog_basic(args, fuses_dict) File "C:\Users\Albert\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10/tools/prog.py", line 201, in pymcuprog_basic args_start) File "C:\Users\Albert\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10\tools\libs\pymcuprog\pymcuprog_main.py", line 545, in _start_session backend.start_session(sessionconfig) File "C:\Users\Albert\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10\tools\libs\pymcuprog\backend.py", line 362, in start_session sessionconfig.interface_speed) File "C:\Users\Albert\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10\tools\libs\pymcuprog\programmer.py", line 83, in setup_device options=self.options) File "C:\Users\Albert\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10\tools\libs\pymcuprog\nvm.py", line 42, in get_nvm_access_provider accessprovider = NvmAccessProviderSerial(transport, device_info, baud=frequency, options=options) File "C:\Users\Albert\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10\tools\libs\pymcuprog\nvmserialupdi.py", line 57, in __init__ self.avr.read_device_info() File "C:\Users\Albert\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10\tools\libs\pymcuprog\serialupdi\application.py", line 125, in read_device_info self.logger.info("PDI revision = 0x%02X", self.readwrite.read_cs(constants.UPDI_CS_STATUSA) >> 4) File "C:\Users\Albert\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10\tools\libs\pymcuprog\serialupdi\readwrite.py", line 25, in read_cs return self.datalink.ldcs(address) File "C:\Users\Albert\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10\tools\libs\pymcuprog\serialupdi\link.py", line 88, in ldcs "{} byte(s) expected {} byte(s)".format(numbytes_received, self.LDCS_RESPONSE_BYTES)) pymcuprog.pymcuprog_errors.PymcuprogError: Unexpected number of bytes in response: 0 byte(s) expected 1 byte(s) Error while burning bootloader.
This is the HV puls and the DTR signal on the scope:
In 2020, burning the bootloader worked fine and I wrote an article about it:
https://avdweb.nl/arduino/attiny3217/bootloader-attiny3217
Dear Spence
In 2020, we discussed the ATtiny3217, and I had created a guide on programming it, which you can find here: https://avdweb.nl/arduino/attiny3217/bootloader-attiny3217
However, things are changed now, particularly in the UPDI programming method.
I intend to rewrite the page to reflect these changes, but I'm facing difficulty due to the lenght of your guide here: https://github.com/SpenceKonde/AVR-Guidance/blob/master/UPDI/jtag2updi.md
It's become challenging to find the necessary steps for uploading the bootloader to the ATtiny.
Could you please assist me by providing a concise guide, perhaps around 10 lines or so, outlining the bootloader uploading process?
Thank you,
Albert
On the page:
https://github.com/SpenceKonde/AVR-Guidance/blob/master/UPDI/jtag2updi.md
However, if your choice is between a resistor and a silicon diode, as opposed to as Schottky one, always pick the Schottky, because the silicon diode will not work.
should presumably read:
However, if your choice is between a resistor and a silicon diode, as opposed to a Schottky one, always pick the resistor, because the silicon diode will not work.
I was wondering how you do UPD and Serial togther but the link all the way on the end of this page (last line) is dead:
https://github.com/SpenceKonde/AVR-Guidance/blob/master/UPDI/jtag2updi.md
Not really an issue, but a problem and solution. I was having no joy uploading using a chinese (CH340) Nano clone to a 1614 F and found it would only work with no resistor in circuit with the UPDI pin. Avrdude was reporting either no power or incorrect state errors during upload.
Hopefully this might be helpful to someone experiencing the similar issues in future.
The page:
https://github.com/SpenceKonde/AVR-Guidance/blob/master/UPDI/jtag2updi.md
is a bit daunting for someone just wanting to get UPDI to work with DxCore or megaTinyCore.
It's great to have all that information available, but first there should be a simple circuit that will work in most cases. After reading all your advice I think this should be:
-------------------- To Target device
DTR| 470Ω BAT43 __________________
Rx |---------------------,-----------| UPDI
Tx |----/\/\-----|<|----' ,----| Gnd
Vcc|---------------------------/-----| Vcc
CTS| / |__________________
Gnd|-------------------------'
--------------------
I believe this will work whether or not the USB to Serial adapter has an internal resistor in series with Tx, or the target device has a resistor in series with UPDI. For most people the BAT43 will be easier to solder than an SMD diode, and it's available at most hobby shops.
Put this first, and then have all the suggestions about what to do if you don't have a Schottky diode available, etc., under a Further Information heading.
Not sure if this is an issue on my side but, I get this error trying to upload.
My python version is 3.10.2
SerialUPDI
UPDI programming for Arduino using a serial adapter
Based on pymcuprog, with significant modifications
By Quentin Bolsee and Spence Konde
Version 1.2.3 - Jan 2022
Using serial port /dev/ttyUSB0 at 460800 baud.
Target: attiny1614
Set fuses: ['2:0x01', '6:0x04', '8:0x00']
Action: write
File: /tmp/arduino_build_669110/Blink.ino.hex
Traceback (most recent call last):
File "/home/eturd/.arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/prog.py", line 285, in
main()
File "/home/eturd/.arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/prog.py", line 127, in main
An error occurred while uploading the sketch
setup_logging(user_requested_level=logging_level)
File "/home/eturd/.arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/pymcuprog/pymcuprog.py", line 47, in setup_logging
configfile = yaml.safe_load(file)
File "/home/eturd/.arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/yaml/init.py", line 94, in safe_load
return load(stream, SafeLoader)
File "/home/eturd/.arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/yaml/init.py", line 72, in load
return loader.get_single_data()
File "/home/eturd/.arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/yaml/constructor.py", line 37, in get_single_data
return self.construct_document(node)
File "/home/eturd/.arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/yaml/constructor.py", line 46, in construct_document
for dummy in generator:
File "/home/eturd/.arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/yaml/constructor.py", line 398, in construct_yaml_map
value = self.construct_mapping(node)
File "/home/eturd/.arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/yaml/constructor.py", line 204, in construct_mapping
return super().construct_mapping(node, deep=deep)
File "/home/eturd/.arduino15/packages/megaTinyCore/hardware/megaavr/2.5.10/tools/libs/yaml/constructor.py", line 126, in construct_mapping
if not isinstance(key, collections.Hashable):
AttributeError: module 'collections' has no attribute 'Hashable'
hello does jtag2updi support avr128da28 to be programmed by arduino uno? , i want to program avr128da28 chip using arduino uno as a programmer, can anyone provide me steps to do that
Hi, I am programming an attiny816. Everything works fine with USB to TTL Cable but no way to program it using Raspberry GPIO without USB to TTL..any hint ?
Raspberry GPIO electric level is 3.3V and attiny816 is 5V, but attiny816 can read a 3.3V signal correctly.
Is a level shifter needed? Has it to be OpenDrain or with a specific output?
tks
Using the MegaTinyCore and PIN_Pxn references do not work for Serial.pins() or analogRead(). Under this scheme is pin A3 (digital pin 16) referred to as PA3_PIN for both digital and analog functions?
Just commenting because you recommend using this notation so I was attempting to "do it right" but got stymied pretty quickly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.