Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samd21: spi: fix power regression #5868

Merged
merged 1 commit into from
Sep 27, 2016
Merged

Conversation

immesys
Copy link
Contributor

@immesys immesys commented Sep 27, 2016

tl;dr commit 845ef0d introduced a power consumption regression by leaving the MISO pin floating

Despite this being a one line fix, this took us four days to find, so allow me to elaborate. @Hyungsin and I have been working on getting RIOT running at ~10uA average current for a duty cycling SAMR21 based mote, basically we have #2309 and #5608 along with a set of changes here and there. We got everything working, sampling temperature at 1Hz with ~10uA consumption and we patted ourselves on the back with a "lets quickly rebase and then submit patches upstream". We rebased, (it was just four days of commits) and one of those commits was merging #5743.

Nothing worked.

Ah well, we consoled ourselves, at least this means RIOT is active, this is a good problem to have. So we got everything to compile and redid the platform support only to find that our MCU-only power consumption had gone from 2.5uA in idle to over 70 uA. Somewhere in the more than 10k changed lines, there was a problem. We spent a few days inspecting all the clocking config (we thought there must be a new RUNSTDBY clock). We scoured the PM registers, nothing. Eventually I started bisecting the PR, and discovered that 845ef0d was to blame, but nothing seemed blatantly wrong. Eventually by reverting it line by line we discovered that the new code does not configure the pullup resistor on MISO. Adding that brought us back 👍

img_20160926_195730

Hallelujah:

img_20160926_195538

I guess to make this kind of thing easier to find in future we

a) might want to add power consumption tests of a physical device to the CI
b) might want to split large PR's into mostly-harmless refactor (updating the ASF and moving headers for example) and things that change implementation details, so that problems don't get buried in 10kloc batches.

Now that this is sorted out, I will get back to preparing a PR for low-power SAMR21 platforms.

The MISO pin cannot be left floating as it increases power consumption
@Hyungsin
Copy link

We are happy to move on to the next step :)

@jnohlgard
Copy link
Member

jnohlgard commented Sep 27, 2016 via email

@jnohlgard
Copy link
Member

My question is only to stimulate discussion and thought around power savings, I won't object to merging this PR. I don't want to hinder the progress on your project.

@immesys
Copy link
Contributor Author

immesys commented Sep 27, 2016

I don't think it is necessary to try and turn the pullup on/off. We don't do that with I2C where the pullup is normally strong (<5k) and here the pullup/down is nominally 40k so the current during the periods where SPI is active is negligible (80uA) compared to the current of having the processor active and doing SPI.

What would be a greater power savings is if we started doing I2C and SPI using DMA, so that we could turn the CPU off during those transfers. That is a problem for another day :p

edit: necessary is maybe the wrong word. It is probably the right thing to do, but not the most significant at the moment

@PeterKietzmann PeterKietzmann added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 27, 2016
Copy link
Member

@PeterKietzmann PeterKietzmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK for this PR. Tested SPI on a samr21-xpro. If there is need for further discussions it would be great if you could open an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants