The target board (TB) can be designed to run at any voltage. The target MCU will have its own power lines, separate from the rest of the circuit. This will let me disconnect the MCU from the TB power and connect it to the programmer power supply.
I will use two relays for this. The first one will simply switch VCC to target MCU on and off. The second one will connect the target MCU to either the programmer power lines, or the TB power lines.
Another pair of relays will connect/disconnect the RESET, SCK, MOSI and MISO lines.
For smaller Atmegas, I will make another daugtherboard and simply disconnect all lines from the target circuit.
The device stores the WiFi SSID and password on the MCU EEPROM. When you start it up with the DIP switch at PD2 in the on position (reading low), it goes into web configuration mode. In this mode, you can set the WiFi SSID and the password. In order to do that, you first need to connect to the WiFi network displayed on the screen, the ESP8266 operates in access point mode when you boot it up like this. The default SSID and password for this are "wifiprog" and "hunter2". After this, you can browse to the displayed IP address (at port 1011) and set the SSID/passwd pair for normal mode.
In normal mode (DIP switch off), the ESP8266 operates in station mode and connects to the given network just like any other device.
The accompanying host software can configure the SSID/password pair for configuration mode. This is only active when the device is in normal mode.
The circuit seems to work fine at 115200bps. The Atmega328 data sheet suggests that I could go even higher to 690Kbps but I don't dare. With this crystal at 115200bps, the interrupt routine needs to run within 768 cycles, which it does with room to spare. I'm not even sure that the ESP8266 supports higher rates, this is the highest I've seen being discussed. Also, writing a 32K program to the target will take about 2.3 seconds with this rate so I'm happy with it. In any case, it seems to work fine at high rate and I could reduce it if necessary later on.
The firmware stores the last set baud rate in EEPROM. Upon reboot it tries to establish contact with the wireless module at that rate. If this fails, it goes thru a list of rates, trying to get a meaningful response to the command "AT". When this happens, the rate gets stored in the EEPROM and communication continues at this rate.
It's pretty impressive compared to the usbasp result, which was 19 seconds. I think this is the final iteration of the base platform. I should get going with the programmer itself. Anyway, I can put the usbasp away for a while, the self programming seems to work fine.
Also, I made use of the second DIP switch, connected to PD3. If this switch is on, the device erases its own EEPROM (only the used parts). This is useful for when I add new variables into the EEPROM area. The addresses of the variables change when I do that and they need to be reset. When the device boots like this, it simply goes into an infinite loop without doing anything. You just need to reset it with the DIP switch off.
I wrote it for both Atmega8A and Atmega328P chips but tested only with the 328 so far.
The following are the things I didn't implement for it:
This package also includes a USB programmer. I had written it to debug the serial communications with the ESP8266 module and to develop the programming routines. There is nothing left in it to transfer over here so I will remove it in later releases.