mirror of
https://github.com/Optiboot/optiboot.git
synced 2025-07-03 05:42:30 +03:00
Day of testing and minor edits.
The RTC might be busy at startup. This seems to be working - code successfully uploaded, after I got all the fuses right.
This commit is contained in:
@ -134,6 +134,17 @@ optiboot_version = 256*(OPTIBOOT_MAJVER + OPTIBOOT_CUSTOMVER) + OPTIBOOT_MINVER;
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
FUSES = {
|
||||||
|
// .WDTCFG, /* Watchdog Configuration */
|
||||||
|
// .BODCFG, /* BOD Configuration */
|
||||||
|
.OSCCFG = 2, /* Oscillator Configuration */
|
||||||
|
// .TCD0CFG, /* TCD0 Configuration */
|
||||||
|
.SYSCFG0 = 0xC8, /* RESET is active */
|
||||||
|
.SYSCFG1 = 0x06, /* startup 32ms */
|
||||||
|
// .APPEND = 0, /* Application Code Section End */
|
||||||
|
.BOOTEND = 2 /* Boot Section End */
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* optiboot uses several "address" variables that are sometimes byte pointers,
|
* optiboot uses several "address" variables that are sometimes byte pointers,
|
||||||
* sometimes word pointers. sometimes 16bit quantities, and sometimes built
|
* sometimes word pointers. sometimes 16bit quantities, and sometimes built
|
||||||
@ -203,7 +214,7 @@ typedef union {
|
|||||||
* some code space on parts with smaller pagesize by using a smaller int.
|
* some code space on parts with smaller pagesize by using a smaller int.
|
||||||
*/
|
*/
|
||||||
#if MAPPED_PROGMEM_PAGE_SIZE > 255
|
#if MAPPED_PROGMEM_PAGE_SIZE > 255
|
||||||
typedef uint16_t pagelen_t ;
|
typedef uint16_t pagelen_t;
|
||||||
#define GETLENGTH(len) len = getch()<<8; len |= getch()
|
#define GETLENGTH(len) len = getch()<<8; len |= getch()
|
||||||
#else
|
#else
|
||||||
typedef uint8_t pagelen_t;
|
typedef uint8_t pagelen_t;
|
||||||
@ -230,7 +241,8 @@ static void getNch(uint8_t);
|
|||||||
#if LED_START_FLASHES > 0
|
#if LED_START_FLASHES > 0
|
||||||
static inline void flash_led(uint8_t);
|
static inline void flash_led(uint8_t);
|
||||||
#endif
|
#endif
|
||||||
static inline void watchdogReset();
|
#define watchdogReset() __asm__ __volatile__ ("wdr\n")
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RAMSTART should be self-explanatory. It's bigger on parts with a
|
* RAMSTART should be self-explanatory. It's bigger on parts with a
|
||||||
@ -287,6 +299,7 @@ int main(void) {
|
|||||||
* and still skip bootloader if not necessary
|
* and still skip bootloader if not necessary
|
||||||
*/
|
*/
|
||||||
ch = RSTCTRL.RSTFR;
|
ch = RSTCTRL.RSTFR;
|
||||||
|
RSTCTRL.RSTFR = ch; // reset causes, for now.
|
||||||
|
|
||||||
// Skip all logic and run bootloader if cause is cleared (application request)
|
// Skip all logic and run bootloader if cause is cleared (application request)
|
||||||
if (ch != 0) {
|
if (ch != 0) {
|
||||||
@ -329,6 +342,8 @@ int main(void) {
|
|||||||
|
|
||||||
#if LED_START_FLASHES > 0
|
#if LED_START_FLASHES > 0
|
||||||
// Set up RTC counting at about 1/8s (input is 32kHz)
|
// Set up RTC counting at about 1/8s (input is 32kHz)
|
||||||
|
while (RTC.STATUS & RTC_CTRLABUSY_bm)
|
||||||
|
; // RTC is used by startup logic (!) and might be busy.
|
||||||
RTC.CTRLA= RTC_PRESCALER_DIV4096_gc | RTC_RTCEN_bm;
|
RTC.CTRLA= RTC_PRESCALER_DIV4096_gc | RTC_RTCEN_bm;
|
||||||
RTC.DBGCTRL = 1; // enable during debug
|
RTC.DBGCTRL = 1; // enable during debug
|
||||||
#endif
|
#endif
|
||||||
@ -428,9 +443,9 @@ int main(void) {
|
|||||||
address.word += MAPPED_EEPROM_START;
|
address.word += MAPPED_EEPROM_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do {
|
||||||
*address.bptr++ = getch();
|
*(address.bptr++) = getch();
|
||||||
while (--length);
|
} while (--length);
|
||||||
|
|
||||||
// Read command terminator, start reply
|
// Read command terminator, start reply
|
||||||
verifySpace();
|
verifySpace();
|
||||||
@ -530,13 +545,6 @@ void flash_led(uint8_t count) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Watchdog functions. These are only safe with interrupts turned off.
|
|
||||||
void watchdogReset() {
|
|
||||||
__asm__ __volatile__ (
|
|
||||||
"wdr\n"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void watchdogConfig(uint8_t x) {
|
void watchdogConfig(uint8_t x) {
|
||||||
_PROTECTED_WRITE(WDT.CTRLA, x);
|
_PROTECTED_WRITE(WDT.CTRLA, x);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user