Skip to main content
Willunen
Associate III
May 28, 2018
Question

STM32CubeMX for STM32F4 configures inputs as outputs

  • May 28, 2018
  • 3 replies
  • 2048 views
Posted on May 28, 2018 at 17:39

Inputs for (at least) Timers and U(s)arts are being configured as PushPull outputs. There is no option to change this, so it produces the code below.

I'm using a STM32F407VET and all the lastest STM32CubeMX software.

(and I know how to fix it, in my code, not STM32CubeMX :) )

0690X00000604YlQAI.jpg

GPIO_InitStruct.Pin = LL_GPIO_PIN_9|LL_GPIO_PIN_10;

GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;

GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_MEDIUM;

GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;

GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;

GPIO_InitStruct.Alternate = LL_GPIO_AF_7;

LL_GPIO_Init(GPIOA, &GPIO_InitStruct);0690X00000604bKQAQ.jpg

GPIO_InitStruct.Pin = LL_GPIO_PIN_7|LL_GPIO_PIN_9;

GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;

GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;

GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;

GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;

GPIO_InitStruct.Alternate = LL_GPIO_AF_1;

LL_GPIO_Init(GPIOE, &GPIO_InitStruct);
    This topic has been closed for replies.

    3 replies

    waclawek.jan
    Super User
    May 28, 2018
    Posted on May 28, 2018 at 18:25

    Inputs for (at least) Timers and U(s)arts are being configured as PushPull outputs. There is no option to change this,

    The direction for pins set as AF is given by the connected peripheral.

    The purpose of that setting is to set the items which are not governed by the peripheral, i.e. whether there are any pullups/pulldowns, and - if the peripheral turns it to output -  whether the pin is PP or OD, and what's its speed.

    You may want to read the GPIO chapter of the RM.

    JW

    Willunen
    WillunenAuthor
    Associate III
    May 28, 2018
    Posted on May 28, 2018 at 19:41

    So, no matter that it says that RX is configured as an output, it becomes an input because of the AF setting...

    Testing it at this moment, and it appears to be so.That is rather confusing!

    See here how it shows for a STM32F1 usart in STM32CubeMX.

    0690X00000604bPQAQ.jpg

    To me this makes more sense.

    But as I see at this moment for STM32F4 this:

    GPIO_InitStruct.Pin = LL_GPIO_PIN_9|LL_GPIO_PIN_10;

    GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;

    GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;

    GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;

    GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;

    GPIO_InitStruct.Alternate = LL_GPIO_AF_7;         //so this turns PA10 into an INPUT, weird...

    LL_GPIO_Init(GPIOA, &GPIO_InitStruct);