Skip to content

Commit

Permalink
cpu/stm32_common: minimize consumption on STM32L1
Browse files Browse the repository at this point in the history
  • Loading branch information
olegart authored and fjmolinas committed May 6, 2019
1 parent 13706bf commit bc43e8c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cpu/stm32_common/cpu_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @author Víctor Ariño <victor.arino@zii.aero>
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Vincent Dupont <vincent@otakeys.com>
* @author Oleg Artamonov <oleg@unwds.com>
*
* @}
*/
Expand All @@ -49,6 +50,28 @@ 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)
uint32_t ahb_gpio_clocks;
GPIO_TypeDef *port;

/* enable GPIO clock and save GPIO clock configuration */
ahb_gpio_clocks = RCC->AHBENR & 0xFF;
periph_clk_en(AHB, 0xFF);

/* switch all GPIOs to AIN mode to minimize power consumption */
/* can't be more than 12 ports on STM32L1 */
for (int i = 0; i < 12; i++) {
port = (GPIO_TypeDef *)(GPIOA_BASE + i*(GPIOB_BASE - GPIOA_BASE));
if (IS_GPIO_ALL_INSTANCE(port))
port->MODER = 0xffffffff;
else
break;
}
/* restore GPIO clock */
periph_clk_en(AHB, ((RCC->AHBENR & ~((uint32_t)0xFF)) | ahb_gpio_clocks));
}
#endif
#ifdef MODULE_PERIPH_DMA
/* initialize DMA streams */
dma_init();
Expand Down

0 comments on commit bc43e8c

Please sign in to comment.