Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions firmware/bootloaderconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ these macros are defined, the boot loader uses them.
# define MCUCSR MCUSR
#endif

#define APPCHECKSUM
//#define APPCHECKSUM

/* tiny85 Architecture Specifics */
#ifdef __AVR_ATtiny85__
# define TINY85MODE

# ifndef APPCHECKSUM
# define APPCHECKSUM
# endif
//# ifndef APPCHECKSUM
//# define APPCHECKSUM
//# endif

// number of bytes before the boot loader vectors to store the tiny application vector table
# define TINYVECTOR_RESET_OFFSET 4
Expand Down
10 changes: 9 additions & 1 deletion firmware/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,21 @@ static void writeWordToPageBuffer(uint16_t data)
data = 0xC000 + (BOOTLOADER_ADDRESS/2) - 1;

// write 2's complement of checksum
#ifdef APPCHECKSUM
if(CURRENT_ADDRESS == BOOTLOADER_ADDRESS - APPCHECKSUM_POSITION)
data = (uint8_t)(~checksum + 1);
#endif

if(CURRENT_ADDRESS == BOOTLOADER_ADDRESS - TINYVECTOR_RESET_OFFSET)
data = vectorTemp[0] + ((FLASHEND + 1) - BOOTLOADER_ADDRESS)/2 + 2 + RESET_VECTOR_OFFSET;

if(CURRENT_ADDRESS == BOOTLOADER_ADDRESS - TINYVECTOR_USBPLUS_OFFSET)
data = vectorTemp[1] + ((FLASHEND + 1) - BOOTLOADER_ADDRESS)/2 + 1 + USBPLUS_VECTOR_OFFSET;

#ifdef APPCHECKSUM
// only calculate checksum when we are writing new data to flash (ignore when writing vectors after bootloader programming)
checksum += (uint8_t)(data/256) + (uint8_t)(data);
#endif

// clear page buffer as a precaution before filling the buffer on the first page
// TODO: maybe clear on the first byte of every page?
Expand Down Expand Up @@ -544,7 +548,9 @@ static inline void tiny85FlashInit(void)

// TODO: necessary to reset CURRENT_ADDRESS?
CURRENT_ADDRESS = 0;
checksum = 0;
# ifdef APPCHECKSUM
checksum = 0;
# endif
}

static inline void tiny85FlashWrites(void)
Expand All @@ -557,7 +563,9 @@ static inline void tiny85FlashWrites(void)
eraseApplication();
sei();

#ifdef APPCHECKSUM
checksum = 0;
#endif
eraseRequested = 0;
}
#endif
Expand Down