Raspberry Pi Pico PIO - 8 Little Processors You Can Program

  Переглядів 86,812

Gary Explains

Gary Explains

День тому

The processor in the Raspberry Pi Pico, the RP2040, has a feature called PIO - Programmable Input/Output. As a result you have access to 8 little processors with their own assembly language which you can program to create deterministic interfaces to the real world.
The Pico's PIOs are programmable like general processors. The 8 state machines processors can independently execute programs to manipulate GPIOs and transfer data.
RP2040 Datasheet (look for Chapter 3: PIO): datasheets.raspberrypi.com/rp...
Pico MicroPython Examples: github.com/raspberrypi/pico-m...
Let Me Explain T-shirt: teespring.com/gary-explains-l...
Twitter: / garyexplains
Instagram: / garyexplains
#garyexplains

КОМЕНТАРІ: 114
@bertkoerts3991
@bertkoerts3991 4 місяці тому
Gary, thank you for this content, I’m a retired hobbyist that between Christmas and new year’s eve discovered the existence of FPGA boards. Rather daunting, but this story might help me a bit. I do know assembly, and the pi pico is rather accessible to me. I’ll be following your channel for sure, and I will also look into what you produced so far. Thanks a lot, very helpfull and motivating! 👍😊
@chrisforeman5745
@chrisforeman5745 2 роки тому
took me back to my 6502 days back in the mid 80's thanks 🙂
@nevg9932
@nevg9932 2 роки тому
Thank you Gary for keeping us educated! We love your work!! Cheers
@muddyexport5639
@muddyexport5639 2 роки тому
Yet another excellent production. Please keep producing these types of educational videos. Good job, professor!
@rbus
@rbus 4 місяці тому
The truly genius move by the Raspberry Pi Foundation, FPGA I/O features without complicated dev tools, amazing flexibility for interfacing.
@g0hjq
@g0hjq 2 роки тому
Thank you Gary. You've made understandable what every other website and channel has carefully avoided. I'm going to have a play and see how it goes.
@rugwalle
@rugwalle 9 місяців тому
Exactly what I needed to get my state machine working the way I wanted. Thanks!
@markharrisllb
@markharrisllb 2 роки тому
Do we really need any more channels besides yours and Explaining Computers?
@VerticalWit
@VerticalWit Рік тому
Dont be silly. Ben Eater, Mitxela, BigClive?
@sparky173j
@sparky173j Рік тому
This kind of thing is amazing! It really saves main CPU clocks cycles, rather than having to service high frequency interrupts. You've produced a great video demo, thanks. Some NXP chips (I work with MPC5534 and MPC5777C) have a similar I/O coprocessor they call an eTPU. It concentrates more on timing. It has two independent timers, one can have dynamically variable speed. Each I/O (I think there's 32 per eTPU. 5534 has one eTPU, 5777C has 3) has two capture/compare registers, and can trigger interrupts. You can code the ISRs in a weird dialect of C or different weird dialect of C++, but may have to pay for a compiler. Each I/O can be assigned RAM, as well as global eTPU RAM. Any RAM declared as public can be accessed by the CPU(s) as well as the eTPU. It's amazing what can be done with it, but it can be hard to ensure proper coherency when you start doing complex things.
@shlamdrago8295
@shlamdrago8295 Рік тому
Exactly what I was looking for !!!!! Great work !!!! Keep up the good work 🙂
@andrewdoble2378
@andrewdoble2378 Рік тому
Many thanks for this video. I was trying to program the PIOs using Rust and could not get it to work. This really helped me sort out my thinking mistakes and get it working (the translation from Python to Rust was not so difficult). I also wasted a lot of time on the difference between OUT and SET pin mappings - pity I didn’t watch this beforehand.
@DukeofEarl1961
@DukeofEarl1961 2 роки тому
Good video Gary, but with all the Time delays in Python you kind of missed the point of the PIO for new users. The key is that once started, the PIO routines run separately in the background and do not affect the performance of the main Pico processors so, for example, a PIO could be reading serial data with very accurate timing, while the main processors run complex mathematics on the data...
@GaryExplains
@GaryExplains 2 роки тому
True, I thought I explained that. Sorry if it wasn't clear.
@Anon.G
@Anon.G Рік тому
I think you missed the point, not the creator
@kychemclass5850
@kychemclass5850 2 роки тому
Thanks for this Gary. Very educational!
@werpu12
@werpu12 Рік тому
The PIO is one of the things which make the picopi so great compared to other systems in this area, thanks for this video! I have relatively quickly hit a block which probably would not have been solvable properly on other systems but now I have had a serious look at the PIO yesterday, and my judgement is, that it is solvable with minimal effort compared to for instance an Arduino !
@fluiditynz
@fluiditynz Рік тому
That's some seriously good bit-banging pico capabilities!
@godfreyw5412
@godfreyw5412 Рік тому
he explained PIO well basically in the first 40 seconds. awesome
@johnwettroth4060
@johnwettroth4060 Рік тому
You really do have a knack for explaining things- thanks very much.
@GaryExplains
@GaryExplains Рік тому
Glad you think so!
@Bubby9767
@Bubby9767 Рік тому
Very well explained. Thanks
@mikeywisniewski
@mikeywisniewski Рік тому
Thank you. Very good video on such a great feature.
@AllThingsCloudie
@AllThingsCloudie 6 місяців тому
Wonderful, interesting and easy to follow - thank you
@Abdulaziz-vz6op
@Abdulaziz-vz6op 2 роки тому
Thanx for the explanation 👍
@jonathanstein6056
@jonathanstein6056 Рік тому
If you can get ahold of one, the Teensy 4 and 4.1 have a suped-up version of the PIO called FlexIO. That would make a very interesting episode. And that can all be done within the Arduino IDE.
@williamstevenson2649
@williamstevenson2649 2 роки тому
Excellent! Thank you
@stefanweilhartner4415
@stefanweilhartner4415 2 роки тому
it seems that we can make a nice bus interface for interfacing to a classic old school cpu bus, like a c64. maybe as an active cpu emulation or a bus interface to emulate an io chip or the SID chip. i have to dig into that a bit closer and explore the possibilities here. writing to the program counter is super powerful to emulate a CPU.
@askmartyn
@askmartyn Рік тому
This is very exciting
@fred-9929
@fred-9929 Рік тому
Great tutorial! One thing: jmp(dec_x, ...) does not decrement X before testing it, but *after*! So, if X is 1, the jump will occur (and X will be decremented).
@uajoku
@uajoku 2 роки тому
A really insightful tutorial. Thank you, Gary. BTW, is the 8xPIO programming only available on the Pico?
@GaryExplains
@GaryExplains 2 роки тому
On any board using the RP2040
@prawnmikus
@prawnmikus 2 роки тому
Be cool to see how a VGA driver is written using the PIO, or is that something more suited to the main CPUs?
@Marc_Wolfe
@Marc_Wolfe Рік тому
Async matters. Good stuff.
@markwarburton8563
@markwarburton8563 2 роки тому
Thanks Gary! The inclusion of the pio in the Pico is revolutionary. I'm hoping later iterations give us more than a 32 instruction memory shared with all 8 of the state machines! While having these state machines is wonderful, having more instruction space would make this truly wonderful!
@yum33333
@yum33333 2 роки тому
Not ragging on the Pico at all - but interfaces like these have been available on many MCUs for years. For example the Teensy 4 has it, many STM chips have it, etc. That said, I am glad to see it becoming more mainstream through the Pico, it's a powerful combo between MCUs and FPGAs that I've been anticipating for years. Hopefully they will release another version of the Pico in a BGA package with a lot more IO pins. And native USB 2.0. Then it would be useful for something more sophisticated than hobby projects.
@markwarburton8563
@markwarburton8563 2 роки тому
@@yum33333 I am familiar with the Teensy 4 and 4.1, but the 3x FlexIO interfaces (loosely PIO equivalents) on those are quite different in philosophy. The Pico's PIO instructions all execute within 1 cycle and have multiple functions going on at the same time in the same instruction. For example, writing out of the Output Shift Register (OUT instruction) can additionally shift the bits at the same time as well as adding delays (if desired). Each PIO command is highly code and execution efficient and can run at the same frequency as the ARM core itself. The PIO state machines effectively allow certain limited parallel operations to occur, often faster than even a dedicated ARM core itself could. On the other hand, Teensy's FlexIO is limited to 120MHz, which on a 600MHz Teensy 4.1 makes it less useful, as in it is really only intended to offload deterministic bit-banging operations from the ARM core. It does not execute instructions faster than the ARM core itself. This difference in the Pico's PIO philosophy has made projects, like a logic analyzer using the PICO operating with 21 digital channels with up to 120 MHz capture speed (hackaday.com/2022/03/02/need-a-logic-analyzer-use-your-pico/) possible. A 120MHz logic analyzer run on a humble device costing just $4 is quite an achievement and illustrative of the difference in PIO philosophy.
@abraxalito
@abraxalito 2 роки тому
@@yum33333 Which STM chips have PIO functionality like this? Got an example part number? I came across something similar in the LPC4300 many years ago but not so far met it in STM.
@AttilaAsztalos
@AttilaAsztalos 2 роки тому
@Mark Warburton "revolutionary"...? HAHAHA. Parallax Propeller, two-fucking-thousand-six. en.wikipedia.org/wiki/Parallax_Propeller
@markwarburton8563
@markwarburton8563 2 роки тому
@@AttilaAsztalos That Parallax Propeller is an eight core MCU that is at least an order of magnitude more expensive, even now, compared to the RP2040. The reason is it has 8 fully functional cores that are more similar to the dual ARM cores in the Pico than to the PIO. The Pico's "revolutionary" approach is to offer multiple PIO state machines running at the same frequency as the ARM cores and taking up very little die space to achieve that, so keeping costs down.
@John.0z
@John.0z 2 роки тому
The RP2040 is starting to sound like the old CDC Cyber 7x and 17x series "mainframes", with their single register PPUs used for all I/O!
@Winnetou17
@Winnetou17 2 роки тому
Challenge: have a drink whenever you encounter 31 But back to getting serious, I like the incremental program examples. I don't have a Pico, though I was thinking of getting one, and this might be helpful.
@trevorschrock8259
@trevorschrock8259 2 роки тому
I'm thinking about patterns that allow for sending multiple buffers over different high-frequency (30MHz) SPI lines in parallel. You'd still have to feed individual words to each fifo in the main program, right? i.e. each PIO unit doesn't have access to RAM, so you'd need to keep feeding them.
@GaryExplains
@GaryExplains 2 роки тому
Section 3.6.1 of the RP2040 datasheet shows you how to do full duplex SPI. Also section 3.2.7 covers Interactions Between State Machines, where it says, "State machines can not communicate data, but they can synchronise with one another by using the IRQ flags."
@trevorschrock8259
@trevorschrock8259 2 роки тому
@@GaryExplains Oh, neat. Thanks for the reference.
@martinmckee5333
@martinmckee5333 2 роки тому
@@trevorschrock8259 Also, it is possible to configure DMA to feed (empty) the FIFO and, again, offload the main processor.
@BartdeBoisblanc
@BartdeBoisblanc 2 роки тому
Gary I have a question since the I/O processors (state machines) are independent of the main CPU. Can you run a seperate program on the CPU if it does not interfere with the I/O.
@GaryExplains
@GaryExplains 2 роки тому
Yes
@BartdeBoisblanc
@BartdeBoisblanc 2 роки тому
@@GaryExplains Great, Thanks for the quick response.
@Cold-1
@Cold-1 2 роки тому
I think you confused the rx and tx queues in your bouncer program. You said "rx is output" and "tx is input" (at around 20:02). That startled me for a moment ;-)
@GaryExplains
@GaryExplains 2 роки тому
Well of course rx and tx are relative to which side you are on. But they do have defined names, so sorry if I confused them.
@Rahat2995
@Rahat2995 2 роки тому
@@GaryExplains plz tell about ur other chanel speed test g???
@nikolaivorontsov9895
@nikolaivorontsov9895 2 роки тому
@16:40 don't we need the last nop() be [30] delay? To have a perfect 50% duty cycle? A jump will take one cpu clock, so the last nop should delay a bit less.
@GaryExplains
@GaryExplains 2 роки тому
I don't think a wrap is actually a jump. At the end of the code, the PC for the next instruction is set to the wrap target rather than PC+1.
@SimonJackson13
@SimonJackson13 2 роки тому
So 4 of them for a video signal generator?
@ice2642
@ice2642 11 місяців тому
Cool video. I wold like to ask, if it is possible access this I/O controllers, using ASM Like old school PEEK POKE using mmbasic instead python?
@GaryExplains
@GaryExplains 11 місяців тому
I don't know if it is supported by mmbasic, I guess it would be best to ask the mmbasic people.
@sabinacharya5496
@sabinacharya5496 2 роки тому
When you will make video on 'Speed Test G'?
@sambeard4428
@sambeard4428 4 місяці тому
kan one statemachine change multiple pins? looking at the naming (pins vs pin) and set_base (implying that you can use more pins from that value). That would be useful for some programs, like an uart loopback, or more complex protocols that require precise timing on multiple lines.
@BrianCompston
@BrianCompston 3 місяці тому
Yes, out_base defines the start pin, so if say gpio16 is set as the base, pins greater than that can be used. Also, look at the use of the .side() option on commands which can also be used to control additional pins.
@paulwratt
@paulwratt Рік тому
Hmmm.. A video, using the pico, to _play_ that _outro music_ , Yes? :)
@tsclly2377
@tsclly2377 Рік тому
YA.. blinking LED for your drone.. the red and green navigation lights.. a higher bit rate, programed could be used for communication.. better know the gate rate although.
@zan6254
@zan6254 Рік тому
Hey great video Gary I want to implement I2C using PIO can you suggest me some tips in how to do it
@GaryExplains
@GaryExplains Рік тому
The Raspberry Pi people already did that here: github.com/raspberrypi/pico-examples/blob/master/pio/i2c/i2c.pio
@zan6254
@zan6254 Рік тому
@@GaryExplains thanks for the reply I've seen this code it's in c but I wanted to do in micropython
@zan6254
@zan6254 Рік тому
I also wanted my pico to be used as a I2C slave
@GaryExplains
@GaryExplains Рік тому
OK, so it isn't in C, it is in PIO assembly language, all you need do is convert those to the equivalent Micropython calls or even just use .exec(). Lots of examples here : github.com/raspberrypi/pico-micropython-examples/tree/master/pio
@zan6254
@zan6254 Рік тому
@@GaryExplains thanks for the help Gary
@VioletGiraffe
@VioletGiraffe Рік тому
The oscilloscope on the background image - is it the soviet C1 series?
@GaryExplains
@GaryExplains Рік тому
Sadly I have no idea, it is just a stock photo.
@jankomuzykant1844
@jankomuzykant1844 2 роки тому
16:19 If blinking time (sleep) is different then is it possible to stop pio in state the led stays on ?
@GaryExplains
@GaryExplains 2 роки тому
That is a good question. Looking at the source code it seems that the activate() function just sets a bit in the CTRL register. The documentation says, "When disabled, a state machine will cease executing instructions" which implies that it stops on the next cycle (I guess). So I think that means that you can stop it with the LED on.
@Rahat2995
@Rahat2995 2 роки тому
Garry why your speed test g chanel is dead?
@chrisw1462
@chrisw1462 8 місяців тому
ISR means Interrupt Service Routine on just about any processor with interrupts. Why the @#%% would they have something else called ISR in this thing??
@climbeverest
@climbeverest 7 місяців тому
We need to understand programmed IO better please
@TurtleKwitty
@TurtleKwitty Рік тому
Hello quick question, I was under the impression that the PIO could access multiple pins is this incorrect?
@GaryExplains
@GaryExplains Рік тому
Yes, the PIO can access multiple pins.
@NicholasAndre1
@NicholasAndre1 Рік тому
Reading through the data sheet is a roller coaster: "Ok only 9 instructions." "holy crow each instruction can do like 5 things" "ok I think I got these" "oh INJECTING instructions from the main processor???" "oh look there are 9 ways to trigger/dma/pull/irq things in and out" "oh good 8 interrupts, 4 external, giant enum of configs..."
@taranagnew436
@taranagnew436 Рік тому
Is there a sketch that uses/users can program the shift redigure?
@taranagnew436
@taranagnew436 Рік тому
Is a state machine when you create a define a function?
@mheermance
@mheermance Рік тому
That sounds a bit like the Parallax Propeller chip.
@heliosak
@heliosak 2 роки тому
Bring back speed test G
@trannusaran6164
@trannusaran6164 Рік тому
if you squint, it's almost like you've got 8 lil 6502s :)
@twobob
@twobob 2 роки тому
dear me the too loud music is very distracting. Keeps making me reach over to turn it down. Anyway thanks for the code.
@AndroidDevViral
@AndroidDevViral 2 роки тому
Wow just like the computer game TIS100
@tubeDude48
@tubeDude48 Рік тому
NOP - No Operation
@suki4410
@suki4410 Рік тому
Mining with a pico?
@GaryExplains
@GaryExplains Рік тому
🤣
@ahbushnell1
@ahbushnell1 2 роки тому
beaglebone black has to that can be programed in C
@GaryExplains
@GaryExplains 2 роки тому
The Pico can be programmed in C as well. So with the Pico you get the option of Python or C and it costs just $4.
@ahbushnell1
@ahbushnell1 2 роки тому
@@GaryExplains cool
@ahbushnell1
@ahbushnell1 2 роки тому
@@GaryExplains So the microcontrolers can be programmed in C or the main pricoessor?
@GaryExplains
@GaryExplains 2 роки тому
The Cortex-M0+ processors (there are two of them) can be programmed in C or Python. The PIO have their own special assembly language as I explain in this video. That special language can be loaded into the PIOs from C or Python.
@ahbushnell1
@ahbushnell1 2 роки тому
@@GaryExplains Two ARM processors plus another 8 micros. The 8 are assembly and the two are C or Python. I saw the video on the dual core programing. Is there shared resources?
@jonshouse1
@jonshouse1 2 роки тому
Finally a good useful description of something I want to know, about real time deterministic fast I/O .. then you somewhat spoil it by muddling it with Python, yet another fashionable interpreter of the time but completely pointless alien speak to me.
@GaryExplains
@GaryExplains 2 роки тому
You can use C instead, the principals are the same.
@jonshouse1
@jonshouse1 2 роки тому
@@GaryExplains Yes, I know I am about to do it. I was hoping the video would give me a head start, but I did not get that much useful from it. No real explanation of "pins", still not sure how that works... how does it compete with GPIO, does it have some form of mask, Interaction with ISRs?. The PIO compiler in the SDK is not shown as you went the python route.I will go and read the data now, but it is a bit of shame as the title of video got my hopes up but I came away having felt I learnt little other "The PIO has 8 programmable units"
@GaryExplains
@GaryExplains 2 роки тому
Well, I am sorry to hear that, but of course you understand that I didn't contact you before I made the video and asked you what you wanted. I made a different video and plenty of people seem to have found it useful, sorry you didn't. All the information you need is in the datasheet which I link to in the description.
@jonshouse1
@jonshouse1 2 роки тому
@@GaryExplains To be fair you videos are well made with good presentation, but had you added the word "python" to the title I would have ignored it and saved myself some time.
@duncanwalduck7715
@duncanwalduck7715 Рік тому
There's more 'boilerplate' in the typical C version of things: the 'in-line assembler' in Python is more 'terse', so why not go ahead with it here, because the theme here is the PIOs themselves (quite well treated, I think). There was basically no support from the main processor(s) in these examples, except a little poke and peek to the queue depth. To get properly into this you would probably need interrupts and DMA and all that jazz, which would be much more likely well done in C, alas. Gary's series on a muti-tasking OS for the Pico has been quite hot on the low level, though.
@COMATRON.
@COMATRON. 2 роки тому
still: 4 president!
@Lissuo
@Lissuo 2 роки тому
sorry for caps
@Lissuo
@Lissuo 2 роки тому
i DO NOT UNDERSTAD BUY i LIKE ANYWAT
Arduino vs Pico - Which is the Best Microcontroller For You?
20:38
Gary Explains
Переглядів 278 тис.
RP2040 - Introduction to Assembly Language - BMA-01
25:21
Life with David
Переглядів 9 тис.
ОДИН ДОМА #shorts
00:34
Паша Осадчий
Переглядів 5 млн
Excited Dog Zooms In and Out of Sliding Door!
00:18
The Pet Collective
Переглядів 13 млн
Raspberry Pi Pico PIO - Ep. 8 - Introduction to DMA
18:21
Life with David
Переглядів 17 тис.
Has Generative AI Already Peaked? - Computerphile
12:48
Computerphile
Переглядів 315 тис.
#372 How to use the two Cores of the Pi Pico? And how fast are Interrupts?
14:25
The Pi Pico has problems, so I made my own, the ProPico
7:17
Dmytro Engineering
Переглядів 34 тис.
rust runs on EVERYTHING (no operating system, just Rust)
18:10
Low Level Learning
Переглядів 333 тис.
Can the RP2040 output 1080p? I think so, with a little help...
10:46
The ARM chip race is getting wild… Apple M4 unveiled
4:07
Fireship
Переглядів 722 тис.
PicoMiteVGA: Raspberry Pi Pico Boot-to-BASIC Microcomputer
23:58
ExplainingComputers
Переглядів 120 тис.
I Can Save You Money! - Raspberry Pi Alternatives
15:04
Linus Tech Tips
Переглядів 3,2 млн
The Raspberry Pi Pico WAS Overrated! But that changed!
10:18
GreatScott!
Переглядів 582 тис.