 Hello hello Hopefully everything is working If you're watching this after the fact make sure you check the description below for time codes This stream is typically Like two hours long so you can check the time codes to skip round Push Mark just got a circuit Python board going Let me pause my windows here. Sorry. I'm a little late Took me a smidge longer than I expected to get everything going so but we're going and I think Everything is going okay Let me know if it's not How do you it's good? Thank you David. Thanks to David for taking notes as always We'll get the show on the road here. I'm kind of tired Minnesota Menta said missed you last week. Oh, thank you Oh, it's in honey the link to the stream is you can't hear me because my volume is a little low Hmm I Can move it up. Is that better? Maybe not I can turn it up here, too Test test test test test test test test test I can be I'm kind of a loud person So I don't want it to be super loud. Otherwise it'll clip All right, let me say hi to folks and then we'll do housekeeping and then we'll dive right in so The stuff I've been working on Hello Bruce hello unexpected maker hello, Beata hello, Minnesota Menta. Hello Linux 203 hi Todd Todd are Thank you all for being in the YouTubes In discord we have Keith the EE We've got Mark gambler. We've got DCD love the factory oats and honey Dexter starboard and doctor So hello everyone Compared to loads compared to other videos and streams I've been listening today I mean, I'm hitting the red on OBS. So I don't think I want to push it too much more Okay, so let's do housekeeping Hello, everyone, my name is Scott and I work for Adafruit on circuit Python Adafruit is an open-source hardware and software company based out of New York City I am here in Seattle The Sun is out and causing it to be a bit bright in here I work remotely for Adafruit technically as a contractor and I work on circuit Python So circuit Python is a version of Python designed for microcontrollers. Here's unexpected Makers board here That is Has a Wi-Fi capable microcontroller on it called the ESP 32 s2 you plug it in it shows up as a drive and you can edit files the code.pi file on them on the Master rich device there just like a USB drive would so circuit Python. That's what it is basically These is oh if you want to support me you can do that indirectly by supporting Adafruit They pay me to do these streams By going to Adafruit.com and purchasing stuff there if you want to chat with me and a lot of others outside the Bounds of a stream were always available on the Adafruit discord server, which you can join by going to the URL adafru.it slash discord and So that's discord. This is a deep dive It happens nearly every week. I took last week off. It's normally Fridays at 2 p.m. Pacific, which is this time But it's occasionally shifted to Thursdays at 2 p.m. If I want to do it, but not on Friday I typically typically goes for two hours more and questions are welcome So feel free to ask me questions. We've had lots of really good topics come up Thank you or from From questions from the audience. So thank you to everybody who's asked questions Unexpected makers board is the feather s2 unexpected maker feather s2 is on the circuit python org slash downloads page Thank You doctor. I used to warn about the cat being epileptic, but he's been doing so good I think I'm gonna actually take that off my off my list here Hello to ship you hello Simon Simon asks how my break was it was really good We did a quick trip down to South Carolina to see a friend the weather is beautiful got the worst shorts Yeah, it was just it was very pleasant Good to take a break Hello from Sweden. I started watching you from your one-minute videos and got pretty interested. Would you please explain the topic? Yeah, so these this will not be a one-minute video. This is more going to be about a two-hour video but it is Going to deep dives are all about the low-level stuff that I'm working on for circuit python Today, we're going to take a look at continue looking at the low-level bits of the raspberry pi Not the pi pico, but actually the like proper raspberry pi They are more complicated systems on a chip and We're gonna take a look at those I'm actually I think I'll open the window here because I'm already starting to get hot and Hey, we just started But yeah, so we're specifically I want to show off the SVD files which are these system view descriptions and then We'll also talk about interrupts A asks what education courses did you go to to get to this point? So my background for those of you who are new or haven't heard this is I went to I started learning programming in 2002 I was self-taught based on a book and then I went to the university I went to the University of Washington for four years got a computer engineering degree there I worked at Google for six years after that and then I took a year off to do my own thing Which was embedded programming for drones. So I did Board design and porting some open source software to work on the drone Yeah, go Huskies and then that was I left Google in 2015 2016. I joined Adafruit and they had Micro-Python on their radar, but Micro-Python did not run on their their main chip that they used in a lot of their stuff and they hired me to do that and That grew into circuit Python and we've been doing that for five years now Which is super exciting it's come a long way and now we're trying to bring circuit Python to the Raspberry Pi First, let me open my window. I think I might have enough cable to do it without It's fall now. So I don't know like I Can usually get away with the window being closed But then again, I get all amped up for for these streams Okay So let me let me just get caught up on the discord here Um Thanks for the links. Hello JP Constantinow Hi, ask Patrick a Big Adafruit box with all the circuit Python posters. That's awesome Yay for interrupts The cat in the cat cam he is you can kind of see his reflection. He's like between the cardboard thing in the window He's just a got him from a shelter or a rescue place not from a shelter Do I miss working on drones not at all an expected maker asked me that um I Was not a huge fan of the community that we had around the drones. It's a lot of a lot of men a lot of dudes and What I discovered by by doing all of the the drone work was that I liked embedded it wasn't it was it was less so the Less so the drone part and more because drones to fly drones You need a lot of space and I live in the city and that's kind of hard to come by But I discovered that I really liked embedded work So that that was really good but and and designing boards and stuff was really fun, too Which I do occasionally well actually I think I got the overhead working so we'll talk about a board. I just designed Which I do kind of on my on my in my spare time Linux 203 asks was the chip you ported the CMD 21? Yes, exactly. That was the chip that I ported micro Python 2 Yeah, so the the very first thing we started with was like a pretty large project For that but I was so excited about it that I Got the basics going pretty quickly Keith II says board design is something I need to give a shot at where would you recommend starting for board design? um key cad obviously and key cad is an open-source e-cad so electronic computer aided design drafting design program that I use and Recommends for there's two stages to board layout There's like schematics and then once you have schematics you can do the PCB layout Which is like how you actually draw the traces on the board? Yeah, I contextual electronics has has videos of key cad And then Oshpark is my go-to for how you get it How do you get it manufactured? Oshpark charges $5 a square inch For three copies of For three copies of the board that you're making and there's links in the discord. Thank you folks for for linking to things But yeah, I I think it's really fun. It's really fun to cut like in the end end up with something physical Because I I spend all my my time in the software world. That's cool to have some things that I actually did. Hi, Paul Hi, Redford I Did have a good break although it was a pretty busy travel weekend Another question in terms of salary versus work joy didn't Google meet your needs Google Should be a great work workplace. It is I was there almost six full years and I worked on Google Maps, but I The the teams around maps were changing and the things that they wanted me to work on were things I wasn't particularly interested in and I didn't like working kind of in the black hole that is Google, right like You see me now. I'm like doing these streams. Like that's not something I I would be able to do if I was at Google I can talk about like pretty much everything I know now But when I'm at Google, it's kind of a like you need to know all these really detailed things that I can't tell you in order to just understand what I'm working on so It was time for me to look for something else and Adafruit's been a wonderful place for me to be able to actually like Work in the open and talk about the stuff we're doing and have a lot of influence over what we're doing and how we're doing it and all that stuff so Teach me PCB. Oh Yeah, there's a class for it. Yeah, starting small is good. I Do say key cad and I think the creator of key cad says key cad, but kai cat is also a popular pronunciation Yeah, I learned a lot from watching Adafruit videos That's part of the way that I got into working for Adafruit in the first place Doctor asks, what do you feel is the most important thing you learned while at Google? That's a good question. I feel like the things that I came away with After being at Google worthy like There are very few places that have that much code and that many users Right like I in particular was working on the server that like serves up the the map tile data And so we're really like we were kind of a critical service that like a lot a lot a lot of people used so seeing how they handle Upgrades and changing things and just day-to-day maintenance is just something that You can't get everywhere and then being in a large organization with a lot of code you also you work in his team so you have a lot of people around you who are more knowledgeable and you learn for them and You can also see like the policies that are that have been put in place to make like a lot of people working in the same code base sustainable and not Not too terrible Keithy says, how did you start getting surface mount parts? It seems like a steep investment if you're just trying to start and I I've kind of always done 0603 surface mount parts and then when you design your PCB You could do hand soldering footprints and that's generally just means that the The pads on the PCB are larger so it's easier to just use a soldering iron I've thought about doing the toaster oven thing, but I've just like I tried to do my own Which was a mistake, but generally you can handle several a lot of stuff even if it's surface mount The one thing that's really hard to do surface mount With that The hard thing to surface mount with an iron is anything with a pad and all completely underneath But it's actually like not that common So I think I think more people would be I think people would be better off doing more surface mount than they think they can Because it's really not too bad. Of course, I have pretty good eyes and I'm pretty young So I don't have like too many dexterity challenges But generally I think it's actually Better. Yeah, and flux is good flux is it's a flux is a Compound like a liquid that cleans the joint and makes solder flow smoother around the joint Sotter on its own won't kind of like Flow you need to flux so even when you have a wire of solder like it's got flux in it to make it move But sometimes that flux in the wire is not enough so you need like extra stuff Um a Asks I can see a soldering station behind you. Do you learn to solder at the computer education? I did not I Kind of wish I did I actually it was Definitely one of the hurdles that it took me some time to get over I The very first thing that I designed that I needed soldered was like some headers And I like went to a makerspace and paid them to solder them for me The soldering is not as hard as it can seem if you've not done it before There are some really good tutorials, I know Collins made some really good videos about soldering It's good to start just with pin headers so like pin headers are like Here so on something like this Let me change the camera mode. So so this is a pico, right? and If I were to get into soldering like what I would start Practicing with it just like pin headers so like these are pin headers And so there is little holes in the board that you'll get and what you'll do is you'll use a breadboard to just sit The headers in and then have the board on it So it won't move around and then what you do is you kind of like put your iron like in the corner Between like so that's touching the pad and the pin and then you'll touch that joint with the solder And it should like kind of suck into the joint if if the temperatures right and stuff If it doesn't kind of flow like that then you're doing your temperatures probably too low But pin headers are a great way to just get some practice with soldering And then it gets kind of more detailed from there But there are pretty good inexpensive soldering setups that you can start with this one is not inexpensive It's a bit fancier But that won't matter until you have some practice Dylan says I thought I was terrible at soldering until I bought a better iron with temp control Yep, should there be opportunities to learn soldering in a CPE degree. I don't know what you mean by CPE computer engineering I Was kind of surprised that I didn't do it like PCB design seems like fun and Something we should have done in school. I took a couple electrical engineering classes, but didn't actually do PCB design Starting with tacking the far corners of pin headers is really helpful to you get the outside bits then work to the middle of the line Oh, yeah, so a general rule for Soldering is it the first solder joint you do for anything. That's the one that's gonna Dictate the position. So if you're doing a whole line of pins Do one and make sure that it's lined up like it could be crooked But if it's if it's crooked what I would do is just put your iron back You'll smelt the solder again and then make sure that it's straight and then let then Take the iron off let the solder salt solidify and then double check that it's in the position you want That works for other surface mount things as well So like always make sure that after the first joint you do for something. It's where you want it But once you have it there on that first joint, then it's easier to to do that and folks are pointing out that microscopes and Like eyeglasses things can make it easier to Who did you recommend watching regarding soldering didn't get that so in the a different channel one of the other folks That works for a different has done some soldering videos So just look in the Adafruit like just under Adafruit look for soldering. There's gonna there's they'll be good stuff there This ship who says next week. We're going to run a soldering workshop at the local University and also circuit Python programming That's awesome. Oh, yeah smart pants 28 says SMD is an art in itself I've tried with dot stars law nightmare for me. Yeah, so dot stars are definitely one of the more difficult things to solder Hands-otter Neopixels are kind of tricky too They're definitely not the things I recommend starting with Largely because Some surface mount things like the pins will actually kind of like come out and that me that means it's easier to like touch it with your iron But if that's not true In the case of like dot stars you you kind of have to like get it up against the side of the thing and you can risk melting it But even when I melt the things it tends to work still so you'll figure it out I Think it's worth it. Don't don't be scared of it. Get yourself a You know hundred dollar iron or less and and start from there. Just do it especially pin headers pin headers are really easy to start with That'll get you used to like how the solder flows and stuff Okay, so since we're talking about boards, why don't we start with that? So let me Switch to the overhead and just show the board I designed. Did I talk about this before on the thing? I'm not sure Let's Switch to the overhead. Hopefully it's still working It is And I'll just it's warm So here's the the board that we're working on So this is the let me hit the walk See what people are saying you mentioned the board, but you hadn't received it yet. Thanks DCV Check with your local hacker space, I'm sure they can run something yeah My first SMD project used paste and regular iron the pace made it easier. Yeah, so I Think pace can actually be kind of hard because if you if you have to position the part you might actually smear the paste more places But if you are soldering something that has multiple joints, you can put the solder on the first spot before Before you put the part there and there's like you can move the part onto there once it's liquid So this is the raspberry pi CM4 IO board. It's just a little bit too big for how high I have it But that's like there's a little bit of a power section here That will just have off-screen. So this is the the CM4. This is the CM4 compute module for right So this is like all the stuff that is on a raspberry pi 4 but on a module So there's connectors under here that set down sit down on this board and then it breaks out all the things So like here's the SD card that has all of the software on it This is USB, and this is a USB device here. This is ethernet to HDMI's And then this is like screens and camera connectors that I'm not using But what what is here is the normal 40 pin raspberry pi header So I designed this board and I have More copies of it that I haven't soldered together that I haven't assembled So what it is is it's the 40 pin header and basically it's it's wiring up all these connections So that I don't have to do it every time. So there's a JTAG header Which is both JTAG and this SWD. It's it's the SWD form factor, but it's still JTAG Wiring it's just in the different thing and then so that's so that you can use a debugger to connect directly to the raspberry pi core There's a STEMI QT that I haven't tested yet. There's these six pins for the UART So what you can do is I've got this I've got this USB to UART converter here, and I just have it so that the pinout matches exactly So all I have to do it like there would be a USB cable plugged in here, but I can just plug that in and now I've got my like Debug your output directly going to the USB which is cool and Then what I did is because I was debugging by blinking LEDs. I just added four LEDs to it. So these are four three millimeter round LEDs that you can buy off Adafruit and these are four resistors These are all 1k resistors. They're not that you don't really like 1k is kind of the highest value. I think But these are in series with the LEDs So LEDs won't restrict current on their own. So you need to have a resistor along the same kind of wire and So that's what these resistors are for these are just the current limiting resistors for the for the LEDs And then this header here this five It's it's a ground and then it's the four lines that are also connected to the LED So this is like if you want to use a salient to like measure your blinks You can do that And then yeah, this is the chickadee that I logo that I designed back when I was doing the flight controller stuff I still like to put it on Yeah Lady Aida just asked me if if she wanted to join the stream. So maybe maybe she'll drop by later Okay, so this is Yeah, so this is the board I did I haven't tested everything. I've been you I've been using it So a lot of it does work. I haven't tested the I squared C Cuz I haven't I don't have I squared C working yet And I haven't actually tested the JTAG connector because it was too far away I Got like an extra length of cable by just using the SWD instead which worked So yeah, if you want to buy a copy of this and then assemble it yourself You can get it off Oshpark right now. I think it's about $30 It's not super cheap because it's kind of a large board. Maybe it's not 30 Oh, you know what? I think it was 30 because I got it rush But it's probably 15 if you if you're willing to wait a little bit longer So I think I can just let's just pull it up I will switch Just a second So here's my project history and you can see like I Have a lot of different boards that I was experimenting with But I can copy this Guest tease. Yeah, no promises. She just pinged me in ass It's been a while since we've had Lady on the show so Lady Ada on the show So I'll always take her up on it if she wants to She probably wants to see how far how much progress I've been Dexter says could you use the board with raspberry? OS yes, you could yeah, so it's just like one particular pinout of the connector I'm not sure I think you can debug Linux I Think you can debug Linux even if it's on if it's running. I assume we can I've just never done it There is some like settings that you have to put in your config.txt to get the JTAG pins SmartyPants says is Oshpark very expensive even with larger quantities Oshpark has a medium service But I tend to suggest like PCB shopper Like they have The four their four-layer service six-layer service and this bulk order Volume discount for prototype and four-layer 40% price reduction I think of them more as prototyping. There's also PCB shopper.com. I think it's a pretty good like comparison shopping in terms of pricing Here's another fun fact that I think According to Drew, I'm the person that inspired this after dark The after dark version of Oshpark, I think I can take credit for that. So if you look at my Take my website still up. Yeah, this is like I'm not doing my drone stuff anymore Yeah, so here's a picture of one of my boards, this is kind of an ugly version this is a four-layer board and It couldn't do the black FR4 or this is a weird version of the black FR4 Oh Yes, but here you can see this Style which Oshpark now makes available is after dark what it is is that the core fiberglass of the PCB is dyed black and then the The solder paste or not the solder paste solder mask on top is clear And so you can see the copper of all the traces on the board And then the places that don't have the solder mask are end up getting plated gold The only way Lady Aiden knows what you've been up to is to watch your streams I mean, we do have internal meetings, but I We have a circuit by the meeting on Monday that I missed because I was out on Monday I Think there are convict settings to boot in a debug mode for most distros. Yeah, I don't know I haven't tried using it with Linux Stuff, but there's no reason it like there's nothing fundamental about the thing like the pinout for the I squared C For example is the same so it should just work, but I haven't tried it Okay, so that's the board I Think I've made a lot of progress. It's been two weeks and I've been pretty like sucked into this Which is bad for the blue the blue two stuff, but good for my productivity Smarty Pamp says is troubleshooting the four-layer board difficult for example if there's issues with the tracing Generally, generally with a four-layer board. What you'll do is the two inner layers you'll use for power only Which means that your signals are still on the outside So if you have to have to have to do something to the signals you still can I did have a bit of an issue with one of my designs when I was doing the drone stuff where the I had updated all of the copper layers, but the the where the drills was wasn't updated And so I ended up like connecting two parts that I shouldn't have So yeah, that was not good Yeah, so there's this repo here. I don't know if I've shown this so Did I talk about this peripheral stuff So we have this sandy peripherals repo that we did kind of a while back when we added the sandy 51 support This is meant to be like a little bit of an abstraction above the registers That is not specific to circuit pythons, but still like kind of helpful and circuit python uses it So I started working on the same thing here for the Broadcom chips for the Raspberry Pi So if you go to this URL, I'll just dump in the chats So what this is going to be is it's My goal with this is to kind of this is all the stuff to get you to where you would be with like a Cortex-M Like very basic firmware. So it should boot everything for you. It should set up all the interrupts So the way that interrupts work and this is what I've been working on some of my brains there but in Cortex-M generally with the way that interrupts work is All you have to do is define a function called interrupt name underscore handler And it takes no arguments and then that gets called when an interrupt happens And the way that that works is there's some code in the startup stuff that Calls those functions with those names based on what interrupts happen and There's a default implementation which in GCC you can mark as weak Which basically says like only use this version if no other version exists. So You provide a weak version of it that does nothing and then When you want to use it in your like actual code that you're working on you just define it again But don't mark it weak and that will kind of It will override the other one So this This is kind of like meant to do all this convenient stuff One thing that I've been working on a lot is there are these SVD files And what these do is they describe the memory map of everything in a Cortex-M system on a chip usually so Maybe it's worth just talking Let's just pull up the same D data sheet because we we showed this chart before Let's just take a Week interrupt handlers that's pretty cool. Yeah Let's just recap briefly like what system on chips are and let's we'll do that by Looking at the data sheet here So this is for the sandy 21. So this is what I started working on For a different it's much simpler much much simpler than a lot of other chips. So I'd like to start with it So this is just to get this is not for the Raspberry Pi specifically, but this is to get you in the mindset so This is kind of why they're called socks or a system on a chip There's a CPU and then there's a whole lot of other stuff so Think of if you've ever made a desktop computer, right? You like you plunked the the CPU in that's kind of their their system on chips, too But they're largely just CPU so you can think of that as one bit and then there's like NVM Which is non-volatile memory So this is like your hard drive, right and then you have RAM like your RAM sticks But all of this is incorporated in in microcontrollers and some microprocessors Kind of all on one chip and in fact like the Raspberry Pi these two things are not on the same chip, right? Like you actually have the equivalent of NVM for the Raspberry Pi is your SD card And then you actually have RAM a separate RAM chip external to the CPU or external to the main chip and Then there's this bus and then there's all these different peripherals And I really like to emphasize that people think of these just like you would think about a temperature sensor on an iSquared Z bus This is another piece of electronics that is running separately from your your CPU They might actually be synchronized in the sense that they're using the same clock signal But reality is that they're like relatively independent What's the main difference between a dot SVD versus say a flash to XML? I don't know what flash to XML is so I'd be curious to know SVD is an arm thing specifically and It covers kind of all of these things so Maybe I should just pull up the SVD for a sandy 21 to So what we can see here is there's this like high-speed bus matrix So this is like the way that the CPU talks to a bunch of other stuff So Generally the way that you talk over this is you just it's called memory mapped IO so each of these individual peripherals will have registers that are Sets of state that that cause the peripheral to do something and the way that you read and write to those is through memory mapped IO and so what you get is that You have this chip that has a CPU and RAM and like other memory mapped IOs for peripherals And so you can see that through Is it product mapping? Yeah So this is the memory space So it's a 30 this sandy 21 is a 32-bit system So you have between zero and like all F's and you can see that like at the very highest level They kind of split things into chunks So for example, like here's the chunk where RAM is it starts with a two and all the peripherals Registers are memory mapped Starting at four and then this shows us a okay starting at the four now We have these three bridges here bridge a bridge be in bridge C Which if we go back to the block diagram, we can see here here is light blue is bridge a green is bridge B and Bridge C is this like more Robbins egg blue. So there's like some like control here at this level that's like Looking at those couple bits in the address and deciding between these three things So that's there and then now we can see that they tell us exactly the memory locations So for like if we're looking at bridge C and circum Which is what does I squared C and spy like you can see circum zero is at this address For example, so what the an SVD file could do is it can kind of explain that in a programmatic way that you can then use There's kind of two ways that that's used. It's used It's super useful for debugging so it allows you to like Browse all of the state of the registers and then it can also be used to generate C code and see data structures like structs So by having an SVD file to kind of explain all this stuff It will explain not only where everything is but like all the individual registers and what the values mean as well So maybe let's just let me get my Raspberry Pi back going I wonder if I can Know what I could probably do it under the I can probably actually do it under the overhead. So let me just show that And maybe I'll just back it up. Okay, so how do I have this set up? I had HDMI setup because I do have a display on my desk here, but I'm not using it at all So we don't read really need it I have all these wires. I'm untangling so first up. I've got power so I have it on a switch so I can turn it off and on So I will just plug it on plug it in the switches off And then the only other thing I need is because I'm on a debug it I have a J-link on my desk and I can barely reach so this is going to the J-link here and I'll just plug it in To the SWD. Oh And I also was doing the USB UART so I will plug that like that So this is my debugging setup and let me do Desktop with overhead so here what we have is this is my fancy terminal setup that I've got going and So what do I have here so this left window? I'm using for two things. I'm using it for a running open OCD, which is the thing that Interfaces with the chip itself and then provides like a standard API that GDB can talk to In the right hand corner is GDB So this is where I can inspect stuff and then this is the UART output here So you can see that because I was showing you it disconnected and now reconnected So I already have the the micro SD card in so let's get it started and we'll see it start up And it takes a little while, but we can see we got the debug print output And now what we can do is we can do this open OCD command and it Successfully like connected to the CPU core and now we can control it. So I've actually been doing it a little bit before So let I'll just reconnect and so now it's telling me where I'm at I'm in this. It's checking to see if USB is initialized and I've already loaded this Thing that is awesome and and anybody who does GDB stuff should take a look at it. So there is It's called Pi Cortex MD bug So you can actually run Python like Python is built into GDB So what you can do is you can like hook into GDB and like do extra stuff With Python. So when you run a command it calls some Python code that does some stuff Which is super powerful. So there's this B. Nay Hill Pi Cortex MD bug thing And what it does is it reads SVD files and then makes it easier to browse the register state And I'll show you what I mean So I already did this SVD. You can do SVD load which I already did and I have an alias for called SVD BCM. I'll just do it again. You can see that This is the Broadcom peripherals repo inside of tiny USB and in there you can generate a BCM 2711 LPA dot SVD. So that's an SVD file That has the data for all the peripherals as if when they're in the low peripheral address mode Cortex ASGate more complicated because from the CPU you can have you can move around the registers and the memory and stuff But for now we're this is kind of for the one-to-one mapping of that And that's I think probably the last thing we talked about because I remember we got it working at the end of the last stream So what I can do now is now that I've loaded the SVD info I can just type SVD and And now we can take a start taking a look at some of the stuff that I've already defined So there's this VC mailbox thing. This is how The CPU code talks to the GPU code on the Raspberry Pi And that's important because power stuff for example turning on the USB power to the USB peripheral is Controlled from the GPU so That's one example so we can do SVD VC mailbox And now we can take a look at like all of the registers and their state for the particular thing And if you do this slash X it'll do it as hex rather than this decimal So we can go back to SVD and we can see start to see the things that I've defined I have this GPIO one. We have a UART zero We have the LIC which is just this legacy interrupt controller that I'll add more to later Right now. It's really basic And then GIC is this generic interrupt controller. This is the new thing for the Pi 4 and where I'm like really looking at right now because it it's How you get interrupts, which is the next which is the thing I'm working on But then you can see there's like three different USB things and then there's also more UARTs So we could just say like UART 5 And we can see all the registers And I actually copied this. This is a standard UART from ARM And so I just found another microcontroller that actually had the same UART. So I just copied all of that those definitions there I Wasn't able to do this for the generic interrupt controller So I've done more work on that myself. So if we just look at the GIC dist This is the distributor part of the Actually, let's make it wider This is the distributor part of the interrupt controller and They do have it. I have a lot of tabs open So it is publicly documented in a couple ways there's The specific controller I have Open here. So this is the ARM documentation for the GIC 400 and It will tell you like What all the registers are So you can see that like here's the names of the registers the description Whether they're read only read write and what the offsets are So I took all this stuff and I copied it and moved it into the SVD file So that what I can do is I can just use this Pi Cortex MD bug thing to print out the value of all the registers And then what I can do is here like oh this this register has something besides non-zero So the this is this the status register And so I can do something like this and now I can see that For these interrupts we I can see whether they're active or not So the USB interrupt is active multi-core sync 3 is active and nothing else is active So I had to I had to do non-trivial amount of work to just get that listed and Then a lot of these peripherals actually have registers that just have fixed values as IDs and so that's what these PIDR and CIDR registers are is that I set it up so that They know what the value should be and they can tell you that it's valid Gordy asks what tiling manager are you using I'm just using console And it's just the the console stuff. I'm not using like a Separate tiling manager at all. It's just like the terminal on KDE And then there's also these clusters So I did these as clusters because there's a lot of state that you maintain for every incoming Interrupt so maybe I should talk more broadly about what interrupts are since I've gotten into the weeds So let's pull up the BCM Arm peripherals thing and this is the obviously I had this graphic pulled up. It's really helpful So if you've ever done like a an I squared C sensor, it's not uncommon to see an IR Q-line for that and that's just a It's an individual pin that just says when this pin is low There's something There's some reason that we we wanted to interrupt you and we wanted to let you know that thing that you wanted to know When happened did happen and that's like the most generic kind of Way to talk about interrupts is like they're literally their intention is to actually Stop what CPU is doing and have the CPU do something else and How quickly that happens and at what priority and blah blah blah is complicated But the idea just being that like if this thing goes low Then we want to interrupt and we want the CPU to say like oh, I gotta go do this thing for a little while And then I'll go back to what I was doing and so all of the peripherals on the chip and Have these wires In this case, they're all wires that are running to this like central place That's managing which one of these wires We actually want to pay attention to and at what priority and things like that. So it gives them these IDs so like the VC peripheral IR Q's are all between IDs 96 and a hundred and fifty nine and They're defined here So here's all of the video core interrupts And you can see what they are and so I listed all these out in that repo for example So if you don't have to copy this now, there's a Python file that has a list of all this stuff But that's what then generates the SVD file that says like this particular Register for interrupts is for this particular interrupt on this on this chip Which is really handy for just debugging to see like oh is like how far is the USB interrupt getting? because The highest of my goals right now is to get the USB examples working from tiny USB and in order to do that I have to get USB working I have to get USB interrupts working so like the host computer will send a thing and that will Trigger the CPU to be like hey like the host computer is asking you something like we've got to do some of this So yeah interrupts are a way for for external kind of devices Like peripherals to to let the CPU know that something happened So it's up to the CPU to say like I care when this thing happened And there's kind of like all these stages along that way to like tell things that you care about it So like the peripheral itself has to say that It has to know that you care and then that will basically cause the signal to leave the peripheral And then that will go somewhere else and you have to like tell it as well that you care about it And then generally there's a switch as well so Yeah interrupt request IRQ one thing that threw me off when I first looked at this is that there's PPI and SPI I was like, okay great. We need we need SPI as a We need SPI as an acronym in this case because you know that wouldn't be confusing to anyone at all It's an arm from what I can tell it's an arm terminology thing. So PPI is a private peripheral interrupt. I think the middle P is peripheral and the private means that it's a Specific to the individual CPU core So one thing that's more complicated about the Raspberry Pi chips is or these Broadcom chips is that they have multiple CPU cores Up until now all of all the things well, that's not true The RP2040 has two cores, but we only use one of them And it's got two copies of the interrupt stuff But basically if you have more than one core you have to worry about who's going to handle an interrupt And So that's added complexity here. So these private peripheral interrupts are interrupts that are specific to a single core They're kind of like independently done Whereas this SPI is shared peripheral interrupt Meaning that once one core handles it the other cores won't see it as pending anymore So so generally what happens is that a signal from the peripheral comes in and the controller The interrupt controller says okay, that's pending I see that that interrupts coming and then it goes from pending to active when the CPU is actually working on the interrupts actually responding to it and then After it's finished you can either go to active again or it could be pending again or it could be Inactive or it could be pending Because it's possible that as you were handling an interrupt the interrupt came in again And so that would be like a case where it's both you're working on it and it happened again So when you stop working on it the first time it's still pending the second time So, yeah, it's kind of complicated Interrupts are kind of complicated But this is something that it's interesting because Circuit Python doesn't expose this directly to User code and this is something that we've heard time and time again that people want But one thing you want to make sure of is that If you're in an interrupt lower priority interrupts don't get handled There's a notion of like what what is the highest priority? And so you always want to make sure that your interrupt handlers are really fast So that both you can get back to the work that you were doing and other interrupts can be handled Keith says do you think the existence of shared peripheral interrupts being something you need to address here will drive more Multiprocessing focused work in circuit Python core or is this enough of a subset of kinds of tasks that you can address? This is without needing to solve multiprocessing. I don't think we need to hand solve multiprocessing at this point I think that you can I think we can just treat it as like we're only going to route stuff to the first core and in fact I started actually writing some code that turns on and Interrupts and I made it turn if you call enable interrupt it will automatically say enable it for the core that that called it So yeah, I'm not getting in the multi-core stuff yet It's just it's gonna be a lot of work It's it's really interesting for me to learn how Cross-core stuff is managed though So like this one thing that I haven't seen in the so the interrupt controller on the Cortex-M stuff is typically the nested vector interrupt controller the NVIC And I haven't seen it having software generated interrupts, but this does So the GIC 400 has software generated interrupts So you could have one core write a register on the interrupt controller saying turn on this interrupt This numbered software interrupt and then you can have another core get interrupted as a result of that Which is pretty neat. There's all sorts of different ways of talking between cores SmartyPath says do you need to set up delays for interrupts? No, I don't think we have any sort of delays that we need to do One of the tricky things as far as I can tell I haven't gotten this working yet So it's not entirely sure that it's right One thing that the interrupt controller on the Cortex-N's the NVIC will do is it will automatically Kind of store all of the register state for you and then call into your code And then restore all of the register state after but that's not the case I don't think for these Cortex-A level stuff So there's some initial code that I copied from one of the OS Tutorials for Raspberry Pi that just like stores all the register state So, you know one of the delays that happens with registers is just what's called context switching Like you're storing all the relevant state Before you change it and then restoring it as you're after you're done It's called kind of a context switch and that can take time Good night doctor. Thanks for hanging out. Yeah, it's just the Sun's gonna go down earlier and earlier. So Yeah Okay, so what do I have? I'm assuming at some point we'll we'll chat with Lady 8 of it Before then I Mean she might have other stuff come up, too So I've done a lot of work on the SVD file, which is really helpful for debugging It also generates a header a giant giant giant header file. So let's just show that so it's this SV I'm calling it Broadcom Jan and then the header file. It's just as the just this giant file That's actually generated with a program from ARM Oh Benjamin's asking can you even have delays inside of an interrupt you can but you generally don't want to because it It If you have delays inside of an interrupt you you're you're blocking Everything lower priority from running right? So if you get that interrupt again, for example, it won't be handled It'll be ignored. So so like the interrupt controller if an interrupt happens multiple times, but you don't service it It just knows it happened once So there's a risk that you lose resolution on your interrupts But then also like interrupts have priority. So if you're doing something high priority and you delay nothing else can happen Including like the code the code that's not in an interrupt at all won't run either and This is like the basic Microcontroller model of the world. There's like more complicated things you could do with interrupts as well So here's the generated file. This is generated by SVD conv that you can get from the Simpsons repository for ARM One thing it does is it pulls out all of the interrupt numbers? Which is quite cool And in fact, I what I didn't say yet is that I'm actually using Jinja So Jinja is a Python templating system So instead of having one big long SVD file all written I use Python to generate the root the final one So here's the top level of it. It's got The the top level information about what board it is But then it uses Jinja macros to Fill in all the in all of the individual peripherals. So in order to have like you are Two and three and four and five. I'm actually just there's a SVD thing for saying it's derived from something else But this is how I'm like pushing or this is how I'm like piecing it all together So for an individual thing, I've got this like okay. Here's the GPIO dot SVD dot Jinja thing so To instantiate it you give it the name that you actually want and the base address So this should make it easy to generate different SVD files for different like memory layout static memory layouts that you that you want to do Bruce says I've had very small delays in interrupt routines where we had some hardware issues, but not normally done as Scott said Yeah, generally you want to do it pretty quickly. So for example the inner the USB interrupt what it does is it it generally just Adds an event to a queue that then gets processed later So the only thing that's really happening during the interrupt is just like queuing up some more work that'll be done outside the interrupt So here for example just this is not I'm abusing there's a Jinja Jinja HTML syntax that makes it easier to see So this is you can see here's the macro. So if it's if it's curly brace Percent sign, then it's like a It's a control flow thing if it's just two curly braces. It's kind of just like replace this area So you can see here that I'm like taking the base address formatting it and then replacing it there I'm putting in the interrupts and I have the interrupt offset set. So this is the offset like into the VC Range of interrupts and Then I'm using like you can do in Jinja. You can do for loops and stuff. So I also have I Did a lot of work for the GPIOs so that there's a thing called alternate functions Which is like what thing inside the SOC is actually controlling the output and so I have it generating Like nice names for all the different alternate functions as well So yeah individual files individual files here for the different peripherals and then a top-level one that kind of Brings it all together and then when you generate it you get this giant SVD file Which is this and it's 40,000 lines long Something like that and it this is like individual fields within a register and description and how big it is and all that stuff goes in Here so it's a giant file. That's not very fun to do and then what you can do from there is you can generate this thing a nice lightweight summary Hopefully So one thing it does is it creates this enum of all the interrupts numbers, which is really handy So if you wanted to just reference the like your interrupt you could just say your IRQN And then it does all of these That's a boilerplate, but it does all of these giant structs So like this is This is a single register and this register has this many fields And so it generates all of these C structs. It allows you to say like Perferal arrow register dot something and you can like set a particular bit or you can read the whole thing And that's just like a lot a lot a lot of that Somewhere in here So it has all of the base addresses for everything and then it casts those addresses to The struct types that represent them so you can in your c code You could do just like GPIO arrow and and that's how you're like interacting with this struct type And then lastly you also get like all of these bit masks of like Exactly what position and mask like all of this data in a particular register is Just a lot of boilerplate generated code There's some more enums just like tons of stuff like 17,000 lines But yeah all meant to like both make it easy to interact with registers from C But also to use the SVD thing in GDP to understand like the state of everything So that's all the SVD work now Though I did the GPIO alternate function stuff I brought in the USB stuff and like had to reorganize it some and now I'm on I'm trying to get the the interrupts working I think so I got I got to the point where if we see Like here we can see these are these three init statements are initialization statements from tiny USB And then if we look where we are here, we're actually past the initialization of the USB peripheral so I I We got memory mapping working and then the next step was to get the I Was it was trying to reset the USB device and that wasn't working And the reason that wasn't working is because it wasn't powered on and so I had to do the VC mailbox stuff So I have a Quick function I did in here Called Get power state and set power state so you can say like hey set the USB device to on and USB devices Let's find in this generated file Which I have another Python script to do to generate this stuff from So yeah, so I've I think I'm correctly starting the USB device But I don't have the interrupts coming from it yet, so it won't really be able to make any progress Because it won't be able to tell us like hey time to time to like something happened. Take a look And so the next step is to to get into the interrupt handler and how does that work? Well in assembly So here's all the startup code This is the Loading the vector table so the vector table is a like if these exceptions happen call this functions BSS is the zero place and then we go to main So the So this is what I was talking about saving state during an interrupt So there's this macro called IRQ enter so it saves all of the register states To the stack exit does the reverse it loads it off the stack and then returns And we have this exception vector thing Which I should actually check This EO one IRQ Yes, that should be I don't know what the difference between EO one T and EO one H is Hmm. I should double-check this although All of these all of these things that are set up are alias to this how it handle invalid entry So this is how we were like debugging. I was debugging some crashes Is that it ends up in this invalid entry because this invalid entry It saves some state to registers after doing the initial thing and then it just hangs And that was working Hi G3 holiday Yeah, so I Think these vectors are set up correctly because we were having some synchronous faults come in here those are the things that like if you read the wrong memory or set something up wrong or like Something air errors out like it's it's the equivalent of like a hard fault handler in Cortex M world We're like you try to divide by zero Or load zero things like that So this should work I think But it doesn't So what what so this is the top-level table that the CPU looks at when an exception happens These are different types of exceptions that happen. One of them is the IRQ exception, which then Should go to this branch and link to handle IRQ Which is in here. It's also weak Which I mean maybe there's a small chance we have a separate handle or a queue Like that looks right because it's got our break in it Um So I don't think that's wrong either But basically what once we could get to this handle IRQ we can then read from the interrupt controller Hey, what interrupts caused me and then we can call out to the one ah H is for handler T is for thread. Thank you Andrew Should work, but doesn't I know right? I mean the MMU thing was just the access bit like Yeah, so just figuring out like exactly how the bit should be So basically what I'm trying to do is I'm trying to get here and then hit a breakpoint just to show that I managed to get there So what I was doing before I Took a break before the stream and had lunch was trying to use the SVD to make sure that I set all the bits I thought I should have So What I didn't check was the USB so if we look here There's this interrupt register So, I mean I assume that so it like interrupts start from This is what is interesting. So generally what will happen is that there's a lot of signals in the in the peripheral itself and then it masks which ones it should pay attention to and Then if any of the ones that it wants to pay attention to or set then it will have one line go out of the peripheral To the interrupt controller. So reading by reading this register. I can see which of the Which of the the internal signals to the peripheral actually caused it So that's that I Don't know these red this register mapping very well There is an a device version that we can look at too It's not working quite right So it has control and status. Oh It does have interrupts as well each endpoint interrupt register and register mask So like each USB endpoint has interrupts as well. I don't think I should be I shouldn't I don't think I should have to manage this I I I'm hoping that USB will just manage tiny USB will manage it for me because this is an existing peripheral that it's already Already works on STM chips that have the same peripheral So the next thing kind of down the line is the interrupt controller and that's specifically the distributor So if we look here, and then we look at the interrupt the line Like we did a little bit earlier We can see here that like USB is active So it is the peripheral is saying I'm active Assuming one thing I should maybe triple check is that this number is correct like this mapping is correct I mean, I believe it. I believe that USB is active, but it's possible that like I'm not correctly designated Correctly designating these things Which is possible But I don't know so that's one thing to check there's another thing to check which is just the control register Is it on at all? CTLR so like group one right group zero interrupts are set If I try to look at the group so these are clusters. So there's just a lot of them I'm not sure what group it's in. Maybe it's in two But I do have it Matt, I didn't hear shortly USB group zero should be fine Everything's just group zero and then we can check if it's enabled. I think it is Yeah, USB is enabled there So it goes from the distributor and then it goes out to the CPU interface Doesn't work. It shouldn't be active, but it should be pending. We can trick check that Do-do oh Yeah, you probably won't be able to see me. I cannot hear you Are you muted? I'm saying I'm seeing a hmm. It's worked before I Still see the mute I got next to you. I don't know why that is can't unmute Oh No We could try it on slack. We could have Lady Aida do maker shades Does it show you as muted? Like I'm not marked as streaming. Oh Yeah, try crew. I'm not reading the discord chat quite yet We're doing a role play this sort of every meeting Okay, I think this is fine now. Yeah, I can hear you now We're Firefox is like it's like you have a mic it sees the mic, but it's still but it still doesn't work Yeah, all right. What's going on? What's going on? Are you what are you doing? I'm trying to get interrupts working on the Cortex m8 a8 on the the BCM 2711 What's working so far? Let's see this whole saga I had to get the tool chain going so using the AR version of GCC and Then I had to get then I wanted to use the standard library Which is compiled for unaligned accesses in order to support that I had to get the Had to get the MMU setup Because once the MMU is set up or by default the MMU is set up so that you treat everything everything like a register Which means that any unaligned accesses it doesn't like So we got that working two weeks ago on the stream There was a bit that I needed to set that I didn't realize I needed to set and then it worked Which is pretty awesome So it just maps the like the virtual addresses straight over to the physical addresses Which is of course a new topic coming from Coming from the world of Cortex M where they don't have virtual memory Addresses address you want to read? I know right? We'll let you go for it go to town. Yeah So getting the MMU going was good And then like once I did like once I could do that I could get sterling Sterling string length working, which meant I could do print debugging It's out a you art because I can measure how long the strings were And So that's working I have that Debug working and then I can blink LEDs with that too. And like I felt pretty good once I Felt pretty good once I got that And so I kind of stepped back and did the like broadcom peripherals repo Which has now has an SVD file which allows you to do like header files and Some GDP integrations, which was really nice So I was showing that in the stream earlier today and a Tiny USB so so the whole like I'm trying to get the tiny USB like CDC mass storage example going And the next hurdle for that was that I was Tiny USB was trying to reset the USB peripheral But it was never coming out of reset like you'd write the one to the bit And then it would never get cleared because it was never resetting and so I had to add support for the Video core mailbox, which is like telling the GPU like hey do this thing for me meaning Turning on the power to the USB peripheral and then once I did that it got all the way through all of the init stuff and So now that I'm not the point I'm at now is it's it's just looping seeing like if the USB is connected And so I know that I'll have to hook up interrupts from the USB peripheral. So that's what I've been working on And like fingers crossed once it or has to work. We can actually see stuff over USB Is there any examples out there from you know low level code for they can we use or is it you're kind of I've been picking manual. I've been picking stuff up here and there There are some like relatively good tutorials for like oh you want to make an OS by yourself on Raspberry Pi Here's kind of how you do it I don't think a lot of those are coming from the like microcontroller world like I am So like I really do want to treat it like a micro and like they don't necessarily do all the legwork to do that Yeah, so that's largely what this whole Broadcom peripherals repos for is to like really treat it Like to lay all the foundation so you can treat it like a Cortex M So I was talking about like you know how in Cortex M Usually to to do an interrupt you like define the handler for it and then it just gets called so like trying to figure out Like I have to I have to write the code to like do that in the peripheral thing And then we'll be able to just say USB handler calls the tiny USB handler thing and and often away it goes. Hopefully All right, cool. Yeah, so I mean it's been like slow and steady progress on the stuff like I've been letting you know like I'm not hitting too many walls. I'm just hitting a lot of hurdles that I am getting over Yeah, you have to you have to do the implementation Yeah, and like a lot of reading and a lot of learning about like how just like the complexities that come with like there's four cores And like what does it what do interrupts mean in a world where you have multiple cores that can do those interrupts and things like that so It's been it's been a lot of fun and I'm still digging through it and trying to get that stuff 2231 puppy is Show or asking about low-level develop on YouTube. I I did see that It's a yeah, I'm trying to do a bit more software engineering than a lot of the tutorials have So like once I get it interrupts going like I'm hoping interrupts work for everything Whereas like some tutorials might just have like one simple piece of the bigger puzzle Yeah, how are you? Just finished up the state of the fruit. I'm gonna test out Jebler's camera code and I just have a ton of email to do some kind of an email land So you're like let me go on Scott's dream and said so I don't have to do all my email Well, I have to take a break cuz my my brain starts getting frazzled because it's like you email for like 45 minutes And I'm like I need a break, but I thought I would just check in wanting to see I haven't been in for so long I was like I should say I do have to go because I did our time, but I Did want to come by and just I was like you're doing this thing and I was like, where are you? I don't know. I should go check it out. Yeah, they were Earlier when I said you would stop by people were like is that how Lady Aida knows what you're working on is just by watching your stream And it's like, yeah, basically Well, you know that and that and then the weekly meetings and I look at the commits and everything I see every commit that goes by so I kind of know what people are looking on right Yeah, and I think I've been pretty good about pushing to that broadcom peripherals repo now Yeah, I don't want to lose that's part of it Yeah, for sure. I mean like that's another thing. It's like how do you make it to get the whole workflow toolchain for for deploying to this kind of chip? It's it's a lot different than a microcontroller, you know, yeah, just super nice Yeah, I'd like to I'd like to do like a Get in the Raspberry Pi imager at some point which would be pretty neat Yeah, I think it'd be interesting. I mean, I think another thing is, you know, there's probably other people who are interested in You know working on on that low level Raspberry Pi stuff I don't know if in the pi forms people have chatted about it and because it's like the peripherals library is useful for multiple things Yeah, there's some pretty good resources there and I one of the reasons I wanted to go kind of the SVD route as well as because I know the rust people do a lot of tooling on top of SVD files It's like all the rust embedded people like they automatically generate like a bunch of s or a bunch of rust code based on that stuff So I was like this will be helpful for more than just me if we have these SVD files Totally. Yeah, I think that's I think that's part of what you're learning right every time. It's a new platform You're like exposed to it's like they made decisions and they made decisions for a good reason, right? You just have to figure out and figure out why why did they make those decisions? I think that's I think that's something that you know, you're you're really good at you're never like Oh, they did something in it stupid. You're like they did something and there's a reason for it I just have to figure out How why are they doing it and then I can analyze how to? Interface with like their their decision process like it's it's all engineering's about trade-offs And so I think you you know that the hardest part of engineering is Being able to put yourself in the mind of the other engineer and be like, okay Well, why did they do this? It could be that the code could be different or the design could be improved, but there's probably a reason So like what what is that? You know documentation doesn't Contestation tells you what it does, but not always why it does. Well, I mean That's what's so nice about us working in the open on all the all the Adafruit stuff Is that a lot of those decisions happen in the public and people can see the reasoning behind it and see how things have evolved? And that's not a luxury we have with stuff that gets thrown over the wall occasionally from these vendors. Yeah, like Yeah, I mean we can we can ask vendors to do stuff, but if it's a binary blob We don't you know, you know, we know we've asked vendors like hey We think you're not setting this flag, but like right there's no way to know it's definitely you know, I think it's interesting that you know people talk about security in You know firmware and stuff like oh, I want I don't want to release my code But then you know eventually you're you're running your code on a Linux computer where it's like you can't secure a Linux computer Like not really, you know, you can always mount the file system. You can always get the executables and files off Right, right. Yeah, we don't get the code, but but you have physical access So which can actually somebody was asking me about that. It was like, oh, you know, you can't secure Micro-Python circuit Python. I'm like there's no such thing as file security. You should be using an external chip for authentication You know Anyways be on the topic, but I do I do have to go. I just wanted to drop in and say hi and I had everybody. Thanks. Thanks everybody for dropping in and Sorry, I'm I'm in and out, but I do have to test have a great weekend All right. Thanks, and everybody enjoy your weekend and a long weekend too if you're having it All right Tomonsku asks what are SVD files? It's a system view description It's a thing that Cortex-N's usually have which tells you like what peripherals and registers there are and where they are in the memory map They're super handy. I went into it earlier So I'm not going to go into depth now, but they're they describe all the register or the memory addresses and stuff I've been looking at the Linux code for USB I'm surprised that they don't have like SVD style stuff As far as I can tell Linux only really has the device tree stuff, which is like kind of higher level than that Then SVD. SVD covers like each bit of a register Which is really really handy, but device tree does not The device tree will tell you where things are, but it won't tell you the lowest levels of things The unique way that ECOS operating system handle it They're doing something Protobuf descriptions files for peripherals. Yeah, I'll just I can show you it here So this is like this Broadcom peripheral and we if we just scroll down there is like it's all XML which You know whatever But you can say like oh here's a peripheral. We're calling it VC mailbox. Here's a description Here's the base address. Here's how many addresses it is and then here's a register It's called read. Here's a description offset and like access for it If it has fields, you can say like how big the fields are and stuff You can also say like what C types match up with stuff too But I haven't done that But yeah, it's it's incredibly handy and you can generate like C structs and stuff off that too There is an unhappy kid outside the window But yeah, it's this giant file like all the bits and you can have enum values and things like that too so that Things get Better formatted to and you can derive from other ones So if you have like multiple copies of the same thing, you don't have to have copies of all the registers and Yeah, there's a an arm provided thing called SVD com That will generate a giant header file for you that looks like This so it has like all of the interrupt numbers the there are more I just haven't defined them all and Then it defines these giant structs that have like all the bit names and register names and things like that So yeah, they're super handy They're really really handy And I'm using Jinja on top of it so that I can move things around and and like put files together Instead of having to have one giant one To maintain So yeah, that's all in the Adafruit slash I get hub.com slash Adafruit slash broad com dash peripherals Is where you can follow along as I add stuff there. There's certainly more to add. I Will add it as I need it Oh Yeah, and the other thing Timon is that you can use this Python extension to GDB to actually print out the register states and Like have nice names for the different bits and all that stuff. So here we can see like this is the The pending state of all the interrupts based on the name of the interrupts rather than just like the number Which is really handy So USB Right, so we've got 20 minutes if you have questions feel free to ask them. I Was checking all of the all of the settings along the way So the distributor I should show this I have a graphic It doesn't show here although There is a so there's actually two different interrupt controllers in the Raspberry Pi 4 chip and the BCM 27 11 There's the legacy one and the regular one and the generic one the generic one is one from arm And you can actually select between the two And I'm not sure what that checks that out I thought by default on the Raspberry Pi for it's the GIC by default So that should be set up It's possible that something else is changing the state of it So that's one thing we could check the late deferred service routines So I do have to add this these registers to the IRQ to the Brain brain words Add them to the SVD file at some point to make these easier to check Depending is Have too many tabs too many tabs So I think here. So this is the information for the GIC version 2 spec. So like the GIC 400 is the specific Instance and then the spec is the v2. Thanks unexpected maker. Have a good one Ah, this is the where's the dot. There's a diagram. There's all words. I don't want words I have too many tabs open is this oh This is the you are at documentation. No, that's the arm core docs Where it's in here Can I make this big enough that I will name this sidebar? Oh Oh, there we go. It was right on the cusp. This is not what I want though. I Found a good diagram, but basically so the So There's a good diagram, and it's not in this doc so there's Different pieces to the the generic interrupt controller There's the distributor which manages all the incoming signals and then forwards those signals into Specific CPU interfaces, and it says that there's one for each processor This virtual stuff we're going to ignore because we're not doing virtual machines But we're the distributor is just kind of global settings amongst all the CPUs and then There are specific CPU interfaces Build a chief tracker for model aviation. Oh Yeah, I I was in the drone world just put a beely beacon on it Yeah, so the signals get gated by the distributor for the global thing and then there's a target So it's a bit mask of what what CPUs want to hear about a given interrupt so if we look at the distributor and We find the targets we can see targets here And we can print that out and then I'm not sure we must be in this bucket here it's a It's eight bits so This one value is a one in the one spot Which tells should I thought set the target bit for the core zero for USB? But let's Once it goes there, then it goes out to the CPU interface, which is the GIC CPU which we can look at the control register to make sure that That signaling of group want the group zero is enabled Which it looks like it is Interrupt acknowledge so this is the register you read to figure out what woke you up And then it turns out you actually write that back to tell it when you're done Which is new and what that will do is then that will clear the interrupt for everyone else as well, which is interesting We can see there's this ID register that we know is valid because I added the enum Which is good so in a world where you can like mess up your addresses, it's nice to have those like identifying Identifying registers just to feel more confident We can see that there's this highest priority pending interrupts This is a way to see like what you're going to do later Or what you would do now if you if you did this interrupt acknowledge The 1023 is a value that says like nothing right now It's called a spurious interrupt and that can actually happen like Say you have an interrupt coming in and there's two processors that are trying to To handle it at the same time What can happen is like one will get it and the next one will It will have been interrupted But the one that it reads will just be a spurious and just it's supposed to just go back to what it's doing So that looks right to me I Wonder like we're running in EL to non-secure mode And There is some complexity. So if we look at Yeah, 1023 is is a magic number It's a magic number to say that it's a spurious interrupt and I know that because in The so there's this PDF that the GIC V2 spec it what tells you it's what tells you like how to handle stuff I wonder if we can just Search for 1023 a processor reads the GC GICC So the second C there is for CPU attains the interrupt ID 1023 indicating a spurious interrupt The processor can return from its interrupt service routine without writing to the end of interrupt register It indicates the original interrupt is no longer pending typically because another target processor is handling it So that's kind of like that race race condition thing and they actually have two types of two types of Interrupts the one to n is the is the like Only one person needs to handle it and then there's also end to end end to end Which means that like when it happens all the processors need to deal with it And oh, this is kind of a nice diagram for like how How the state changes for interrupts so like Inactive and then it goes to pending and then it can either go to pending active or just active Depending on what happens Have a good one John There's a lot of past episodes and I've been doing this quite a while, but For the Raspberry Pi stuff, I think there's maybe like three or four episodes so you can catch up with the Raspberry Pi stuff This is the first day. We've talked about interrupts though We were talking about other stuff before So the question is is why Why oh, why are we not actually getting into the interrupt handler? because Well, it's not being marked as pending. Let's go over the Distributor register model Processor targets These registers are bite accessible a register field corresponding to an unimple reads a zero G's GSID target SR is zero to seven are read only numbers plus one CPU targets Right, so like bit one is oh Yeah, P-boy. That's a good idea to do those show notes. Oh, I bet you got blocked. So we'll post it It's poop. Do you want to go out? Yeah, why don't you come up here? He's meowing at me. You probably can't hear me on at me So it doesn't seem like we're seeing it as pending. We're seeing it as pending in the We're seeing it as pending in the distributor, but we're not seeing it as the next thing to hit The CPU interface. So maybe there's more to it than that Maybe there's something else Meaning of CPU targets bit field bit values like bit one is CPU interface zero, which we should always just be on on CPU zero Kitty the corresponding GICD target is and or interrupt ID and Divided by four, I mean we can double-check this offset is that By offset of the required Priority field Required priority field. I left all the priorities is zero. I wonder if that's not valid What does priority say? If anybody has final questions, go ahead and ask them. I'll probably wrap up pretty quick here Corresponding to an unimplemented interrupt reads is zero Like zero is the highest priority, but maybe oh Interesting that the priority registers are banked for each processor. Oh No, just the start starting ones Have a good one Minnesota meant that Yeah, we're just about to wrap up. It's actually interesting that like viewership drops After the two-hour mark From an implementation defined range To lower the value of the greater the priority But I wonder if it's a wonder of zero isn't valid Let's look at that so the implementation docs are here Distributor doesn't say about priority I could try setting it to like one And just see if that works Yeah, it doesn't tell it doesn't tell me Can you display the priorities with the SVD command? Yeah, I can I can do that Didn't I do that? I did target did pending Big group I don't know any priority All right, let's do it. It's in its own cluster and then Oh, yeah, I mean it's all zero But I don't know if Robotrix minus two Moto Timmo is asking just received the ESP 32 C3 dev kit. Where are we with possible circuit Python support? There's two C3s already supported in circuit Python They do use the ur interface so they have a big warning that they're not proper circuit Python but I believe that Micro dev is working on BLE support. So the plan with C3 is you'll be able to do the BLE workflow stuff Yeah, so right now it's just priority zero But I just wonder let's just as a as a Hail Mary with three minutes left here I wrote the code to set the priority. So let's just try setting it to one Just to see if like zero isn't valid. I don't think so doesn't make sense to me, but Let's just try it. It'll be nice. Yes. Melissa's been working on code.circuit.co.org as well repos and usb examples device CDC mass storage build raspberry pi Overwrite it remove which kills my desktop thing for some reason every time Yeah, the IDF has been updated Or for the S3, I don't know for I don't know I don't know a version we're on for that Okay, so we got our Mass storage out, but we'll start it back up, but no cd and see where we are we're in FIFO read and If we look at the priority registers, they're all zero still That's true Even though I thought I said it what number is it? We think that USB interrupt is 105 Good night. Does she boo. I mean, that's a little interesting that It's still zero Okay, well, let's wrap up I might keep poking at this. We'll see. I don't know. It's weekend Thank you all so much for joining me for another Deep dive here on the Adafruit YouTube channel if you want to support me You can do so by supporting Adafruit by going to Adafruit comm purchasing some stuff there Check out. Maybe they have some Adafruit or some raspberry pi Pi for stuff that maybe we'll get this working with at some point Once we figure out why why it read zero, which is weird that that is intriguing Thanks again to DCD for doing notes and thanks to ask ask Patrick W for making sure that they end up in the notes repository We let's see what else this is deep dive next week should be at the same time on Friday 2 p.m. Pacific here on the Adafruit streams Join us on discord if you want to chat with us throughout the week You can go to the URL adafru.it slash discord to get into the discord Follow those two repos it should be in the description to check out the work as I do it and Help me out if you want to help me out. That'd be awesome Follow along that'd be cool, too. I Think that's about it I'll go to cat cam and pet the cat cuz he wants some pets and then we'll call it So thank you all have a great weekend and we'll see you next week Yeah