ZeroPhone / Discussion-and-Research

General-purpose ZeroPhone discussion (mostly happening in Issues tab)
GNU General Public License v3.0
9 stars 0 forks source link

ZeroPhone ATMega328P firmware/bootloader bootstrap #15

Open CRImier opened 6 years ago

CRImier commented 6 years ago

There's a problem when self-assembling the ZeroPhone - if you're not harvesting the ATMega chip from an Arduino Pro Mini board, it will have neither the bootloader needed for serial upload nor the firmware needed for the keypad to work. However, ZeroPhone itself is very capable of flashing ATMega chips through the SPI port on the back board - and there's now an app for that. So, ZeroPhone could bootstrap its own firmware.

The first problem is - there isn't any direct connection between front board ATMega ISP connections and SPI (and none are planned as of now). So, you need to make connections. Okay, no problem, both front board ISP and back board SPI pinouts are available - 6 wires and we should be done. We do need to make connection diagrams, though - for both Gamma and Delta boards.

Second problem - ZPUI is not accessible; since the ATMega is not yet flashed, the keypad does not yet work. So, we can't use the menu to pick the avrdude app. Also, it's likely that we don't have a screen attached yet (since front board is connected to SPI, it's not convenient to plug it on). Clearly, some kind of ZPUI-less solution is needed - which should nevertheless be able to tell its status to the user. We also need to make sure that this solution doesn't activate all the time, sending random data to attached SPI devices.

My proposal is a small Python script that uses the pyavrdude library I just developed and the onboard RGB LED (available through zerophone_hw package), and starts if it detects a flag file on the SD card's boot partition (the first small partition that pops up when you plug the Raspbian SD card in). Workflow would be as such: you create the flag file on the SD card, plug it in, connect the front board ISP wires to the back board, power the back board. The script would run, detect the chip, program it, and flash out the success/error codes (in RGB).

Links:

CRImier commented 5 years ago

Now, I'm also thinking - we can add a failsafe mode to ZPUI, in which, if it doesn't find the keyboard controller on the I2C bus, it enables the USB port and expects a keyboard to be connected there - once there's a keyboard, it starts the HID driver with it and allows you to actually navigate to the Avrdude app.