Skip to content

Conversation

olegart
Copy link
Contributor

@olegart olegart commented Sep 26, 2018

Contribution description

Automatically configure all STM32L1 GPIOs as analog inputs.

GPIOs on STM32L1 MCUs are configured as digital inputs with Schmitt triggers, which means, if they are left floating, their power consumption is not 0 but few microamperes per GPIO due to random noise on high-impedance pin and constant random trigger switching.

To achieve minimum possible consumption, GPIOs must be reconfigured as analog inputs. It can be done automatically during MCU initialization.

Function needs cpu_check_address to check what GPIOs are available (it depends on MCU package and so can't be deduced from MCU model data available to RIOT).

Newer STM32 energy-efficient series (L0, L4) already have GPIO configured as AIN by default.

Testing procedure

STM32L1 power consumption without this patch in STOP+RTC mode and GPIOs left floating may be as high as 100 uA. With the patch, it should be < 2 uA.

Issues/PRs references

Depends on PR #10051

@PeterKietzmann PeterKietzmann added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: cpu Area: CPU/MCU ports Platform: ARM Platform: This PR/issue effects ARM-based platforms labels Sep 27, 2018
@PeterKietzmann
Copy link
Member

@MichelRottleuthner this is a good candidate for you to review, right :-)?

@PeterKietzmann
Copy link
Member

@olegart would you address the codacy issue please?

@olegart
Copy link
Contributor Author

olegart commented Sep 28, 2018

@olegart would you address the codacy issue please?

First one addressed, on the second issue (whether uint32_t is an unsigned int or a long unsigned int) Codacy is in disagreement with gcc-7.

@olegart olegart force-pushed the riot-stm32l1-gpios-state branch from 05bfeaf to 08398f3 Compare September 28, 2018 14:12
@@ -49,6 +49,20 @@ void cpu_init(void)
periph_clk_en(APB1, BIT_APB_PWREN);
/* initialize the system clock as configured in the periph_conf.h */
stmclk_init_sysclk();

#if defined(CPU_FAM_STM32L1)
Copy link
Member

Choose a reason for hiding this comment

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

This approach is valid for the whole stm32 family AFAIK

Copy link
Contributor Author

@olegart olegart Sep 28, 2018

Choose a reason for hiding this comment

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

It's valid, but not needed at least on L0 and L4 - they have GPIO configured as analog inputs by default (see default MODER value in the Reference Manual).

Not sure about F1 (not an energy-efficient series anyway), but probably newer F-series don't need it either.

@RIOT-OS RIOT-OS deleted a comment Sep 28, 2018
@olegart
Copy link
Contributor Author

olegart commented Sep 28, 2018

Added option (enabled by default) to preserve the state of JTAG pins - PA13, PA14, PA15, PB2 and PB3 configured as Alternate Function Mode.

Doesn't affect power consumption if those pins are left floated.

@RIOT-OS RIOT-OS deleted a comment Sep 28, 2018
@fjmolinas
Copy link
Contributor

Closing since ##11832 was merged.

@fjmolinas fjmolinas closed this Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports Platform: ARM Platform: This PR/issue effects ARM-based platforms 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.

4 participants