cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX v4.24.0 - STM32F1 GPIO LL - LED blinking fails

Posted on January 22, 2018 at 23:26

Hi,

Excited by the LL support added to the F1 line I generated simple project for STM32F103C8 board where the PC13 is connected to a LED: HSE enabled, PC13 Push-Pull output.

Generated GPIO initialization code seems to be fine:

static void MX_GPIO_Init(void)

{

  LL_GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */

  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC);

  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOD);

  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);

  /**/

  LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);

  /**/

  GPIO_InitStruct.Pin = LED_Pin;

  GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;

  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;

  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;

  LL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);

}

Added the blinking part:

/* USER CODE BEGIN WHILE */

  while (1)

  {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

        

        LL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);

    LL_mDelay(1000);

  }

  /* USER CODE END 3 */

But unfortunately the LED is not blinking.

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

Entered Keil debuger, GPIOC and noticed that MODE13=0, so entered manually value 1 (MODE13=1) and the LED started blinking.

It seems that the LL GPIO driver is somewhat broken because the MODE is wrongly set.

The whole project is attached.

1 ACCEPTED SOLUTION

Accepted Solutions
Imen.D
ST Employee
Posted on February 19, 2018 at 12:04

Hello,

This issue is confirmed for LL Gpio pins greater than 8 initialization with LL-Init() function and this will be fixed in the next release.

We propose thisfix for ll_gpio driver with LL_GPIO_Init function:

ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
{
 uint32_t pinmask = 0x00000000U;
 uint32_t pinpos = 0x00000000U;
 uint32_t currentpin = 0x00000000U;
 
 /* Check the parameters */
 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
 assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
 assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
 assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
 
 /* ------------------------- Configure the port pins ---------------- */
 /* Initialize pinpos on first pin set */
 
 pinmask = (GPIO_InitStruct->Pin & 0x00FFFF00U) >> 8 ;
 pinpos = POSITION_VAL(pinmask);
/* Configure the port pins */
 while ((pinmask >> pinpos) != 0U)
 {
 /* skip if bit is not set */
 if ((pinmask & (1U << pinpos)) == 0U)
 {
 pinpos++;
 }
/* Get current io position */
 if(pinpos <8 )
 {
 currentpin = (0x00000101U << pinpos);
 }
 else
 {
 currentpin = ((0x00010001U << (pinpos-8)) | 0x04000000U);
 }
 
 if (currentpin)
 {
 /* Pin Mode configuration */
 LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
 
 /* Pull-up Pull down resistor configuration*/
 LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
 
 if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
 {
 /* Check Output mode parameters */
 assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
/* Output mode configuration*/
 LL_GPIO_SetPinOutputType(GPIOx, currentpin, GPIO_InitStruct->OutputType);
/* Speed mode configuration */
 LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
 }
}
 pinpos++;
 }
 return (SUCCESS);
}

Hope this is helpful for you.

Kind Regards,

Imen.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

View solution in original post

14 REPLIES 14
Posted on January 24, 2018 at 07:27

DAHMEN.IMEN

How to reproduce:

If you want to make PC13 and PC15 outputs:

GPIO_InitStruct.Pin = LED_Pin|LL_GPIO_PIN_15;

GPIO_InitStruct.Mode =

LL_GPIO_MODE_OUTPUT;

GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;

GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;

LL_GPIO_Init(GPIOC, &GPIO_InitStruct);

You can see that CRL is configured by the LL:

0690X00000609M3QAI.png

instead of CRH:

0690X00000609TLQAY.png

so when you try to fix it you use:

GPIOC->CRH = 0x24244444;

Can you consider it a bug?

Posted on February 01, 2018 at 11:08

I wonder if this issue was confirmed by the ST?

Posted on February 01, 2018 at 14:53

Hello

Golab.Bogdan

,

There is an

interesting note

described in the datasheet, please check this:

'

PC13, PC14 and PC15 are supplied through the power switch. Since the switch only sinks a limited amount of current (3 mA), the use of GPIOs PC13 to PC15 in output mode is limited: the speed should not exceed 2 MHz with a maximum load of 30 pF and these IOs must not be used as a current source (e.g. to drive an LED).

'

Best Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on February 01, 2018 at 15:14

This issue is not about LED blinking - it's about wrong pin setup...

Posted on February 01, 2018 at 15:25

Checked the schematic:

I=(3.3V-1.6V)/510ohm ~ 3.3mA so I am sure it won't break the MCU.

Anyway, I was complaining about wrong port setup (I guess for pins 8-15) of the port GPIOC. But i believe it also applies to other GPIOX.

Instead of setting up pins 8-15, the pins 0-7 are configured.

Posted on February 02, 2018 at 02:57

https://community.st.com/0D50X00009XkhPcSAJ

.

I'm afraid it hit me too, withF4 variant. What a nuisance.

-- pa

Posted on February 02, 2018 at 07:22

HAL works fine - output is alive

LL is affected and requires a fix  - in this case (PC13): GPIOC->CRH = 0x24244444;

That's why I think it's a bug AND lack of consistency (HAL vs LL).

If they do not to configure a pin as an output they shall not add the following lines in the generated code:

&sharpdefine LED_Pin LL_GPIO_PIN_13

LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);

But the did, what is against the intention of prohibiting the PC13 as an output AND it is not consistent with HAL where all works fine.

Posted on February 02, 2018 at 07:33

Yes, the link yo are pointing is exactly the same as I observed. Nice catch - I have not found it myself.

Simon Brouwer
Associate II
Posted on February 02, 2018 at 16:02

See

https://community.st.com/0D50X00009XkhPcSAJ