cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429BIT6 PB6 & 7 as GPIO.

ALooi.1
Associate II

I tried configuring PB6 and 7 as GPIO but PB7 always stuck at H and PB6 always L.

Here are my codes for PB7. I read in other forum they face similar issues when configuring these pins as I2C, and the issue is with the sequence of initialization. Please advise.

//green LED

#define LED_GREEN_PIN       GPIO_PIN_7

#define LED_GREEN_PORT       GPIOB

#define LED_GREEN_GPIO_MODE   GPIO_MODE_INPUT

#define LED_GREEN_GPIO_PULL    GPIO_PULLDOWN

#define LED_GREEN_GPIO_SPEED    GPIO_SPEED_FAST

#define LED_GREEN_CLK_ENABLE()   __HAL_RCC_GPIOB_CLK_ENABLE()

GPIO_Init_Structure.Pin                                             =            LED_GREEN_PIN;

GPIO_Init_Structure.Pull                                             =            GPIO_NOPULL;

GPIO_Init_Structure.Speed                                        =            GPIO_SPEED_HIGH;

GPIO_Init_Structure.Mode                                        =            GPIO_MODE_OUTPUT_PP;

LED_GREEN_CLK_ENABLE();

HAL_GPIO_Init(LED_GREEN_PORT, &GPIO_Init_Structure);

HAL_GPIO_WritePin(LED_GREEN_PORT,LED_GREEN_PIN, GPIO_PIN_RESET);

9 REPLIES 9
TDK
Guru

Custom board?

The code you wrote will initialize PB7 as output and try to set the output level to low. If the pin is directly tied to VDD, the pin state will still read as high. This is one possibility.

> #define LED_GREEN_GPIO_MODE  GPIO_MODE_INPUT

You're not using this in the code you wrote, but this should be GPIO_MODE_OUTPUT if you want the pin to be an output.

The bug could be in the code you're not showing us. How are you verifying the pin is low or high? Did you probe the pin itself?

If you feel a post has answered your question, please click "Accept as Solution".
S.Ma
Principal

just go in debug mode, put breakpoint at the end, then view the gpio registerd and write manually to try to control them. you should find the bug faster than the forum

ALooi.1
Associate II

Thanks for your replies.

The code does work. When I change "#define LED_GREEN_PIN       GPIO_PIN_7" to "#define LED_GREEN_PIN       GPIO_PIN_10", I am able to toggle PB10.

Similarly for Port G pin 6 and 7, They works. just that Port B pin 6 and 7 can't.

The code was inherited from ST's EVK.

I will ask my software colleague to post more details, but I am wondering if the sequence of code matters, as indicated in another thread that the sequence does matter. Or there was a known bug related to this in ST EVK code.

Thanks.

TDK
Guru

I would guess a hardware error. Make sure those pins aren't tied to a rail or other components and can be toggled freely.

If you feel a post has answered your question, please click "Accept as Solution".
ALooi.1
Associate II

Thanks for your reply. These pins are floating. They are only connected to a test point.

Do what . said above - read out and check/manipulate the GPIO registers content.

JW

Hi, with this reply say pin are floating scene is complete.

Is GPIOB clock enabled? Don't see on your code. (sorry is done in the middle) Move to top.

No clock to peripheral you can do extended initialization but no clock equal no register, no peripheral.

Regards

Yes. the GPIO clock is enabled.

Uhm, after reading back again from top, code has some strange define as noted from community.

About "Floating pin" are pin not connected or floating in sense open HiZ?

As suggested try single step checking GPIO Register, try move clock initiation to topo of code, leave some clock cycle before to use.

Regards