cancel
Showing results for 
Search instead for 
Did you mean: 

Disabling GPIO Clocks for AF I/O Fails.

HermannKleier
Associate II
Posted on June 12, 2017 at 18:30

The data sheet for the STM32L476xx (DocID025976 Rev 4 states on page 124, footnote 2 of table 40) states:

� In order to save the full GPIOx current consumption, the GPIOx clock should be disabled in the RCC when all port I/Os are used in alternate function or analog mode (clock is only required to read or write into GPIO registers, and is not used in AF or analog modes).

Paying heed to this advice and trying not to waste power, I initialized the GPIO part of an SPI like:

LL_AHB2_GRP1_EnableClock (LL_AHB2_GRP1_PERIPH_GPIOA);

LL_GPIO_SetAFPin_0_7 (GPIOA, LL_GPIO_PIN_5, LL_GPIO_AF_5); // SCK

LL_GPIO_SetPinMode (GPIOA, LL_GPIO_PIN_5, LL_GPIO_MODE_ALTERNATE);

LL_GPIO_SetPinSpeed (GPIOA, LL_GPIO_PIN_5, LL_GPIO_SPEED_FREQ_VERY_HIGH);

LL_GPIO_SetAFPin_0_7 (GPIOA, LL_GPIO_PIN_6, LL_GPIO_AF_5); // MISO

LL_GPIO_SetPinMode (GPIOA, LL_GPIO_PIN_6, LL_GPIO_MODE_ALTERNATE);

LL_GPIO_SetPinSpeed (GPIOA, LL_GPIO_PIN_6, LL_GPIO_SPEED_FREQ_VERY_HIGH);

LL_GPIO_SetAFPin_0_7 (GPIOA, LL_GPIO_PIN_7, LL_GPIO_AF_5); // MOSI

LL_GPIO_SetPinMode (GPIOA, LL_GPIO_PIN_7, LL_GPIO_MODE_ALTERNATE);

LL_GPIO_SetPinSpeed (GPIOA, LL_GPIO_PIN_7, LL_GPIO_SPEED_FREQ_VERY_HIGH);

LL_AHB2_GRP1_DisableClock (LL_AHB2_GRP1_PERIPH_GPIOA);

Alas, when I invoke

LL_SPI_TransmitData8()

and

LL_SPI_ReceiveData8()

later, the device does not output any SCK signals. Therefore the SPI interface failed. When I remove the last line

LL_AHB2_GRP1_DisableClock (LL_AHB2_GRP1_PERIPH_GPIOA);

�,

everything works fine.

What�s wrong?

#gpioa-clock #alternate-function #stm32l4 #low-power
2 REPLIES 2
Posted on June 12, 2017 at 20:21

Please post a minimal but complete compilable example exhibiting the problem.

JW

Posted on June 12, 2017 at 23:09

I’ll do, but this’ll take some time. My initial question concerned SPI1, meanwhile I have observed the same behaviour for I2C1. Therefore, I’ll hang on.