Skip to content

Commit 1c0a34a

Browse files
Implement 120MHz clocking
1 parent 57f6841 commit 1c0a34a

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

targets/TARGET_NXP/TARGET_LPC17XX/device/system_LPC17xx.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include <stdint.h>
2727
#include "LPC17xx.h"
28+
#include "mbed-target-config.h"
2829

2930

3031
/** @addtogroup LPC17xx_System
@@ -297,20 +298,28 @@
297298
#define CLKSRCSEL_Val 0x00000001
298299
#define PLL0_SETUP 1
299300

300-
#ifdef MCB1700
301-
# define PLL0CFG_Val 0x00050063
302-
# define PLL1_SETUP 1
303-
# define PLL1CFG_Val 0x00000023
304-
# define CCLKCFG_Val 0x00000003
305-
# define USBCLKCFG_Val 0x00000000
301+
// If in 120MHz mode, clock the PLL at 480MHz as this is the only frequency that can give us both 120MHz for the core
302+
// and 48MHz for USB.
303+
#ifdef MBED_CONF_TARGET_LPC17XX_CORE_CLK_120MHZ
304+
// Multiplier for PLL0. Example: if MBED_CONF_TARGET_LPC17XX_XTAL_FREQ is 6MHz, this will be 40
305+
# define PLL0_MULTIPLIER (240000000/MBED_CONF_TARGET_LPC17XX_XTAL_FREQ)
306+
# define PLL0CFG_Val (PLL0_MULTIPLIER-1) // PLL0 clock = <input clock> * <PLL0 multiplier> * 2 / 1 = 480MHz
307+
# define CCLKCFG_Val 0x00000003 // CPU clock = PLL0 clock / 4 = 120MHz
308+
309+
# define USBCLKCFG_Val 0x00000009 // USB clock = PLL0 clock / 10 = 48MHz
306310
#else
307-
# define PLL0CFG_Val 0x0000000B
308-
# define PLL1_SETUP 0
309-
# define PLL1CFG_Val 0x00000000
310-
# define CCLKCFG_Val 0x00000002
311-
# define USBCLKCFG_Val 0x00000005
311+
// Multiplier for PLL0. Example: if MBED_CONF_TARGET_LPC17XX_XTAL_FREQ is 6MHz, this will be 24
312+
# define PLL0_MULTIPLIER (144000000/MBED_CONF_TARGET_LPC17XX_XTAL_FREQ)
313+
# define PLL0CFG_Val (PLL0_MULTIPLIER-1) // PLL0 clock = <input clock> * <PLL0 multiplier> * 2 / 1 = 288MHz
314+
# define CCLKCFG_Val 0x00000002 // CPU clock = PLL0 clock / 3 = 96MHz
315+
316+
# define USBCLKCFG_Val 0x00000005 // USB clock = PLL0 clock / 6 = 48MHz
312317
#endif
313318

319+
// Don't enable PLL1. It is much more limited in input frequency and only acceps 10-24MHz.
320+
#define PLL1_SETUP 0
321+
#define PLL1CFG_Val 0x00000000
322+
314323
#define PCLKSEL0_Val 0x00000000
315324
#define PCLKSEL1_Val 0x00000000
316325
#define PCONP_Val 0x042887DE
@@ -402,8 +411,7 @@
402411
/*----------------------------------------------------------------------------
403412
Define clocks
404413
*----------------------------------------------------------------------------*/
405-
#define XTAL (12000000UL) /* Oscillator frequency */
406-
#define OSC_CLK ( XTAL) /* Main oscillator frequency */
414+
#define OSC_CLK MBED_CONF_TARGET_LPC17XX_XTAL_FREQ /* Main oscillator frequency */
407415
#define RTC_CLK ( 32000UL) /* RTC oscillator frequency */
408416
#define IRC_OSC ( 4000000UL) /* Internal RC oscillator frequency */
409417

targets/targets.json5

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,14 @@ mode is recommended for target MCUs with small amounts of flash and RAM.",
456456
"us-ticker-timer": {
457457
"help": "Chooses which timer (0-3) to use for us_ticker.c",
458458
"value": 3
459+
},
460+
"lpc17xx-xtal-freq": {
461+
help: "Frequency of external crystal or clock source connected to the XTAL pins. Frequency in MHz must be an integer factor of 24 (e.g. 12MHz, 6MHz, and 1MHz are OK but 5MHz is not).",
462+
value: 12000000
463+
},
464+
"lpc17xx-core-clk-120mhz": {
465+
help: "If true, the core will be clocked at 120MHz. Otherwise, it will be clocked at 96MHz. This is only officially supported with LPC1759/69 chips, but can work with others as an overclock.",
466+
value: false
459467
}
460468
},
461469
"overrides": {
@@ -494,7 +502,7 @@ mode is recommended for target MCUs with small amounts of flash and RAM.",
494502
},
495503
"image_url": "https://os.mbed.com/media/cache/platforms/LPC1768.jpg.250x250_q85.jpg"
496504
},
497-
"LPCXPRESSO_LPC1769": {
505+
"LPCXPRESSO_LPC1769": { // AKA LPCXpresso LPC1769. CMSIS-DAP version (OM13085UL) should also work.
498506
"inherits": [
499507
"MCU_LPC17XX"
500508
],
@@ -504,7 +512,8 @@ mode is recommended for target MCUs with small amounts of flash and RAM.",
504512
"LOCALFILESYSTEM"
505513
],
506514
"overrides": {
507-
"default-adc-vref": 3.3 // Vref is 3.3V
515+
"default-adc-vref": 3.3, // Vref is 3.3V
516+
"lpc17xx-core-clk-120mhz": true
508517
},
509518
"image_url": "https://www.embeddedartists.com/wp-content/uploads/2018/06/lpc1769_xpr_540x333-540x333.png"
510519
},

targets/upload_method_cfg/LPC1768.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ set(OPENOCD_UPLOAD_ENABLED TRUE)
3737
set(OPENOCD_CHIP_CONFIG_COMMANDS
3838
-f ${CMAKE_CURRENT_LIST_DIR}/openocd_cfgs/lpc1768.cfg)
3939

40-
# For some reason, as of summer 2024, git version of OpenOCD does not work with LPC1768. So, it seems like
41-
# the last compatible version will be the current release 0.12.
40+
# Due to the new quirks mode, as of summer 2024, git version of OpenOCD does not work with LPC1768.
4241
set(OPENOCD_VERSION_RANGE 0.10...<0.13)
4342

4443
# Config options for LINKSERVER

targets/upload_method_cfg/LPCXPRESSO_LPC1769.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ set(OPENOCD_UPLOAD_ENABLED TRUE)
3737
set(OPENOCD_CHIP_CONFIG_COMMANDS
3838
-f ${CMAKE_CURRENT_LIST_DIR}/openocd_cfgs/lpc1768.cfg)
3939

40-
# For some reason, as of summer 2024, git version of OpenOCD does not work with LPC1768. So, it seems like
41-
# the last compatible version will be the current release 0.12.
40+
# Due to the new quirks mode, as of summer 2024, git version of OpenOCD does not work with LPC1768.
4241
set(OPENOCD_VERSION_RANGE 0.10...<0.13)
4342

4443
# Config options for LINKSERVER

0 commit comments

Comments
 (0)