12 years, 5 months ago.

How to use internal crystal with custom LPC1768 breakout?

I have a custom break out board for the LPC1768, but at this time it does not include an external clock.

I found information in this article: http://mbed.org/users/ethankhall/notebook/custom-pcb-with-the-lpc1786/ about modifying the system_LPC17xx.c file, but I can't seem to find that file.

I've removed the defualt mbed import from a new code project and then manually imported the mbed library. I see all the .h files, but no .c files to modify.

How can I most easily make the configuration change necessary to get the mbed binary to tell the LPC1768 to use its internal clock?

Thanks in advance to anyone who can help!

-EDIT-

Ok, so this: https://mbed.org/forum/mbed/topic/3878/

and this: http://mbed.org/users/chris/notebook/Patching-functions-and-libraries/

...get me closer, but not quite there. I'm still left with trying to replace the source file _LPC17xx.c so that I can either override or recompile the SystemInit() method.

It seems like I just need to be able to set:

  1. define PLL0_SETUP = 1;
  2. define PLL0CFG_Val = 0x0005012B;

I found the source file at: https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/vendor/NXP/cmsis/LPC1768/system_LPC17xx.c

But I don't know how to replace the .o file used in the mbed library with the modified .c file...

I also tried coding an override for SystemInit() but didn't get it right because it didn't work. Here's what I tried:

#include "mbed.h"

DigitalOut myled(p26);
Serial pc(USBTX,USBRX);

extern int stdio_retargeting_module;
//extern "C" void $Super$$SystemInit (void);

 extern "C" void $Sub$$SystemInit (void)
 {
    LPC_SC->CCLKCFG = 0x00000002;
    LPC_SC->PCLKSEL0 = 0x00000000;
    LPC_SC->PCLKSEL1 = 0x00000000;
    
    LPC_SC->CLKSRCSEL = 0x00000001;
    LPC_SC->PLL0CFG = 0x0005012B;
    
    LPC_SC->PLL0FEED  = 0xAA;
    LPC_SC->PLL0FEED  = 0x55;
    LPC_SC->PLL0CON   = 0x01;             /* PLL0 Enable                        */
    LPC_SC->PLL0FEED  = 0xAA;
    LPC_SC->PLL0FEED  = 0x55;
    while (!(LPC_SC->PLL0STAT & (1<<26)));/* Wait for PLOCK0                    */  
    LPC_SC->PLL0CON   = 0x03;             /* PLL0 Enable & Connect              */  
    LPC_SC->PLL0FEED  = 0xAA;  
    LPC_SC->PLL0FEED  = 0x55;  
    while (!(LPC_SC->PLL0STAT & ((1<<25) | (1<<24))));/* Wait for PLLC0_STAT & PLLE0_STAT */
    
    LPC_SC ->PCONP = 0x042887DE;
    LPC_SC ->CLKOUTCFG = 0x00000000;
    
    stdio_retargeting_module = 1;
    
 }

int main() {
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
        pc.printf("cycle\n");
    }
}

At one point I thought to call the default Init method and then modify my values, but the default blocks waiting for the external crystal and since there isn't one, I assume the code is forever blocked at that while statement. So I gave up calling the base function and just commented the reference to it.

If anyone can shed any light on this at all (how to replace the .o file with the .c file, or how to write the override correctly, or any other way to successfully use the internal crystal!) I would be very grateful.

I wish there were some kind of simple compiler option to select the internal crystal if desired.

1 Answer

Reed Kimble
poster
12 years, 5 months ago.

-misunderstood how forum worked - -wanted to add detail, not add "answer"-