2017-06-12 09:30 AM
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()
andLL_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-power2017-06-12 11:21 AM
Please post a minimal but complete compilable example exhibiting the problem.
JW
2017-06-12 04:09 PM
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.