Ok, so I used the application note to get flash erase / write working...
Just to write a long word (which is the least you can do now which is also annoying in itself as these are small processors its common to want to write a single byte, then, later write another byte straight after that byte), anyway, I compiled the code and it takes 80 bytes of RAM to program one long word. This processor only has 512 bytes of RAM.
The example I supplied in my first post only uses 8 bytes of RAM. So when someone gets time at freescale maybe have a look at my code and do it this way for future...? Making a 512 byte RAM processor then expecting us to allocate 80 of those bytes to write a byte to flash is a bit silly. For this project I can get away with the 80 bytes, but im sure people have had to, or, will have to make it happen in less.
And by the way, the application note has two mistakes in it:
1. There are no defines for the flash commands you have to go and manually work out what they are, and they are no descibed the same, maybe include references when you give examples, I added these two for the example as that is all I am using, not sure if they are correct, I have not tested my code yet:
#define FLASH_CMD_ERASE_SECTOR 0x0A
#define FLASH_CMD_PROGRAM 0x06
2. You need to add the arrays for reference, lucky I realised i had old code like this, but it took 15 minutes to work out why it would not work...
extern char __SEG_START_FLASH_ROUTINES[]; //Used for copying code to RAM
extern char __SEG_SIZE_FLASH_ROUTINES[]; //Used for copying code to RAM