# SiFive FE310-G002: Using WFI together with MTIMECMP

**URL:** <https://forums.sifive.com/t/sifive-fe310-g002-using-wfi-together-with-mtimecmp/6365>\
**Category:** HiFive1 Rev B\
**Created:** [December 29, 2023, 3:24pm UTC](https://forums.sifive.com/t/sifive-fe310-g002-using-wfi-together-with-mtimecmp/6365 "2023-12-29T15:24:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vazhnov](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/vazhnov/32/1364_2.png) [@Vazhnov](https://forums.sifive.com/u/Vazhnov)\
**Post date:** [December 29, 2023, 3:24pm UTC](https://forums.sifive.com/t/sifive-fe310-g002-using-wfi-together-with-mtimecmp/6365/1 "2023-12-29T15:24:38Z")

</div>

Hi!

I’m trying to write a small program in Assembly to blink with LED(s) without a CPU loop, but using `WFI` (wait for interrupt), which should save some energy.

The code is here: [Blink-all-GPIO-timer\_asm](https://gitlab.com/vazhnov/native-blink_asm_sparkfun_red-v_thing_plus/-/tree/main/Blink-all-GPIO-timer_asm/src).

By some reason, it doesn’t work: after running, all GPIOs are always ON.

I use [SparkFun RED-V thing plus](https://www.sparkfun.com/products/15799), if it is important. I use PlatformIO for compiling and flashing.

Could you please help me to understand, why the program doesn’t work?  
Maybe it was bad idea to use `WFI` and `MTIMECMP`?

---

<div class="post-metadata">

**Author:** ![pds](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pds](https://forums.sifive.com/u/pds)\
**Post date:** [January 7, 2024, 2:46am UTC](https://forums.sifive.com/t/sifive-fe310-g002-using-wfi-together-with-mtimecmp/6365/2 "2024-01-07T02:46:49Z")

</div>

Not a bad idea at all @Vazhnov it should work.

What first initializes `t2` at line 94, first time through _Main\_loop_? Seems like unspecified, to me.

There is some discussion of `wfi` [here](https://stackoverflow.com/questions/63484173/what-is-intended-correct-way-to-handle-interrupts-and-use-the-wfi-risc-v-cpu-ins)

Also, it’s good you remembered to use `.balign 4` for each entry in the jump (vector) table, lines 30-54. You could equivalently prefix the table with `.option push` and then `.option norvc`, following the table with `.option pop`. That way you don’t have a whole bunch of `.balign`’s to repeat; you’d need only one of them before the _push_. Of course, it would make assembled code longer–extra credit for analogue forcing use of only compressed, 16-bit jump instruction forms, albeit with limited jump range.
