Hi westfw,
- Code space reduction (alas, more features show up to consume the saved space)
- 380 optiboot has problems uploading sketches bigger than about 30 KB
the fix for issue 380 (see below) is consuming 32 additional bytes which I badly needed for my BlueController extensions. Therefore I could not use the overlapping boot_page_erase() and serial communication. For the Bluetooth communication this doesn't matter. Comparing the time with and without overlapping erase gave no difference. I haven't tested it with USB UART communication right now.
The code that could be saved is in bold:
+ // If we are in RWW section, immediately start page erase
+#if !defined(BLUECONTROLLER)
+ if (address < NRWWSTART)
+ 1fcba: 80 e0 ldi r24, 0x00 ; 0
+ 1fcbc: e8 16 cp r14, r24
+ 1fcbe: 80 ee ldi r24, 0xE0 ; 224
+ 1fcc0: f8 06 cpc r15, r24
+ 1fcc2: 20 f4 brcc .+8 ; 0x1fccc <main+0xcc>
+ __boot_page_erase_short((uint16_t)(void*)address);
+ 1fcc4: 83 e0 ldi r24, 0x03 ; 3
+ 1fcc6: f7 01 movw r30, r14
+ 1fcc8: 87 bf out 0x37, r24 ; 55
+ 1fcca: e8 95 spm
+ 1fccc: c2 e0 ldi r28, 0x02 ; 2
+ 1fcce: d2 e0 ldi r29, 0x02 ; 2
+#endif
[...]
+ // If we are in NRWW section, page erase has to be delayed until now.
+ // Todo: Take RAMPZ into account
+#if !defined(BLUECONTROLLER)
+ if (address >= NRWWSTART)
+ 1fcd8: f0 e0 ldi r31, 0x00 ; 0
+ 1fcda: ef 16 cp r14, r31
+ 1fcdc: f0 ee ldi r31, 0xE0 ; 224
+ 1fcde: ff 06 cpc r15, r31
+ 1fce0: 20 f0 brcs .+8 ; 0x1fcea <main+0xea>
+#endif
+ __boot_page_erase_short((uint16_t)(void*)address);
+ 1fce2: 83 e0 ldi r24, 0x03 ; 3
+ 1fce4: f7 01 movw r30, r14
+ 1fce6: 87 bf out 0x37, r24 ; 55
+ 1fce8: e8 95 spm
+ }
+#endif
Without loosing any performance or functionality, the code can be optimized to compare only the high-byte of the NRWWSTART, (because the low byte of NRWWSTART will always be zero) which saves 6 bytes:
// If we are in RWW section, immediately start page erase
#if !defined(BLUECONTROLLER)
if ((uint8_t)(address >> 8) < (uint8_t)(NRWWSTART >> 8))
7eb0: 8d 2d mov r24, r13
7eb2: 99 27 eor r25, r25
7eb4: 08 2f mov r16, r24
7eb6: 80 37 cpi r24, 0x70 ; 112
7eb8: 20 f4 brcc .+8 ; 0x7ec2 <main+0xc2>
__boot_page_erase_short((uint16_t)(void*)address);
7eba: 83 e0 ldi r24, 0x03 ; 3
7ebc: f6 01 movw r30, r12
7ebe: 87 bf out 0x37, r24 ; 55
7ec0: e8 95 spm
7ec2: c2 e0 ldi r28, 0x02 ; 2
7ec4: d1 e0 ldi r29, 0x01 ; 1
#endif
[...]
// If we are in NRWW section, page erase has to be delayed until now.
// Todo: Take RAMPZ into account
#if !defined(BLUECONTROLLER)
if (!((uint8_t)(address >> 8) < (uint8_t)(NRWWSTART >> 8)))
7ece: 00 37 cpi r16, 0x70 ; 112
7ed0: 20 f0 brcs .+8 ; 0x7eda <main+0xda>
#endif
__boot_page_erase_short((uint16_t)(void*)address);
7ed2: 83 e0 ldi r24, 0x03 ; 3
7ed4: f6 01 movw r30, r12
7ed6: 87 bf out 0x37, r24 ; 55
7ed8: e8 95 spm
}
#endif
I don't understand why the compiler generates the mov+eor+mov instructions for the first compare, maybe you have an idea?
Michael