Skip to content

Commit

Permalink
Merge pull request #11249 from dylad/pr/saml1x_waitstate
Browse files Browse the repository at this point in the history
cpu/saml1x: set wait state according to datasheet
  • Loading branch information
emmanuelsearch authored Mar 24, 2019
2 parents 930dd0a + 82aa6c0 commit 1859d03
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions cpu/saml1x/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
#include "periph/init.h"
#include "board.h"

#ifdef CPU_FAM_SAML11
#define _NVMCTRL NVMCTRL_SEC
#else
#define _NVMCTRL NVMCTRL
#endif

static void _gclk_setup(int gclk, uint32_t reg)
{
GCLK->GENCTRL[gclk].reg = reg;
Expand All @@ -40,6 +46,7 @@ void cpu_init(void)
MCLK->APBAMASK.reg = MCLK_APBAMASK_MCLK
| MCLK_APBAMASK_OSCCTRL
| MCLK_APBAMASK_GCLK
| MCLK_APBAMASK_PM
#ifdef MODULE_PERIPH_GPIO_IRQ
| MCLK_APBAMASK_EIC
#endif
Expand All @@ -53,6 +60,13 @@ void cpu_init(void)
while (GCLK->CTRLA.reg & GCLK_CTRLA_SWRST) {}
while (GCLK->SYNCBUSY.reg & GCLK_SYNCBUSY_SWRST) {}

PM->PLCFG.reg = PM_PLCFG_PLSEL_PL2;
while (0 == PM->INTFLAG.bit.PLRDY) {}

MCLK->APBBMASK.reg |= MCLK_APBBMASK_NVMCTRL;
_NVMCTRL->CTRLB.reg |= NVMCTRL_CTRLB_RWS(1);
MCLK->APBBMASK.reg &= ~MCLK_APBBMASK_NVMCTRL;

/* set OSC16M to 16MHz */
OSCCTRL->OSC16MCTRL.bit.FSEL = 3;
OSCCTRL->OSC16MCTRL.bit.ONDEMAND = 0;
Expand All @@ -61,11 +75,6 @@ void cpu_init(void)
/* Setup GCLK generators */
_gclk_setup(0, GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSC16M);

#ifdef MODULE_PERIPH_PM
/* enable power managemet module */
MCLK->APBAMASK.reg |= MCLK_APBAMASK_PM;
#endif

/* trigger static peripheral initialization */
periph_init();
}

0 comments on commit 1859d03

Please sign in to comment.