diff options
| author | cpldcpu <cpldcpu@gmail.com> | 2014-03-16 09:16:27 +0100 | 
|---|---|---|
| committer | cpldcpu <cpldcpu@gmail.com> | 2014-03-16 09:16:27 +0100 | 
| commit | 8773da4c5ff13ced369e8bc169956dd36a613918 (patch) | |
| tree | a570c13651e74ada385c4ac78cf3efac7f7a6b0d | |
| parent | 07d3143f40e5cee6eae60014a6a6655aefde7a7d (diff) | |
| download | micronucleus-8773da4c5ff13ced369e8bc169956dd36a613918.tar.gz micronucleus-8773da4c5ff13ced369e8bc169956dd36a613918.tar.bz2 micronucleus-8773da4c5ff13ced369e8bc169956dd36a613918.zip | |
firmware: ATtiny841 - proper page erasing
| -rw-r--r-- | firmware/configuration/t841_default/Makefile.inc | 2 | ||||
| -rw-r--r-- | firmware/main.c | 32 | 
2 files changed, 15 insertions, 19 deletions
| diff --git a/firmware/configuration/t841_default/Makefile.inc b/firmware/configuration/t841_default/Makefile.inc index d6198e4..e1ec4ce 100644 --- a/firmware/configuration/t841_default/Makefile.inc +++ b/firmware/configuration/t841_default/Makefile.inc @@ -15,7 +15,7 @@ DEVICE = attiny841  # - for the size of your device (8kb = 1024 * 8 = 8192) subtract above value 2124... = 6068  # - How many pages in is that? 6068 / 64 (tiny85 page size in bytes) = 94.8125  # - round that down to 94 - our new bootloader address is 94 * 64 = 6016, in hex = 1780 -BOOTLOADER_ADDRESS = 1800 +BOOTLOADER_ADDRESS = 1A00  FUSEOPT = -U lfuse:w:0xe2:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m  FUSEOPT_DISABLERESET =  # TODO diff --git a/firmware/main.c b/firmware/main.c index 187ef54..8a86b33 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -24,8 +24,14 @@  #include "usbdrv/usbdrv.c"  // verify the bootloader address aligns with page size -#if BOOTLOADER_ADDRESS % SPM_PAGESIZE != 0 -  #error "BOOTLOADER_ADDRESS in makefile must be a multiple of chip's pagesize" +#if (defined __AVR_ATtiny841__)||(defined __AVR_ATtiny441__)   +  #if BOOTLOADER_ADDRESS % ( SPM_PAGESIZE * 4 ) != 0 +    #error "BOOTLOADER_ADDRESS in makefile must be a multiple of chip's pagesize" +  #endif +#else +  #if BOOTLOADER_ADDRESS % SPM_PAGESIZE != 0 +    #error "BOOTLOADER_ADDRESS in makefile must be a multiple of chip's pagesize" +  #endif    #endif  #if SPM_PAGESIZE>256 @@ -98,7 +104,11 @@ static inline void eraseApplication(void) {    uint16_t ptr = BOOTLOADER_ADDRESS;    while (ptr) { +#if (defined __AVR_ATtiny841__)||(defined __AVR_ATtiny441__)     +    ptr -= SPM_PAGESIZE * 4;         +#else      ptr -= SPM_PAGESIZE;         +#endif          boot_page_erase(ptr);    } @@ -306,22 +316,8 @@ int main(void) {        LED_MACRO( idlePolls.b[0] );            // Test whether another interrupt occurred during the processing of USBpoll and commands. -       // If yes, we missed a data packet on the bus. This is not a big issue, since -       // USB seems to allow time-out of up the two packets.  -       // The most critical situation occurs when a PID IN packet is missed due to -       // it's short length. Each packet + timeout takes around 45µs, meaning that -       // usbpoll must take less than 90µs or resyncing is not possible. -       // To avoid synchronizing of the interrupt routine, we must not call it while -       // a packet is transmitted. Therefore we have to wait until the bus is idle again. -       // -       // Just waiting for EOP (SE0) or no activity for 6 bus cycles is not enough, -       // as the host may have been sending a multi-packet transmission (eg. OUT or SETUP) -       // In that case we may resynch within a transmission, causing errors. -       // -       // A safer way is to wait until the bus was idle for the time it takes to send -       // an ACK packet by the client (10.5µs on D+) but not as long as bus -       // time out (12µs) -       // +       // If yes, we missed a data packet on the bus. Wait until the bus was idle for 10µs to  +       // allow synchronising to the next incoming packet.         if (USB_INTR_PENDING & (1<<USB_INTR_PENDING_BIT))  // Usbpoll() collided with data packet         {         | 
