2022-03-22 08:01 AM
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.
2022-03-22 08:40 AM
> 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.
> 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.
2022-03-22 08:52 AM
>>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
2022-03-22 09:07 AM
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
2022-03-22 09:56 AM
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;
2022-03-22 10:16 AM
> 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.
2022-03-22 11:02 AM
Without pullup it might be floating.
How do you set a pin to a predefined state without either pullup/pulldown?
2022-03-22 11:34 AM
2022-03-22 11:55 AM
Thanks.
2022-03-22 12:11 PM
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.