Browse Source

Cleanup and reduce size

tags/v3.0
Olaf Rempel 8 months ago
parent
commit
0416a2f536
2 changed files with 26 additions and 29 deletions
  1. +7
    -6
      README.md
  2. +19
    -23
      main.c

+ 7
- 6
README.md View File

@@ -3,17 +3,17 @@ twiboot is a simple/small bootloader for AVR MCUs with integrated TWI peripheral
It was originally created to update I2C controlled BLMCs (Brushless Motor Controller) without an AVR ISP adapter.

twiboot acts as a slave device on a TWI/I2C bus and allows reading/writing of the internal flash memory.
As a compile time option twiboot also allows reading/writing of the whole internal EEPROM memory.
As a compile time option (EEPROM_SUPPORT) twiboot also allows reading/writing of the whole internal EEPROM memory.
The bootloader is not able to update itself (only application flash memory region accessible).

Currently the following AVR MCUs are supported:

AVR MCU | Flash bytes used (.text + .data) | Bootloader region size
--- | --- | ---
atmega8 | 724 (0x2D4) | 512 words
atmega88 | 744 (0x2E8) | 512 words
atmega168 | 744 (0x2E8) | 512 words
atmega328p | 744 (0x2E8) | 512 words
atmega8 | 706 (0x2C2) | 512 words
atmega88 | 726 (0x2D6) | 512 words
atmega168 | 726 (0x2D6) | 512 words
atmega328p | 726 (0x2D6) | 512 words

(Compiled on Ubuntu 18.04 LTS (gcc 5.4.0 / avr-libc 2.0.0) with EEPROM and LED support)

@@ -33,7 +33,7 @@ A TWI/I2C master can use the protocol to
- write the internal eeprom (byte wise)
- exit the bootloader and start the application

As a compile time option twiboot can output its state with two LEDs.
As a compile time option (LED_SUPPORT) twiboot can output its state with two LEDs.
One LED will flash with a frequency of 20Hz while twiboot is active (including boot wait time).
A second LED will flash when the bootloader is addressed on the TWI/I2C bus.

@@ -85,6 +85,7 @@ Write 1+ eeprom bytes | **SLA+W**, 0x02, 0x02, addrh, addrl, {* bytes}, **STO**
The multiboot_tool repository contains a simple linux application that uses
this protocol to access the bootloader over linux i2c device.

The ispprog programming adapter can also be used as a avr910/butterfly to twiboot protocol bridge.

## Development ##
Issue reports, feature requests, patches or simply success stories are much appreciated.


+ 19
- 23
main.c View File

@@ -141,26 +141,24 @@ static void write_flash_page(void)
uint8_t size = SPM_PAGESIZE;
uint8_t *p = buf;

if (pagestart >= BOOTLOADER_START)
if (pagestart < BOOTLOADER_START)
{
return;
}

boot_page_erase(pagestart);
boot_spm_busy_wait();
boot_page_erase(pagestart);
boot_spm_busy_wait();

do {
uint16_t data = *p++;
data |= *p++ << 8;
boot_page_fill(addr, data);
do {
uint16_t data = *p++;
data |= *p++ << 8;
boot_page_fill(addr, data);

addr += 2;
size -= 2;
} while (size);
addr += 2;
size -= 2;
} while (size);

boot_page_write(pagestart);
boot_spm_busy_wait();
boot_rww_enable();
boot_page_write(pagestart);
boot_spm_busy_wait();
boot_rww_enable();
}
} /* write_flash_page */


@@ -168,12 +166,11 @@ static void write_flash_page(void)
/* *************************************************************************
* read_eeprom_byte
* ************************************************************************* */
static uint8_t read_eeprom_byte(void)
static uint8_t read_eeprom_byte(uint16_t address)
{
EEARL = addr;
EEARH = (addr >> 8);
EEARL = address;
EEARH = (address >> 8);
EECR |= (1<<EERE);
addr++;

return EEDR;
} /* read_eeprom_byte */
@@ -223,6 +220,7 @@ static uint8_t TWI_data_write(uint8_t bcnt, uint8_t data)
case CMD_WAIT:
/* abort countdown */
boot_timeout = 0;
cmd = data;
break;

default:
@@ -231,8 +229,6 @@ static uint8_t TWI_data_write(uint8_t bcnt, uint8_t data)
ack = 0x00;
break;
}

cmd = data;
break;

case 1:
@@ -334,7 +330,7 @@ static uint8_t TWI_data_read(uint8_t bcnt)

#if (EEPROM_SUPPORT)
case CMD_ACCESS_EEPROM:
data = read_eeprom_byte();
data = read_eeprom_byte(addr++);
break;
#endif /* (EEPROM_SUPPORT) */



Loading…
Cancel
Save