SiFive FE310-G002: Using WFI together with MTIMECMP


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.

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

I use SparkFun RED-V thing plus, 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?

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

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.

1 Like