I'm trying to make a bootloader for a MC9S08PT60 using the processor expert (CW 10.6), but I'm having some problems.
I've looked at this project for inspiration:
But I'm trying to adopt it to my cpu, and I need to do some other changes, so I'm basically trying to do it from scratch.
First off, I want to use the internal eeprom as a bootloader/main-app selector.
I've made a selector-function, and added it to "User code before PE initialization" under "build options" of the cpu.
And I've added the header-file where the selector-function is declared under "user data declaration".
And to read from the eeprom-area I'm using the PE-generated "IEE1_GetByte"-function.
But I get 0xFF in return, regardless of the content of the cell (and I get err=OK)...
The eeprom functions works well in the main-function after "PE_low_level_init()"
So I'm guessing that I need to initialize the eeprom in some way, in my selector-function?
And secondly, I dont understand how the jump to the main-app is done in that example:
What exactly does this row do?
((void(*)(void))startup)(); /* Jump to application startup code */
Here's the declaration and assignment of "startup" from the same example:
uint32_t startup; /* assuming 32bit function pointers */startup = ((uint32_t*)APP_FLASH_VECTOR_START); /* this is the reset vector (__startup function) */
Can anyone please help me with this?
Thanks in advance!
Ps. one more thing: The eeprom area always erases itself every time I re-program the cpu with CW and the BDM-connector.
How can I prevent that from happening?