 If you're watching this video after the fact, make sure and check the notes in the description below for all the topics that we cover and when we cover them in the video. I'm not very organized, so this means you don't have... If you don't have two hours to spend hanging out with us, that's a great way to skip around and stuff. And I should say that there is now a GitHub repository full of all the old notes docs. I think it's github.com. Hey Johnny, hey Doctor. So github.com. So github.com. So github.com. So github.com. So github.com. So github.com. So github.com. So github.com. So github.com. So github.com. And then Patrick was awesome and went through and wrote a script so that all of the timecodes are linked. So if you ever wanna like figure out when I was talking about something, this is a great way to do that. And while I'm thinking of it, this would not be possible without David, who takes notes every week. So thank you, or almost every week. So thank you so much David for that. And thanks to Patrick for the things. Um, hi Keith, hi Keithie, hi Mark, hi Beata, thanks for hanging out, um, David pinged me like 10 minutes or 15 minutes ago and I was like still out chatting with the neighbors, so luckily I have a list of all the stuff I need to do before I get things going, um, we do have, uh, no cats in the cat cam, I left the door open and the cleaner vacuumed in here, which is awesome, um, but scared the cats out, so no cats in here and they're on their own, and I am actually in the middle of the stuff too, but we'll, uh, get there when we get there, it's only two o'clock, we'll wait a little while longer, I don't think I'm gonna need the overhead, I hadn't thought about that, hey Dishapu, thanks for joining, hey Bruce, I've got ice water, keep me cool, it's 85 in here right now, I think the high today was 86, I'm not sure what that is in Celsius, I'm sorry, but I think everything's going okay, you all can hear me, I sound okay, Haddon Jones says probably a silly question, but 7.0.0 of what, that's not a silly question, if you're new here, uh, Circuit Python, so Circuit Python, actually let me just do the housekeeping, hi 3D electronic, all right, so 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 in New York City, they pay for me to work on Circuit Python and do these streams, they are also obviously this is their channel, they're based in New York City, I work remotely for them, so I'm in Seattle here, it's kind of warm, 30 Celsius says the chat, thank you Dishapu and Bruce, so Circuit Python is a version of Python designed to run on microcontrollers, which are little inexpensive computers, they end up on boards kind of like this, the chip here is the microcontroller, they're kind of like all in one computers that you run Python, which is awesome, so been working on that for a few years now, and yeah, so that's generally what we talk about, Adam had the question about 7.0 fixes is the title of the stream, hello Patrick, so that's what we're going to talk about, although I was working on something before so I may, we're going to veer into like PyOCD land probably, because that's where I left off before I went and got lunch, so if you want to chat with me and a lot of others, feel free to join our Discord server, that's the middle box here is our Discord channel, you can do that by going to the URL adafru.id slash Discord, this is a deep dive, it happens every week, normally Fridays at 2pm Pacific, but occasionally shifted to Thursdays, it typically goes for two hours or more, so get comfortable, go ahead and do something else, I try to read off questions so that you don't have to be watching the screen, questions are always welcome, and next week will also be on Friday because next Friday is Circuit Python Day, so I should chat about that a little bit, but I saw some questions in in the chat, so I'll get to those first, I don't have to say about the cat because he's not in here, he went downstairs, okay, so hello Dave, I think I said everyone, hello Dexter, hello Minnesota Mentat, hi DCD, hi Rakbit, that's an awesome animation, hi FomyGuy, hi Bruce S, hi Paul, hi Mr. Shortley, okay so FomyGuy had a question, Mama Rolf says hi OCD, what did I call it, hi OCD, I think we're talking about the same thing, so FomyGuy asks random meta question about the screen, how do you feed the Sony camera into your computer to get it into the screen, it plugs in with USB and has a driver or something, yeah so I have a magewell, so the camera outputs HDMI and then there's a magewell box that does USB 3 to my computer, and then just shows up as a regular kind of like camera for Linux, wow Bruce was busy, Mark says it's 95 there today in Canada, I haven't, I don't use the webcam driver, I did go for a walk as well, capture card or video capture device, yes, I have a magewell and if you want to know exactly what version it is, it was what Phil recommended I pick up, so I picked that up and he paid for it I think, so that's the dealio, I had a lot of trouble beforehand and when I updated my motherboard I was specifically looking for, specifically looking for a strong USB motherboard, Mr. certainly asks what was the deciding factor for the magewell versus the Elgato offerings, it was just whatever, I just went by what Phil recommended because he's been doing a lot of stuff, you know he's been streaming for a while so I just went with that, but Johnny says I use the webcam driver it works fine except for Microsoft Teams, Bruce says firesmoke.ca showing our current level, yeah it's a, I can spell it a little bit, it was, I noticed it like yesterday or the day before but it really, it's been not very noticeable, I have this, somebody has a call coming in, it's not me, I don't think, stay hydrated, thanks John, I've got you covered, I've learned to also go to the bathroom right before I stream because I drink so much water, ooh ribs and pulled pork barbecue, I'm barbecuing salmon tonight, that's gonna be good, okay, where do we want to start, let's start with Circuit Python Day, so I don't forget to talk about it, I don't know what we posted about Circuit Python Day, oh there's this cool video, did you all watch this video, yeah so I'll be doing, it's funny, oh you can't see my screen, so tentative activities, we have Jeff, Dan and Katnier doing a stream again, I think they're gonna show off some stuff, yeah we've had bad smoke days but it's not been too bad, I actually do have, I can hold this up, so I have this and maybe folks know, but I've got this thing I rigged for last year, this is the particle sensor, but it started giving me weirder readings, so it's saying like five right now, when it was really smoky here, it was up in the like hundred range or in the tens range, but I have that setting set up and it looks like it's actually kind of right now, for a while it was really bad, but yeah it doesn't look too bad and the windows are open, so it's not too bad, so yeah so somebody tacked on the special edition for the deep dive next week, if folks have ideas on how I could make the deep dive stream next week more special edition please let me know, otherwise it'll probably be the same thing, although it's not on here, but I think Keith the EE, correct me if I'm wrong, hello I am Joel, we are planning on doing a Reddit AMA next week I think and Keith can confirm and if there's a link Keith can put that in the discord as well, but I think that's the plan, yeah so we'll do what we're gonna do is we're gonna do a circuit python AMA on the python discord, the python subreddit so that should be fun and maybe there's some topics that'll come out of that that would be interesting, I'm Joel too, no I'm Scott, but that's clever, okay so keep an eye out on the python subreddit for the for the AMA announcement, but we are, Keith the EE was asking me about it and I was like you know it would be cool to do that for a circuit python day next week and he was like uh okay yeah sorry for all the folks that are dealing with smoke it's no fun, I can relate, there'll be a pinned post on the main page of the python subreddit, oh foamy guy we can put this in this article, so foamy guy says it's less official capacity but I'm planning to stream at 11 a.m. Eastern on circuit python day as well, so yeah there'll be lots of streams, we'll do the AMA, so that'll be cool and if you have ideas that I could do to make my deep dive special next week please let me know, the best way to let me know is just like join circuit python dev on um circuit python dev on discord and and just at me in there, so yeah okay uh there was one other thing, oh so deep dive notes, what was else on the list uh the red at AMA, okay so I cover that, so ask patrick w who watches these streams occasionally and has been super helpful was asking me whether I have a collection or a place where all the deep dive notes are um and so what I was like oh well we could just make a github repo for it and the nice thing about github repos is that what you can do is wear a purple hat, I don't know if I have a purple hat um I don't know I could wear something I guess uh yeah so there's github.com slash adafruit slash deep dive notes you can clone it and then you can um what you can do is you can like just grab it like search their repo I guess you could search on github as well because it's not a fork so if you ever want to find something uh on the previous deep dives from when we had uh notes thanks to david um check this repo out and patrick did a cool thing and I think I showed it earlier but I'll show it again if you click into particular day um the time codes are actually links so the they'll link to like the specific spot in the specific video which is pretty awesome so thanks to patrick and thanks to david uh for taking notes and putting that together all right uh if folks have more questions go ahead and ask them otherwise I think I'm gonna just jump into all right I could look at what I've fixed maybe I'll do that first before I get into debugging but I have been doing some debugging that I haven't figured out yet so I want to get back to that but let's just take a look at the PRs that came through this week um so oh yeah so thanks to david uh suggesting using all four leds on the mag tag as a status thing um dashipu asks how hard do you think it would be to get circuit by then to run on the sam l21 as opposed to the d21 talk to the electronic cats folks I think they've tried it um they would have a better idea because I I think they were working on it so I would I would google around I think somebody has been trying to do that and I think it's electronic cats folks that have um the other person I think joey castillo might have been looking at it as well for his watch so I think people have been looking at it um how hard I don't know they would have a better idea um okay so we'll take a look at that and the pulse out stuff I did oh and you know what I have a review to do to dan for dan so I should do that as well multiple status neopixels um yeah I think that's it so uh I'll do the I'll do the review for dan too um so a couple of fake see fake sleep bugs on nrf and esp so um fake sleep is when you write circuit python code that is doing a deep sleep so when you do a deep sleep it it exits your exits your code um and then shuts ever as much as it possibly can down before and then wakes up based on the conditions you set before you went into deep sleep um but the way that it works is that if you're on usb like you're testing your code um what will happen is that it won't actually deep sleep because deep proper deep sleep will lose usb connection so but if you're prototyping it we have a mode that is fake deep sleep which is your code still exits but the circuit python stays running the whole time um and we had a couple bugs in uh that code that had leaked in so um those are on the nrf and the esp so um one thing I did was we added the ability for uh thanks to christian christian added the ability to save the exception string from a run uh so that you can access it the next time you run um and there was a problem with that with doing the deep sleep trace back because the way deep sleep works is when you say exit and deep deep sleep it actually raises the deep sleep deep sleep exception um and so to fix a bug with that what I did is it just said like oh if the so this is in pyexec click it a little bit further so where it's actually running your code is right here so this is like okay so this is somewhere in it's like in pyexec parse compile loop or something um so it sets up and it does a function call to run your code and then as it exits it figures out like oh was there did it exit because of an exception and then if it's a deep sleep exception we'll set the return value to indicate that it's deep sleep but then also if if there is a result what it will do is it will save it in this exception thing and that's what gets printed by the the exception printer thing and so what I did is like it was crashing when trying to use the deep sleep exception so instead what I did is I just said like oh if it's deep sleep don't bother setting the exception so that was one fix another fix on the s2 was that um if you did one real deep sleep and then did and then usb connects and you're doing uh fake deep sleeps the fake deep sleeps would not work um on the esp because this the esp idf when you do this get wake up cause uh was returning the value from the first deep sleep so um there's a flag here that just says like oh is this the first time we woke up and if not um don't don't listen to the idf um this is the real well the the bug that got me into it the the bug that got me into it was that um when you're doing a time sleep that's one way to wake up from a deep sleep or or a light sleep is based on time and uh what was happening is that when we were fake deep sleeping a time wait on esp you weren't able to control c out of it like it says you can um and so what I did here is the esp is a little weird and that has two tasks running um and so the usb stuff still works because the usb is running in a different task than circuit python um but what we were doing is we were only triggering the circuit python task when the interrupt character was set but that's only set when user code is running um so what I did is I moved it kind of outside this check so that whenever control c is uh is seen by tiny usb will trigger the circuit python task and ask patrick found that a sam l 21 um and then this is just a minor thing for i'm i'm trying to get it going on gc gcc 11 and this is a minor um thing for checking um nrf time sleep wasn't working because it wasn't setting these this internal state when the alarms are actually set it was setting it too early and then i deleted a bunch of debug this it was setting resetting it back to me um so i fixed that as well that was one thing um this is the thing i was working on a while um pwm out we're switching the api to take in a pin uh frequency in a duty cycle rather the old api takes in a pwm out and then controls that which is great but it assumes how it assumes the method for implementation and the esp 32 s2 doesn't actually need the resources that a pwm out uses in order to do it so we started moving to this model and you'll see it in i think it's in six but it's in at least in earlier betas where like you can kind of do both ways but you could only do you could only do that newer way on esp so what i went back and made all of the implementations work like the new api which takes the pin um and then i also found some pwm out problems um so i fixed those as well and thanks to dm com for doing some some thorough testing on my stuff um i added support for multiple status new pixels which i think i did on the stream last week um so that's good too and uh did that for the playgrounds and i did that for the the mag tag at david's request as well uh any questions folks want me to answer hi on car i say it right um maybe i should take a look at this so this is uh dan's been like working for weeks to try to make the audio playback better um so let me see here he's got six files changed i could probably do that on here cat and he's gonna try it crunchy playback and program hanging he's still working on it oh and there's 45 checks failing maybe i'll wait i don't need to do that on the street ate a fruit can build home automation full product in future i'm not sure exactly what you're asking home automation is a lot of different things to different people all right i think i'm gonna ignore this since there's more work to be done i think i'll do that next week um so i thought i thought um talking about pi ocd would be a very cool thing for us to do so folks may know open ocd which is a way to uh david says any progress on your gameboy related personal project i now have a rp2040 game link adapter and i follow someone making an rp2040 powered cartridge i have not made any progress but i will love to see those two things if you have links for them please share them with me i'd love i'd love somebody else to make the hardware honestly um what's this ocd thing yeah so um open on chip debugger so ocd is on chip debugger and it's the software oh great infinite redirect brilliant uh so it's the software that um translates between your debugger nothing's too much of a tangent krs13 says what gameboy project if it's not too much of a tangent so i was working the gameboy project i was working on was a samd51 powered um gameboy cartridge that you could program in circuit python so what circuit python did is it queued up assembly instructions to the gameboy to do different things like loading tile like sprites into memory and moving them around and all of that um i have a talk that i did at pterodome gameboy i think it was a super charger hardware old man who was circuit python i think that's it yeah all right uh thank you everybody for coming uh i always talk louder than i intended to post watching online now and thank you uh first an introduction uh i'm scott schachroff i go by clock and power i showed the website earlier okay i i don't need to watch my own presentation but i will link to it in the chats uh but yeah the basic idea is that um tangent of the past yeah 2019 um deep tangents is my nickname for this stream yeah people have come to expect that um all right let's not look at the terrible recommendations okay so uh yeah so the idea was making a pcb i am not the owner of adafruit concar asks um but yeah really trying to leave all your like gaming logic in the circuit python cart but then using the gameboy for button inputs and and display and stuff like that so yeah anthony says i think they're asking if the home automation support will be complex enough to have its own api framework for circuit python i don't think so i don't think that we'll have our own framework if you look we already have like an mqtt library um and that's pretty good and then a lot of our focus on the on the ios side right now is with whippersnapper which is very cool and i suggest people look at that but it's like a no code like just on the website you say what sensors are connected and then that automatically will give you the values back from it um adam jones says and yay since nothing is since nothing is too much of a tangent i'm getting back into microcontrollers to do a hobby project and looking for help finding any projects or libraries for signal triangulation um uh i don't know uh but hopefully some folks in the chat here will have ideas for for signal triangulation um i would say i would ask what like types of signals you're talking about like what radio rate what rf frequency ranges and things um krs 13 i work on a python based gameboy emulator if you want to talk more about that sounds like a cool project probably too slow for circumcised on but yeah that's awesome on kiwi str is a suggestion um yeah it was interesting it was really interesting from their perspective of the the gameboy cart stuff because like it was us answering the cpu rather than us being the cpu like like emulators are reading the roms right and then doing stuff whereas like we're kind of doing the reverse when we're the cart itself but i would love to see if we could find if somebody found the hardware like i did most of the software i really got hung up i think the rp 2040 is a better chip for it but i think the way that i was doing it with the cmd 51 i was occasionally um i was occasionally having to um i think the dma on the samd 51 was not always timely enough for the gameboy so i think what was happening is that i was end up ended up um returning the wrong data and then it goes off into the weeds and crashes and stuff so so i got it a long ways through it um i got it so folks are asking racpet asks as a gameboy cart you have to embed the nintendo logo for copy protection right yes so you have so the the roms on the gameboy will request the memory for the gameboy logo for the nintendo logo twice um once as a copy protection thing and once as a like now i'm going to display it sort of thing um and because we're not actually fixed memory what i have have the circuit so i have code for circuit python to to do all this like i got pretty far um and i got it working on the gameboy color as well um so what i would do is i would return the nintendo bytes logo bytes back the first time and then the second time i wouldn't the second time i would return something else i think i return it like i got an adafruit logo instead um so there's both um ble trilateral trilateralation is on my short list of projects for my home system so you have a recommendation um or ham radio fox hunt stuff um nice gameboy type thing with a big sharp display that's what the um um what these have the they just opened pre-order to these two i think right um tithe on twitch this can't find a whipper snapper software you talk of any chance of a link yeah let me find it i think if you go to blog to adafruit.com and then i think it's spelled wrong which we like to do i think there's probably a blog post about it my first step for wednesday yeah so here's i think the best link for it it's part of i o um somebody uh on gameboy cartridge using rp2040 all right let's pull it up oh not there oh that's awesome um mine had midi which is pretty neat but i would totally just go with interesting i wonder how it is connected i shall follow this person because that is curious thank you for the link dude it looks a lot less crowded than my version but my version has midi stuff which is pretty needed all right pretty cool um talking about triangulation and like indoor location stuff um let's just find this see i think more put more folks asked questions once we establish tangents are okay um all right let's make it a little smaller bealy beacon so somebody was asking about bealy beacon yeah so in this thomas here just linked to two studies about um using bealy beacons for indoor navigation so i would recommend this as well dexter says is there a limit on the sample rate of a wave file for rp2040 um we have dan's working on this actively um and check out that pr that he had um but basically if it sounds bad try a lower sample rate um dan's doing a lot of debugging on the audio playback of waves on their rp2040 right now so yeah sit tight that the audio playback should be getting better oh cool eventually it would be cool to have narrated nature walk with the proximity base triggers but also um at nighttime have lights illuminate as you walk near them have a text i'm such a terrible live streamer um we have visitors coming later so tan needs tangents that's a very core scenario for bealy beacons at museums and stuff need to be see it done and certified on that would be amazing um laura and blue fruit solutions might be better if you use for your use case yeah if you're talking about location stuff doctor says some streamers just do things and totally ignore the audience so you're not that bad and the mark says the esp32 s2 has something coming last i saw about wi-fi location type says thanks god got foxed by the british love of silent ages well that and like usually the way that eight of your brand's things is like even if the if you even if you think you know how it's spelled it's not always the case so yeah happy to link you that's i'm happy to do that on my stream happy to help people all right um should we pop the stack and get back to ocd so there's open ocd which i've kind of like had mixed feelings about it's so it's the software that bridges talking kind of to a microcontroller and talking to like a standard debugger like gdb or l o db um i don't use that jlink has their equivalent which is the like jlink um gdb server which does that too um so there's that oh the bot might have not liked the long jump comment sorry about the bot if if you think it was mistaken then that's fine uh or we can fix it later um so there's also this project called pyocd which is what i want to actually where i'm trying to go with this pyocd is pretty cool it's all python and it's python that talks to uh hey asden nice to tune in once again welcome we're just hanging out if you have questions or i'd like to i'd love to hear how things are going to um ah okay we did it hey unexpected makers here too this is why i stream for two hours so that people can drop in 30 minutes into it that's the only reason it's not all the tangents it's not the fact that i haven't gotten to the thing that i would make sure and do or that i wanted to do oh does it and everybody's deleting stuff funny that you talk about open ocd and pyocd right when i tune in yeah i was wishing i had a black magic probe i'm not sure i do um hey james getting off work ah yeah good tangent following engaged yeah so pyocd is really cool um it requires them so yeah i mean i like i also got a jlink and like the jlinks worked really well but here's the but so this has been the problem that i've had is that right now arm gdb hates me david says i got my black magic recently do i need to borrow i might actually have one so what's the unexpected maker asks what's the difference between pyocd and open ocd so i think open i think they they have the same role but the way that so there is some um differences or some configuration that needs to happen on a kind of like per chip basis and the open ocd stuff is in like tickle or something so like i obviously am biased um yeah it's the site doesn't work still so if we look in open ocd like i've always said yeah there's like tcl stuff and it's like all this like it supports a lot of stuff but it's like in a thing that i don't really understand um so it does a lot of things it has a lot of support um but i have a python bias so that's part of my problem um rack that says pyocd does use the jlink software whereas open ocd talks to the jlink directly as far as i know for my jlink education addition for instance it will pop up the daily warning window oh interesting but i have been enjoying using pyocd a lot yeah so i have a jlink base um so what i've been doing so i have this problem i i'm trying to debug some crashes on the feather nrf 52840 board in the like bealy workflow stuff i got really hamstrung by it because what is happening is that the crashes happen when i do an lto link time optimized version so link time optimization is uh where it takes all the code for the whole thing all of circuit python and it optimizes it all together there's not something you can traditionally do for like big applications but because like microcontrollers are quite small um like i we just do that and that means that it's also like a little bit more optimized because the the linker and the and the compiler can optimize like the whole thing all all together um but for some reason when i that's called link time optimization and i call it lto for sure the problem is that my gdb has started hanging and just taking more and more memory when i try to load those binaries up um and i'm not sure why so i basically can't debug lto compiled things right now in gdb um i was trying my darndest to use lldb which is the llvm version of the debugger um it loads okay but it was at one point it wasn't walking the stack kind of i was getting a hard fault handler and it only walked the stack up to the top of the hard fault hard fault handler it wouldn't go past that so i started looking into this pi ocd thing because i was like heck i'll just write my own you know me i'm like what if i maybe i'll just write my own debugger um nice evan psd is now in the discord as well so you found the great place to ask about uh the positioning indoor positioning stuff um i finally got open ocd working on my mac to flash sandy via my atma ice but i prefer to use python if i could yeah so i've gotten flashing working it's using the jlink so that i have the jlink connected to the feather um it is not very fast but i kind of assume that's a a jlink thing not a pi ocd thing um so yeah so i've been playing around with pi ocd so i've got the script that i'm working on and basically what happens with circuit python in these cases is that it's just crashing when it starts up so um what i have is just a script that is just like connect to the thing and like print some stuff out so um here's some i forget what i started with some pi ocd thing and then you can actually have it um load so if i want to load the file i can uncomment this um elf symbol provider is the like given an address we can figure out where it is um i feel like saying roll my own ocd is almost like saying roll my own crypto well so the thing that seems pretty cool about this is that like i don't this is kind of my debugger um to some degree it's not interactive but it is like giving me enough information so what i've got it doing right now is like i'm loading the symbols i'm printing out the sections i'm loading the file but not really because i have to comment it out and then i just halt the target and then i start reading stuff so i read the program counter the stack pointer the two different stack pointers so dwarf dwarf info is all of the debug info so i get the dwarf stuff i get some ranges main compilation unit and now i can do this like what line for this or then i build this table for like given an address what is the lines more debug stuff um but i have this thing here i know i invited that's not that's fine this walks the stack so for every value on the stack it tries to like figure out where where the value is coming from and that gives me like a course back trace of everything so um i'll show you what that looks like so here's an example that i just ran um here you can see that i i was gonna have it so one way if we have a safe mode crash in circuit python all of those go through this reset into safe mode so yeah dcd asks is this python code talking through the j-link correct so this python code controls my nrf uh my nrf device um through python bruce says i'm not sure what fast means i use the mini edu jlink to flash nrf feather boards and it seems okay yeah so what we have here is we can see the program counter this is the symbol info for the program counter and then this is actually the line info so what we can see is that like when this halted um it ended up in this like startup phase thing so what i've been trying to do is figure out why it's crashing um um so it's it's crashing really it it something is being corrupted so let me just comment this out and we'll rebuild the load let's make it i'll double click it hey mark i don't think i said how do you yeah okay copy that over as then if you're still watching you might be able to help um i was trying to use so there's a gdb server in pyocd and i was trying to use it from lldb but lldb i was trying to run uh like run the run command and it doesn't work with pyocd because it does some weird signaling stuff this is the problem that i got burnt out a while back on okay so i just copied it over yeah lldb is using the protocol differently yeah yeah this protocol that seems like a standard but that's not a standard so i'm just gonna hit uh restart on there it blanked red for the um for the bootloader but then didn't do anything gdb lld but db side is not specified only the side of the server yeah even when i looked up like the k command for kill it was like this is different like it's not well defined david asks i remember you mentioning somewhere about a bug requiring it a hit-enabled device for macropod that got fixed i think i'm hitting it what do you do what do i need to get the fix latest cp lives other um i'd not i would just try the absolute latest from absolute latest version of circuit python first try that first um otherwise i would hop on the discord and post the the error that you're having anthony asks who thinks that optimization is not worth it optimizing early is not a is not worth it for sure ah marx says i was playing with open pyocd earlier today script flashing scripting flashing from our universal testing that's pretty awesome asden says in any case if you implement a client you have trouble making sure it will work with other implementations that is why lldb does not always work same thing with other debuggers yeah and that's kind of why i was like maybe i'll just see what i can do with pyocd myself um one thing i asked added in the script was like if it hits a hard fault handler it like automatically will print out like the hard fault registers which i think is pretty neat so i think there is a place for these like i'm just going to start circuit python up run it and then see where it stops um and these back traces are like not spectacular but they're also not terrible so like what we're seeing here is now we're in port in it um and we can see the line is port c line 156 and that's coming from the reset handler so there's some weird memory corruption happening and i'm not sure why um but if we pull up port we can see that right in the top of port and that i have this like if the preschooler is not equal to this value then just spin um oh yeah there's the if you heard the honking like the uh the intersection here has had like a number of times where people have gotten in accidents it used to be it's just an intersection it used to have no stop signs at all that was always a problem and then they added two stop signs so one direction you don't stop in the other direction you're supposed to stop it's just like they need to put a round about it it's like it's a residential neighborhood people don't need to go fast um so so what this is doing is that there's this rtc rtc config that initializes to this value and then at the very start of port in it which actually is the start of main um what we're doing is we're saying if it's not equal to the value that it should be then we're then we're infinite looping oh so i tried that uh as in says train to add support for the black magic probe to radari 2 was a nightmare as they used the protocol wrong i actually tried that a little bit to see if i could get that going and it was like like no good either um mark says i couldn't get open ocd to flash an stm 32 l0 that uh was in low power it wouldn't wake up before flashing but pyocd did it really easily it's the whole pie versus tickle thing yeah yeah so i think pyocd is really neat and uh it it seems like a really really handy tool if anybody wants to figure out how to unwind the stack that would be amazing but i was starting to look at it it was like it is complicated figuring out like where all the variables are and stuff but yeah i would love to see i want like a pi db like not not pdb which is like the python debugger for debugging python code but i would love like the pyocd equivalent of gdb i think that would be awesome because python is just like so much more extensible and easier to easier to understand okay um yeah so i have this check that's saying like oh this value that should be initialized at startup is not what it is then like wait and so i was trying to figure out maybe what i want to do is i actually want to do an option so so port here is checking rtc config and then what i thought so the place that so the way that this works the when you reset the bootloader goes and then it changes um changes the interrupt vector offset and then it calls the reset handler so the bootloader calls this reset handler directly and it does two sorts of memory initial memory initialization tasks the first here is that it copies data from flash to ram because those are all the like initialization values that are going to get used so if we look back at this port c we can see that this rtc config is not const which means you can actually change these values so um so that has to get initialized somehow and the way that it's initializes with the startup nrf 52 840 and this it's just a wire loop that copies data from flash into the spot in memory and then the second thing is bss is i don't know what it stands for but it gets zeroed out so this does the whole range of zeros so this is anything that is like that first dropped but all of the values are zero they just get you just do like a whole pass zeroing everything out and then we call this system in it which is i looked at it looks like it's just setting it some hardware stuff um but it if i add this after so this loop is a lot like this first loop except what it's doing is it's saying um it's just checking it's saying if the destination is not equal to the source value then we infinite loop and we'll see it on our backtrace otherwise uh just increment the both and uh then go around the loop again um so very very similar so oh so if i save that as then what have you been up to what's the latest and greatest from one bit squared as i compile and reload it blocks started by symbol is bss very old school thing from ibm times according to wikipedia open ocd i think can do esp stuff whereas like pyocd doesn't do esp chips yet i don't think which i guess i should have said earlier when unexpected maker was talking about it jean dunn says i'm fascinated by how many types of debugging and analysis can be done definitely a bit above my depth for now but i know it's coming he it's true this i mean this is the first time i've done pyocd i used i've done it um i've done similar stuff before with uh gdb but okay it's just the weirdest thing it just like the very first time it happened to me i just like my linux computer screeched to a halt as it the whole ram got filled up and i've been waiting to see like a new version of gdb come in and i haven't seen it um and it's only lto builds that do it too so i it's the weirdest thing as in is fighting the chip shortages for glasco oh yeah the chip shortage stuff is rough analog discovery too will get me working with all sorts of low data flows like that it's true yes it will okay so so now we're we're stuck in the startup and line 69 so the thing i was gonna add was actually i was gonna add a um register register print um oh not using open ocd with esp 30 so i think register prints can be pretty simple i was gonna do four i and i think there's 12 that we can read we can print i've been doing f strings because f strings with all the rage string i guess that's not what i want just one and then value is equal to target read corner register print value but we're gonna do it as a hex so i'm curious to see what addresses are in there and as in says we made an fpga mechanical keyboard atreus keep it keyboard conversion with fpga instead of an mcu now working on a demo scene game console hardware with icebreaker bits inside working on a new revision of the black magic probe to to compensate for chip shortages and add some new features nice good to stay busy i versus reg i suppose you beat the you beat the scripts Linux to boot on the icebreaker that's ridiculous i did like the pie five stuff seems uh pretty neat as well really uh remove this so i think ram starts i don't actually know what ram 20 second boot time that's impressive let's take a look at the map because i think this uh 2001 000 is the end of ram and then this 8064 must be we are so the map file there's a great talk from elicia oh and i'm wrong this um 2001 is the start it's the start of the data section which is where we should start by copying this 2001 0 55 cc is not there huh because i was kind of hoping to figure out where in that loop it was when it's validating that's like like so something's weird right like it feels like something in system in it is clobbering my memory so i don't know what happens if i do debugging stuff like this is like very satisfying when you figure it out but and then while you're doing it it's not not very fun but like there was another failure mode i saw this is where the timer stuff gets corrupted but i found a spot where the some data about the u arts is corrupted as well and so like whenever you see memory corruption like that like it's bad news and you should really try to find it this is why i need to do rust at some point because rust has more semantics that the language gives you and which should make it easier for the compiler to detect them so you don't have to do debugging like this um okay i'm gonna hit reset and then we'll do the script again the other thing we could do is a watchpoint actually that might be the next thing i do or make a random comment or print and hope the memory error goes away become a fellow rustation it's only a matter of time i i the people that have come being like i want rust in circuit python i'm like you get the build system going and i'm there right like i would love to start doing rust in circuit python because i have spent so much time dealing with memory corruption issues that it's the worst it's only a matter of time oh look at this so this this value here is not at the start it's later on um but i guess we're also now we're in port and at 156 so even though we commented out we're still there like there's gotta be something super obvious the program color is important it what is it obstum i like i do miss having pattern not found like it could be some battery reordering here we go no see like here's main and it's port and it they're like it branches right to port and it i just got an email from instagram saying we're we're sorry you're having trouble logging in instagram i did not just try to get into instagram who's trying to log into my instagram is there a button say it wasn't me well there isn't a button this isn't one of the okay well it could be official too Todd says i get those all the time great that's what we want um a space at the end of a max length string so much love for rust i'm really excited to see where it'll be in a couple years yeah so it seems like it's still not correct i thought i had tested so where's the reset handler i expected that to be in here do i need to do capital d i just like put this extra like space into it i just have a i have a while loop that is checking that the initialized value is what it should be and it's not even though there's like no code that should happen before it oops the vectors isn't it responding to me there we go it's reset underscore handler go figure okay like it just branches to main so like what is what is messing my memory up you know i was thinking it could be um some weird dma or something let's see if we get set a watch point we have a number um let's just do the script again this is what i like about this script is like i'm not restarting the device every time i'm just like changing the way that i'm inspecting it i really should remove the cfi stuff i was trying to reset unwind the stack but i'm not using it at all i couldn't figure out how to get the right addresses all right so we're in port now in reset handler right interesting so we catch it in port it seems like a timing thing like it's something that is so weird let's just watch this address so i think what we do is we say so somewhere comment it out here i have set breakpoint goodnight dave i wonder if there's a watch point of that address and then what we want to do is we want to reset and halt i think is what it is and then resume and then since we're gonna wait let's wait like one second is it set set watch point one thing that pyocd does not do that they should is uh read the docs for all this sort of stuff yeah that's right set watch point has a size and a type what do we think that is i don't know what else it needs right and oh it just calls up to the dw if type not in watch two what are my options oh i see um i want writes yeah open source is the best it could be the soft device i mean size is gonna be four sizes in bites maybe although their comments aren't there great watch size to mask well that should work four is a power of two all right let's try it and i'm gonna cannot save it it's not gonna know what target is either offset line 70 see you offset let's just wait a little longer which memory are you trying to ensure is not being corrupted stack data vss or code uh data i'm on the chair yeah do not model my posture my posture is bad it's still not happy and the stack pointer hasn't moved what is that like there's this i don't know if reset and haul is changing my program counter or not oh there we go now the program counter is in the reset handler this cfi loading is wow 59 halt and catch fire it's still pretty slow that's the slow part it could be it must be uh these oh see we have a watch point so what we have to do is we have to this is the first time it's set which is fine so what we're gonna do is we're gonna do a loop of this four two we want to do this twice we don't care about the first time we care about the second time and this is why pyocd is really neat but look at that like the second time because core zero is not halted well where the heck is it so it's like something besides the cpu is clobbering it which is super bizarre is it possible my ram is broken i had it at one point read it back like i'm on usb i wonder if i disable usb whether it works or not okay so now we're in the port stuff so let's just print out this memory address so we can print see we can read memory it i don't know if we can read memory well it's not halted do you have a second nrf board i do in fact i have one right here to check against batteran how do you get the not equal sign i'm used to using exclamation equals it's the font so i type exclamation equals and the font changes it yep i think you folks are right we should do a i have another feather right here i'll just test it um it's zero which doesn't seem right bruce says fear of code yeah i think that's what i'm using too yeah as in says ligature fonts to the for the win yeah so ligatures are different symbols that happen when two characters are next to each other um i get also i get nice arrows as well well apparently i don't have it in my terminal oh they did huh well it didn't do the arrow there um that's so weird i don't actually know what the value should be one glyph for multiple characters these three good-looking prints it's all zeros no we could do we could print out this whole range let's do that for i in so if we look at our memory map again we're curious to go from this is e data yeah maybe we're so that's the end and we're gonna want to go on four bite boundaries i can actually tell range to go by four right see when i can read the flash flash start is from the load address i'm looking at the data section and the load addresses this okay let's see what that does it'll probably crash programming fonts with ligatures cast katia calling it target maybe isn't good that's very true assuming that's what the problem is offset offset's not defined either do so this is the time out ah okay so you know the other thing i could do is i could say whether they're the same or not it looks like they are this could totally be not even a problem or something weird it doesn't it doesn't make any sense to me yeah the script thinks it's all okay why is that but now we're in portline 156 maybe this is not being initialized correctly portline 156 is if rtc prescalar does not equal frequency to prescalar rtc config is here so it should be within our range what am i doing wrong any chance you can give a short overview of the issue i missed bits and pieces what should happen so what i was finding is i was finding that um so this is checking the rt rtc prescalar value and if i remove this loop it hits an assert later on in the code that fails the assert is equivalent the assert is tickier than this but like i don't see any reason why like it should be the same 006 i was get yeah i was i was hitting asserts that's that was my problem is that i'm hitting asserts i don't know i could look at this next week and be like what was i thinking this is not a problem but it it seems proper and it seems weird what are the types for that struct maybe a type misalignment possible i am compiling it with lto let's find this rtc config i'm in debug mode that's why i'm hitting the asserts and i'm doing lto nrf x how no not how they include here it is it's a unit 16 followed by so why is it it's six so two bytes one byte one byte one byte so it looks like it's aligned this is where field spugger would be nicer i wouldn't have to do it ad hoc but it should be at the start of that dealer so three thirty i want to print out i mean it seems weird right something to construct this static and not moving since it isn't like that i mean that seems so weird it's so weird to me that i mean i do have edits to this see so if i save it and what are the variables immediately able for an after pyocd doesn't say anything's getting crashed though which is very weird oh you know what we were going to try a different one i'm going to switch the feather out right now data lines back on if this works i'm gonna like i hope it doesn't i spent way too much time on this this is how it goes though it's copying copying copying oh it didn't start up i get no blinky oh we got an e there that's a different value though oh look at that it's all different that seems weird we're in startup dot c line 69 like it wasn't able to copy any of it over like it does look like it's not right at all let me um hit the that was unexpected yeah i did not expect that it's still e and it's still wrong it's like completely wrong did i break like this is right right yeah dcd i had a code review for dan that i was thinking about doing but i wonder if it's reordering it i mean it's being too smart i mean that it could be true i decided not to do the review for dan because it wasn't working perfectly is this what you were seeing before no it's not like you would think it would be smart about ordering so we've got 20 more minutes i'll probably just keep banging my head on this if folks have questions and want to distract me and take me on the tangent uh now's a great time so i don't have to keep banging my head against the wall yeah it's easy to say the compiler is wrong but in practice it's usually not all right so there's a completely different value in there now was e it still says it's completely wrong oh you know why i bet the bounds i hard coded the bounds of the uh that's what it is i hard coded the bounds of what i'm comparing so if we look at these two at this number it's probably completely different what is the load address now a ffd8 that's the problem with the hard coding and how long is it i bet i could look it up from the debug stuff i have but i'm not sure how about having a gdb stub in the circuit pipeline so you can connect with gdb directly this is something you can do in situations where you want to some debugging an easy way and provide it without having a jtag swg adapter um i mean my problem isn't that the stub problem i don't really know what that entails and given that the pyocd gdb stub doesn't work that well but like my problem is gdb right now my problem is that if i load an elf that is an lto into gdb it just takes all my memory up and if i use l ldb it loads okay but then the backtrace is not as good as like it doesn't when i saw it it wasn't going past the uh hard fault antlers in this case it might work maybe i should try that all right so interesting did i have an off by one error that there's a single value that's wrong um ask patrick w asks so it's watching you use the salient in some older episodes you mentioned your own analyzer project have you had time to think about that at all um mark gambler i think did a lot and as estin might know that actually estin might know the sigrock people last i heard mark had gotten the rp20 40 connecting to a sigrock and had a pull request open but hadn't heard back to the from the sigrock people um so mark got really far with it but then hit the wall of like trying to get it into sigrock and mark's in the chat so mark will give us an update it takes time to bring things in i mean i understand that but last i heard he hadn't even gotten a reply like i spend a lot of my time doing email mark got it going and k match did the work k match did the work to get it into sigrock so there's one value that's different okay sorry i was wrong mark did some good stuff to csv but k match really did the work to get it into sigrock get all the control stuff going so the first memory address is different but by the time we're stopping we're in um port i don't trust this power warning handler start up line 73 we've definitely made uh right so we're in main and now we're in port line 73 we're not in the assert we're in ticking it ticking it is in port 120 oh yeah so i have a similar check here and if i don't comment that or comment that good night dishipu i might have missed you doesn't make any sense to me it's no sense i copied it but we're right is this the mage ball you have uh i think so yeah usb capture hdmi plus sounds right this is okay i'm not worried about that changing because we are further in the call stack um i can bug me after the stream and i'll look at my email to confirm the mage ball yeah see so here now we're in um assert so we're in this nrfx rtc init which had an assert problem which is only gonna happen in debug which causes us to print it out and then we get into printing stuff and we're in printing stuff and we're in printing stuff and we're in printing stuff and we have problems printing stuff and we're trying to allocate an exception i've got to stop writing for us we have guests um the $20 hdmi dongle is really close in quality if you're going to text you have to share your screen with the whole class you missed it earlier i was texting earlier too um that's not how it works yeah so this is the problem this is why i was like adding these things previously so he's like at some point i hit the cert statement and i have a problem so i was like using these wild truths to like stop earlier to figure out where is it she being changed and why doesn't it why isn't it right um let me let's just take a look at what this is see it's just a bit of math so it's rtc input frequency divided by that minus one which should be okay guess as in non household humans in the same physical space strange concept it is i think they're the first guess we've had is this all before interrupts are enabled like no other code can run in spite of the wild true now i think interrupts are on i think interrupts are on but by the time we halt but by the time we halt it should have run and we should see it right like we should be able to confirm that it's happening because we're printing out the memory right like here are we not going far enough we're only going to oh you know what i bet that's it let's see i'm dividing by four here and then i'm going by four again that's wrong so i'm not going to print everything off 2231 puppy says i've never seen fish shell before should i try it doesn't work on mac it works on mac and i recommend it um so why was the first word reporting the difference i mean it's it's far enough long that maybe something's changing it like i don't know what variable is there um but everything here still is the same and we're still in this ad spot what is the address of the rtc config is 334 it's zero it's being saved as zero because it's little and in i think so zero one dfc the first eight bytes or something is not user memory but is something internal that the nbr soft device uses really i mean that i mean there's system system core clock is what's there that first word is system core clock i think we do set aside the ram ourselves for the soft device so i don't think that's the problem and out of ideas like it's possible it's zero which seems like it would be okay the assert that we're actually failing is i looked it up my brain is toast rtc init config p config preschooler set did i like accidentally type something did i delete a no rtc config with an ampersand this is where i wish i could print rtc frequency to prescalar 32k wait so we got past this is this all just prescalar set i don't know i can wrap up here oh it's in here see assert value has to be less than prescalar mask which zero zero should be i think mac comes with zz shell now yeah set up a software ur yeah i don't know i'm with mark that says i give up all right yeah i'm gonna call it um sorry sometimes you just spend a lot of time and you don't end up with anything that's the way that programming goes um thank you all for joining me for this deep dive it's been a pleasure if you have ideas on what how we can make circuit python days deep dive next week special let me know check out the python subreddit for information about the am a that will do next week and if you want to support me go support ate a fruit by going to ate a fruit dot com purchasing stuff there they pay me to flounder around and not fix any bugs that may or may not exist um so uh thank you everybody for that uh if you want to chat with me or you have ideas about the circuit python day stuff you can go to the url adafru.it slash discord to join uh there and you can at me at at ten new uh there um usually deep dives are more successful but they're always include all these tangents i do them fridays at two p.m. pacific next week will be friday and two two p.m. pacific as well uh thank you for hanging out um and uh it's been a pleasure and i'll i can't pet the cat because he's not here so i'll just tell us see you next week for circuit python day have a great weekend