I am thinking of expanding the possible program size for over the air updates and when I look at the boot loader it seems like it should be easy enough to do. I’m not sure I want to actually do it, and it could be way more in-depth than this but it looks like it is just expanding the data size, using the larger bootloader memory option, and using the extended macros. Might need to use the normal macros for addresses less than 2 bytes and extended for larger ones. I’m not sure yet.
I have 2 questions to get opinions on. What is with the circular casting they chose to do, and am I missing something obvious?
uint16_t i,b;
MACRO((uint16_t)(void*)i,b);
I don’t understand the casting they did. It doesn’t make any sense to me. That combined with when I half heartedly tried changing to a large data type uint32_t if gave me an error that it didn’t give before with the uint16_t.
Here are the errors it through
Error:
cast to pointer from integer of different size
and
cast from pointer to integer of different size
and here are the unmodified and modified code sections.
I’m not so much looking for actual answers as much as thoughts and opinions.
Unmodified Code Section.
uint16_t b, i, nextAddress=0;
LED_PIN |= _BV(LED);
for (i=0; i<imagesize; i+=2)
{
//read 2 bytes (16 bits) from flash image, transfer them to page buffer
b = FLASH_readByte(i+12); // flash image starts at position 10 on the external flash memory: FLX:XX:FLASH_IMAGE_BYTES_HERE...... (XX = two size bytes)
b |= FLASH_readByte(i+13) << 8; //bytes are stored big endian on external flash, need to flip the bytes to little endian for transfer to internal flash
__boot_page_fill_short((uint16_t)(void*)i,b);
//when 1 page is full (or we're on the last page), write it to the internal flash memory
if ((i+2)%SPM_PAGESIZE==0 || (i+2==imagesize))
{
__boot_page_erase_short((uint16_t)(void*)nextAddress); //(i+2-SPM_PAGESIZE)
boot_spm_busy_wait();
// Write from programming buffer
__boot_page_write_short((uint16_t)(void*)nextAddress ); //(i+2-SPM_PAGESIZE)
boot_spm_busy_wait();
nextAddress += SPM_PAGESIZE;
}
}
Modified Code Section.
uint32_t b, i, nextAddress=0;
LED_PIN |= _BV(LED);
for (i=0; i<imagesize; i+=2)
{
//read 2 bytes (16 bits) from flash image, transfer them to page buffer
b = FLASH_readByte(i+12); // flash image starts at position 10 on the external flash memory: FLX:XX:FLASH_IMAGE_BYTES_HERE...... (XX = two size bytes)
b |= FLASH_readByte(i+13) << 8; //bytes are stored big endian on external flash, need to flip the bytes to little endian for transfer to internal flash
__boot_page_fill_extended_short((uint32_t)(void*)i,b);
//when 1 page is full (or we're on the last page), write it to the internal flash memory
if ((i+2)%SPM_PAGESIZE==0 || (i+2==imagesize))
{
__boot_page_erase_extended_short((uint32_t)(void*)nextAddress); //(i+2-SPM_PAGESIZE)
boot_spm_busy_wait();
// Write from programming buffer
__boot_page_write_extended_short((uint32_t)(void*)nextAddress ); //(i+2-SPM_PAGESIZE)
boot_spm_busy_wait();
nextAddress += SPM_PAGESIZE;
}
}