mraardvark / pyupdi

Python UPDI driver for programming "new" tinyAVR and megaAVR devices
MIT License
212 stars 73 forks source link

Can't write fuses to AVR128DB32 #74

Closed Miraculix200 closed 3 years ago

Miraculix200 commented 3 years ago

Using a 3.3V FTDI Basic serial connection with 4.7k Ohm resistor (as seen in the ASCII schematic in the README)

With pyupdi I can successfully write a bootloader to the device (at least it says that it was successful) and read the fuses. However it does not successfully set the fuses.

This is the bootloader I flashed: https://github.com/SpenceKonde/DxCore/blob/master/megaavr/bootloaders/hex/optiboot_dx128_ser0.hex

When doing something like python.exe pyupdi.py -d avr128db32 -c COM3 -fs 2:0x01 -b 9600 -v (that was just for testing, not for changing the oscillator)

I get this response:

Verify error for fuse 2, expected 0x01 read 0x00
Error during processing

The fuses simply stay the same as they were before.

Any idea what the problem could be? When setting fuses of a ATmega4808 I don't have any problems.

Full verbose output when trying to set fuse: https://gist.github.com/Miraculix200/c237eeb85cd46688b02ecc341ae5ba86

Reading fuses: https://gist.github.com/Miraculix200/fe1d25380a1f50111b34e5085431e126

mraardvark commented 3 years ago

Hi, Could you perhaps try pymcuprog as a replacement to pyupdi? pip install pymcuprog pymcuprog -t uart -u COM3 -c 9600 -d avr128db32 write -m fuses -l

Miraculix200 commented 3 years ago

I don't know what I just did (it expected me to enter a value, so I entered "1"), but it looks like it wrote something to the fuses memory:

pymcuprog -t uart -u COM3 -c 9600 -d avr128db32 write -m fuses -l 1

Writing literal values...

Done.
Miraculix200 commented 3 years ago

pyupdi doesn't like what I did, now it hangs when I read the fuses, but I see the 0 fuse has changed from 0x00 to 0x01

Would be nice to have an example on the pymcuprog homepage, how to set a specific fuse. As it expects a different format than pyupdi.

Edit: I guess I got it pymcuprog -t uart -u COM3 -c 9600 -d avr128db32 write -m fuses -o 2 -l 0x01

mraardvark commented 3 years ago

Yes, we could always do with more examples... once it gets to github it will be easier to add examples there. Are you able to write flash and other memories you need too then?

Miraculix200 commented 3 years ago

I can now write sketches to it using DxCore on Arduino IDE, after setting the correct fuses (BOOTSIZE and RSTPINCFG). I don't need anything else right now, but I see no reason why it wouldn't work with pymcuprog.

Thanks for the hint.

Miraculix200 commented 3 years ago

I'll write a small step by step guide (like this https://oshwlab.com/Miraculix200/minimegazero24_copy) on the page of a open source dev board for AVR*DB32 I created, so maybe you can also give a hint how I can flash a bootloader without destroying the MCU :)

Otherwise the step by step guide would include both pyupdi and pymcuprog. Though I guess I could also figure it out myself tomorrow.

mraardvark commented 3 years ago

Sure. FYI - pymcuprog will be maintained with new devices going forward well before pyupdi; but will always maintain a consistent API (since its used for various purposes)

One oddity (/issue) right now is that the device must be erased in a separate command: pymcuprog erase After that, you can write a hexfile to flash simply using pymcuprog write -f Besides that, the "ping" command is a useful "connectivity check" which i run before anything else

Miraculix200 commented 3 years ago

That also worked. So I guess unlike pyupdi, pymcuprog can do everything it's supposed to.

I've tried it without "pymcuprog erase" on a fresh AVR128DB32, which worked without problems.