tomek-szczesny / OpenUPS

A versatile, high power SBC UPS
12 stars 0 forks source link

UPS PCB AVR Code #6

Open tomek-szczesny opened 1 year ago

tomek-szczesny commented 1 year ago

The microcontoller selection has been narrowed down to 28-pin AVR DA or DB families, either SOIC or SSOP package. For now the development effort assumes either of those, unless it's necessary to narrow down the selection for any reason. Chip availability is one of the concerns here. We may end up with larger memory model just because of that.

The programming interface is UPDI, and a passive converter to UART will be implemented on PCB. Direct access to UPDI pin will be inherently provided.

avrdude should support this configuration with any 3.3V UART converter, be it FTDI or SBC UART pins directly. The programmer type is serialupdi. Further configuration may be required to select a UART port. The solution is relatively new and thus should be considered risky/unstable. A fallback plan is to use some other programming method via exposed UPDI pin.

Up the development chain, avr-libc appears to support DA and DB families after version 2.1. Thus I assume avr-gcc should support these chips just as well.

AVR Assembler avra shows no signs of supporting DA/DB families. This only supports the preemptive decision of using C as a language of choice. I can imagine literally nobody being able to work with my ASM code.


As a baseline, AVR will work with maximum clock frequency of 24MHz generated by internal oscillator. As such it's not super precise, but should be reasonably accurate to measure fan RPM, for example. All power supplies will come from LM317-regulated 3.3V source, and external 2.5V ADC reference generated by TL431 or equivalent. I2C bus should work at 400kHz in both directions for maximum compatibility and stability. Master bus may be sped up to 1MHz as it will be used only within the PCB.

Code requirements TBD

tomek-szczesny commented 1 year ago

I created a branch with a code template that appears to build fine. No way to test it with hardware unfortunately, but it actually produces binary outputs and de-assembly makes sense.

A linker script seems to be buggy out of a box, so I included a modified version that make build will use. Information taken from here: https://www.avrfreaks.net/s/topic/a5C3l000000UbT6EAK/t157820?comment=P-1262496

At this point avr-libc, >=2.2 is required to include support for AVR DB family. In Manjaro it was available in AUR package avr-libc-git, but it may also be built from source: https://github.com/avrdudes/avr-libc

AVR firmware requirements coming soon and I decided to write them down in Wiki instead.

tomek-szczesny commented 1 year ago

@paulcrawford, I updated Wiki with a stub of AVR code documentation, here: https://github.com/tomek-szczesny/OpenUPS/wiki/AVR-Firmware Let me know if you need anything. :)