Skip to main content
Visitor II
December 17, 2024
Solved

Help to use PA15 as GPIO Output on NUCLEO-L476RG

  • December 17, 2024
  • 4 replies
  • 1446 views

Hi,

 I am a newbie with STM32. I need help.

I want to configure that PA15 pin (which by default is used as JTDI), as a GPIO output.

I've added the following two lines to the beginning of the generated code of MX_GPIO_Init():

LL_GPIO_SetAFPin_8_15(GPIOA,LL_GPIO_PIN_15,LL_GPIO_AF_5);

LL_GPIO_SetPinMode(GPIOA,LL_GPIO_PIN_15,LL_GPIO_MODE_OUTPUT);

But it does not work. I connected a LED and tried to change the state of the pin high and low,

but it did not work.

I appreciate if someone help me to figure out what I am missing.

Thanks

    This topic has been closed for replies.
    Best answer by Karl Yamashita

    @DZado.2 wrote:

    I did two changes:

    1) I removed the lines (as gbm proposed):

    //LL_GPIO_SetAFPin_8_15(GPIOA,LL_GPIO_PIN_15,LL_GPIO_AF_5);

    //LL_GPIO_SetPinMode(GPIOA,LL_GPIO_PIN_15,LL_GPIO_MODE_OUTPUT);

    1) And I added 

    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);

    in addition to

    __HAL_RCC_GPIOA_CLK_ENABLE();

     

    Now it is working. I have no clue why.

    If I remove LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA), it does not work.

    Would you please explain why?

     

     


    I'm not sure? The LL and HAL are setting the same register/bit, though the LL is static inline

    Look at the disassembly to see what each is doing.


    // HAL
    #define __HAL_RCC_GPIOA_CLK_ENABLE() do { \
     __IO uint32_t tmpreg; \
     SET_BIT(RCC->AHB2ENR, RCC_AHB2ENR_GPIOAEN); \
     /* Delay after an RCC peripheral clock enabling */ \
     tmpreg = READ_BIT(RCC->AHB2ENR, RCC_AHB2ENR_GPIOAEN); \
     UNUSED(tmpreg); \
     } while(0)
    
    
    
    
    
    // LL
    #define LL_AHB2_GRP1_PERIPH_GPIOA RCC_AHB2ENR_GPIOAEN
    
    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
    
    __STATIC_INLINE void LL_AHB2_GRP1_EnableClock(uint32_t Periphs)
    {
     __IO uint32_t tmpreg;
     SET_BIT(RCC->AHB2ENR, Periphs);
     /* Delay after an RCC peripheral clock enabling */
     tmpreg = READ_BIT(RCC->AHB2ENR, Periphs);
     (void)tmpreg;
    }

     

    4 replies

    Graduate
    December 17, 2024

    Is the GPIOA enabled in RCC? Setting AF is not needed, it's enough to set the output mode. You may do the same via CubeMX.

    DZado.2Author
    Visitor II
    December 17, 2024

    I did enable RCC by this API: __HAL_RCC_GPIOA_CLK_ENABLE();

    It does the job. Doesn't it?

    Graduate II
    December 17, 2024

    Yes, either way should set the bit.

    Which L4 are you using?

    Are you using a Nucleo board or a custom board?

    Graduate II
    December 17, 2024

    You haven't indicated if you enable the GPIO clock?

     

    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);

     

    KarlYamashita_0-1734466006067.png

     

    DZado.2Author
    Visitor II
    December 17, 2024

    Thanks for your reply.

    I did by the HAL function: __HAL_RCC_GPIOA_CLK_ENABLE();

    I am not sure if I can mix up the LL and the HAL functions together :)

    Graduate II
    December 17, 2024

    It seems you've added code manually. So have any peripherals been enabled that could be using that same pin? 

    DZado.2Author
    Visitor II
    December 26, 2024

    Thanks a lot Karl and gbm.

    You solved my issue.

    Happy new year