Skip to content

need samd21 cpu/clock configuration options #7913

@photonthunder

Description

@photonthunder

I would like options to adjust clock configuration options that are found in cpu.c. I wanted to model what is done with other peripherals in periph_conf.h but the plethora of options makes it challenging. I used to mock ASF for using a big include file where you set the clock settings as necessary but I am now starting to think it might be the only option. Any suggestions on how to setup clock structures so that one could modify and use the different options without it being overwhelming to periph_conf.h?

Currently, the way I see it you would need a structures for the 2 base sources currently implemented in code (8 MHz internal, 32 kHz external - 32 kHz internal is always on), the structure for the 9 clock generators (only have to include the ones that were being used of course), then structures for DFLL and PLL. Something like this:

#define CLOCK_SRC                   (CLOCK_USE_PLL)
#define CLOCK_DIV                   (1)
#define CLOCK_CORECLOCK             (48000000U)
    
static const internal_8MHz_conf_t internal_8MHz_config = {
    .enable         = true,
    .prescaler      = 1,
    .ondemand       = false,
    .standby        = false,
};

static const external_32kHz_osc_conf_t external_32kHz_osc_config = {
    .enable         = true,
    .startup        = 6,
    .output_1kHz    = false,
    .output_32kHz   = true,
    .ondemand       = false,
    .standby        = false,
};

static const clock_gen_conf_t clock_gen_config[] = {
    {    /* GCLK Gen 0 */
        .enable     = true,
        .standby    = false,
        .prescaler  = 1,
        .output     = false,
        .clk_src    = CLOCK_USE_PLL,
    },
    {    /* GCLK Gen 1 */
        .enable     = true,
        .standby    = false,
        .prescaler  = 8,
        .output     = false,
        .clk_src    = CLOCK_USE_8MHZ,
    },
    {    /* GCLK Gen 2 */
        .enable     = false,
        .standby    = true,
        .prescaler  = 1,
        .output     = false,
        .clk_src    = CLOCK_USE_XOSC32,
    },
    {    /* GCLK Gen 3 */
        .enable     = true,
        .standby    = true,
        .prescaler  = 32,
        .output     = false,
        .clk_src    = CLOCK_USE_ULP32,
    },
};
    
static const pll_conf_t pll_config = {
    .enable         = true,
    .standby        = false,
    .ondemand       = false,
    .clock_multiply = (((CLOCK_CORECLOCK * CLOCK_DIV) / 1000000U) - 1)
    .gclock_src     = GCLK_CLKCTRL_GEN_GCLK1,
    .flags          = PLL_FLAGS_NONE
};
    
static const dfll_conf_t dfll_config = {
    .enable         = false,
    .standby        = false
    .ondemand       = false,
    .gclock_src     = GCLK_CLKCTRL_GEN_GCLK2,
    .flags          = DFLL_FLAGS_NONE
};

However, that is a lot to add to periph_conf.h, but it does give you cleaner control over standby and on demand which you will need if you are going to do any low power implementations.

Any thoughts or insight?

Metadata

Metadata

Labels

Platform: ARMPlatform: This PR/issue effects ARM-based platformsState: staleState: The issue / PR has no activity for >185 days

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions