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

drivers/sx127x: optimize power consumption on nss pin #11384

Closed

Conversation

aabadie
Copy link
Contributor

@aabadie aabadie commented Apr 12, 2019

Contribution description

With this PR the power consumption drops from 6mA to 40uA when a stm32l0 CPU is sleeping.
I'm not sure it's the best fix and perhaps there's still for improving power consumption.

cc @fjmolinas who might be interested.

Testing procedure

Issues/PRs references

Required by #11237

This drops the power consumption from 6mA to 40uA when a stm32l0 CPU is sleeping
@aabadie aabadie 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 Area: pm Area: (Low) power management Area: LoRa Area: LoRa radio support labels Apr 12, 2019
@fjmolinas
Copy link
Contributor

@aabadie I think handling the NSS pin should be done but this doesn't seem to me like the right way to do so.

The SPI interface is active LOW. With this PR the device would always think it is active since after read or write actions to a register your are setting the pin as input with a pull down. This could interfere with other SPI devices on the same line.

I think the correct way would be using spi_init_cs() and passing the cs_pin when calling spi_acquire(). The NSS mode should be OUT_PP with a pull-up resistor. I thinks that should work for minimizing current consumption for the NSS pin.

@fjmolinas fjmolinas self-requested a review April 16, 2019 14:56
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

@aabadie I looked into this again... I came to the conclusion the reason we were seeing the excessive power consumption was because of the X-NUCLEO-LPM01A. I connected a multi-meter directly between the NSS_PIN and the board and I get 0uA of current draw (same for all I/O pins going to sx1276).

Doing some further measurements I can Identify sources of excessive current draw threw MISO, MOSI and SCK. NSS isn't a problem since it's inactive state is by default HIGH.

To minimize the current draw on MOSI and SCK they must be pulled low before going to sleep. From measurements after releasing the SPI device there state isn't 0 but close to 0. Two options for handling this:

  • initiate them with pull-downs
    gpio_init(spi_config[bus].mosi_pin, GPIO_OUT_PD);
    gpio_init(spi_config[bus].sclk_pin, GPIO_OUT_PD);
  • clear the gpio's before entering sleep
    gpio_init(spi_config[bus].mosi_pin, GPIO_OUT); 
    gpio_clear(spi_config[bus].mosi_pin);
    gpio_init(spi_config[bus].sclk_pin, GPIO_OUT);
    gpio_clear(spi_config[bus].sclk_pin,);

I think option 2 is better since it can be handled by the driver. This has to be done since according to reference manual (at least for stm32) "If software configures a GPIO pin as Alternate Function Output, but peripheral is not activated, its output is not specified".

In the case of MISO the SPI device should be initialized with the corresponding pull-up (in this case since it would be the inactive state).

gpio_init(spi_config[bus].miso_pin, GPIO_IN_PU);

I tested this using a nucleo-l1073rz and an mbed sx1272 sheild runing examples/lorawan. When in sleep the shield consumes 8uA and the node around 2uA.

DIOs are tied to VDD upon initialization and RESET is already in proper inactive state by default.

@aabadie
Copy link
Contributor Author

aabadie commented May 21, 2019

Closing in favor of #11542

@aabadie aabadie closed this May 21, 2019
@aabadie aabadie deleted the pr/drivers/sx127x_consumption branch August 6, 2019 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers Area: LoRa Area: LoRa radio support Area: pm Area: (Low) power management 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.

2 participants