Clock generation and configuration


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 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 it is mentioned that a constructor is used to configure the PLL. More specifically, here is shown that the CPU is driven by the hfclk which is described here 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 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,

Something I learned about the CPU clock