Re: samples/basic/blinky

Lawrence King

Hi Patrice:


Your statement that the behavior of the LED is ‘inverted’ is completely correct.


Your statement about the current is at best confusing. It is true that the GPIO doesn’t need to ‘source’ the current to turn the LED, but the GPIO does need to ‘sink’ the current. The amount of current flowing either into or out of the GPIO will be same no matter how the LED and resistor are connected. The reason we electrical engineers always choose to have the GPIO ‘sink’ the current is purely historical.


In the dark ages when we used +5V TTL logic (example 74LS04), the outputs of a logic gate could only source a small amount of current typically 6mA, and could sink a larger amount of current, typically 18mA. The LEDs available at the time needed at least 10mA to light up (and even at 10mA were not very bright), hence we were forced to use the sink capabilities of the gate to connect a LED to an output.


For no good reason we have continued with this convention, current generation LEDs are very bright with only 2mA of current, and current logic gates are symmetric drive which can source or sink 10mA or even 20mA. There is no good reason to have the logic ‘inverted’ other than historical convention.


I haven’t tried out all of the features of the new GPIO functions yet, but I think you can setup a GPIO to be “GPIO_ACTIVE_LOW” when calling gpio_pin_configure() and then drive the pin to GPIO_OUTPUT_ACTIVE when calling gpio_pin_set(), I believe this should turn the LED on.


Lawrence King

Principal Developer



From: users@... <users@...> On Behalf Of patrice.gerin via
Sent: Monday, May 4, 2020 3:41 AM
To: users@...
Subject: Re: [Zephyr-users] samples/basic/blinky


Hellor Tristen,

The behavior of your LED seems normal!
In embedded design, LED are usually and voluntary inverted. Doing this will avoid the GPIO pin to provide the current by itself, the LED current will be supplied by the power directly.
                led       resistor
VCC |------|>|-----^v^v^v----------< GPIO |
If GPIO is set => no current
if GPIO is unset => current from VCC to the GPIO, no current provided by the stm32!
The LED is "active low".

Join to automatically receive all group messages.