AnsweredAssumed Answered

Disabling GPIO Clocks for AF I/O Fails.

Question asked by kleier.hermann on Jun 12, 2017
Latest reply on Jun 12, 2017 by kleier.hermann

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?

Outcomes