Skip to main content
NVoid.1
Associate
Mar 19, 2021 6:09 AM UTC
Solved

STM32CubeIDE code generate "LL_GPIO_SetOutputPin" in inappropriate code line

chip: F103VET6

IDE version: STM32CubeIDE v1.6.0 Build: 9614_20210223_1703 (UTC)

Firmware Package : STM32Cube FW_F1 V1.8.3​

Lib: low layer driver​

​

in GPIO Configuration:

​ �?GPIO output level �? generate code BEFORE GPIO_init, that makes LL_GPIO_SetOutputPin invalid.

---------------------------------------------------------------------------------------------------

void MX_GPIO_Init(void)

{

 LL_GPIO_InitTypeDef GPIO_InitStruct = {0};

 /* GPIO Ports Clock Enable */

 LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);

 LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);

 /**/

 LL_GPIO_SetOutputPin(GPIOB, LEDG_Pin|LEDB_Pin|LEDR_Pin);

 /**/

 GPIO_InitStruct.Pin = LEDG_Pin|LEDB_Pin|LEDR_Pin;

 GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;

 GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;

 GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;

 LL_GPIO_Init(GPIOB, &GPIO_InitStruct);

}​

​

This topic has been closed for replies.
Piranha
PiranhaBest answer
Principal III
Mar 19, 2021 7:38 AM UTC

No, that is not inappropriate and not a bug. The peripheral clocks are already enabled and LL_GPIO_SetOutputPin() is not related to LL_GPIO_Init(). It is done deliberately for the output value to be at the desired level immediately when LL_GPIO_Init() switches the pin to an output mode.

LL is not a high-level library and is basically renamed register level programming. The only thing it adds is another layer of (small) bloat and potential bugs, and doubles the amount of work, because one has to translate everything from LL to registers and back.

2 replies

Piranha
PiranhaBest answer
Principal III
Mar 19, 2021 7:38 AM UTC

No, that is not inappropriate and not a bug. The peripheral clocks are already enabled and LL_GPIO_SetOutputPin() is not related to LL_GPIO_Init(). It is done deliberately for the output value to be at the desired level immediately when LL_GPIO_Init() switches the pin to an output mode.

LL is not a high-level library and is basically renamed register level programming. The only thing it adds is another layer of (small) bloat and potential bugs, and doubles the amount of work, because one has to translate everything from LL to registers and back.

NVoid.1
NVoid.1Author
Associate
Mar 20, 2021 2:28 AM UTC

Thanks a lot for your explanation.