Skip to content
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

Could a pre-compiled binary be made available? #4

Open
AaronD-GH opened this issue May 7, 2024 · 1 comment
Open

Could a pre-compiled binary be made available? #4

AaronD-GH opened this issue May 7, 2024 · 1 comment

Comments

@AaronD-GH
Copy link

For those of us that don't want to modify it, but "just drop it in and go", it would be nice to have something that is already known to work with a standalone programmer.

I can export a hex file from the Arduino IDE, but it only includes the Flash, not the Fuses. I guess that's a start, but the Fuses are important too! How to get those? Read the datasheet and build them up manually from the screenshot of the author's (old now) Arduino IDE?

Why I think I need this:

I rearranged the schematic and PCB from here, to make it a hat for a Raspberry Pi that uses the Pi's GPIO UART, driven from pymcuprog with its recommended schematic for UPDI. ( https://pypi.org/project/pymcuprog/ and https://github.com/microchip-pic-avr-tools/pymcuprog/blob/main/help.md and https://community.platformio.org/t/pymcuprog-cant-use-my-uart/40104/6 ) A set of jumpers allows the same UART to program the onboard ATtiny202 instead of an external target. As far as the ATtiny202 is concerned, it does the exact same function with the exact same code.

Of course, HV UPDI isn't available for the onboard chip, so I need to make absolutely sure that I don't brick it while still setting the rest of the Fuses to make the key work. But I don't see a UPDI setting in the Arduino IDE anymore, which makes me nervous. Did it get dropped? And does the new default setting brick it by accidentally requiring HV?

So, with pymcuprog by itself, not the Arduino IDE, how to make the connection between the documentation here and a completely programmed chip? I think a complete set of binary data would do that, and it appears from the middle link above that using pymcuprog by itself to read a working key would produce that data in a single hex file.

@AaronD-GH
Copy link
Author

AaronD-GH commented May 7, 2024

I can export a hex file from the Arduino IDE, but it only includes the Flash, not the Fuses. I guess that's a start, but the Fuses are important too! How to get those? Read the datasheet and build them up manually from the screenshot of the author's (old now) Arduino IDE?

Well, that's pretty much what I did:

  • Read the blank chip twice, once to a hex file and once to the terminal, because I needed the one and the other is much easier to read.
  • Matched the sizes of the different regions, and put some temporary labels in the hex file just to keep myself straight.
  • Manually overwrote the Fuses in the easier-to-read version, between the old screenshot here and the datasheet, making ABSOLUTELY sure that the UPDI setting was correct.
  • Translated the easier-to-read Fuse values to their section of the hex file that was read from the blank chip, and fixed the checksum to be valid with the new data.
  • Replaced the Flash section with what came from the Arduino IDE.
  • Removed my temporary labels to make it a valid hex file again.
  • Wrote that new hex file to the chip.

And it seems to work!

Here's the contents of that new hex file. I make no guarantee that it's error-free, but it's what I'm using so far.

:020000040000FA
:1000000019C034C033C032C031C030C02FC02EC080
:100010002DC01BC12BC02AC029C028C027C026C0A4
:1000200025C024C023C022C021C020C01FC01EC0C4
:100030001DC01CC011241FBECFEFCDBFDFE3DEBF4C
:100040008091400080934000811105C098ED21E02F
:1000500094BF209341008CBB2FE3A0E8BFE301C015
:100060001D92A039B207E1F721D1D6C1C9CFE0E096
:10007000F4E080E8858383EC99E00197F1F700C014
:10008000000082E0858394E79A95F1F700C08683AB
:100090002FEC8EE791E0215080409040E1F700C0C6
:1000A00000000895E0E0F4E088E08583818382E445
:1000B0008A95F1F700C0089598E090930604E7EF61
:1000C000F0E03197F1F700000000000000000000B0
:1000D0000000000000000000000000000000000020
:1000E00048E0282F30E080FF50C04093050435954C
:1000F0002795822FE7EFF0E03197F1F7000000003D
:1001000000000000000000000000915051F788E05E
:100110006623F1F18093050487EF90E00197F1F7F2
:1001200000000000000000000000000000000000CF
:100130000000000000000000000088E0809305043B
:10014000E7EFF0E03197F1F7000000000000000059
:10015000000000000000000000000000000000009F
:1001600000008093050487EF90E00197F1F700000D
:10017000000000000000000000000000000000007F
:100180000000000000000000089540930604AFCF77
:1001900080930604E7EFF0E03197F1F7C1CF1F93AA
:1001A000CF93DF93C0E0D4E018E019831D831E8352
:1001B00000000000000000008B89877F8B8B1A8372
:1001C00085EA9EE00197F1F700C000006BDF60E078
:1001D00085E572DF61E080EE6FDF61E080E26CDF79
:1001E00061E087E669DF60E08FE666DF60E082E776
:1001F00063DF60E080E560DF60E08DE45DDF60E0AC
:1002000086E55ADF60E08EE457DF4CDF1A838B8986
:10021000877F8B8B85EA9EE00197F1F700C0000095
:1002200041DF60E085E548DF3DDF1A838B89877F0A
:100230008B8B85EA9EE00197F1F700C0000080E813
:100240008E83DF91CF911F9108958F9382E08093E9
:100250000B0A8FB78F93EF93FF93E0E8FFE39F9331
:1002600068948FEF0FC0E8948481958188589D4FE2
:1002700084839583885E934010F08FEF03C084835E
:1002800095838EEF9081981B919390819F4F9193CE
:1002900090819F4F919390819F4F919326F39F91CF
:1002A000FF91EF918F918FBF8F91189581E098ED1D
:1002B00094BF80936100E0E0F6E092E592839DE0D8
:1002C000958390E293838083809302028093030A54
:1002D0008EEF8093260A8093270A8BE08093000A92
:1002E00092E090930A0A789484E0809302048091CB
:1002F000120488608093120488E08093020480E4F2
:1003000080930104809305049093010480E8809316
:100310000104ADDEF89443DF7894D3E0C0E400E05C
:1003200010E4E12C88E0F82EDD24D39480910804B9
:1003300082FF4DC080918F3F8823C1F010928F3F84
:10034000C09306042FE78AE196E021508040904058
:10035000E1F700C00000C093050489DEF8941FDFB8
:10036000789422E42A95F1F700C0E0CF80918D3F88
:1003700090918E3F8F3F2FE3920728F40196809350
:100380008D3F90938E3F10928B3F10928C3F8091C7
:100390008B3F90918C3F8F3F974041F4E0928B3F91
:1003A000F0928C3FD0928F3F10928A3F80918A3F8B
:1003B00020918D3F30918E3F2F3F3F43D1F40093EA
:1003C0008D3F10938E3F8F5F80938A3FCACF80917D
:1003D0008B3F90918C3F8F3F27E0920728F4019646
:1003E00080938B3F90938C3F10928D3F10928E3F65
:1003F000CECF823009F0B5CFD0938A3FC0930604A8
:100400002FE78AE196E0215080409040E1F700C05C
:0C0410000000C0930504A5CFF894FFCFB6
:02000004008278
:09000000004002FF00F7030000BC
:00000001FF

And the command to write it to the chip.

$ pymcuprog write --erase --verify -d attiny202 -t uart -u /dev/ttyAMA0 -f UpdiKey.hex
Connecting to SerialUPDI
Pinging device...
Ping response: 1E9123
Erasing device before writing from hex file...
Writing from hex file...
Writing flash...
Verifying flash...
OK
Writing fuses...
Verifying fuses...
OK
Done.
$ 

Hopefully this helps someone. I'm not going to close this issue yet, because I'm not completely confident that it's an exact image of what the author intended, but like I said, it does seem to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant