Puffergas
Posts: 255
Joined: Thu Dec 19, 2019 12:16 am

GPIO Current Rating

Thu Jan 28, 2021 12:05 am

The GPIO appears to be directly from the RP2040. In the 637 page datasheet it states, on page 255, "Output drive strength can be set to 2mA, 4mA, 8mA or 12mA." Is that set with uPython? It must be current limited and thus short proof? Without any third party output module, the GPIO pins can sink/source up to 12ma? The output appears to be a totem pole output? Or does it need a pull up/down resistor?

Thanks.

Lordanubis
Posts: 46
Joined: Mon Dec 23, 2013 8:13 pm

Re: GPIO Current Rating

Thu Jan 28, 2021 10:10 pm

I am brand new with the pico, did receive then today and did open the package three hours ago.
After some playing, I am curious for the same answers as asked above by Puffergas.

Any one some idea's how to?

Thank you

emma1997
Posts: 1799
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: GPIO Current Rating

Thu Jan 28, 2021 10:49 pm

As part of a test to destruction campaign I've measured actual max GPIO current to be 31ma to gnd and 39ma to 3v. Similar to Pi and IMO quite beefy for such a cute little bugger. Can't recall what the legal spec is.

Unfortunately all pins have default pull downs (drawing 38ua). No pull-ups. Not great news for those of use who like to depend on defaults for safe system startup with active low signals like with a real Pi.

PS haven't actually managed to destroy one yet. Not trying too hard since no easy way to buy any more ATM.

Puffergas
Posts: 255
Joined: Thu Dec 19, 2019 12:16 am

Re: GPIO Current Rating

Sat Jan 30, 2021 4:09 pm

Judging from the above, 20ma may be a safe limit.

Appears that I am miss-reading the "Output drive strength can be set to 2mA, 4mA, 8mA or 12mA" statement. That would of been an interesting hack to get four different states from one output.

Cool device !

GregAC
Posts: 53
Joined: Sun Aug 17, 2014 9:48 pm

Re: GPIO Current Rating

Sat Jan 30, 2021 5:12 pm

I was also wondering what the max draw might be, like you I never found a clear max rating, just the drive strength settings.

In the C++ SDK there's no way (that I could find anyway) to set them, so you'd need to do the register writes directly so I suspect no way to set them in uPython either.

In section 5.2.3.5 of the datasheet you can see some plots (page 627) of current draw vs pin voltage for different drive strengths. As you increase current draw pin voltage starts to drop. If you look at the 12mA drive you're down to 3V at 15mA out and 2.7-2.8V at 20 mA out and you hit the V_OH minimum (minimum high output voltage) of 2.62 at 27-28 mA To me that suggests 28 mA is the upper limit of what you'd want to draw from a single pin and you'd be better off at more like 15-20 mA (given emma1997's comments about testing to destruction at 31mA!). You see a similar thing for current sinking, only this time the pin voltage is going up from 0, you hit V_OL maximum (maximum low output voltage) of 0.5V at 17 mA sunk current. Maybe you can safely source more than you can sink?

If you've ever looked at the datasheet for an AVR (used on most Arduinos) they've got a maximum total current draw across all pins rating (which you could exceed by drawing 20 mA from all GPIO pins), and I haven't seen anything like that on the RP2040 datasheet.

GregAC
Posts: 53
Joined: Sun Aug 17, 2014 9:48 pm

Re: GPIO Current Rating

Sat Jan 30, 2021 5:14 pm

Seems the datasheet encourages a try it and see approach to current limits: 'Of course, if your application doesn’t need such tightly controlled voltages, then you can source or sink more current from the GPIO than the selected drive strength setting, but experimentation will be required to determine if it indeed safe to do so in your application, as it will be outside the scope of this specification.' (from the text that goes along with the graphs of voltage vs current for the pins).

stevend
Posts: 723
Joined: Fri Oct 11, 2013 12:28 pm

Re: GPIO Current Rating

Sat Jan 30, 2021 5:17 pm

The data sheet (page 625) specifies that the 2, 4, 8, 12mA currents are the maxima that can be drawn while maintaining adequate logic high or logic low voltages. For 3.3V supply, the output high voltage will be a minimum of 2.62V; the output low voltage will be a minimum of 0.5V.

You can draw more current, as emma1997 has found, but with more voltage drop across the chip

Puffergas
Posts: 255
Joined: Thu Dec 19, 2019 12:16 am

Re: GPIO Current Rating

Sun Jan 31, 2021 7:08 pm

Thanks, everybody. At least we can say ~20ma. That is close enough for me.

Thanks again !

aleopardstail
Posts: 212
Joined: Sat Jan 23, 2021 4:20 pm

Re: GPIO Current Rating

Sun Jan 31, 2021 7:48 pm

this is something that can be solved with two lines in the documents, at the front, next to where you get the other electrical specifications such as input voltages.

"maximum current sourced/sinked per GPIO pin: xx/xx mA"
"maximum total current sourced/sinked across all pins combined: yy/yy mA"

and stick a "*" next to the per pin readings with a reference to how the amount can be varied in code and where to find the information on how.

job done

first thing I did was try to see if I could, safely, drive an LED from one of the pins (not all MCU can), finding the answer was not straight forwards

W. H. Heydt
Posts: 16361
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: GPIO Current Rating

Sun Jan 31, 2021 8:51 pm

aleopardstail wrote:
Sun Jan 31, 2021 7:48 pm
first thing I did was try to see if I could, safely, drive an LED from one of the pins (not all MCU can), finding the answer was not straight forwards
Practically the first thing the "Getting Started..." book has you do is blink an LED (the one on the board), which is quickly followed by projects to do various controls with externally attached LEDs, from variable brightness (using a PWM control) and a "traffic light" controlling three LEDs.

I think you approached the Pico with too much prior experience/knowledge.

aleopardstail
Posts: 212
Joined: Sat Jan 23, 2021 4:20 pm

Re: GPIO Current Rating

Sun Jan 31, 2021 9:40 pm

W. H. Heydt wrote:
Sun Jan 31, 2021 8:51 pm
aleopardstail wrote:
Sun Jan 31, 2021 7:48 pm
first thing I did was try to see if I could, safely, drive an LED from one of the pins (not all MCU can), finding the answer was not straight forwards
Practically the first thing the "Getting Started..." book has you do is blink an LED (the one on the board), which is quickly followed by projects to do various controls with externally attached LEDs, from variable brightness (using a PWM control) and a "traffic light" controlling three LEDs.

I think you approached the Pico with too much prior experience/knowledge.
I was more commenting that most products data sheets include the output current rating somewhere easy to find, I'm assuming the lack of it here is just an oversight

I have no idea if the on board LED uses 2mA or 20mA

why on earth would I need to buy a getting started book and read an example of traffic lights (does that quote the current rating of the LEDs?) in order to find such basic information. I mean many on line LED circuits use 5v, yet the datasheet here says to use 3.3v quite clearly

cleverca22
Posts: 8190
Joined: Sat Aug 18, 2012 2:33 pm

Re: GPIO Current Rating

Sun Jan 31, 2021 10:00 pm

W. H. Heydt wrote:
Sun Jan 31, 2021 8:51 pm
Practically the first thing the "Getting Started..." book has you do is blink an LED (the one on the board), which is quickly followed by projects to do various controls with externally attached LEDs, from variable brightness (using a PWM control) and a "traffic light" controlling three LEDs.

I think you approached the Pico with too much prior experience/knowledge.
i had also started by building all of the examples, before the pico had even arrived, and i found that the blink example didnt work when built from my distro
but building it from an ubuntu docker image worked, i had to get SWD and openocd involved to track down all of the issues, my arm-gcc toolchain was broken
but thanks to that bug, i now have openocd working, and that makes the test cycle a whole lot simpler

