lupyuen / pinetime-rust-mynewt

PineTime Smart Watch firmware based on Rust and Apache Mynewt OS
https://lupyuen.github.io/articles/sneak-peek-of-pinetime-smart-watch-and-why-its-perfect-for-teaching-iot
Apache License 2.0
210 stars 54 forks source link

Higher consumption on nRF52832 when boot from mcuboot #36

Open vbelloir opened 3 years ago

vbelloir commented 3 years ago

Hi @lupyuen, I'm working with @JF002 on power consumption of Pinetime watch, using Infinitime from JF.

I noticed that consumption is higher when Infinitime is booted by mcuboot than when it is stand-alone. Difference is about 500µA.

As a example, I disabled watchdog in bootloader, and add a simple __WFE loop in main function of Infinitime. Booting from mcuboot gives a consumption of 574µA, while booting in stand-alone configuration gives 170µA.

Resources may be used in mcuboot/mynewt and not de-initialized in mcuboot, nor in Infinitime.

Do you have any idea for me? How can I identify which resource is consuming power?

Thanks for your help. Vincent

lupyuen commented 3 years ago

Is it possible that the SPI Flash is consuming the extra power?

Remember that MCUBoot starts the SPI Flash Driver to render the boot logo to the display.

Might be good to power off SPI Flash after rendering the boot logo.

vbelloir commented 3 years ago

I don't really. I can make a try.

I was also asking myself if semihosting in mynewt, or serial log in mcuboot were or not activated.

I will see if I managed to deinit SPI flash, and keep you in touch.

lupyuen commented 3 years ago

Yep thanks 🙂

vbelloir commented 3 years ago

Hi @lupyuen, I didn't try yet to deinit SPI Flash (and DMA!) before boot.

I opened same issue in mcuboot repo : https://github.com/mcu-tools/mcuboot/issues/958

But I don't really know how to implement answers I was given. (And last few weeks, I had some difficulties to get time for that)

vbelloir commented 3 years ago

DO you know how I can change mcuboot to point on nrfconnect fork?

lupyuen commented 3 years ago

Sorry not sure about that. Could you post the question to the Mynewt or MCUBoot community on Slack?

https://mynewt.apache.org/community/

vbelloir commented 3 years ago

That's ok, I found how to do that: So, in my mynewt project.yml file, I changed:

repository.mcuboot:
    type: github
    vers: 0-dev
    user: JuulLabs-OSS
    repo: mcuboot
With
repository.mcuboot:
    type: github
    vers: 0-dev
    user: mcu-tools
    repo: mcuboot

And perform a newt upgrade

$ newt upgrade
WARNING: Repo's "origin" remote points to unexpected URL: https://github.com/mcu-tools/mcuboot.git; correcting it to https://github.com/nrfconnect/sdk-mcuboot.git.  Repo contents may be incorrect.
Skipping "apache-mynewt-core": already upgraded (0.0.1)
Skipping "apache-mynewt-mcumgr": already upgraded (0.0.0)
Skipping "apache-mynewt-nimble": already upgraded (0.0.0)
Making the following changes to the project:
    upgrade mcuboot (579b30c29999860f9f7d843a25ff5453b6542cce --> 0.0.0)
mcuboot successfully upgraded to version 0.0.0

Now, I good error during compilation.

Compiling repos/mcuboot/boot/bootutil/src/tlv.c
Error: repos/mcuboot/boot/bootutil/src/loader.c: In function 'boot_validated_swap_type':
repos/mcuboot/boot/bootutil/src/loader.c:731:10: error: variable 'upgrade_valid' set but not used [-Werror=unused-but-set-variable]
  731 |     bool upgrade_valid = false;
      |          ^~~~~~~~~~~~~
cc1: all warnings being treated as errors

EDIT : manage to build project, deleting this variable. Quite ugly, but it works.

vbelloir commented 3 years ago

I tried to to back port this commit : https://github.com/nrfconnect/sdk-mcuboot/commit/18a0a8a5f5bdbaf74b192f08f9ef4b49a68c4af1

And especially the function nrf_cleanup_peripheral.

I put this back port at startup of Infinitime , in main function.

You can find my work in this commit : https://github.com/vbelloir/InfiniTime/commit/f486e4f944f775ef025381fbe1372c78944c11bb

Do you think that I should do this in bootloader instead?
I try to deactivate spi with nrf_drv_spi_uninit but compilation failes. Can you help?

Thanks.

lupyuen commented 3 years ago

Sorry I'm tied up with LoRa on BL602, I won't be able to help right now.

I hope you're updating the new repo for PineTime Bootloader?

https://github.com/JF002/pinetime-mcuboot-bootloader

nanch commented 3 years ago

A savings of 500µA for managing the SPI flash sounds like a great win!

@vbelloir How are you measuring the current draw? I'd like to investigate this further.

Also, what's the compile error you're getting when you deactivate spi with nrf_drv_spi_uninit?

vbelloir commented 3 years ago

Hi @nanch , right now, I only measure current draw with a 6.5digit multimeter Agilent 2000.
Letter, if possible, I can measure it with a Power Analyser Keysight N6705B, but it is not needed right now.

I don't really remember the compile error I had.
As you can see in my previous message, I don't modify bootloader (@lupyuen yes, I'm using JF002 fork of bootloader :+1: ), but I try to modify Infinitime startup, to get same consumption as when it is standalone.

vbelloir commented 3 years ago

hi @nanch, if you think you can help, it would be great. I got few time, and not very skilled in firmware. I'm an hardware guy.