This isn't a request for help, I'd just like to share an issue I encountered during my last project when using the LPC1768 (NXP), configured with an external clock source with internal PLL and CPU clock divider used to boost the CPU clock to its operational speed (80MHz). I'm sharing this for anyone who wants to use this IC series in this configuration with the debug environment.
This info was valid with MDK-ARM 4.21 using uLink PRO.
LPC1768 used an external 20MHz oscillator which was then fed through PLL0 and CCLKCFG to end up with a CPU Clock of 80MHz.
The issue was that after the IC was reset, it would begin using its internal 4MHz oscillator as the CPU Clock by default, which is what the uVision IDE and uLink PRO would synchronise with at the start of the debug session. When the IC executed its bootup code in my application, the clocking subsystem was configured, resulting in the CPU Clock changing dynamically from 4MHz to 80MHz. This caused the debug session to end as the uLink PRO lost sync with the CPU.
The solution to this was to write a debugger script to pre-configure the clocking subsystem during the initialisation of the debug session. This meant that the CPU clock was already operating at 80MHz by the time the session started. The code block that configured the clocking subsystem in the application was ignored when in debug.
The debugger script used to configure the PLL block is given below (use at your own risk):
/*------------------------------------------------------------------- ** Define the function to enable the trace port **-----------------------------------------------------------------*/ FUNC void EnableTPIU (void) { _WDWORD(0x4002C028, 0x00000008); // Enable TPIU in PINSEL10 } FUNC void SetupMainOsc (void) { unsigned long SCS; SCS = _RDWORD(0x400fc1a0); //Get the value of System Control & Status Register _WDWORD(0x400fc1a0, SCS | 0x00000030); //Initialise the OSCRANGE and OSCEN flags } FUNC void PLLFeed (int pllnum) { if (pllnum == 0){ _WDWORD(0x400fc08c, 0x000000aa); _WDWORD(0x400fc08c, 0x00000055); } else { _WDWORD(0x400fc0ac, 0x000000aa); _WDWORD(0x400fc0ac, 0x00000055); } } FUNC void SetupPLL0 (void) { unsigned long CLKSRCSEL, PLL0CON, PLL0CFG, PLL0N, PLL0M, CCLKCFG, USBCLKCFG,CPUDIV; PLL0M = 12; //Calculated from PLL spreadsheet PLL0N = 2; CPUDIV = 3; CLKSRCSEL = _RDWORD(0x400fc10c); //Get value of Clock Source Select Register PLL0CON = _RDWORD(0x400fc080); //Get the value of PLL0 Control Register PLL0CFG = _RDWORD(0x400fc084); //Get the PLL0 Config register value CCLKCFG = _RDWORD(0x400fc104); //Get the CPU Clock Config register value USBCLKCFG = _RDWORD(0x400fc108); //Get the USB Clock config register value PLL0CFG |= (PLL0M - 1) | ((PLL0N - 1) << 16); //Configure PLL Config with M value and N value CCLKCFG = CPUDIV -1; //Configure divide-by-3 for CPU Clock from PLL0 //*** NOTE YOU MUST ALSO UPDATE SYSTEM_LPC17XX_DEBUG.C WITH NEW DIVIDER VALUES OR THE BOARD WILL NOT WORK!!!! ******/ //********* BEGIN PLL CONFIGURATION SEQUENCE ******* // Instructions as per NXP LPC1768 manual Chapter 4 //Send feed sequence to begin PLL0 setup PLLFeed(0); //Disable the PLL for the moment and send feed sequence to lock in value PLL0CON &= 0xfffffffc; _WDWORD(0x400fc080, PLL0CON); PLLFeed(0); //Configure main oscillator as input to PLL0 CLKSRCSEL |= 0x00000001; _WDWORD(0x400fc10c, CLKSRCSEL); //Set up PLL0 configuration and send feed sequence to lock in change _WDWORD(0x400fc084, PLL0CFG ); PLLFeed(0); //Enable the PLL0 and allow it to lock onto requested frequency PLL0CON |= 0x00000001; _WDWORD(0x400fc080, PLL0CON); PLLFeed(0); //Set up CPU clock divider _WDWORD(0x400fc104, CCLKCFG); //Set the USB Clock Divider (48MHz signal required) so divide PLL0 by 5 USBCLKCFG |= 4; _WDWORD(0x400fc108, USBCLKCFG); //Wait for PLL0 to lock onto feed while ((_RDWORD(0x400fc088) & 0x04000000) == 0){ printf("Waiting for PLL0 Lock\n"); } printf("PLL0 Locked!\n"); //Connect PLL0 to CPU Core PLL0CON |= 0x00000002; _WDWORD(0x400fc080, PLL0CON); PLLFeed(0); printf("PLL0 Connected to CPU Core\n"); } /*------------------------------------------------------------------- ** Invoke the function at debugger startup **-----------------------------------------------------------------*/ EnableTPIU(); SetupMainOsc(); SetupPLL0();