LPC 2368 example code

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

LPC 2368 example code

944 次查看
remibusseuil
Contributor I

Hi All

 

I recently started to support an old design using a LPC 2368.

I went to download the code example from the official NXP website and was struct by the level of the code...

Something was strange when I noticed the values where stored in name in lowercase, magic numbers everywhere. It smelt like the official code was written by somebody with very little experience in programing.

Then I looked at this function:

void ConfigurePLL ( void )
{
  DWORD MValue, NValue;

  if ( PLLSTAT & (1 << 25) )
  {
	PLLCON = 1;			/* Enable PLL, disconnected */
	PLLFEED = 0xaa;
	PLLFEED = 0x55;
  }

  PLLCON = 0;				/* Disable PLL, disconnected */
  PLLFEED = 0xaa;
  PLLFEED = 0x55;
    
  SCS |= 0x20;			/* Enable main OSC */
  while( !(SCS & 0x40) );	/* Wait until main OSC is usable */

  CLKSRCSEL = 0x1;		/* select main OSC, 12MHz, as the PLL clock source */

  PLLCFG = PLL_MValue | (PLL_NValue << 16);
  PLLFEED = 0xaa;
  PLLFEED = 0x55;
      
  PLLCON = 1;				/* Enable PLL, disconnected */
  PLLFEED = 0xaa;
  PLLFEED = 0x55;

  CCLKCFG = CCLKDivValue;	/* Set clock divider */
#if USE_USB
  USBCLKCFG = USBCLKDivValue;		/* usbclk = 288 MHz/6 = 48 MHz */
#endif

  while ( ((PLLSTAT & (1 << 26)) == 0) );	/* Check lock bit status */
    
  MValue = PLLSTAT & 0x00007FFF;
  NValue = (PLLSTAT & 0x00FF0000) >> 16;
  while ((MValue != PLL_MValue) && ( NValue != PLL_NValue) );

  PLLCON = 3;				/* enable and connect */
  PLLFEED = 0xaa;
  PLLFEED = 0x55;
  while ( ((PLLSTAT & (1 << 25)) == 0) );	/* Check connect bit status */
  return;
}

 

 

Noticed the while loops ?

while ((MValue != PLL_MValue) && ( NValue != PLL_NValue) );

 

Is all the code provided by NXP of that quality?

 

0 项奖励
3 回复数

925 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

Demo code developed by different teams/engineers may use different naming convention.

Before release, we test its function correct. user can refer it or revise it for customized project.

 

Have a nice day,

Jun Zhang

0 项奖励

913 次查看
bernhardfink
NXP Employee
NXP Employee

I remember that we discussed such things from time to time in reviews and there were different opinions about it.

There were the ones from the bare metal party who said that any event which prevents a PLL from locking at this stage represents a corruption of the system anyway and the watchdog should simply restart the system.

And there was the RTOS party who said that at any point in time the software should go into a controlled state and wait there. But wait for what? Again the watchdog? So where is the difference?

However, endless loops in the main part of the code (so not in the board setup) has been called "bad style" by both parties

Anyway, at this time we had "example code" and not real "driver code". So we left it up to the individual programmer to design the system according to his philosophy. And the more simple the code was, the easier was it to adapt it to own needs.

 

Regards,

Bernhard.

0 项奖励

926 次查看
converse
Senior Contributor V

LPC2368 is really rather old (released in 2006). NXP didn't have their software act together in those days, so it doesn't surprise me that the code is poor. Unfortunately, they have not updated it either. The later (Cortex-M based parts) are much better supported with, initially, LPCOpen and latterly with SDK. Unfortunately, none of this is available for the ARM7 or ARM9 base parts in the LPC2xxx and LPC3xxx families.

0 项奖励