default handler LPC1227

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

default handler LPC1227

1,501 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by alexxx on Fri Feb 22 04:21:35 MST 2013
Hi!

I am new in cortex-m0 core, recently I made an application using LPC1227.

Sometimes when application starts, after reset and during oscillation initialization, the code fails to continue and brances into default handler and there it stays until I reset the code. This happens either with the debugger running or not.
I have found a solution, by initialising the watchdog before oscillation initialization, so after default handler application restarts via watchdog and then it runs properly.

But I don't like this solution, since I have yet no idea why this is happening.

Has anyone faced a similar problem?

Besides that, how can I write code inside the default handler? I have wrote code for other handlers (like sys tick and uart0), but when I create a function for default handler, all breakpoints inside it are deactivated during compile time and I get a warning "[I]Discarded breakpoint of type EMUL_CODE, unknown to the current driver.[/I]".

I am using external crystal 24MHz, IAR compiler.

Thanks in advance.
0 项奖励
回复
10 回复数

1,416 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by RKPDIGITAL on Fri Aug 15 11:30:25 MST 2014
I changed the PSEL bits in the SYSPLLCTR register to no effect. What do they do?

Note: I don't trust the description in UM10441 page 50.

I set SY&SPLLCTR to 0x02, 0x22, 0x42 and always got 36mhz. As shipped it was 0x41 which is 24mhz.
0 项奖励
回复

1,416 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Tue Mar 05 02:12:19 MST 2013
Here's my entire init function (not written by me, comes pre-canned in the Xpresso environment)


void SystemInit (void)
{
  uint32_t i;

  LPC_SYSCON->SYSMEMREMAP = 0x2;    /* remap to internal FLASH */

  /* System clock to the IOCON needs to be enabled or
  most of the I/O related peripherals won't work. */
  LPC_SYSCON->SYSAHBCLKCTRL = 0x0001001FUL;

#if (CLOCK_SETUP)                                 /* Clock Setup              */

#if (MAINCLK_SETUP)                                /* System Clock Setup       */

#if (SYSOSC_SETUP)                                /* System Oscillator Setup  */
  /* bit 0 default is crystal bypass, 
  bit1 0=0~20Mhz crystal input, 1=15~50Mhz crystal input. */
  LPC_SYSCON->SYSOSCCTRL = 0x00;
  /* main system OSC run is cleared, bit 5 in PDRUNCFG register */
  LPC_SYSCON->PDRUNCFG     &= ~(1 << 5);          /* Power-up System Osc      */
  LPC_SYSCON->SYSOSCCTRL    = SYSOSCCTRL_Val; ==> 0x00000000
    /* Wait 200us for OSC to be stablized, no status indication, dummy wait. */
  for (i = 0; i < 200; i++) __NOP();
#endif  // #if (SYSOSC_SETUP)

#if (SYSPLL_SETUP)
  LPC_SYSCON->SYSPLLCLKSEL  = SYSPLLCLKSEL_Val;   ==> 0x00000000 /* Select PLL Input         */
  LPC_SYSCON->SYSPLLCLKUEN  = 0x01;               /* Update Clock Source      */
  LPC_SYSCON->SYSPLLCLKUEN  = 0x00;               /* Toggle Update Register   */
  LPC_SYSCON->SYSPLLCLKUEN  = 0x01;
  while (!(LPC_SYSCON->SYSPLLCLKUEN & 0x01));     /* Wait Until Updated       */
                                /* System PLL Setup         */
  LPC_SYSCON->SYSPLLCTRL    = SYSPLLCTRL_Val;    ==> 0x00000041
  LPC_SYSCON->PDRUNCFG     &= ~(1 << 7);          /* Power-up SYSPLL          */
  while (!(LPC_SYSCON->SYSPLLSTAT & 0x01));          /* Wait Until PLL Locked    */
#endif // #if (SYSPLL_SETUP)

  LPC_SYSCON->MAINCLKSEL    = MAINCLKSEL_Val;   ==> 0x00000003  /* Select PLL Clock Output  */
  LPC_SYSCON->MAINCLKUEN    = 0x01;               /* Update MCLK Clock Source */
  LPC_SYSCON->MAINCLKUEN    = 0x00;               /* Toggle Update Register   */
  LPC_SYSCON->MAINCLKUEN    = 0x01;
  while (!(LPC_SYSCON->MAINCLKUEN & 0x01));       /* Wait Until Updated       */

#endif  // #if (MAINCLK_SETUP)


  LPC_SYSCON->SYSAHBCLKDIV  = SYSAHBCLKDIV_Val;    ==> 0x00000001
  LPC_SYSCON->SSPCLKDIV  = SSPCLKDIV_Val;    ==> 0x00000000
  LPC_SYSCON->UART0CLKDIV= UART0CLKDIV_Val;    ==> 0x00000000
  LPC_SYSCON->UART1CLKDIV= UART1CLKDIV_Val;    ==> 0x00000000


#endif  // #if (CLOCK_SETUP)
}
Note that there are many values defined elsewhere, when this happens I've added the HEX value after ==> that my system shows for that definition, eg.

