Skip to content

Instantly share code, notes, and snippets.

@Aflecht
Last active June 22, 2021 11:41
Show Gist options
  • Save Aflecht/8745572 to your computer and use it in GitHub Desktop.
Save Aflecht/8745572 to your computer and use it in GitHub Desktop.
Configure LPC43xx ARM Cortex M4 microcontroller to 204 MHz using 12 MHz crystal.
//
// Configure LPC43xx ARM Cortex M4 microcontroller to 204 MHz using 12 MHz crystal
//
#define CMSIS_BITPOSITIONS
#include "lpc43xx.h"
void Configure_Clocks()
{
// Enable crystal oscillator
LPC_CGU->XTAL_OSC_CTRL = 0;
for (volatile uint32_t i = 0; i < 1000000; ++i);
// Set the PLL to 204 MHz
uint32_t control_register = LPC_CGU->PLL1_CTRL;
control_register &= ~(CGU_PLL1_CTRL_MSEL_Msk | CGU_PLL1_CTRL_CLK_SEL_Msk | CGU_PLL1_CTRL_PD_Msk);
control_register |= 16 << CGU_PLL1_CTRL_MSEL_Pos; // Feedback-divider division ratio = 17 ---> 17 * 12 MHz = 204 MHz
control_register |= 6 << CGU_PLL1_CTRL_CLK_SEL_Pos; // Clock source = crystal oscillator
LPC_CGU->PLL1_CTRL = control_register;
while (!(LPC_CGU->PLL1_STAT & CGU_PLL1_STAT_LOCK_Msk));
// Set M4 clock to PLL1
LPC_CGU->BASE_M4_CLK = 9 << CGU_BASE_M4_CLK_CLK_SEL_Pos | // Clock source = PLL1
1 << CGU_BASE_M4_CLK_AUTOBLOCK_Pos; // Block clock automatically during frequency change
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment