Professional Documents
Culture Documents
Daniel Widyanto
September 2010
Disclaimer
2
Contents
3
Understanding LPC11xx Clock
Hands On
4
Understanding LPC11xx Clock
5
Understanding LPC11xx Clock
Internal RC oscillator
6
Understanding LPC11xx Clock
Watchdog oscillator
7
Understanding LPC11xx Clock
System Oscillator
8
Understanding LPC11xx Clock
9
Understanding LPC11xx Clock
1)
10MHz <= Fclkin < 25MHz
2)
Fclkin <= Fclkout <= 50MHz
Fcco3) = 2 x P x Fclkout
3)
156MHz <= Fcco <= 320MHz
10
Understanding LPC11xx Clock
Initializing PLL
1. Select PLL input
2. Toggle ENA bit on SYSPLLCLKUEN
3. Fill the ‘M’ and ‘N’ value to SYSPLLCTRL
4. Power on SYSPLL
11
Understanding LPC11xx Clock
Main clock
12
Understanding LPC11xx Clock
System clock
– Control core’s clock, flash, ROM, RAM, and most of the
peripherals
13
Understanding LPC11xx Clock
Peripheral clocks
14
Understanding LPC11xx Clock
Watchdog peripheral
15
Understanding LPC11xx Clock
CLKOUT pin
16
Understanding LPC11xx Clock
Hands On
17
In-Application Programming
Hands On
18
In-Application Programming
What is that ?
– Capability of the MCU to reprogram its own flash from user’s
software
– No external circuitry is needed
Usage:
– Field firmware upgrade
– EEPROM replacement
– Firmware configuration storage
– Data storage
– Etc
Limitation:
– Can only be erased in 1-block size (ie. 4kBytes)
– Slow erase time (100ms) and writing time (1ms)
– Flash is not accessible during write / erase time
• The codes need to be run from RAM during IAP 19
In-Application Programming
LPC1114 Implementation
IAP functions
ARM ISP functions
Flash Checksum functions
Cortex-M0
……
……
ROM
RAM Peripherals
20
In-Application Programming
GPIOSetDir( 0, 7, 1 );
Function pointer
– Can use the same concept using function pointer
21
In-Application Programming
Function pointer
#define IAP_LOCATION 0x1fff1ff1
iap_entry=(IAP) IAP_LOCATION;
iap_entry (command, result);
// Result is in result[0]
return result[0];
}
22
In-Application Programming
23
In-Application Programming
– To write sector:
• Issue ‘Prepare sector(s) for write operation’ command first, followed by
‘Copy RAM to Flash’ command
– To read sector:
• Read like ordinary memory
• Eg. If the data is 4-bytes long, written at 0x020, use:
uint32_t stored_value = * ((uint32_t *) 0x20);
24
In-Application Programming
25
In-Application Programming
Hands On
26
LPC11xx Power Management
Hands On
27
LPC11xx Power Management
Sleep mode:
– Stops the processor clock -> execution of instructions is
suspended until either a reset or an interrupt occurs
– Implemented by all of ARM Cortex-M3 vendors
28
LPC11xx Power Management
29
LPC11xx Power Management
0 0 Sleep
SLEEPDEEP
DPDEN
30
LPC11xx Power Management
Options
– PDRUNCFG (0x4004 8238)
• Control peripherals power during active mode
– PDWAKECFG (0x4004 8234)
• Control peripherals power that needs to be activated after wake up
– PDSLEEPCFG (0x4004 8230)
• Control watchdog and brownout circuit when entering deep sleep
mode
– SLEEPONEXIT on SCR (0xE000 ED10)
• Control whether system should sleep after finish serving IRQ
31
LPC11xx Power Management
32
LPC11xx Power Management
Things to remember
– Never let main clock source from PLL or system oscillator during
power saving mode
• The system will never be awaken (for deep sleep and power down
mode)
• If periodic wake up is needed, use watchdog oscillator as main clock
source
• Otherwise, always set the internal RC oscillator as main clock
– The ‘start logic pins’ interrupt must be activated to enable start
logic
• Including power down mode
33
LPC11xx Power Management
Hands On
1
Disclaimer
2
Contents
3
Understanding LPC11xx Clock
Hands On
4
Understanding LPC11xx Clock
5
Understanding LPC11xx Clock
Internal RC oscillator
The internal RC oscillator is calibrated at NXP manufacturing site. The calibration value is
written by bootloader during boot up.
User can change the register value to change the internal RC oscillation frequency, but it
is not recommended since each device has different characteristic (ie. The frequency
change per TRIM value change is not always same for each device).
6
Understanding LPC11xx Clock
Watchdog oscillator
Any FREQSEL value will generate output frequency within 40% tolerance. Hence, it is not
recommended for application that needs accurate timing
7
Understanding LPC11xx Clock
System Oscillator
System oscillator can be bypassed if user wants to use external clock instead of crystal.
8
Understanding LPC11xx Clock
System PLL can use internal RC oscillator or system oscillator as its source. Refer to
SYSPLLCLKSEL for the PLL input source. Both clocks must be running before clock
source is updated.
After the PLL input source is changed, the ENA bit should be toggled. Here’s the code
example:
9
Understanding LPC11xx Clock
1)
10MHz <= Fclkin < 25MHz
2)
Fclkin <= Fclkout <= 50MHz
Fcco3) = 2 x P x Fclkout
3)156MHz <= Fcco <= 320MHz
10
The PLL can only accept 10Mhz – 25Mhz input (either from internal RC oscillator or
system oscillator). This frequency will be multiplied according to user’s target frequency
(Fclkout).
The Fclkout cannot over than 50MHz since the silicon die is guaranteed to work correctly
according to the specification until 50Mhz.
The Fcco can range from 156MHz – 320Mhz. The lower Fcco, the lower PLL power
consumption is.
10
Understanding LPC11xx Clock
Initializing PLL
1. Select PLL input
2. Toggle ENA bit on SYSPLLCLKUEN
3. Fill the ‘M’ and ‘N’ value to SYSPLLCTRL
4. Power on SYSPLL
11
Changing PLL value must started with power down the PLL first
The PLL parameter value cannot be changed during PLL locked is active. It may cause
software crash.
11
Understanding LPC11xx Clock
Main clock
12
By selecting MAINCLKSEL = 0x01, user can use the main oscillator frequency (bypassing
the PLL).
After the MAINCLKSEL is updated, the ENA bit at MAINCLKUEN must be toggled. Here’s
the code example to toggle it.
LPC_SYSCON->MAINCLKSEL = MAINCLKSEL_Val; /* Select PLL Clock Output */
LPC_SYSCON->MAINCLKUEN = 0x01; /* Update MCLK Clock Source */
LPC_SYSCON->MAINCLKUEN = 0x00; /* Toggle Update Register */
LPC_SYSCON->MAINCLKUEN = 0x01;
while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); /* Wait Until Updated */
12
Understanding LPC11xx Clock
System clock
– Control core’s clock, flash, ROM, RAM, and most of the
peripherals
13
System clock controls core and most of the peripherals clock, including
SYSAHBCLKCTRL
13
Understanding LPC11xx Clock
Peripheral clocks
14
14
Understanding LPC11xx Clock
Watchdog peripheral
15
After the MAINCLKSEL is updated, the ENA bit at MAINCLKUEN must be toggled.
15
Understanding LPC11xx Clock
CLKOUT pin
16
16
Understanding LPC11xx Clock
Hands On
17
17
In-Application Programming
Hands On
18
18
In-Application Programming
What is that ?
– Capability of the MCU to reprogram its own flash from user’s
software
– No external circuitry is needed
Usage:
– Field firmware upgrade
– EEPROM replacement
– Firmware configuration storage
– Data storage
– Etc
Limitation:
– Can only be erased in 1-block size (ie. 4kBytes)
– Slow erase time (100ms) and writing time (1ms)
– Flash is not accessible during write / erase time
• The codes need to be run from RAM during IAP 19
The LPC11xx Flash data retention is 10K program/erase-cycles. The programming can
be done as minimum as 256kBytes for each writing operation. Hence, each sector could
be written 16 times before it is erased.
19
In-Application Programming
LPC1114 Implementation
IAP functions
ARM ISP functions
Flash Checksum functions
Cortex-M0
……
……
ROM
RAM Peripherals
20
20
In-Application Programming
GPIOSetDir( 0, 7, 1 );
Function pointer
– Can use the same concept using function pointer
21
When a function is disassembled, its parameters are passed through the registers (or
stack, but not in ARM architecture case), then the address of the function is called
We can reuse the concept using function pointer to call ROM functions in C
21
In-Application Programming
Function pointer
#define IAP_LOCATION 0x1fff1ff1
iap_entry=(IAP) IAP_LOCATION;
iap_entry (command, result);
// Result is in result[0]
return result[0];
}
22
22
In-Application Programming
23
The IAP takes two parameters: the pointer to command table, and pointer to result table.
The command parameter address is passed through R0, the result table address is
passed through R1.
23
In-Application Programming
– To write sector:
• Issue ‘Prepare sector(s) for write operation’ command first, followed by
‘Copy RAM to Flash’ command
– To read sector:
• Read like ordinary memory
• Eg. If the data is 4-bytes long, written at 0x020, use:
uint32_t stored_value = * ((uint32_t *) 0x20);
24
24
In-Application Programming
25
25
In-Application Programming
Hands On
26
26
LPC11xx Power Management
Hands On
27
27
LPC11xx Power Management
Sleep mode:
– Stops the processor clock -> execution of instructions is
suspended until either a reset or an interrupt occurs
– Implemented by all of ARM Cortex-M3 vendors
28
The deep sleep behaviour may be different from ARM Cortex-M3 vendors.
28
LPC11xx Power Management
29
29
LPC11xx Power Management
0 0 Sleep
SLEEPDEEP
DPDEN
30
30
LPC11xx Power Management
Options
– PDRUNCFG (0x4004 8238)
• Control peripherals power during active mode
– PDWAKECFG (0x4004 8234)
• Control peripherals power that needs to be activated after wake up
– PDSLEEPCFG (0x4004 8230)
• Control watchdog and brownout circuit when entering deep sleep
mode
– SLEEPONEXIT on SCR (0xE000 ED10)
• Control whether system should sleep after finish serving IRQ
31
31
LPC11xx Power Management
32
32
LPC11xx Power Management
Things to remember
– Never let main clock source from PLL or system oscillator during
power saving mode
• The system will never be awaken (for deep sleep and power down
mode)
• If periodic wake up is needed, use watchdog oscillator as main clock
source
• Otherwise, always set the internal RC oscillator as main clock
– The ‘start logic pins’ interrupt must be activated to enable start
logic
• Including power down mode
33
The PLL and system oscillator needs software configuration to run. If one of them is
enabled as main clock source during power saving mode, there will be no clock to run the
software to configure
33
LPC11xx Power Management
Hands On
The LPCXpresso will download the debugged program into flash. Hence, even if the IDE
is not running, the program can still run from the board.
34