Skip to main content
Bogdan Golab
Lead
January 22, 2018
Solved

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

  • January 22, 2018
  • 14 replies
  • 2851 views
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.

    This topic has been closed for replies.
    Best answer by Imen.D
    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.

    14 replies

    Bogdan Golab
    Lead
    January 24, 2018
    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?

    Bogdan Golab
    Lead
    February 1, 2018
    Posted on February 01, 2018 at 11:08

    I wonder if this issue was confirmed by the ST?

    ST Technical Moderator
    February 1, 2018
    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

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
    Bogdan Golab
    Lead
    February 1, 2018
    Posted on February 01, 2018 at 15:14

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

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

    See

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

    ST Technical Moderator
    February 6, 2018
    Posted on February 06, 2018 at 10:28

    Hello

    Golab.Bogdan

    ,

    simon.010

    ,

    We will take in charge to check and raise this issue internally to the appropriate team.

    Thank you for highlighting this issue.

    Best Regards,

    Imen.

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
    Imen.DBest answer
    ST Technical Moderator
    February 19, 2018
    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.

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
    Bogdan Golab
    Lead
    March 16, 2018
    Posted on March 16, 2018 at 19:20

    Just tested a STM32VLDIscovery board and the issue still exists in CubeMX 4.25.0 with the v1.6.0 HAL/LL drivers.

    Bogdan Golab
    Lead
    March 19, 2018
    Posted on March 19, 2018 at 17:07

    Just tested STM32CubeF1 Firmware patch Package V1.6.1 - GPIO works fine.

    ST Technical Moderator
    March 22, 2018
    Posted on March 22, 2018 at 09:52

    Hello,

    We would inform you that the new patch of STM32CubeF1 Firmware package V1.6.1 is released to fix this issue.

    Best Regards

    Imen

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks