NOTICE: NXP has started migrating LPCWare.com to NXP.com. Many LPCware.com pages are being redirected to NXP.com. Please visit software and tools page for information on LPC microcontrollers.
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 ?
which LPCXpresso board are you using?
- NXP European team -
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.
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.