i have done basic AVR stuff in the past (only down to C, not asm), and i have been doing a lot of baremetal stuff on the rpi lately

danjperron
Posts: 4504
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: GPIO Current Rating

Sun Jan 31, 2021 10:12 pm

Well in micropython I was able to change the current of GPIO28 using the machine module.

import machine

the pad control bank page 313. specify address 0x4001c000

the GPIO28 is at the offset 74
I changed the value from 0x52 to 0x42 and The light of my lcd nokia lcd drop.
B.T.W. I connected directly the back light pin to gpio 28.

import machine
machine.mem32[0x4001c074]=0x42

video https://www.dropbox.com/s/inzfu37wstb90 ... 0.mp4?dl=0

cleverca22
Posts: 8190
Joined: Sat Aug 18, 2012 2:33 pm

Re: GPIO Current Rating

Sun Jan 31, 2021 10:44 pm

danjperron wrote:
Sun Jan 31, 2021 10:12 pm
import machine
machine.mem32[0x4001c074]=0x42
aha!, i was wondering if micropython had any way to do raw peek/poke, that opens up a lot of options for filling in unhandled hw, without having to go the full extending with C route

WestfW
Posts: 271
Joined: Tue Nov 01, 2011 9:56 pm

Re: GPIO Current Rating

Mon Feb 01, 2021 2:07 am

Keep in mind that the microcontroller (ANY microcontroller, AFAIK) does not artificially LIMIT the current delivered to any particular pin. It just had some chip designer Iook at the design and say "with this size of output transistor, I think a safe current is 3mA. We can add stuff so that we use two of them and have a safe current of 6ma, or maybe even four transistors, to get 12mA. that ought to be enough for any modern purpose."
Then some chip test person measured it and confirmed "Yep, with this configuration and that current source/sink magnitude, the output voltages are still within specs for the logic levels", and they print the preliminary data sheets.
That doesn't mean that the pin will LIMIT the current to those "safe" levels. If you are willing to put up with the voltages going out-of-spec, and/or if you're not worried about burning out the output transistors, you can probably get more than 3/6/12mA...

(Modern LEDs are "insanely bright for 'indicator' use" even at ~3mA, and "clearly need more than a microcontroller output pin can provide" for the high-power 'illuminating' LEDs...)

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 32858
Joined: Sat Jul 30, 2011 7:41 pm

Re: GPIO Current Rating

Mon Feb 01, 2021 10:25 am

Although talking about he Pi GPIO, this document will be worth a read.

https://www.raspberrypi.org/documentati ... control.md
Principal Software Engineer at Raspberry Pi Ltd.
Working in the Applications Team.

aleopardstail
Posts: 212
Joined: Sat Jan 23, 2021 4:20 pm

Re: GPIO Current Rating

Mon Feb 01, 2021 9:56 pm

jamesh wrote:
Mon Feb 01, 2021 10:25 am
Although talking about he Pi GPIO, this document will be worth a read.

https://www.raspberrypi.org/documentati ... control.md
useful, actually very useful, and very clever - however it is worth adding somewhere for the Pico what you can get from it and it still be happy and reliable, not just for the RP2040 itself but what the regulator on the board can do as a maximum.

even if just guide numbers for what per pin, and what for the chip as a whole, then what power the 3.3v output can support as a total for the whole board - just a few lines in the basic specs near where the min & max input voltage etc live, with a note the individual pins can be configured and a reference to the section - idea is a quick and dirty "I have this weird gizmo that says it wants 45mA to operate and draws 18.9999mA on its signal pin - will it work out of the box or do I need extra drivers?"

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 32858
Joined: Sat Jul 30, 2011 7:41 pm

Re: GPIO Current Rating

Tue Feb 02, 2021 10:01 am

We are having a big discussion internally about this, because its actually not a simple question and definitely not a simply answer. It may seem to some it should be, but it isn't. Because silicon.

Once we have a definitive answer the datasheet will be updated.
Principal Software Engineer at Raspberry Pi Ltd.
Working in the Applications Team.

User avatar
Burngate
Posts: 6560
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore

Re: GPIO Current Rating

Tue Feb 02, 2021 10:05 am

jamesh wrote:
Mon Feb 01, 2021 10:25 am
Although talking about he Pi GPIO, this document will be worth a read.

https://www.raspberrypi.org/documentati ... control.md
Although dating from 2012, I've assumed it all applies to later Pis (apart from the addresses)
How much of it can we take as gospel for the Pico, and how much is different?
For example, since we're told we can only go up to 12mA rather than 16mA, I assume the first diagram needs modification, as does the Drive strength list at the bottom.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 32858
Joined: Sat Jul 30, 2011 7:41 pm

Re: GPIO Current Rating

Tue Feb 02, 2021 10:12 am

Burngate wrote:
Tue Feb 02, 2021 10:05 am
jamesh wrote:
Mon Feb 01, 2021 10:25 am
Although talking about he Pi GPIO, this document will be worth a read.

https://www.raspberrypi.org/documentati ... control.md
Although dating from 2012, I've assumed it all applies to later Pis (apart from the addresses)
How much of it can we take as gospel for the Pico, and how much is different?
For example, since we're told we can only go up to 12mA rather than 16mA, I assume the first diagram needs modification, as does the Drive strength list at the bottom.
I only posted it to give some people an idea of how the GPIO's work, and why "How much current" is not exactly the right question, rather than giving specific numbers - those are still being discussed internally.
Principal Software Engineer at Raspberry Pi Ltd.
Working in the Applications Team.

aleopardstail
Posts: 212
Joined: Sat Jan 23, 2021 4:20 pm

Re: GPIO Current Rating

Tue Feb 02, 2021 3:01 pm

jamesh wrote:
Tue Feb 02, 2021 10:01 am
We are having a big discussion internally about this, because its actually not a simple question and definitely not a simply answer. It may seem to some it should be, but it isn't. Because silicon.

Once we have a definitive answer the datasheet will be updated.
not being simple is the point, good to know though, this is progress, and good progress

gets the thumbs up, new product, new product range for you guys, what people do with these poor innocent MCU is different to what they may do to a Pi more generally.

just imagine if this was something from the far far flung east, would take an age to get documentation changed, if it ever was :)

Puffergas
Posts: 255
Joined: Thu Dec 19, 2019 12:16 am

Re: GPIO Current Rating

Tue Feb 02, 2021 8:08 pm

jamesh wrote:
Tue Feb 02, 2021 10:12 am
I only posted it to give some people an idea of how the GPIO's work, and why "How much current" is not exactly the right question, rather than giving specific numbers - those are still being discussed internally.
Yes, and very much appreciated. Now I understand the issue a byte more.

Take you time. Great work !

emma1997
Posts: 1799
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: GPIO Current Rating

Tue Feb 02, 2021 8:22 pm

WestfW wrote:
Mon Feb 01, 2021 2:07 am
Keep in mind that the microcontroller (ANY microcontroller, AFAIK) does not artificially LIMIT the current delivered to any particular pin.
Hi Bill, Didn't realize you were a member here but shouldn't be surprised knowing you do get around. We've spent many hours on other sites discussing your excellent upgrades to Optiboot and unrelated stuff too. Won't say more because why spoil the mystery?