LPC_SYSCON->UART1CLKDIV= UART1CLKDIV_Val;    ==> 0x00000000
ART1CLKDIV_Val is 0 on my system.

Note the for loop after setting SYSOSCCTRL.

I've also removed #define blocks that evaluated to false because you wouldn't know if that code was included or not.

_____
Rob
0 项奖励
回复

1,416 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Tue Mar 05 01:18:03 MST 2013
I just had a quick look at your code and glanced through the user manual.
Since I do not own an lpc1227 target I have to make some assumpions though ...

It seems to me you are doing things in the wrong order. You need to make sure that your xtal oscillator is running and stable before using it as the system clock. Right now the code shows that you enable the main (xtal) oscillator right before switching the system clock to the main oscillator.

Since it takes some time for the main oscillator to become stable this means that you may run on an unstable clock.That could well be the cause for your problems.

At least put some delay in between enabling power to the main oscillator and switching over to this. Also, do not connect the clock to anything before this - even if there seems to be nothing wrong; it is just bad habit to clock any hardware with unstable clocks.

Rob
0 项奖励
回复

1,416 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by alexxx on Mon Mar 04 23:18:50 MST 2013

Quote: graynomad
I can post it if you want compare


Thanks graynomad, if you could be so kind and post the initialization code, it would be a help for me, maybe I could understand if there is something wrong. No problem about the different compiler, I will figure it out.

UPDATE:
I just took a look into IAR examples. In some examples there is a delay after setting the SYSOSCCTRL register to allow the oscillator to stabilise. In other examples there is no delay. I looked what the datasheet says about this, but it is not much of a help... I couldn't find any clear guidelines on crystal initialization. In the SYSOSCCTRL register section, no delay is mentioned.
0 项奖励
回复

1,416 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Mon Mar 04 07:01:16 MST 2013
I'm not using IAR so my init code is a lot different, but from what I can see it's doing things in a different order and there is  a delay after setting the SYSOSCCTRL register to allow the oscillator to stabilise.

I can post it if you want compare, the method of accessing regs is different but the names are the same so you should be able to figure it out.
0 项奖励
回复

1,416 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by alexxx on Sun Mar 03 23:12:30 MST 2013
Has anyone looked into the crystal initialization code? Is it OK?
0 项奖励
回复

1,416 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by alexxx on Tue Feb 26 00:25:02 MST 2013
Thanks for the attention guys.


Quote: whitecoe
I imagine that this is the watchdog tripping (it is on by default from reset on LPC12 parts).


I have also noticed this behaviour concerning watchdog, this is why I disable watchdog during debug time.
However, this is a different issue (I think) than the one I mentioned in the OP. The problem is that code is stacked in some place, and then it is going to default handler (file cstartup_M.s).


Quote: graynomad
I'm using the 1227 and have not encountered this.


Below is the initialization routine of the external crystal (24MHz), this is where things are messed up. As I said this happens rarely (something like 10% of the time).



void ExternalXtalClock(void)
{
 
  // The below code is for external clock 
  
  /*Sys Oscilator Enable*/
  SYSOSCCTRL = (MAIN_OSC_FREQ>(20MHZ))?(0x2):(0x0); 
  
  SYSPLLCLKUEN = 0;
  SYSPLLCLKSEL = 1;//system clock to PLL not IRC
  SYSPLLCLKUEN = 1;
  
  /* Set Sys AHB Clock devider    */
  SYSAHBCLKDIV_bit.DIV = 1; //no divider    
  
  /*Power Up SYS Oscilator*/
  PDRUNCFG_bit.SYSOSC_PD = 0;
  /*Enable Internal RC oscilator*/
  PDRUNCFG_bit.IRC_PD = 0;
  /*Select internal RC oscilator for
  Sys clock source*/
  
  MAINCLKUEN = 0;
  MAINCLKSEL = 1; //Select input clock of PLL
  MAINCLKUEN = 1;    
  
  [COLOR=Red]xdelay(100); //sometimes the code never returns from this function[/COLOR]
  
  //CLKout pin enable show main clock
  CLKOUTDIV = 1;
  
  CLKOUTUEN = 0;
  CLKOUTCLKSEL = 3;
  CLKOUTUEN = 1;
  
}


The red line of code calls a function where some nop instructions are executed, nothing more. I tried to add bigger delays (more nop instructions), but that didn't solve anything. Still the code sometimes is not returning from xdelay(), but instead it branches to default handler.

Any ideas?
0 项奖励
回复

1,416 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Mon Feb 25 17:58:27 MST 2013
I'm using the 1227 and have not encountered this.
0 项奖励
回复

1,416 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by whitecoe on Mon Feb 25 01:26:17 MST 2013
I imagine that this is the watchdog tripping (it is on by default from reset on LPC12 parts).

For LPCXpresso, you could look at the FAQ

http://support.code-red-tech.com/CodeRedWiki/LPC12Watchdog

For IAR, you'll need to check their docs.

HTH!
0 项奖励
回复

1,416 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by alexxx on Sun Feb 24 23:48:06 MST 2013
Does any of you guys have a suggestion on the described issue?
0 项奖励
回复