diff options
author | Rocco Marco Guglielmi <roccomarco.guglielmi@live.com> | 2017-08-07 21:41:07 +0000 |
---|---|---|
committer | Rocco Marco Guglielmi <roccomarco.guglielmi@live.com> | 2017-08-07 21:41:07 +0000 |
commit | 53ce03576217052144f2800d0d3634651ef0be01 (patch) | |
tree | 8559779a85d187f14393f8f042fe7f919488c795 /os/hal/ports/SAMA/SAMA5D2x/hal_lld.c | |
parent | e1a4894ab6e5161d9734c36daa411ac12efa1f50 (diff) | |
download | ChibiOS-53ce03576217052144f2800d0d3634651ef0be01.tar.gz ChibiOS-53ce03576217052144f2800d0d3634651ef0be01.tar.bz2 ChibiOS-53ce03576217052144f2800d0d3634651ef0be01.zip |
Complete clock tree initialization for ATSAMA5D2.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10363 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/ports/SAMA/SAMA5D2x/hal_lld.c')
-rw-r--r-- | os/hal/ports/SAMA/SAMA5D2x/hal_lld.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/os/hal/ports/SAMA/SAMA5D2x/hal_lld.c b/os/hal/ports/SAMA/SAMA5D2x/hal_lld.c index 70fcf11ce..114c7dc4a 100644 --- a/os/hal/ports/SAMA/SAMA5D2x/hal_lld.c +++ b/os/hal/ports/SAMA/SAMA5D2x/hal_lld.c @@ -88,16 +88,26 @@ void sama_clock_init(void) { ; /* Waits until MOSCRC is stable.*/
/* Switching Main Oscillator Source to MOSRC. */
- mor = PMC->CKGR_MOR;
+ mor = PMC->CKGR_MOR | CKGR_MOR_KEY_PASSWD;
mor &= ~CKGR_MOR_MOSCSEL;
- mor |= (SAMA_MOSC_MOSCRC | CKGR_MOR_KEY_PASSWD);
+ mor |= SAMA_MOSC_MOSCRC;
PMC->CKGR_MOR = mor;
+ while (!(PMC->PMC_SR & PMC_SR_MOSCSELS))
+ ; /* Waits until MOSCSEL has changed.*/
+
/* Switching Master Clock source to Main Clock. */
mckr = PMC->PMC_MCKR;
mckr &= ~PMC_MCKR_CSS_Msk;
mckr |= PMC_MCKR_CSS_MAIN_CLK;
PMC->PMC_MCKR = mckr;
+
+ while (!(PMC->PMC_SR & PMC_SR_MCKRDY))
+ ; /* Waits until Master Clock is stable.*/
+
+ /* Switching Main Frequency Source to MOSCRC. */
+ PMC->CKGR_MCFR &= ~CKGR_MCFR_CCSS;
+
}
/*
@@ -152,9 +162,13 @@ void sama_clock_init(void) { PMC->PMC_MCKR = mckr;
while (!(PMC->PMC_SR & PMC_SR_MCKRDY))
; /* Waits until MCK is stable. */
- mckr = SAMA_MCK_PRES | SAMA_MCK_MDIV | SAMA_MCK_SEL;
+
+ mckr &= ~(PMC_MCKR_PRES_Msk | PMC_MCKR_MDIV_Msk);
+ mckr |= (SAMA_MCK_PRES | SAMA_MCK_MDIV);
#if SAMA_PLLADIV2_EN
mckr |= PMC_MCKR_PLLADIV2;
+#else
+ mckr &= ~PMC_MCKR_PLLADIV2;
#endif
PMC->PMC_MCKR = mckr;
while (!(PMC->PMC_SR & PMC_SR_MCKRDY))
|