Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
6ae8c428
Commit
6ae8c428
authored
9 years ago
by
Hauke Petersen
Browse files
Options
Downloads
Patches
Plain Diff
cpu/sam3: added clock initialization code
parent
079dd829
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cpu/sam3/cpu.c
+61
-1
61 additions, 1 deletion
cpu/sam3/cpu.c
with
61 additions
and
1 deletion
cpu/sam3/cpu.c
+
61
−
1
View file @
6ae8c428
/*
/*
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2014
-2016
Freie Universität Berlin
*
*
* This file is subject to the terms and conditions of the GNU Lesser
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* General Public License v2.1. See the file LICENSE in the top level
...
@@ -18,6 +18,25 @@
...
@@ -18,6 +18,25 @@
*/
*/
#include
"cpu.h"
#include
"cpu.h"
#include
"periph_conf.h"
/**
* @brief Keys needed for editing certain PMC registers
* @{
*/
#define WPKEY (0x504D43)
#define MORKEY (0x37)
/** @} */
/**
* @brief Start-up time for external crystal (will be multiplied by 8)
*/
#define XTAL_STARTUP (8U)
/**
* @brief PLL is incremented to this value until considered stable
*/
#define PLL_CNT (64U)
/**
/**
* @brief Initialize the CPU, set IRQ priorities
* @brief Initialize the CPU, set IRQ priorities
...
@@ -28,4 +47,45 @@ void cpu_init(void)
...
@@ -28,4 +47,45 @@ void cpu_init(void)
WDT
->
WDT_MR
|=
WDT_MR_WDDIS
;
WDT
->
WDT_MR
|=
WDT_MR_WDDIS
;
/* initialize the Cortex-M core */
/* initialize the Cortex-M core */
cortexm_init
();
cortexm_init
();
/* setup the flash wait states */
EFC0
->
EEFC_FMR
=
EEFC_FMR_FWS
(
CLOCK_FWS
);
EFC1
->
EEFC_FMR
=
EEFC_FMR_FWS
(
CLOCK_FWS
);
/* unlock write protect register for PMC module */
PMC
->
PMC_WPMR
=
PMC_WPMR_WPKEY
(
WPKEY
);
/* activate the external crystal */
PMC
->
CKGR_MOR
=
(
CKGR_MOR_KEY
(
MORKEY
)
|
CKGR_MOR_MOSCXTST
(
XTAL_STARTUP
)
|
CKGR_MOR_MOSCXTEN
|
CKGR_MOR_MOSCRCEN
);
/* wait for crystal to be stable */
while
(
!
(
PMC
->
PMC_SR
&
PMC_SR_MOSCXTS
));
/* select crystal to clock the main clock */
PMC
->
CKGR_MOR
=
(
CKGR_MOR_KEY
(
MORKEY
)
|
CKGR_MOR_MOSCXTST
(
XTAL_STARTUP
)
|
CKGR_MOR_MOSCXTEN
|
CKGR_MOR_MOSCRCEN
|
CKGR_MOR_MOSCSEL
);
/* wait for main oscillator selection to be complete */
while
(
!
(
PMC
->
PMC_SR
&
PMC_SR_MOSCSELS
));
/* setup PLLA */
PMC
->
CKGR_PLLAR
=
(
CKGR_PLLAR_ONE
|
CKGR_PLLAR_PLLACOUNT
(
PLL_CNT
)
|
CKGR_PLLAR_MULA
(
CLOCK_PLL_MUL
)
|
CKGR_PLLAR_DIVA
(
CLOCK_PLL_DIV
));
/* wait for PLL to lock */
while
(
!
(
PMC
->
PMC_SR
&
PMC_SR_LOCKA
));
/* before switching to PLLA, we need to switch to main clock */
PMC
->
PMC_MCKR
=
PMC_MCKR_CSS_MAIN_CLK
;
while
(
!
(
PMC
->
PMC_SR
&
PMC_SR_MCKRDY
));
/* use PLLA as main clock source */
PMC
->
PMC_MCKR
=
PMC_MCKR_CSS_PLLA_CLK
;
/* wait for master clock to be ready */
while
(
!
(
PMC
->
PMC_SR
&
PMC_SR_MCKRDY
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment