cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX for STM32F4 configures inputs as outputs

Willunen
Associate III
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);
3 REPLIES 3
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

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);
Posted on May 28, 2018 at 20:52

Ok. after some more testing I have convinced myself, you are correct. Alternate functions for STM32F4 work somewhat different than they do for STM32F1. But reading and re-reading the RM0090, page 269, table 35 did not make that clear to me. Thanks anyway, I learned something today.