joeycastillo / Sensor-Watch

A board replacement for the classic Casio F-91W wristwatch
Other
1.02k stars 210 forks source link

Work around various silicon errata #340

Closed theAlexes closed 3 months ago

theAlexes commented 6 months ago

Per the Microchip docs, one erratum may freeze the microcontroller (the SUPC/VREG operating in standby), another may cause increased power consumption from the TRNG not being properly disabled, and a third can hard-fault the chip if a standby occurs at the same time as a SysTick. This patch applies the recommended workarounds.

Also, we noticed that the sleep controller documentation specifies that you have to wait for the value to settle in the sleep mode register before actually WFI-ing, so we've modified the HAL to do that.

theAlexes commented 5 months ago

Thanks for catching these!

Could you add references to specific section/page/etc numbers in the manual? That would be useful just to double check that this is all good.

updated accordingly, and included a link to the errata in the GH description.

I'm also curious if you have an idea of whether the RUNSTDBY / STDBYPL0 will affect power usage, although if the docs suggest it we should presumably do it either way, especially given recent reports of freezing issues.

power consumption is something we're pretty fuzzy on, unfortunately.

matheusmoreira commented 4 months ago

I'm also curious if you have an idea of whether the RUNSTDBY / STDBYPL0 will affect power usage, although if the docs suggest it we should presumably do it either way, especially given recent reports of freezing issues.

power consumption is something we're pretty fuzzy on, unfortunately.

That seems to be case for us all. There are some power consumption figures in the sensor watch documentation but they were measured with a Power Profiler Kit II. Absent access to such a profiler, I don't believe any objective statements regarding the power cost of any proposed change can be made.

In any case, if the silicon errata tells us to do something, we should probably do it regardless of any impact on power consumption, right?

matheusmoreira commented 4 months ago

Am now running this code on the real hardware. No problems so far.

matheusmoreira commented 4 months ago

My Sensor Watch Lite board is apparently unable to enter sleep mode when running this code. Have you or anyone else experienced this sleep mode issue?

The most recent change in main to sleep mode functionality:

https://github.com/joeycastillo/Sensor-Watch/blob/af18673e1aa53091880d829a6fa4d7e23a6b4381/movement/movement.c#L529-L536

I suspect it could be somewhat related due to short circuiting behavior which is potentially unintended and might be a bug. This is what actually happens:

// first trip  | can sleep | cannot sleep | can sleep    | cannot sleep
// second trip | can sleep | never runs   | cannot sleep | never runs
//          && | can sleep | cannot sleep | cannot sleep | cannot sleep

I need further testing to determine what impact this has, if any. However it appears you authored this change so I was hoping you'd clarify.

matheusmoreira commented 4 months ago

This is the only patch set in my branch which touches sleep mode

I stand corrected. It seems to be working perfectly. I eventually isolated the issue to the deadline watch face, PR #266.

So far this has been tested on real hardware by both @theAlexes and myself. Seems stable.