cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H747I-DISCO board simple programming question

imarz.1
Associate III

Hello,

I got the demo board: STM32H747I-DISCO.

 I am seeing something that does not seem right. All I am trying to do is to programmatically turn ON/OFF the four user LEDs.

 Here is code:

// Init LED IO ports

 GPIO_InitTypeDef myLed = {0};

 myLed.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;

 myLed.Mode = GPIO_MODE_OUTPUT_PP;

 myLed.Pull = GPIO_NOPULL;

 HAL_GPIO_Init(GPIOI, &myLed);

 HAL_Delay(1000);

// Turn OFF all LEDs

 HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15, GPIO_PIN_RESET);

// Result: Initially all LEDs turn ON, then LEDs 2(orange), and 4 (blue) turn OFF.

// Turn ON all LEDs

 HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15, GPIO_PIN_SET);

// Result: All LEDs are OFF

 Now, two questions:

1- Why the logic is reversed (GPIO_PIN_SET turns OFF LEDs while GPIO_PIN_RESET turns ON LEDs).

2- Why LEDs 2, and 4 don't stay ON. I looked at schematics, and it does not seem like any LED is tied to anything.

Thanks.

10 REPLIES 10
TDK
Guru

> Why the logic is reversed (GPIO_PIN_SET turns OFF LEDs while GPIO_PIN_RESET turns ON LEDs).

LEDs on this board are active low. This is a common configuration as it's often easier/cheaper to sink current than to source it, although the STM32 with happily do either.

0693W00000KdZquQAF.png 

> Why LEDs 2, and 4 don't stay ON. I looked at schematics, and it does not seem like any LED is tied to anything.

Presumably some other code in your program is causing this. Perhaps you are returning from main, or something else. Pins don't change state for no reason, you could debug the program, pause, and inspect registers to determine why they're no longer being driven.

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

>>Why the logic is reversed (GPIO_PIN_SET turns OFF LEDs while GPIO_PIN_RESET turns ON LEDs).

Its about the direction the current flows.. see pointy end of diode

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hello @imarz.1​,

Try this configuration: myLed.Pull = GPIO_PULLUP; instead of myLed.Pull = GPIO_NOPULL;

Please let me know if this solved your problem.

BeST Regards,

Walid

imarz.1
Associate III

Ok, thanks folks

Yes, it is reverse logic(active low). Will just have to live with it.

And yes, because it is active low I changed it to: myLed.Pull = GPIO_PULLUP; 

TDK
Guru

> And yes, because it is active low I changed it to: myLed.Pull = GPIO_PULLUP; 

You can certainly keep the pullup, but it's not doing anything here other than waste current when the pin is low. Adding internal pull resistors to push-pull outputs is silly.

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

Without pullup it might be floating.

How do you set a pin to a predefined state without either pullup/pulldown?

By setting it as a digital push-pull output, it is either being driven high or low. There is no ambiguity or floating state.
An external pull-up might be helpful as it will take effect before the pin is configured. But an internal one does not make sense here.
If you feel a post has answered your question, please click "Accept as Solution".

Thanks.

MM..1
Chief II

If your code is realy

 HAL_GPIO_Init(GPIOI, &myLed);
 HAL_Delay(1000);
 
// Turn OFF all LEDs
 HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15, GPIO_PIN_RESET);
// Result: Initially all LEDs turn ON, then LEDs 2(orange), and 4 (blue) turn OFF.
 
// Turn ON all LEDs
 HAL_GPIO_WritePin(GPIOI, GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15, GPIO_PIN_SET);
// Result: All LEDs are OFF

Then you see 1 second all leds because default pin state is reset and after one second all is off.