At least the bcm2835 (Raspberry Pi 3) I2C/SMBus master has problems
when replying with a NAK to the last byte written to a slave device.
Fix this by replying with NAK one byte later.
- patch reset vector while programming flash page0
Let the reset vector always point to the twiboot start.
- Use another (must be unused!) ISR vector to store the original
reset vector as jump to the application.
- Cache the values for the verification read
- currently works only for devices < 8kB flash (2 byte vector entries)
- using a attiny85 as target
This change is heavily based on the optiboot bootloader.
- Implement a TWI slave using the USI peripheral found in AVR tiny MCUs
- using attiny85 as target (has no bootloader section!)
- USI peripheral in general needs clock stretching support from the
master since the whole statemachine is software based.
For now the actual writing to flash/eeprom is also done during
clock stretching (like original twiboot implementation).
This might be changed later.
- ACK/NAK handling is different:
For TWI peripheral the ACK/NAK of the *next* byte has to be returned
by TWI_data_write(). For USI peripheral the ACK/NAK of the *current*
byte needs to be returned. For now the TWI version remains in the
code and might be changed later.
Do not use ISRs and poll for interrupt flags in the main loop.
No need for moving vector table into bootloader and back.
Remove vector table by adding LDFLAGS = -nostartfiles.
Manually add some code which is now removed, but still needed by C
runtime:
- make sure that r1 is 0x00 (zero register).
- on some MCUs the stack pointer is not initialized correctly after
reset.
- main() need to be placed in special section .init9 to be called at all.
Not sure why the BSS and DATA segment are still initialized.
This change is heavily based on the optiboot bootloader.
TWEA bit in TWCR register needs to be cleared to send NACK.
Clear it when too many bytes were received, re-enable it after
when going idle.
Add missing state for prev. send NACK.
Catch all invalid states and reset bus.
TWINT bit needs to be set every time in ISR.
- sizeof(info) should not be increased (16->18) since the size is never
exchanged with the I2C master. Also using a non 2^x size will result
in bigger code since the compiler can no longer use a simple AND to
implement the bcnt %= sizeof(info).
- when using a info[16] the firmware is small enough to fit in a 512
word bootloader again :)