HCS12 COP and how to disable it when COPCTL is "write once"

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HCS12 COP and how to disable it when COPCTL is "write once"

8,307 Views
AndersJ
Contributor IV
Hi,
 
How can the COP be disabled temporarily,
when the COPCTL register cannot be written more than once?
 
Thanks,
Anders
Labels (1)
0 Kudos
Reply
8 Replies

1,179 Views
AndersJ
Contributor IV
I was hoping for that confirmation.
 
I am a bit confused since:
* The COP CAN be disabled if execution was started by the CW debugger.
* The COP CAN NOT be disabled if execution was started by device standalone power on.
* The COP must be disabled for flash erase/program. How to accomplish that??
 
Anders
 
 
 
 
 
 
0 Kudos
Reply

1,179 Views
Steve
NXP Employee
NXP Employee
Normally the debugger will put the part in special single chip mode which allows the code to change the COP control bits at any time. In normal single chip mode it is write once only.
I'm not sure what you mean by COP must be disabled for flash programming/erasing. In most cases the flash will be programmed once and the COP will be off during this activity. For in-field programming the situation may be different - do you have a particular question in mind?
0 Kudos
Reply

1,179 Views
AndersJ
Contributor IV
This is an infield situation, where the COP cannot, and in general, should not be disabled.
But when erasing and reflashing it is important that nothing interrupts or aborts the reflash procedure.
 
One way is to keep the COP quiet during this procedure, which is fine,
if the COP can be served often enough.
 
Another, perhaps less desirable way may be to disable the COP, if it was possible.
I initially tried this with some success, when running the debugger.
Then after normal, debugger-less power up, it no longer worked, for now confirmed reasons, thx.
 
I am now serving the COP during flash erase and program and it works fine.
 
I believe it as important (even more so) to know why things work, as why they don't work.
That's why I asked for comments on the COP issue.
 
Thanks for your help,
Anders J
 
 
0 Kudos
Reply

1,179 Views
Steve
NXP Employee
NXP Employee
That makes sense Anders - it sounds like you have solution in hand.
0 Kudos
Reply

1,179 Views
Lundin
Senior Contributor IV
Writing to the COP during programming is the serious approach.

It is however possible to disable the COP in normal single chip, and it is rather easy to do.

- Reserve a part of the RAM. In Codewarrior, give the segment the type "NO_INIT" in the .prm file.
- In the regular reset vector at FFFE, you init the variables in this segment to 0.
- When you want to disable the COP, set a flag inside this segment, then write an invalid value to ARMCOP.
- Make sure you have separate vector for COP resets. Inside the COP vector, check the flag. If it is set, then don't enable the COP again.

This is based on the fact that after a COP reset you can still trust the contents in RAM.

If you aren't using the annoying start12.c that comes with CW, then you don't even need to bother about a separate segment, since then there won't be a "zero-out" (initialization) of variables.
0 Kudos
Reply

1,179 Views
AndersJ
Contributor IV
Thanks for this tip,
 
It seems all flash erasing I need to do terminates well within the COP timout,
so I will stay on the safer side, and keep the COP running.
 
The COP depends on internal clocks, and should, in theory be somewhat
less safe than an external WD.
 
Any ideas of how good the COP is in reality?
 
Thanks,
Anders J
 
 
 
 
 
0 Kudos
Reply

1,179 Views
wilero17
Contributor I

I was sawing some tips in the forum about the watchdog timer and I have some questions.

 

actually
I'm working with the HCS12 microcontroller and I need to use the
watchdog timer in order to do  reset. I've configurated the COPCTL
register with 71 (COPCTL=71) the program
stay in a infinite for loop showing a caracter ascii in the
hyperterminal until the watchdog finish. The problem is:  after the
watchdog timer has finished the program doesn't reset o may be yes, but
I can't see more caracters in the hyperterminal until I do a manual
reset.  I've attached the program. I hope that you can help me. many
thanks.


 

 

This is the main function:



 void main(void) {
  /* put your own code here */

  char msn[20]={"Hola"};
  char msn1[5]={"."}; 
  word cont1X;
  word cont2X;

  cont2X=0;
  while(cont2X<=5000)
  {
    cont2X++;
    cont1X=0;
    while(cont1X<=100)
    {
      asm BRN *;
      cont1X++;    
    }    
  }

  SCI0BD = 12;

  SCI0CR1 = 0x00;

  SCI0CR2 = 0x04;

  vfnSCITxMsg(msn);
  COPCTL=71;
  
  for(;;) {
  cont2X=0;
  while(cont2X<=5000)
  {
    cont2X++;
    cont1X=0;
    while(cont1X<=100)
    {
      asm BRN *;
      cont1X++;    
    }    
  }
  vfnSCITxMsg(msn1);
  } /* loop forever */
  /* please make sure that you never leave main */
}
0 Kudos
Reply

1,179 Views
Steve
NXP Employee
NXP Employee
You can't disable the watchdog temporarily. It's either on or off for the application.
0 Kudos
Reply