Having worn semi product engineer hat in another life I recognized how true your little description of the spec etiology was. Sounded just like one of our typical PE meetings (supposedly stood for Product Engineering but most of use knew it as Poor Excuse time to explain why we didn't get this or that done).

Also agree on modern LED efficiency. Kinda funny how some will go on for pages calculating limit resistors when in most cases any old 100r-10k works fine depending on ambient.
Puffergas wrote:
Sun Jan 31, 2021 7:08 pm
At least we can say ~20ma. That is close enough for me.
Depends on how many pins you plan to drive. As part of my Kill The Pico party couple weeks back, just a handful @16ma ea had the chip way too hot to touch and obviously ready to smoke. On the other hand direct shorts of one or two no significant heating. Not an issue on one of the 5 cent MCU w/only 4 IO but with 30 some pins...

I picked up a half dozen more of the $2 deals (til Microcenter ran out) for my junk box now so might just try again to see what it takes to actually permanently fry one of the little cuties.

"Does this hurt? How about this... and this... and THIS!" lol

Superkris
Posts: 27
Joined: Mon Feb 15, 2016 8:48 pm

Re: GPIO Current Rating

Wed Feb 03, 2021 1:24 pm

jamesh wrote:
Mon Feb 01, 2021 10:25 am
Although talking about he Pi GPIO, this document will be worth a read.

https://www.raspberrypi.org/documentati ... control.md
Thank you for that information. It was indeed a very interesting read! If i understand you correctly the Pico uses a similar setup. The choices of "set " maximum current are a little different, but the design is basically the same.

I guess the whole reason this topic exists, are the design parameters. If i start to do some designing with MCU and i want to connect something to the IO i need to check a couple of things. One of them is: Can the GPIO provide enough current to drive the attached circuit. Typically these are things like LED's, octocouplers, transistors, etc.

Its mostly optoelectronics that require currents above a few mA, but capacitieve loads also matter, especially if switched at higher capacities. Also there are plenty of cases where a short circuit can happen to the GPIO and you may want to protect for this. In any case the current can be limited with a external resistor. Choosing a to high value however could result in a to low voltage to power a device so you want to choose a resistor value that is as low as possible that can still protect the GPIO.

Another problem with limiting the current from the GPIO can be the gate charge of large FETS. Especially if you want to drive these at higher switching frequency's you might want to charge the gate as fast as possible to get a fast slew rate on its output. As a designer again you would need to consider if the GPIO can provide enough current, or if you will need to add a additional driver.

Ideally a GPIO output provides a lot of current. When designing the hardware on its output a capability to provide more current is always better. Therefore as a designer i would always want to work with the maximum current level. After reading your link however i understand why you might want to lower this from the perspective of the MCU:
The Raspberry Pi 3V3 supply was designed with a maximum current of ~3mA per GPIO pin. If you load each pin with 16mA, the total current is 272mA. The 3V3 supply will collapse under that level of load.
Big current spikes will happen, especially if you have a capacitive load. That will "bounce" around all the other pins near it. It is likely to cause interference with the SD card or even the SDRAM behavior.


So the designer of the MCU wants to provide as little current as possible to optimize the performance of MCU. The designer of external circuity however wants as much current as possible. Off course both understand that a extremely low current, and a extremely high current will result in a solution what wont work.

Since you are the manufacture of the MCU however i think you need to provide some basic specs to work with. You already do this and even add value by making this controllable to we as designers can use the best possible setting. The current specifications however are much to complicated.

I think you need to provide a single number which is set by default. The MCU will need to be able to provide this current in all (or most common) setups without effecting the stability of the MCU. Besides this fact, you can specify that the current can be increased at the possible costs of making the MCU less stable.

For example
Maximum GPIO sourcing/sinking current: 6mA*

* can be set to 12mA at the risk of decreasing system stability
That would give people a basic number to work with. If they really require more current they can change manually and test. Only very advance users will be interested in lowering the output even further. For those people extended specifications will work fine.

Additionally we would need to know what is the maximum total current we can source from the GPIO. If i would like to connect all 26GPIO to a 12mA LED, i would pull 312mA. Maybe that is fine, but this seems like a lot. If the number would be much lower, 50mA for example, this would be a real limitation to work with, and we would need to know!

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 32858
Joined: Sat Jul 30, 2011 7:41 pm

Re: GPIO Current Rating

Thu Feb 04, 2021 2:58 pm

So the rating is : IOVDD current <=50mA. The Datasheet is being updated.
Principal Software Engineer at Raspberry Pi Ltd.
Working in the Applications Team.

Return to “General”