PCLKSEL0 must be set before enabling and connecting PLL0

26 Aug 2010 . Edited: 26 Aug 2010

Hi,

I have an mbed NXP LPC1768 with an LPC1768 that is revision "-". So, the "initial device revision".

The errata sheet ES_LPC1768.pdf Rev.4 (19 July 2010) says that there is a functional problem with PCLKSELx. See Section 3.5:
------------------------------------
3.5 PCLKSELx.1: Peripheral Clock Selection Registers must be set before enabling and connecting PLL0
Introduction:
A pair of bits in the Peripheral Clock Registers (PCLKSEL0 and PCLKSEL1) controls the
rate of the clock signal that will be supplied to APB0 and APB1 peripherals.
Problem:
If the Peripheral Clock Registers (PCLKSEL0 and PCLKSEL1) are set or changed after
PLL0 is enabled and connected, the value written into the Peripheral Clock Selection
Registers may not take effect. It is not possible to change the Peripheral Clock Selection
settings once PLL0 is enabled and connected.
Work-around:
Peripheral Clock Selection Registers must be set before enabling and connecting PLL0.
------------------------------------

The mbed library sets PCLKSEL0 and PCLKSEL1 to 0
#define PCLKSEL0_Val          0x00000000
#define PCLKSEL1_Val          0x00000000
which means that all peripherals get a clock that is 1/4 of the CPU clock. The CPU runs at 96 MHz. All peripherals are therefore fed with a 24 MHz clock. According to the errata sheet, the programmer of an mbed who uses "mbed.h" cannot choose to work with other peripheral frequencies, because PLL0 has already been enabled by the mbed library.

The problem is that I need PWM1 to run at the highest possible frequency (96 MHz), because I need to generate PWM signals with a repetition rate close to 400 kHz, and with the highest possible frequency resolution.

Is there any workaround?
In this application, I don't need the mbed library. I would gladly avoid it, so that I could use a different value for PCLKSEL0 before PLL0 gets configured.
In fact, I did try creating and compiling a program with only these files (from cmsis_v1p30.zip)

LPC17xx.h   (with the default contents from ARM)
core_cm3.h   (with the default contents from ARM)
core_cm3.c   (with the default contents from ARM)
startup_LPC17xx.s (with the default contents from ARM)
system_LPC17xx.h (with the default contents from ARM)
system_LPC17xx.c (with the default contents from ARM)
main.cpp  (with the contents shown below)

main.cpp:
------------------------------------
#include "LPC17xx.h"
#include "core_cm3.h"
#include "system_LPC17xx.h"

int  k=0;
int  d=0;

int main()
{
 LPC_SC->PCONP     |=(1<<15);         // Turns on GPIO.
    LPC_GPIO1->FIODIR    |=  (1<<18)|(1<<20)|(1<<21)|(1<<23);  // The four LEDs.
    LPC_GPIO1->FIOMASK    =0;
    while (1)
    {
     LPC_GPIO1->FIOCLR   |=  (1<<18)|(1<<20)|(1<<21)|(1<<23);
     for (k=0;k<10000;k++)
     {
      d++;
     } // for k
     LPC_GPIO1->FIOSET   |=  (1<<18)|(1<<20)|(1<<21)|(1<<23);
     for (k=0;k<10000;k++)
     {
      d++;
     } // for k
    } // while
} // main
------------------------------------
So, without the
 #include "mbed.h"
but it didn't work. It compiles OK, but the LEDs don't flash at the target.

Does anyone know how to make a peripheral run at a clock frequency different to cclk/4 ?
Am I missing to include any file? Maybe some instruction, in main.cpp?

Thank you very much.
Cesar Pascual