Any PMU Sleep / Software Reset Example?

Is there any example code available which shows how to set a hifive1revb in sleep mode using the aon domain (pmu and wake-up cause rtc) and proper start-up code?

Thanks.

You can use these two functions (or re-implement them in your code) to sleep for a few seconds: https://github.com/riscv-rust/e310x-hal/blob/f8cded2f409b737802bd9a424fdbc052db7798e7/src/pmu.rs#L193-L222
Note that sleep/wake programs are different for FE310-G000 and FE310-G002.

Thank you very much.

After sleep (self.pmusleep.write(|w| w.sleep().set_bit()); or AON_REG(AON_PMUSLEEP) = 1;) the board should sleep and wake by reset, shouldn’t it? Any idea what’s wrong with this code? Does not go into sleep mode.

AON_REG(AON_PMUKEY) = AON_WDOGKEY_VALUE;
AON_REG(AON_PMUIE) = AON_WAKEUPCAUSE_RTC | AON_WAKEUPCAUSE_DWAKEUP;
AON_REG(AON_RTCCFG) |=  0x0000100f;
uint32_t now = AON_REG(AON_RTCS);
// some time
uint32_t then = now + 10;
AON_REG(AON_RTCCMP) = then;
// send to sleep
// unlook, ch. 14.3
AON_REG(AON_PMUKEY) = AON_WDOGKEY_VALUE;
// sleep, ch 14.5
AON_REG(AON_PMUSLEEP) = 1;

Have you configured a sleep “program” for your board? Other than that part, your code looks the same as the Rust code I posted.

Strange. The board seems to go into sleep when I run the code in the debugger but awakes without considering the timer - which I checked counts correctly - or button. And when awake runs into some deadbeef. Actually, it does not finds its way after awakening into my _start and main function. Could this be some issue with the bootloader? I don’t get it.

And though the board starts from the debugger, it does not run execute my flashed program after reset? Maybe this is the issue.

I crashed the bootloader. After restoring the bootloader, it works finally.