# How to get/set CPU clock frequency for HiFive1 Rev. B?

**URL:** <https://forums.sifive.com/t/how-to-get-set-cpu-clock-frequency-for-hifive1-rev-b/2335>\
**Category:** HiFive1 Rev B\
**Created:** [May 16, 2019, 12:22pm UTC](https://forums.sifive.com/t/how-to-get-set-cpu-clock-frequency-for-hifive1-rev-b/2335 "2019-05-16T12:22:29Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![DanaK6JQ](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@DanaK6JQ](https://forums.sifive.com/u/DanaK6JQ)\
**Post date:** [December 21, 2019, 9:31pm UTC](https://forums.sifive.com/t/how-to-get-set-cpu-clock-frequency-for-hifive1-rev-b/2335/4 "2019-12-21T21:31:47Z")

</div>

@ckuehnel if you’re still looking for an example, I believe this might help - I’ll explain the testing I’ve done below 🙂

```
#include <metal/machine.h>

	long cpu_clock;

	cpu_clock = metal_clock_get_rate_hz(&__metal_dt_clock_4.clock);
    new_cpu_clock = metal_clock_set_rate_hz(&__metal_dt_clock_4.clock, 32000000L);

```

The magic there is “&\_\_metal\_dt\_clock\_4.clock”, have a look at bsp/install/include/metal/machine/inline.h for others

I’m pretty-sure this is correct, I tried it on a SparkFun Red-V which is purported to be effectively identical to a HiFive 1 Rev B. Because I have a first-run Red-V, it has a 100k resistor in series with PLLVDD, which means the enabling the PLL … kills it. SparkFun has already shipped a replacement, as well as some 100 ohm resistors so I can re-work my existing board.

To test this code, I did a set\_clock to 32MHz and that bricked the Red-V as expected, and I measured PLLVDD as something like 0.69V, as expected. To unbrick the Rev-V, I temporarily jumpered the 100k resistor and re-programmed the FE310 😉 So I’m certain that setting the PLL clock enables it, I just can’t confirm how accurate it is yet - replacement is due FedEx tomorrow.

It looks like that setting the PLL clock to anything withing 75% - 125% of the 16MHz input frequency results in the PLL being bypassed. It’s important to check the return from set\_clock() because you don’t always get what you asked for (but you might get what you need 😁 ) .

Cheers,  
Dana K6JQ

---

_[View the full topic](https://forums.sifive.com/t/how-to-get-set-cpu-clock-frequency-for-hifive1-rev-b/2335)._
