I'm talking about embedded system design. So this is really rather tutorial, right? This isn't like a new security invention. This is just basically how to build an embedded system. And this is useful information if you somehow wanted to attack a system , an embedded system, or defend a system. It's a good idea to know how to develop them and , you know, how the development is different than just traditional software. I'm Professor from University of California, Irvine, and I teach this stuff sort of regularly. And this is going to be very compressed, right? I mean, it's only, you know, 50 minutes or something. So it's not like I could summarize the whole thing, but I'm going to touch on everything. And then you can also download the slides if you want to. I have like a QR code at the end if you wanted to. And you could pursue some of these topics more, you know, later if you wanted to. Okay, so what's an embedded system? An embedded system is basically a computer that doesn't look like a computer, okay? So like, yeah, a phone, let's say, or the projector, right? The projector is a good example. All you see, you know, there's computation going on inside it, but the interface isn't the same, right? I don't have to write code directly on it. So to work with it, I press some buttons on it or click some buttons on here, you know? So as an example, typical embedded device, like a car, right? You got a car, old car on the left, and a new car. Now, the interface is basically the same, like the driving interface is the same, right? But the new car has like 60 plus processes in it doing all kinds of internal control. So there's a lot of computation going on, but you as a user, you don't have to deal with that directly. So you have to code for each one of these microcontrollers, right? They're all just doing stuff in the background, making things better, but the interface to you is nice and simple. And so that's basically what an embedded device is. Related buzzwords, I just like to define these. You maybe have heard of cyber-physical systems, or you definitely heard of Internet of Things. These are all basically the same thing. Cyber-physical is sort of an older term. It focuses on industrial systems most of the time, right? With big sensors and actuators, like, I don't know, a plant or something like that. And Internet of Things has that word internet in it. So it focuses on the networking abilities of it. Now, in truth, nowadays most embedded systems are networked anyway, so there's not really much distinction. IoT is really an embedded system. They're all... the only difference between, like, just embedded system, if it has networking, which most of them do, then you'd call it IoT. So they're all similar concepts. So main idea is sort of at a high level, the design... one difference in designing that versus designing regular software is being efficient, right? And I find that when I teach this stuff, you know, so we have undergrads, right, who have taken, like, Python and stuff like this, and efficiency is not what they learn, right? Like, when you turn... when they turn in an assignment, it's like, okay, it worked, right? I tested it out a little bit. Barely... they don't really know how to test, but I tested it out. It worked. But, you know, did it work fast? You know, was it... how much memory did it use? And in a language like Python, you have no idea about those type of things, right? Like, the memory, you have no idea, right? So... but with embedded systems, you have to be efficient, because people... these manufacturers are cheap, cheap, cheap. Like, they don't want to spend anything on these devices. Like, they don't want to, like... like, for instance, you would never take a device like that and say, you know what, I'm just going to put, I don't know, an i9... an Intel i9 microprocessor in there. That would be stupid. It costs way too much, right? They would never do that. They would get the cheapest possible microcontroller. They'd be like, what's the cheapest thing? You know, I could save 10 cents if I got this cheaper one. Let's go for that. You know what I mean? It's always efficiency. So, efficiency is really important. And there's lots of constraints. Design costs, performance, you know, power. Power is a big constraint. How much power is it using? And so, all these things you have to really think of when you're doing embedded systems design, where in software design, pure software design, you're not trained to do that so much. You know, you don't have to... you're not thinking, oh, what is the memory that this thing is requiring? Well, with embedded systems, you really are, like, all the time. Okay. Hardware and software. So, embedded systems have hardware and they have software components, right? So, that's actually the badge from last year. You know, it's a little video game thing. And it's hardware and software. So, there's like a microcontroller in there. There's a little screen. There's some speakers. There's a bunch... I don't know what other devices are in there. Lights, LEDs, that type of thing. And they have to be controlled by some software running on the microcontroller, right? So, you have to consider hardware as well as software and design them together. So, this is not what you do in normal software, right? Normal software, like, if you're writing some Python code, you're not thinking, okay, exactly what type of monitor are they going to be running this on, right? Generally not, right? You're not... like, what is the speaker they're going to use, right? But when they designed this, they knew exactly, like, okay, this is the speaker that we're going to use. This is the cheap monitor. And that changed the way they wrote the code. So, you have to think about the hardware side of it when you're doing the design, too. Okay. Outline of the talk. I might not be able to finish all these slides just because, you know, there's only so much time. But three things. So, first, I'll talk about working with the microcontroller. Then connecting the microcontroller to external devices. So, work with the microcontroller's coding, right? Software, pretty much. Then connecting it to hardware devices, other things you want to talk to. And then debugging tools. Because debugging is different in embedded systems, too. Okay. So, microcontrollers are just these little integrated circuits. And you've seen them. Generally microcontrollers, I mean, people have definitions of these things. But generally, they're just, like, cheaper microprocessors, okay? And you can control everything directly, right? Meaning all the hardware on the chip, the programmer can control. And I'll go through what I mean by that. Normally, you can't control a lot of things on regular microcontrollers, microprocessors, you can't control, okay? Like, say you want to print something on the screen, right? You call print, right? But print asks the operating system to do the control. Basically, it calls a system call. The system calls that, checks it out, calls the driver, and the driver puts it on the screen, you know? So, with microcontrollers, the programmer is doing that directly themselves, okay? Yeah, so, how do you program one of these things? So, you have to program them. So, you write your code on some development environment, like a laptop, and eventually you've got to put it onto the microcontroller. So, either you do it with some programmer like that one, like you have this programmer device connected by USB to your development, and then you put the chip in there and connect it to that. This is a really old-fashioned one, but same idea, right? And you can do it that way. And in fact, that's how it's really done in products, right? Because the other way is like this, which is much more common if you're going to do it yourself. It's built into the board. So, say you buy a board like this, or an Arduino, or whatever. This is a board we use in class, right? And this board, it has the programming hardware built into it, okay? So, all you need to do is connect your laptop, whatever, by USB to the board, and the board will do... actually, with this one, this is the main chip that runs the code. This one deals with the programming. It takes the USB, transfers it into this guy. It has a bootloader running on it, and it programs it, okay? So, this is like what do-it-yourselfers use, but this hardware here is excess. Like, you don't really need that once you deploy the device, right? So , in real devices, they do it this way, and then all they're deploying is this. This is useful, though, in practice for regular people. Okay. So, ARM. So, ARM is the brand of microcontroller that is the most common, okay? So, you know, Intel and AMD, Intel-class machines dominate microprocessors, right? Well, in microcontrollers, Intel has, like, no... they don't make anything that anybody uses, really, right? Instead, ARM makes them. Now, ARM, what they do is they lease the design. So, they don't make silicon, right? They don't make the chip. They lease the designs to other companies who make the chips. So, maybe they lease it to TI, TI makes chips. Maybe they lease it to STMicroelectronics, they would make the chips, right? But ARM is the type of microprocessor, microcontroller that's in there, okay? It's a dominant one, and there are different classes of them that I don't need to go over, that I don't feel like going over right now. But there are, for instance, Macs, right? Those M1, M4s, and all those, those are all ARM, right? Basically, everything in everybody's phone is going to be an ARM. Not everybody's, there's some that aren't, but most of them are going to be ARMs. Like, most of these devices use ARM microcontrollers, you know? And that's only relevant because the machine language is different, but you don't really have to worry about that unless you're coding in assembly, which you probably are not. Okay. Now, microcontrollers have peripherals. What I mean by this is, okay, this, I know you can't read the details of this. I took this out of a data sheet for a microcontroller I used to use for class. Now, up here, I'll just tell you, up here is the CPU, okay? This is the main processor, the ARM microcontroller, right? And that thing is what runs your code. So, it executes instructions, right? The rest of it is all, like, other stuff that connects to it and does useful things, okay? So, for instance, there's memories. I can't even read them. Memories and stuff like this. But what you see, this diagram, just so you know, this was one long column in the data sheet, but I couldn't fit it onto the slide that way, okay? This, but the main thing is this CPU is connected by these two long buses, these buses, right? Connected by these buses to all these peripherals, what are called peripherals. Now, these peripherals are what do interesting stuff on microcontrollers. They do all kinds of things. Like, for instance, general purpose I.O., right? The pins. If you want to control the pins, that's a peripheral. Or if you want to communicate by UART, that's another peripheral. Or if you want to do analog to digital conversion, that's another peripheral, right? There are all these blocks are peripherals, okay? So, when you're coding, you know, some instructions, some things you do are the same, right? C is C. I'm assuming C right now, right? C is C. But the big difference with microcontroller programming is that you have to control these peripherals specifically. You have to tell them exactly what to do step by step, okay? And so, there's a bunch of peripherals that you've got to learn about for any particular microcontroller and learn what it can do and how to control it, okay? Peripheral control. So, common peripherals, okay? Memory, GPIO, general purpose I.O., timers, you've got communication, all these different protocols that you can use, analog to digital converter, there's a whole bunch of peripherals, okay? So, embedded software directly controls peripherals, all right? I said that. Yeah. Yeah, okay. Now, another thing to think about when you're doing embedded system design is this distinction between whether you're using an operating system or not, okay? So, you can make some devices operate with a real operating system, like a full-on operating system. Like, I was seeing a talk, I don't know, yesterday or something like that, and somebody was talking about, you know, he was talking about attacking embedded systems. Like, I've seen many talks like this where they talk about attacking embedded systems. Maybe they use a router as an example, how to dump the firmware, whatever. And these devices, a lot of these devices have just Linux running on them, like a small Linux, right? And that's just running a full-on operating system, okay? So, you can do that. Now, the downside of that is that, you know, it's easy because it's running Linux, but there's overhead, right? You're running an operating system on top of the microcontroller. So, in the operating system, it's a burden on the microcontroller, meaning, you know, it requires a lot more memory and a lot more flash and all kinds of junk, right? So, if you want to be really cheap, you might not want to use a full-on operating system. So, then sometimes people use bare metal. It's the other way. Bare metal is where you don't have any operating system of any kind and you just write your code and you do everything yourself, okay? You control everything in detail. See, if you have a full-on operating system, you have drivers, you have all kinds of stuff that make your life programming easier, right? But if you're doing bare metal, then you don't, right? You have to really understand all the details of how to control the peripherals. And then there's this in-between, which is real-time operating systems. Real-time operating systems are basically stripped back operating systems. They don't have like a nice GUI or any of that stuff, but maybe they support multithreads, you know, threading. They support that and they also support scheduling algorithms. So, basically they're made to satisfy real-time deadlines, right? So, if you have some tasks that need to be performed, like, you know, I got to sample this thing 8,000 times a second, this audio signal, right? And you got to meet that deadline no matter what. A real-time operating system is the way to go because it'll make sure that it interrupts everything around that deadline, you know what I mean? So, they have scheduling algorithms that they use to support that. Okay. So, embedded systems are said to have a, if you're going to program one, you have what's called a toolchain, usually. Toolchain is basically an IDE and they're all sort of the same, right? I mean, that's just generic IDE looking thing, right? This particular one is ST microelectronics IDE, STM cube IDE, but they're all basically the same thing, okay? And you've seen them. Here's the code and here's all the files in the project and all that stuff, right? So, the one difference in an embedded system IDE is that you have a programmer that's attached to it. So, one thing you have to do is, like, once you compile the code, you actually cross-compile the code. So, compiling a code, normally, if I compile code on this machine, it'll be compiled to execute on this machine, right? On this microprocessor. But with an embedded system, you compile it on this machine to run on a different processor, right? That's called a cross-compiler. So, this thing uses a cross -compiler and the last step is to take the cross-compiler executable and program it into the flash of the actual device. And that's what a programmer does. So, it's some programmer software. So , usually this thing has, like, this extra button in there, it's like program, and it just programs it onto the embedded device after you've compiled. Okay. So, IDEs, though, they don't look that much different. Now, one, another sort of painful difference in embedded programming is datasheets. Here's a datasheet, or the reference manual, whatever they call it, okay? These datasheets are massive, okay? They describe everything that a component is supposed to do. Now, you can get datasheets on all kinds of integrated circuits, all kinds of components, right? But right now, I'm talking about the microcontroller. So, like, this is the microcontroller I'm going to use in class in the fall, actually. I'm just starting to learn it and use it in the fall. I was like, oh, let me use it in this talk so I can start getting comfortable with it. Its datasheet is 1,757 pages long, okay? That is a painful datasheet, right? And it describes every peripheral on there, how you use every peripheral, every little detail, okay? And you have to be familiar with a chunk of it, right? And learn how to search really well, okay? Like, you can't memorize all that, but you got to search, you got to remember to look at that datasheet, okay? And then sometimes, in the very worst case, the datasheet is incomplete, right? It doesn't say what happens in a certain case, which is real hard to find, because you're like, well, I couldn't find it, but there are 1,700 pages, right? Maybe I missed it, right? Or it's wrong. That happens too. The datasheet will say something incorrect, and that's very painful, okay? And, you know, I use a lot of Google, because usually, whenever you find that, somebody else hopefully has run into the same issue. So, anyway, you have to get used to reading these datasheets, okay? Just in general. So, importance of datasheets. So, it is very easy to miss important information. So, as a broad example, right? Say I'm talking about my 1,700 page datasheet, and I want to do... it leads to bugs, which can be exploited. This is where a lot of bugs can happen, right? So, say I want to do UART communication, right? I want to communicate with another device by UART, which is protocol, right? So, there's a section in the datasheet on UART, right? Just on that. So, you're like, okay, let me read that whole section, right? Okay, based on that section, my code works. And you test it out, and you're like, okay, it works, right? But then you didn't notice that in this other section, 500 pages later, they were talking about reset, okay? And in reset condition, maybe UART works differently, right? There's like a special case that you missed, because it was far off in the datasheet, right? Very painful, okay ? This happens, right? And as a side note, this is like the first thing, like, if you really wanted to make malware for an embedded system, this is what you would do, like exploit the drivers that are written on there, right? Because it's very easy to put a bug into these things. There's this embedded system capture the flag, embedded capture the flag that MITRE runs, and we have a team that competes in that every year, and the CMU team usually wins. They didn't win this year. But this is how they broke our system and a lot of other systems, was by basically, they didn't say this, but I'm pretty sure they fuzzed the drivers for I2C, which is a communication protocol. They fuzzed the I2C drivers until they found such a vulnerability, and then they exploited it. So, anyway, data cheats are painful and important to understand. Peripheral control registers. Okay. So, when you're writing code, you have to control these peripherals and tell them what to do. So, peripherals are controlled through registers. Now, a register in a chip is just a storage element, you know? Like a 32-bit register. Typically, these are 32-bit devices. They've got a 32-bit register, right? It just stores 32 zeros and ones. And all of these peripherals, every peripheral has associated with it some registers that are used to control it and to observe it, right? And the whole goal of your code, and if you want to talk to a particular register and make it do something, say you want to do analog to digital conversion, you have to read all about its registers, write the right bits into the right registers, and then it'll do it. Okay? That's how you do control. These registers are like the interface to all the peripherals on your microcontroller, okay? So, a lot of this, like, my students, they sort of... a lot of them get sick of this, because you're, like, looking at all these tedious details. Oh, I see it's bit five of this register makes this start, and bit six puts it in this mode and all this. That's why the data sheet's, like, 1,700 pages long, okay? So, that's how you control them, through these registers. So, and if you... anything you want to do, drive a value onto a pin, or do A to D conversion, UART, or whatever. Now, so, as an example, right? I pulled out, on the right, I know you can't see it, but on the right, it's basically a part of a data sheet. It's the schematics inside a data sheet for a particular... for this STMicroelectronics chip, okay? And this schematic is showing me one pin in the GPIO. So, GPIO stands for General Purpose Input Output. That means the pins of the chip. If you drive to ones and zeros to turn lights on, or whatever, right? And you can read them, too. Maybe some of the device is driving a 0-1 output, you want to read it. So, this is, like, the hardware behind a pin. So, over here is the pin, in tiny letters, says IO pin, right? This is the pin. And then, this is all the logic associated with the pin. And then, over here, to the left, over here, is, like, the microcontroller, okay? So, and the only thing I want to highlight here is that they show some of these registers. I put them... I highlighted them in red. And they name them in the data sheet. GPIO... oh, and I'm talking about GPIO port A. There are many ports on these things. So, I'm talking about port A. IDR, GPIO-A-BSS-RR, and GPIO-A-ODR. So, like, IDR is the input data register. So, what that means is, if you want to read, if that, say, some other device is driving a 1 onto that pin, and you want to read what it's driving, you read the IDR register. You read the appropriate bit of the IDR, bit 0 of the IDR register will tell you what's being driven onto port A, pin 1. Pin 0, rather, you know? So, you read this register inside your code, right? And then this register is to set output bits. Say I want to set a particular output bit high. I set the appropriate bit in this register. And say I want to write all the output bits to something. I go to this ODR, output data register, and write all the pin outputs. So, the idea here is just that every peripheral has a set of registers. And you have to learn what all of them do, what they're all for. Okay. Now, registers are memory mapped. So, what that means is that in order to write to a register, you write to a memory address. So, every one of these registers is mapped to an address in memory, which you will find, again, in the datasheet or reference manual, whatever it is, right? In the datasheet, it will be like, GPIOA, output data register, is that address whatever, okay? And then all you do to write to that register is you write to that address, okay? And these addresses are in the datasheet. So, you have to... and now, usually, like, in my class, I have students read the datasheet in hard, you know, hash to find it all at the top of their code, right? They usually, like, with these devices, they usually have, like, a header file that has them all defined for you. You know, most IDEs have that. So, you can just include, hash include, whatever that header file is, and then you can just write to... then these definitions are already made. Otherwise, you have to hash to find them explicitly in your code. By the way, if there's any questions, go ahead and raise your hand. I'm perfectly fine answering questions right in the middle, if that's fine with me. And I know I'm going fast. I always do that anyway, but anyway. All right. So, blinking an LED. So, this is the one I'm going to use in class, STMicroelectronicsBoard. And just... this is the main microcontroller. This is used for loading from... this is a USB connect interface. And say I want to blink an LED. Now, on this board... oh, I should mention here, there's a difference between the microcontroller and the board, okay? The microcontroller is this chip right here, okay? It has this data sheet and all that. The board is this whole thing, which has the microcontroller on it. And the reason I bring that up is because you need both to do this. So, for instance, in order to blink an LED, basically there's going to be an LED that's wired to a particular pin of my microcontroller. And I'm going to have to know what pin is that LED connected to, right? So, now this board, like all boards, they have an LED built in, right? This has multiple. But that little red circle there, I circled the LED. You can't see it, but it's an LED built into the board. And I have to look at the board's data sheet, which is usually much easier, to say what pin is that connected to. So, looking at the board's data sheet, this LED is connected to port D, pin 14, okay? So, I know that. So, now my goal in writing this blinking LED code is to turn on... okay, well, let me skip that first line. I'm going to basically see the while loop, drive a 1 onto the pin, delay, drive a 0 onto the pin, delay. That's the basics, right? And that's a blinking LED. Now, before that, there's a couple of things I have to do. One thing is this first one, turn on the clock to the GPIO port, or D. So, what they do a lot with these peripherals to save power is they turn off the clock to these peripherals. So, there's a clock. A clock is a square wave that determines the rate at which events happen on the chip. If the clock is going, it is consuming power. So, they just shut off the clock to peripherals that are not in use by default. And so, you and your code have to turn on the clock to the peripheral before you can use it. So, you turn on its clock. You're going to have to do that. Again, there's some register. You set a bit, it turns on its clock. Then, you've got to set the port to an output pin. So, these pins, they can be inputs or outputs, okay? So, you're going to set this pin to an output so that you can drive outputs to it, okay? So, you have to do those two things first in your code. Then, you get into a while loop where you just do that, okay? So, just to show a little more detail, and we're going to do this by adjusting values of registers. So, okay. Now, I'm just showing you a few of the registers just to intimidate you, to make you see this data sheet is paying, okay? I don't expect you to understand all this. But, when you look in the data sheet, it has a description of every register. And I just went and zoomed into a piece of that, okay? So, there's this register. RCC, whatever. AHB is a bus name and all this, okay? This controls the clocks for the GPIO pins, okay? So, I've got to turn the clock on for a particular port. So, notice this register has got 0 through 15, right? Up there in the top. That's half the bits in the register. All the registers are 32 bits, right? So, I'm just looking at the first half. And if you zoom way in on this, it says GPIOD EN for enable. And then, in the data sheet, it will say, oh, pin 3 on this register enables the clock to GPIO pin 4D, okay? So, you've got to set that bit to a 1. Then, GPIOD mode register. This is... it'll set the mode... if I want to set it to an output or an input or what kind of output I want it to be, you set it here. So, the particular pin I'm interested in is pin 14, right? That's these two pins. Like, these two are 15. These two pins. And I have to set them to, like, 0, 1, if I recall. And that puts it into output mode. And then, over here, this is the output data register. If I want to set the value on the output to be... I want to set the bit high and set it low, I've got to go to bit 14, because it's pin 14 on the port, and set that to a 1 or a 0. It'll set the pin to a 1 or a 0, right? So, all these... so, I've got to look at not just the register, but the individual bit of this register, put a particular value in there, and it does what I want, okay? Okay. Question? Okay. So, here's my code for that. And I don't really expect you to follow all of it, but let me just say the structure of it. So, one thing is... so, there's a number of registers that I have to control, right? So, first thing I'm going to do, or somewhere in the code, I have to assign the addresses, right? Maybe I did that with hash defines at the top. In this code, I did it here. So, I said, this register equals, and I set it to this address, okay? And then... so, I set it to... I set these registers to their addresses, and then I set them to values. Star that equals a 1 shifted 3 over, because I want to set bit 3 high, and so on. So, I got... I do that. So, these are the initializations I was talking about, making an output register. I initialize the output to 0. Then, here's my while loop. I just say, set it to 0, set the pin to 0. Then, I have a loop, a dummy loop. Then, I set the pin to a 1 at bit shifted to bin 14, and then I have a dummy loop, and that's it. So, that's the code. Question? No? So, I'll talk to you about... I'm curious. So, you know, I've, of course, been thinking about that too, right? Because, you know... and I'm mixed... I've mixed feelings on that, right? Because... so, first of all, I can see how it'd be very useful, but I can also see how it causes people to not bother learning the details, which is exactly how security faults happen, right? You're trusting the AI model, and if it messed up, then you mess up, and you don't even know why, right? So, I don't know. But still, I'm curious, okay? I'm curious, and I might use it, but you always have... it's just not safe, security-wise. Yeah. Yeah, I think so. I mean, I agree. I wonder if that'll change one day, but who knows? But, yeah, I believe it. So, okay. So, this is a Blinky. This is sort of the most low-level type of Blinky you could write, where you directly control these registers and their values. Now, that can be tedious, okay? So, sometimes, a lot of times, when people make these devices, if they're doing bare metal without an operating system, they will use libraries. Libraries, where they make things... you know, you don't have to worry about each individual register. You just call a library function, and it does stuff for you. So, most of the time, when people make these things, they often use these libraries, right? So, there are vendor-specific libraries. Like, I'm using this for STM microelectronics. They have their HAL library, right? STM32HAL. And different vendors have their own libraries. Plus, there are vendor-independent libraries, like CMSYS is a popular one. It's across ARM, platforms, right? And then, Arduino, Arduino itself. So, Arduino, there's a particular... there's Arduino devices you can buy, but they're also... you can use the Arduino... Arduino development board has been ported to other devices, right? So, you can use Arduino. Like, I know... they use it on... there's another class in my school. They use it on an ESP32, right? So, they... but they use Arduino libraries on that, right? Which is another set of libraries. So, it's sort of a high-level library. It makes things easier. But the... yeah, I think it's on the next slide. Yeah, the downside of these libraries is that they hide details, okay? So, with any library, okay? And so, anyway, here's an example of Blinky using the HAL STM32... oh, and they're also slow. They're also slow. Because they often do... like, I was looking at the HAL library functions, and they do a lot of stuff that I don't need, okay? If I just want to make a Blinky, it is much quicker to do it my way. Now, who cares with Blinky, right? But my way is a lot more efficient. I mean, when I say my way, going straight to the registry is a lot more efficient. Like this, okay? This basically, you know, they have a toggle pin, and they have a HAL delay, thousand, whatever. But, like, things like... where is it? HAL init. HAL init initializes all the peripherals. I don't need that, okay? So, they don't have, like, a HAL init just for the GPIO, right? Not that I know of. But you initialize all these peripherals, you don't need it. And I don't even... oh, this guy's for GPIO init, but you got to do the HAL init, too. I don't quite understand the relationship there. But looking at the code, it's just a lot... when I look at the code of them, it's a lot more stuff than I did, okay? So, anyway, that's HAL. And then with Arduino, here's how you might write it. You set up in a loop, and digital write is their function. Now, you know, tradeoffs with the libraries, when you use libraries, the advantage is it makes everything easier. The disadvantage is that the libraries themselves might have exploitable bugs, okay? That's one security difficulty. But also, they're slow. They're generally slower, right? So, it depends on how efficient you really need to be, but they're generally slower. Most of the time, people use these libraries, though, in all honesty, because they do make things more convenient. Okay. Okay. Next bunch of the talk. Connecting the microcontroller to external devices, okay? So, you want to... so, it's not all about just programming the microcontroller. You got to connect to other things. So, analog interfacing, start with that. So, there are a lot of these little analog devices that you might want to control, or you might want to observe. So, like an LED, you might want to turn it off and on. A motor, you might want to drive it, right? And that's if it's an actuator, right? You're driving it to do something. Then there's also sensors that you want to read, like a push button, or a potentiometer, it's a little knob, you might want to read these. This is just a few of them, right? Now, these are all simple ones, okay? Simple analog actuators and sensors. So, with those, you have to do a little bit of analog electronics, a little bit of analog electronics. Now, analog electronics are painful, okay? Analog electronics are hard in general, but this much you can do. So, like with me, I don't do analog electronics. I can do digital. Analog is going too far, but that's like a basic chunk of it that you need to know, and you just reuse, okay? In practice, embedded designers are not generally analog electronics professionals, usually. So, Ohm's law. Okay, this is really, really, like, simple. So, don't be intimidated, you may remember this from physics or something. V equals IR. So, voltage is like the electric pressure, right? I is the current, and R is resistance. So, think of this like water going through pipes. It's exactly the same thing. The pump is like the battery, the voltage source, right? So, it supplies pressure, generates pressure. So, in these pipes, the pipes are the wires. Current is current, right? The flow of electrons per unit time. And then resistance is anything that blocks the current. So, you know, junk, put some rocks in the pipe, or there are low resistance materials or something like that, or narrow wires. A wide wire has a lot less resistance than a narrow wire, and so on. So, anyway, V equals IR. This, you have to be a little familiar with it to use some of these devices. So, diodes and LEDs. So, I'm just going to talk about LEDs, because they're like a simple device, right? LED stands for light emitting diode. So, a diode symbol is just like this, right? A diode, it has one, two ends, an anode and cathode. They are not symmetrical, okay? And current flows from the anode to the cathode, flows straight through, okay? That's all it does, and current can't go backwards. Like, that's what a diode is. It's like a valve, can't go backwards. You have to apply a certain amount of voltage, so the anode side has to have higher voltage than the cathode side, by about 1.9 volts or something like that, and then it flows, right? Below that, it doesn't flow. And then with an LED, a light emitting diode, this is what a regular diode looks like, a light emitting one, when current flows, it lights up, okay? So, that's a diode. All you have to do to make a diode light up is apply current, make this like zero volts, and make this three volts, or some 3.3, whatever you want, and then current will flow to light a light up, okay? So, how do you do that? So, say I want to do that, right? I want to make my, I have an Arduino or whatever board, and I want to make a blinky example, right? So, I want to be able to light up an LED. So, I've got to take that LED, connect its anode, one side of to an output pin, any output pin, pin 13 in this case. The other side goes to ground, which is zero volts. And when I set this pin 13 high, then it's going to light up. When I set the pin low, it's not going to light up, okay? Now, note that I put this little resistor in the way, okay? Now, the reason I did that is so that I didn't blow up my diode, okay? Because these diodes, this is the one little analog electronics you have to know. These diodes are limited in the current that they can deal with. So, if you look in their data sheet, maybe 10 million, like I think 20 milliamps is like the maximum that they can take, right? So, if I'm using a 3.3 volt device thing, like my board is 3.3 volts, right? If I'm using that, and I say, well, what's the current going through it? If I use about 330 ohms of resistance, then I get like 10 milliamps. That's safe, right? So, I need this resistor of 330, okay? That's like all you need to know, okay? You don't really need to know much more analog electronics than that. But yeah, I need a little circuit like that. Now, then once you get it, once you decide, okay, this is how I have to wire it together, right? Like this. Then you got to wire it together, right? Physically wire it. So, notice there's an Arduino or whatever board, and then there are two components, a resistor and a diode. So, I got to put them together, and usually do-it-yourselfers are going to put it together on a breadboard. Now, a breadboard is basically, it looks like this. It's got holes. These holes, stick wires in them, right? And it just sort of grips the wire. But you can pull it up, push it and pull it out. You can redo it. And so, these rows of five are all connected. So, all these pins are connected. All these pins are connected. But this row is not connected to this row, okay? So, the use of this is, say I want to connect a resistor to a diode. I put one pin of the resistor in one hole in the row, put one pin of the diode in another hole in the same row, they are now connected, okay? So, that's how you make connections. So, you can take this picture and connect them on a breadboard like this, okay? That's the idea. And in fact, here's a picture of that. So, I got, you can't read all the details. This is actually an Arduino over here. So, this is pin 13. It's connected to this row where there's a resistor. The other pin of the resistor goes into this row, which is connected to the diode. The other pin of the diode goes into this column, which is connected to ground, okay? So, you have to, that's another thing you have to kind of get used to, seeing a schematic, like a drawing of the components, and then wiring it on a breadboard, right? Like, the relationship between it, you have to be able to do that, okay? But it's straightforward, you just practice it a little. Okay. So, that's, you know, simple electronics wiring, right? So, you do that, and then your program should work and blink the light. Okay. So, I was just talking about GPIO. GPIO is like the first thing you learn to use on your microcontroller. But there are other things on the microcontroller, all kinds of peripherals, a whole bunch of them, and you eventually learn how to use all of them, right? Can't teach them all now, but you learn how to use all of them. And each one of them has a set of registers devoted to it that describe its behavior. Another thing is synchronous protocols. But when you have like a board and you want to connect it to another hardware device, you often use, you have to use some kind of communication protocol. Synchronous protocols are common. They're faster, they share a clock. Anyway, I can't go into details of the protocols, but FPI and I2C are the top ones, you know, that people use. And give you an example. Say I got like this, this is an Arduino, actually. And I only connected it to two components that I bought off of Adafruit or whatever, right? And these two components I know are I2C compatible. So when you look at the data sheet for these guys, it'll say, oh, this speaks I2C, this speaks I2C. So then you say, okay, I'm going to use I2C. So you wire it to the I2C pins of your Arduino. They're SDA and SCL, the two wires, two pins for I2C. SDA is a data line, SCL is a clock, right? And these guys, there's like a master and slaves. If you say this is the master, controlling everything, these are the slaves, and this guy can communicate with these guys using an I2C protocol, okay? Now, I don't have time to describe I2C, but just so you know, all of these protocols, like every other peripheral, is controlled through a set of registers. So there are certain registers like I2C1, CR1, and CR2. Control register one, this should say it too. The control register is used to control different aspects of the I2C, how fast the clock is, and all kinds of stuff about I2C and all its parameters when you look in the data sheet and see what they're all for. Also, I2C DR, DR is its data register. So if I want to write a byte on I2C, I want to send a byte, I write it into the DR register, and it'll get sent, right? So my program doesn't have to, you don't have to know I2C, you just have to know, oh, if I write into this DR register, it will get sent, right? And then on the receiving end, if I read from this DR register, I will receive whatever was sent, okay? So there's hardware built in that deals with all the details of the protocol. Okay, so, okay, good, make it. So, yeah, so the last part is debugging tools. So there are some different debugging tools when you're doing embedded design, right? So here's just my, some random design, okay? And it's got board and some components, some hardware components, all wired together, okay? Now, you probably use standard debuggers, right? You set a breakpoint, you step through the code and all that. So you can do, you can do that, right, with this, but that doesn't, that control, that works on the micro control. You can set a breakpoint, step through it, but what about all the rest of the devices, right? There are other things that you want to view. So it is very common in these designs to want to see the value on a wire. You might want to say, oh, is this high or is this low, okay? Random wire, very common to need to do that. You're like, I wonder what's being sent. Is it a one or a zero, right? So how do you do that? One way is with multimeters. So the first thing, you always have to have it. You gave some out, Sydney, yesterday, right? Multimeter, it's just a little, you get like a handheld one or a bench one, and basically it tells you the voltage between two points. So you can tell if something is high or low. It can read the current, how much current is going through there if you need to know. It can read resistance between two points. It can read connectivity. So it'll like, they almost always have connectivity. So if these two pins are connected, it'll beep. So if you're like, oh, is this wire connected to this one? It'll beep, they are. And they have probes. So these two probes, like you take a black and a red probe, put them in like here and here, right? And then the other ends of these, you touch to the wires that you want to test the voltage on, for instance, okay? So multimeters are like basic tool. But the thing about multimeters is that they are very slow. Meaning, you know, if you have a chip running at 16 megahertz, it's not fast, but that's a heck of a lot faster than a multimeter can respond, right? So multimeters are only good for looking at signals that are constant. It's held high, like for half a second at least, or held low, half a second. Changing signals, you can't use a multimeter. So one thing you use is an oscilloscope. Now an oscilloscope, it basically, it'll have a screen and it just plots voltage over time, okay? Now oscilloscopes though, they're usually very few probes, two or four probes. So they can look at two signals, two wires at a time, or four wires at a time. And here's like an old one, an old analog scope. And now the analog scopes, they only work for repeating signals, okay? So the signal has to be like the same over and over, like a waveform, a sine wave or something. And it'll work for that, right? The old scopes. The new scopes, digital scopes, they're not like that. They can read, they can just sort of read it and capture it, right? Capture it at snapshot time and show it to you on the screen. But then you can say, oh, look at this time, it was high. Now at this time, it was low, right? And these things are very fast. You got to get a, they cost a lot of money, but you can get one that's faster than what you're, it's like 10 times faster than whatever you're sampling. And you can use an oscilloscope. Now oscilloscopes, one thing that they, one thing you need to do with oscilloscopes is do triggering, okay? So triggering is determining when to start recording. So these things, they have a buffer. I don't know, maybe say it has a two gigabyte buffer, okay? But for every, it's sampling, but it's got to be sampling like a lot faster than your signals. So say it's sampling 200, 200 megahertz, that's not even that fast, but say it's sampling 200 megahertz, it will fill up and every sample is recording a lot of data. It'll fill up this buffer very quickly. So you need triggering to determine when to start recording, okay? To see what you want, right? So one way to do is manual triggering. You hit a button and it goes, okay? That works fine if you're approximately know when, when the thing is you want to record, but a lot of times you don't know, like you want to record when a certain event happens, okay? With oscilloscopes, another way triggers level triggering. So they repeatedly trigger whenever the signal reaches a certain level. When it goes above X amount of voltage, it triggers and it draws it, okay? That's another way to trigger. Also, there's one shot versus continuous triggering. So one shot means record once and just put that on the screen and hold it there. Continuous means record once, put it on the screen, record again, put it on the screen, over and over and over. And so for a repeating signal, that's useful. You can see if it's changing or what. Similar to an analog scope. Now, then another thing that's really useful is a logic analyzer. These cost even more, but the downside of a logic analyzer is that they are only digital. See, an oscilloscope is an analog device. It'll measure analog voltage. An oscilloscope is either zero or one, okay? It's only going to show that. So it's less information, but they have a lot more pins. They'll have like 32 pins, 64 pins. So you can see a whole bus at a time, right? A whole big bus, which is useful, but expensive. They cost a lot of money. Or you can get the cheap one, like I do, which has like 10 pins or something, right? And it's like USB connection to my device. Okay. Question? No? Okay. Yeah. So anyway, these are useful like that. And they're actually, they're usually very smart too. They know protocol. So like they know I2C. So they'll just mark it up for you. You know, it's pretty useful actually. Here's one that I have, a USB logic analyzer. So it's connected by USB to my laptop. You download a free app and you can do stuff with it, record and stuff like that. And it's got a lot more wires that you can use to probe. And that's about it. You could download the slides if you want to download the slides and let me know if there's any questions. We do have time for about three to four questions and I'll hand you the mic. Go ahead. I work with a firmware team for whom the idea of cybersecurity is completely new. What is the best way to establish rapport with them on cybersecurity? Because they hear cybersecurity, they say, doesn't belong to me. I make devices, but you know, we're kind of notorious for, I'm an industrial control system. So that it's a new field for us. Yeah. I mean, so one thing you could do is scare them with actual documented, like a hearing these attacks that have happened to industrial control systems. I do that in my class, right? Like to entice the students and show them how important it is. Like, you know, it's easy to find, right? Especially around here. You know what I'm saying? You could get like a list of events and just show it to them. You could also make them participate in that MITRE embedded capture the flag. My undergrads, yeah, that's, so what they do in that it's like six weeks, you get to build a system that they tell you. And then six more weeks, you get to attack everybody else's system. So like these teams, every team turns it, they give you a design and then you got to build it over six weeks, make it secure. And then you give it to, then you trade it to everybody and everybody else attacks and you get points and stuff like that. And that was pretty eyeopening for my students, especially like the talk at the end, where they sort of talk about how they did it, how they attacked, like the CMU guys, saying how they attacked that I2C. Like if they hide some details, so like with the CMU guys, right? They said, yeah, we found vulnerabilities in this I2C driver and we did this and that with it, right? I'm like, I'm thinking, how did they find these vulnerabilities? And they didn't say, they had to do fuzzing. In my conclusion, they had to fuzz it, you know? Because it's not like they eyeballed it and were like, aha. I mean, I would be really shocked if they did that. But anyway, maybe that, I don't know. Yeah. So I don't work in industry, right? So I don't really have to vet anything. But I do in Bad Catch the Flag, I have them fuzz the libraries. I teach them, I do have the lecture material on fuzzing. I'm like, okay, fuzz each one of these that you're going to use because of that CMU attack, actually. But that's what I do. No, no, I just have them do it from scratch. Yeah, I just have them write their own code for fuzzing from scratch, yeah. Thank you, Professor Harris. I'm very interested in your topic. You mentioned this devices to do the diagnostics and stuff, right? But maybe this is something with security diagnostics or geo tag debugging, some stuff that should be covered? Sorry, yeah, I didn't show that. You're absolutely right. So that certainly exists. So this I didn't go into. So generally debugging, like setting breakpoints and all that is harder on an embedded system. Because when you set a breakpoint, you change the memory value, right? But these things, a lot of these embedded systems run in firmware. So you got to change the firmware to set the breakpoint, but you can't just reflash every time you want to set a breakpoint, right? So a lot of times people will use JTAG debugger. I just sort of didn't cover it as a whole. And you can get tons of information out with those, you know, you can get runtime information, like we do, we use embedded trace macro cell where you can get, you can follow all the branches. Actually, so I have a paper where we follow the branches to see if malware is running, right? Because you know, if malware is running, it'll branch to the wrong location. Some, you know, somebody did a buffer overflow and change the return address pointer, it'll jump somewhere weird, right? So with one of these debuggers in real time, you can have another processor that's ruining the branch addresses through JTAG or through whatever, SWD. So those exist. Those exist. I just didn't talk about it. Those are useful. They cost a lot of money, though. That's the problem. They cost a lot of money, like Lauterbach, thousands of dollars for one of these things. But embedded... yeah, go ahead. Yeah, that's right. I'm assuming no more questions. Okay, thanks.