Updated functions to deal with USB clocking. (PPL1) See http://www.nxp.com/documents/user_manual/UM10360.pdf Section 4.6 & 4.7.3

Dependencies:   mbed

Fork of ClockControl by Michael Wei

Committer:
aidan1971
Date:
Mon Sep 12 13:11:32 2016 +0000
Revision:
2:ab85c20317b5
Parent:
1:8b04bd33c7cd
Added comments and command to change TIMER3 prescaler

Who changed what in which revision?

UserRevisionLine numberNew contents of line
no2chem 0:b5d3bd64d2dc 1 #include "mbed.h"
no2chem 0:b5d3bd64d2dc 2 #include "ClockControl/ClockControl.h"
no2chem 0:b5d3bd64d2dc 3 #include "CoreMark/core_portme.h"
no2chem 0:b5d3bd64d2dc 4
no2chem 0:b5d3bd64d2dc 5 int main() {
no2chem 0:b5d3bd64d2dc 6 while(1) {
no2chem 0:b5d3bd64d2dc 7
no2chem 0:b5d3bd64d2dc 8
no2chem 0:b5d3bd64d2dc 9 printf("mbed Clock Control test\r\n");
no2chem 0:b5d3bd64d2dc 10 printf("(c) 2010 Michael Wei\r\n");
no2chem 0:b5d3bd64d2dc 11
no2chem 0:b5d3bd64d2dc 12 unsigned short newM = 12;
no2chem 0:b5d3bd64d2dc 13 unsigned short newN = 1;
aidan1971 1:8b04bd33c7cd 14 unsigned char newUSBdiv = 6;
no2chem 0:b5d3bd64d2dc 15
no2chem 0:b5d3bd64d2dc 16 printf("Value of M? (default = 12):\r\n");
no2chem 0:b5d3bd64d2dc 17 scanf("%d", &newM);
no2chem 0:b5d3bd64d2dc 18
no2chem 0:b5d3bd64d2dc 19 printf("Value of N? (default = 1):\r\n");
no2chem 0:b5d3bd64d2dc 20 scanf("%d", &newN);
no2chem 0:b5d3bd64d2dc 21
aidan1971 1:8b04bd33c7cd 22 printf("Value of USB divider? (default = 6):\r\n");
aidan1971 1:8b04bd33c7cd 23 scanf("%d", &newUSBdiv);
aidan1971 1:8b04bd33c7cd 24
aidan1971 1:8b04bd33c7cd 25 setSystemFrequency(newUSBdiv, 0x3, 0x1, newM, newN);
no2chem 0:b5d3bd64d2dc 26
no2chem 0:b5d3bd64d2dc 27 Serial pc(USBTX, USBRX); // tx, rx
no2chem 0:b5d3bd64d2dc 28
no2chem 0:b5d3bd64d2dc 29 //This code by Simon Ford: http://mbed.org/forum/mbed/topic/229/?page=1#comment-1225
no2chem 0:b5d3bd64d2dc 30
no2chem 0:b5d3bd64d2dc 31 int Fin = 12000000; // 12MHz XTAL
no2chem 0:b5d3bd64d2dc 32 pc.printf("PLL Registers:\r\n");
no2chem 0:b5d3bd64d2dc 33 pc.printf(" - PLL0CFG = 0x%08X\r\n", LPC_SC->PLL0CFG);
no2chem 0:b5d3bd64d2dc 34 pc.printf(" - CLKCFG = 0x%08X\r\n", LPC_SC->CCLKCFG);
no2chem 0:b5d3bd64d2dc 35
no2chem 0:b5d3bd64d2dc 36 int M = (LPC_SC->PLL0CFG & 0xFFFF) + 1;
no2chem 0:b5d3bd64d2dc 37 int N = (LPC_SC->PLL0CFG >> 16) + 1;
no2chem 0:b5d3bd64d2dc 38 int CCLKDIV = LPC_SC->CCLKCFG + 1;
aidan1971 1:8b04bd33c7cd 39 int USBCLKDIV = LPC_SC->USBCLKCFG + 1;
no2chem 0:b5d3bd64d2dc 40
no2chem 0:b5d3bd64d2dc 41 pc.printf("Clock Variables:\r\n");
no2chem 0:b5d3bd64d2dc 42 pc.printf(" - Fin = %d\r\n", Fin);
no2chem 0:b5d3bd64d2dc 43 pc.printf(" - M = %d\r\n", M);
no2chem 0:b5d3bd64d2dc 44 pc.printf(" - N = %d\r\n", N);
no2chem 0:b5d3bd64d2dc 45 pc.printf(" - CCLKDIV = %d\r\n", CCLKDIV);
aidan1971 1:8b04bd33c7cd 46 pc.printf(" - USBCLKDIV = %d\r\n", USBCLKDIV);
no2chem 0:b5d3bd64d2dc 47
no2chem 0:b5d3bd64d2dc 48 int Fcco = (2 * M * 12000000) / N;
no2chem 0:b5d3bd64d2dc 49 int CCLK = Fcco / CCLKDIV;
no2chem 0:b5d3bd64d2dc 50
no2chem 0:b5d3bd64d2dc 51 pc.printf("Clock Results:\r\n");
no2chem 0:b5d3bd64d2dc 52 pc.printf(" - Fcco = %d\r\n", Fcco);
no2chem 0:b5d3bd64d2dc 53
no2chem 0:b5d3bd64d2dc 54 printf(" - CCLK = %d\r\n", CCLK);
no2chem 0:b5d3bd64d2dc 55
no2chem 0:b5d3bd64d2dc 56 printf("Run CoreMark? (Y/N)\n");
no2chem 0:b5d3bd64d2dc 57 char buf[8];
no2chem 0:b5d3bd64d2dc 58 scanf("%s", buf);
no2chem 0:b5d3bd64d2dc 59 if (buf[0] == 'y' || buf[0] == 'Y')
no2chem 0:b5d3bd64d2dc 60 {
no2chem 0:b5d3bd64d2dc 61 mainCoreMark();
no2chem 0:b5d3bd64d2dc 62 }
no2chem 0:b5d3bd64d2dc 63
no2chem 0:b5d3bd64d2dc 64 wait(1);
no2chem 0:b5d3bd64d2dc 65 NVIC_SystemReset();
no2chem 0:b5d3bd64d2dc 66 }
no2chem 0:b5d3bd64d2dc 67 }