There is an ATMEL library that doesn't work with my toolchain (GNU tools for ARM) and I know why, but I don't know why it works for an old YAGARTO and I guess that also for KEIL and IAR
I'm working in an ARMV5 processor (AT91SAM9) that doesn't support unaligned access to ints (4 bytes).
there is a global buffer defined as:
static unsigned char pPageBuffer[AT91C_IFLASH_PAGE_SIZE];
The buffer gets some data and afterwards the data is written to flash, but data has to be taken to flash 4 bytes at a time, thus there is an int pointer called pAlignedSource to take the data 4 bytes at a time.
pAlignedSource = (unsigned int*)pPageBuffer;
But pPAgeBuffer is not necessarily 4 bytes aligned as it is a char array, and pAlignedSource doesn't point to an aligned address. How is it possible that this code is working always in the other toolchain but not in mine?, I already defined the proper CPU to the compiler other than that both compilers get the same code flags.
My problem is that when data gets copied from the buffer to the flash
*pAlignedDestination++ = *pAlignedSource++;
I end with a scrambled version of the data :/, however I fixed this by defining the buffer as
static unsigned int pPageBuffer[AT91C_IFLASH_PAGE_SIZE/4];
And it did the trick, But I am still very curious about this. Why it worked in the other toolchain?