SystemClockUpdate() - Function

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SystemClockUpdate() - Function

1,192 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sherrysamuel on Wed Jul 27 19:03:00 MST 2011
Hi,
I have one question regarding the "SystemClockUpdate" function in main. This function updates the "SystemFrequency" global variable. But I cannot see use of this variable in the project itself.

Can you please explain what is the use of this function if "SystemFrequency" variable is not used  or it used in some libraries ?
0 Kudos
Reply
3 Replies

1,104 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sherrysamuel on Sun Jul 31 16:57:25 MST 2011
Thanks Rob for your detailed answer. I started with an independent project. So I didn't look in other example projects to see how it is used.

Thanx. Sorry for the trouble.
0 Kudos
Reply

1,104 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Fri Jul 29 06:18:03 MST 2011
The variable SystemCoreClock gives you the value of the system core clock (CCLK) and it can be used by your routines to calculate system timing.

As an example, look at the UARTinit() function used in a number of the example projects delivered with the LPCXpresso tools.
In there you'll see the following code:
    LPC_UART1->LCR = 0x83;             /* 8 bits, no Parity, 1 Stop bit */

    Fdiv = ((SystemFrequency/4)/16)/baudrate ;    /*baud rate */

    LPC_UART1->DLM = Fdiv / 256;
    LPC_UART1->DLL = Fdiv % 256;
    LPC_UART1->LCR = 0x03;        /* DLAB = 0 */
    LPC_UART1->FCR = 0x07;        /* Enable and reset TX and RX FIFO. */
(SystemFrequency is a #define of SystemCoreClock on top of the uart.c file).

This shows how the SystemCoreClock variable is used to calculate the baudrate.
SystemCoreClock is set during SystemInit() but if you change the clock (e.g. reprogram the PLL or select a different clock source) then calling the SystemCoreClockUpdate() function will calculate the new CCLK frequency.

Use of the SystemCoreClock variable depends on your project and which files you have in the project. The uart example code uses it and also the FreeRTOS project uses this to calculate the correct timing for the system tick. You can also use it in your own code to do stuff like programming timers, PWM, I2C clock frequency calculation etc. independent of the current frequency you are running at.

Whenever you change PLL settings or select a different clock source, you can call SystemCoreClockUpdate() and after that reinitialize modules that need their timing changed.

This is independent of the LPCXpresso board you are using. It is a system function provided by CMSIS to allow you to update the SystemCoreClock variable when your program changes the core clock frequency.

Regards,

Rob
0 Kudos
Reply

1,104 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Thu Jul 28 11:03:09 MST 2011
Hello sherrysamuel,

which LPCXpresso board are you using?
0 Kudos
Reply