I am trying to implement a bootloader for S12P. I downloaded the AN3275SW which claims to work for all S12 microcontrollers. But when I flash my microcontroller with the code provided, it hangs in the startup file itself. I modified the code to make it deliberately jump to main. It does so but then it hangs as soon as it comes across any function call. Can you tell me what could be wrong? Are there any software updates for AN3275 or are there any changes I need to do in the Standard Settings in CodeWarrior?
--
Cmux
As designed, CodeWarrior points the reset vector to the _Startup routine, whose code is located in Start12.c. _Startup's purpose is to set up the stack, initialize key processor registers, and other stuff that sets up the C run time environment. After that, _Startup calls main(). If you by-pass that routine, none of the crucial initializations take place, and the MCU soon goes out into the weeds. You are dying on a function call because the stack and its pointer have not been set up.
---Tom
Oh I am sorry for the confusion. I flashed the AN3275SW code as it was provided on the freescale site also. That too used to hang. I ran the code in the debugger one step at a time and found that it used to hang in the Start12.c file before it could jump to main(). Did anyone else too face this problem when implementing the bootloader?
--
Cmux
#if defined(__SET_RESET_VECTOR__)
void __interrupt 0 _Startup(void) {
#else
void _Startup(void) {
#endif
/* purpose: 1) initialize the stack
2) initialize the RAM, copy down init data etc (Init)
3) call main;
parameters: NONE
called from: _PRESTART-code generated by the Linker
or directly referenced by the reset vector */
/* Enable the Digital input buffer for bit0 */
ATD0DIEN = 0x01;
/* wait 2 cycles */
asm PSHA;
asm PSHA;
if(PORTAD0_BIT0)
//if(PORTE & 0x20)
{
asm JMP [0xFFFE-BootBlkSize,pcr]/* Run user Program */
}
else
{
_DISABLE_COP();
/* My Working RAM is from 0x5000 - 0x57FF */
INITRM = 0x50;
INITEE = 0x21; /* EEPROM if available is located from 0x2000 */
/* initialize the stack pointer */
INIT_SP_FROM_STARTUP_DESC(); /*lint !e522 asm code */ /* HLI macro definition in hidef.h */
// Init(); /* zero out, copy down, call constructors */
__asm {
ZeroOut:
LDX _startupData.pZeroOut ; *pZeroOut
LDY _startupData.nofZeroOuts ; nofZeroOuts
BEQ CopyDown ; if nothing to zero out
NextZeroOut: PSHY ; save nofZeroOuts
LDY 2,X+ ; start address and advance *pZeroOut (X = X+4)
LDD 2,X+ ; byte count
NextWord: CLR 1,Y+ ; clear memory byte
DBNE D, NextWord ; dec byte count
PULY ; restore nofZeroOuts
DEY ; dec nofZeroOuts
BNE NextZeroOut
CopyDown:
LDX _startupData.toCopyDownBeg ; load address of copy down desc.
NextBlock:
LDD 2,X+ ; size of init-data -> D
BEQ funcInits ; end of copy down desc.
LDY 2,X+ ; load destination address
Copy: MOVB 1,X+,1,Y+ ; move a byte from ROM to the data area
DBNE D,Copy ; copy-byte loop
BRA NextBlock
funcInits: ; call of global construtors is only in c++ necessary
}
/* Jump to main(); Use JMP instead of CALL to not use space on Stack*/
asm JMP main;
}
}
This is the Start12.c file that is included with the AN3275SW. When I run my code the microcontroller just hangs. I then set a breakpoint at asm JMP main and ran the code, it never reached the breakpoint and just hung. I am using S12P128. Are there any device-specific changes I need to make in the code to get it working?
--
Cmux
I would begin by creating a project for the S12P and use the start12.c file it produces. Unless the app note does something very special in the startup code, the start12.c file generated by the wizard should work. If something must be modified to support the bootloader, you would edit this startup file.
---Tom