# Clock generation and configuration

**URL:** <https://forums.sifive.com/t/clock-generation-and-configuration/2783>\
**Category:** HiFive1 Rev B\
**Created:** [August 22, 2019, 7:08pm UTC](https://forums.sifive.com/t/clock-generation-and-configuration/2783 "2019-08-22T19:08:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stef](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@stef](https://forums.sifive.com/u/stef)\
**Post date:** [August 22, 2019, 7:08pm UTC](https://forums.sifive.com/t/clock-generation-and-configuration/2783/1 "2019-08-22T19:08:24Z")

</div>

Hello all from a newbie!

I have a HiFive1 board with the FE310-G000 board on it. To program it, I am using `freedom-e-sdk` repo and especially the branch `v201905-branch` because I wanted something that is not changing so often (if you think that it would be better to use another branch you are free to comment on that).

I am trying to understand how I can control the clock settings from the metal API. In the [clock generation schematic](https://sifive.cdn.prismic.io/sifive%2F4d063bf8-3ae6-4db6-9843-ee9076ebadf7_fe310-g000.pdf#figure.caption.6) all the logic behind the clock generation is explained. As it stated in this manual, `The PLL is also disabled with pllbypass=1 after awakeup reset`. It is also stated that `The pllcfg register is reset to: bypass and power off the PLL pllbypass=1; input driven from external HFXOSC oscillator pllrefsel=1; PLL not driving system clock pllsel=0; and the PLL ratios are set to R=2, F=64, and Q=8 (pllr=01,pllf=011111,pllq=11)`. If I understand correctly, by default the HFXOSC drives the `hfclk` with a frequency of 16MHz and when I upload my program to the device the PLL is disabled (please comment if I am mistaken here).

I want to change this functionality and to enable the PLL so that my application runs faster. In the [freedom-metal developer guide](https://sifive.github.io/freedom-metal-docs/devguide/fe310-g000-pll.html) it is mentioned that a constructor is used to configure the PLL. More specifically, [here](https://github.com/sifive/freedom-e-sdk/blob/v201905-branch/bsp/sifive-hifive1/design.dts#L19) is shown that the CPU is driven by the `hfclk` which is described [here](https://github.com/sifive/freedom-e-sdk/blob/v201905-branch/bsp/sifive-hifive1/design.dts#L69) and it has  
`clock-frequency = <16000000>`. In this file, I can modify the frequencies of the clocks but it is not clear to me if I can modify the value of the `psdclkbypass`, `pllcfg`, `pllsel` registers. According to my understanding I cannot hardcode the frequency of this clock to something different and I should use all these registers. So,

1. How I can modify the values of all these registers through my program that is written in C? Is there an interface, or I need to write some assembly instructions.

Furthermore, I have checked the [API documentation](https://sifive.github.io/freedom-metal-docs/apiref/clock.html) and it seems that there are some functions that allow clock manipulation through software. However, in the end it is mentioned that `Note that no mechanism for obtaining a pointer to a struct metal_clock has been defined, making it impossible to call any of these functions without invoking implementation-defined behavior` which is not very clear to me.

1. How I can instantiate a pointer to a valid `struct metal_clock` which will be used as an argument to all these API calls?

Thanks and sorry for the long post,  
Stef
