1 00:00:00,000 --> 00:00:02,280 I'm talking about embedded system design. 2 00:00:02,280 --> 00:00:04,680 So this is really rather tutorial, right? 3 00:00:04,680 --> 00:00:07,140 This isn't like a new security invention. 4 00:00:07,140 --> 00:00:10,200 This is just basically how to build an embedded system. 5 00:00:10,200 --> 00:00:15,560 And this is useful information if you somehow wanted to attack a system , an embedded system, or defend a system. 6 00:00:15,600 --> 00:00:23,060 It's a good idea to know how to develop them and , you know, how the development is different than just traditional software. 7 00:00:23,440 --> 00:00:29,980 I'm Professor from University of California, Irvine, and I teach this stuff sort of regularly. 8 00:00:30,000 --> 00:00:32,720 And this is going to be very compressed, right? 9 00:00:32,720 --> 00:00:35,240 I mean, it's only, you know, 50 minutes or something. 10 00:00:35,480 --> 00:00:39,020 So it's not like I could summarize the whole thing, but I'm going to touch on everything. 11 00:00:39,020 --> 00:00:40,980 And then you can also download the slides if you want to. 12 00:00:40,980 --> 00:00:43,920 I have like a QR code at the end if you wanted to. 13 00:00:43,920 --> 00:00:47,580 And you could pursue some of these topics more, you know, later if you wanted to. 14 00:00:48,220 --> 00:00:50,080 Okay, so what's an embedded system? 15 00:00:50,360 --> 00:00:54,960 An embedded system is basically a computer that doesn't look like a computer, okay? 16 00:00:54,960 --> 00:00:59,500 So like, yeah, a phone, let's say, or the projector, right? 17 00:00:59,500 --> 00:01:01,020 The projector is a good example. 18 00:01:01,020 --> 00:01:05,500 All you see, you know, there's computation going on inside it, but the interface isn't the same, right? 19 00:01:05,500 --> 00:01:07,600 I don't have to write code directly on it. 20 00:01:07,600 --> 00:01:12,420 So to work with it, I press some buttons on it or click some buttons on here, you know? 21 00:01:12,440 --> 00:01:15,760 So as an example, typical embedded device, like a car, right? 22 00:01:15,760 --> 00:01:19,820 You got a car, old car on the left, and a new car. 23 00:01:19,820 --> 00:01:24,660 Now, the interface is basically the same, like the driving interface is the same, right? 24 00:01:24,660 --> 00:01:30,300 But the new car has like 60 plus processes in it doing all kinds of internal control. 25 00:01:30,360 --> 00:01:34,720 So there's a lot of computation going on, but you as a user, you don't have to deal with that directly. 26 00:01:34,720 --> 00:01:37,800 So you have to code for each one of these microcontrollers, right? 27 00:01:37,800 --> 00:01:42,960 They're all just doing stuff in the background, making things better, but the interface to you is nice and simple. 28 00:01:43,080 --> 00:01:46,060 And so that's basically what an embedded device is. 29 00:01:47,340 --> 00:01:49,860 Related buzzwords, I just like to define these. 30 00:01:49,980 --> 00:01:53,640 You maybe have heard of cyber-physical systems, or you definitely heard of Internet of Things. 31 00:01:53,640 --> 00:01:55,880 These are all basically the same thing. 32 00:01:55,940 --> 00:01:58,420 Cyber-physical is sort of an older term. 33 00:01:58,420 --> 00:02:02,820 It focuses on industrial systems most of the time, right? 34 00:02:03,260 --> 00:02:07,560 With big sensors and actuators, like, I don't know, a plant or something like that. 35 00:02:08,040 --> 00:02:11,040 And Internet of Things has that word internet in it. 36 00:02:11,040 --> 00:02:14,060 So it focuses on the networking abilities of it. 37 00:02:14,060 --> 00:02:19,660 Now, in truth, nowadays most embedded systems are networked anyway, so there's not really much distinction. 38 00:02:19,660 --> 00:02:21,380 IoT is really an embedded system. 39 00:02:21,380 --> 00:02:28,120 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. 40 00:02:28,820 --> 00:02:31,100 So they're all similar concepts. 41 00:02:31,400 --> 00:02:35,640 So main idea is sort of at a high level, the design... 42 00:02:35,640 --> 00:02:40,400 one difference in designing that versus designing regular software is being efficient, right? 43 00:02:40,400 --> 00:02:51,680 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? 44 00:02:51,680 --> 00:02:52,520 Like, when you turn... 45 00:02:52,520 --> 00:02:55,120 when they turn in an assignment, it's like, okay, it worked, right? 46 00:02:55,120 --> 00:02:56,820 I tested it out a little bit. 47 00:02:56,840 --> 00:02:59,040 Barely... they don't really know how to test, but I tested it out. 48 00:02:59,040 --> 00:02:59,860 It worked. 49 00:02:59,880 --> 00:03:02,120 But, you know, did it work fast? 50 00:03:02,120 --> 00:03:04,420 You know, was it... how much memory did it use? 51 00:03:04,420 --> 00:03:08,200 And in a language like Python, you have no idea about those type of things, right? 52 00:03:08,200 --> 00:03:10,080 Like, the memory, you have no idea, right? 53 00:03:10,680 --> 00:03:16,480 So... but with embedded systems, you have to be efficient, because people... these manufacturers are cheap, cheap, cheap. 54 00:03:16,480 --> 00:03:18,840 Like, they don't want to spend anything on these devices. 55 00:03:18,840 --> 00:03:28,780 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. 56 00:03:28,780 --> 00:03:29,520 That would be stupid. 57 00:03:29,520 --> 00:03:31,300 It costs way too much, right? 58 00:03:31,300 --> 00:03:32,600 They would never do that. 59 00:03:32,600 --> 00:03:35,120 They would get the cheapest possible microcontroller. 60 00:03:35,160 --> 00:03:36,380 They'd be like, what's the cheapest thing? 61 00:03:36,380 --> 00:03:38,800 You know, I could save 10 cents if I got this cheaper one. 62 00:03:38,800 --> 00:03:39,860 Let's go for that. 63 00:03:39,860 --> 00:03:40,380 You know what I mean? 64 00:03:40,380 --> 00:03:41,700 It's always efficiency. 65 00:03:41,700 --> 00:03:43,280 So, efficiency is really important. 66 00:03:43,340 --> 00:03:44,440 And there's lots of constraints. 67 00:03:44,440 --> 00:03:48,020 Design costs, performance, you know, power. 68 00:03:48,020 --> 00:03:49,040 Power is a big constraint. 69 00:03:49,040 --> 00:03:50,240 How much power is it using? 70 00:03:50,260 --> 00:03:59,500 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. 71 00:03:59,500 --> 00:04:03,100 You know, you don't have to... you're not thinking, oh, what is the memory that this thing is requiring? 72 00:04:03,100 --> 00:04:05,860 Well, with embedded systems, you really are, like, all the time. 73 00:04:07,260 --> 00:04:07,800 Okay. 74 00:04:08,000 --> 00:04:09,180 Hardware and software. 75 00:04:09,180 --> 00:04:13,100 So, embedded systems have hardware and they have software components, right? 76 00:04:13,140 --> 00:04:16,220 So, that's actually the badge from last year. 77 00:04:16,580 --> 00:04:18,460 You know, it's a little video game thing. 78 00:04:18,480 --> 00:04:19,740 And it's hardware and software. 79 00:04:19,740 --> 00:04:21,560 So, there's like a microcontroller in there. 80 00:04:21,560 --> 00:04:22,560 There's a little screen. 81 00:04:22,560 --> 00:04:23,520 There's some speakers. 82 00:04:23,520 --> 00:04:24,040 There's a bunch... 83 00:04:24,040 --> 00:04:25,500 I don't know what other devices are in there. 84 00:04:25,500 --> 00:04:27,240 Lights, LEDs, that type of thing. 85 00:04:27,260 --> 00:04:31,540 And they have to be controlled by some software running on the microcontroller, right? 86 00:04:31,540 --> 00:04:35,340 So, you have to consider hardware as well as software and design them together. 87 00:04:35,660 --> 00:04:37,860 So, this is not what you do in normal software, right? 88 00:04:37,860 --> 00:04:44,580 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? 89 00:04:44,600 --> 00:04:46,060 Generally not, right? 90 00:04:46,100 --> 00:04:48,700 You're not... like, what is the speaker they're going to use, right? 91 00:04:48,700 --> 00:04:53,220 But when they designed this, they knew exactly, like, okay, this is the speaker that we're going to use. 92 00:04:53,220 --> 00:04:54,520 This is the cheap monitor. 93 00:04:54,520 --> 00:04:56,620 And that changed the way they wrote the code. 94 00:04:56,620 --> 00:05:01,020 So, you have to think about the hardware side of it when you're doing the design, too. 95 00:05:03,240 --> 00:05:04,040 Okay. 96 00:05:04,180 --> 00:05:05,080 Outline of the talk. 97 00:05:05,080 --> 00:05:09,660 I might not be able to finish all these slides just because, you know, there's only so much time. 98 00:05:09,800 --> 00:05:11,360 But three things. 99 00:05:11,360 --> 00:05:14,380 So, first, I'll talk about working with the microcontroller. 100 00:05:14,620 --> 00:05:17,620 Then connecting the microcontroller to external devices. 101 00:05:17,620 --> 00:05:19,860 So, work with the microcontroller's coding, right? 102 00:05:19,960 --> 00:05:21,040 Software, pretty much. 103 00:05:21,040 --> 00:05:24,780 Then connecting it to hardware devices, other things you want to talk to. 104 00:05:24,780 --> 00:05:26,180 And then debugging tools. 105 00:05:26,180 --> 00:05:29,420 Because debugging is different in embedded systems, too. 106 00:05:29,960 --> 00:05:30,180 Okay. 107 00:05:30,180 --> 00:05:33,100 So, microcontrollers are just these little integrated circuits. 108 00:05:33,380 --> 00:05:34,440 And you've seen them. 109 00:05:34,460 --> 00:05:38,780 Generally microcontrollers, I mean, people have definitions of these things. 110 00:05:38,780 --> 00:05:42,080 But generally, they're just, like, cheaper microprocessors, okay? 111 00:05:42,600 --> 00:05:46,440 And you can control everything directly, right? 112 00:05:46,440 --> 00:05:50,460 Meaning all the hardware on the chip, the programmer can control. 113 00:05:50,460 --> 00:05:52,120 And I'll go through what I mean by that. 114 00:05:52,120 --> 00:05:59,580 Normally, you can't control a lot of things on regular microcontrollers, microprocessors, you can't control, okay? 115 00:05:59,580 --> 00:06:02,020 Like, say you want to print something on the screen, right? 116 00:06:02,020 --> 00:06:03,700 You call print, right? 117 00:06:04,080 --> 00:06:06,860 But print asks the operating system to do the control. 118 00:06:07,080 --> 00:06:08,920 Basically, it calls a system call. 119 00:06:08,920 --> 00:06:14,440 The system calls that, checks it out, calls the driver, and the driver puts it on the screen, you know? 120 00:06:14,440 --> 00:06:20,020 So, with microcontrollers, the programmer is doing that directly themselves, okay? 121 00:06:21,540 --> 00:06:24,100 Yeah, so, how do you program one of these things? 122 00:06:24,100 --> 00:06:25,580 So, you have to program them. 123 00:06:25,780 --> 00:06:32,980 So, you write your code on some development environment, like a laptop, and eventually you've got to put it onto the microcontroller. 124 00:06:32,980 --> 00:06:44,100 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. 125 00:06:44,100 --> 00:06:46,980 This is a really old-fashioned one, but same idea, right? 126 00:06:46,980 --> 00:06:48,960 And you can do it that way. 127 00:06:49,920 --> 00:06:53,840 And in fact, that's how it's really done in products, right? 128 00:06:53,920 --> 00:06:58,640 Because the other way is like this, which is much more common if you're going to do it yourself. 129 00:06:58,800 --> 00:07:00,220 It's built into the board. 130 00:07:00,220 --> 00:07:03,420 So, say you buy a board like this, or an Arduino, or whatever. 131 00:07:03,420 --> 00:07:05,800 This is a board we use in class, right? 132 00:07:05,840 --> 00:07:09,360 And this board, it has the programming hardware built into it, okay? 133 00:07:09,360 --> 00:07:19,200 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. 134 00:07:19,200 --> 00:07:20,580 This one deals with the programming. 135 00:07:20,580 --> 00:07:24,040 It takes the USB, transfers it into this guy. 136 00:07:24,040 --> 00:07:27,860 It has a bootloader running on it, and it programs it, okay? 137 00:07:27,880 --> 00:07:34,340 So, this is like what do-it-yourselfers use, but this hardware here is excess. 138 00:07:34,720 --> 00:07:38,100 Like, you don't really need that once you deploy the device, right? 139 00:07:38,100 --> 00:07:42,280 So , in real devices, they do it this way, and then all they're deploying is this. 140 00:07:42,280 --> 00:07:45,280 This is useful, though, in practice for regular people. 141 00:07:46,580 --> 00:07:47,140 Okay. 142 00:07:47,140 --> 00:07:48,420 So, ARM. 143 00:07:48,420 --> 00:07:54,240 So, ARM is the brand of microcontroller that is the most common, okay? 144 00:07:54,240 --> 00:07:59,700 So, you know, Intel and AMD, Intel-class machines dominate microprocessors, right? 145 00:07:59,700 --> 00:08:05,440 Well, in microcontrollers, Intel has, like, no... they don't make anything that anybody uses, really, right? 146 00:08:05,640 --> 00:08:07,700 Instead, ARM makes them. 147 00:08:07,700 --> 00:08:12,860 Now, ARM, what they do is they lease the design. 148 00:08:12,860 --> 00:08:14,460 So, they don't make silicon, right? 149 00:08:14,460 --> 00:08:15,520 They don't make the chip. 150 00:08:15,520 --> 00:08:18,600 They lease the designs to other companies who make the chips. 151 00:08:18,600 --> 00:08:21,160 So, maybe they lease it to TI, TI makes chips. 152 00:08:21,200 --> 00:08:24,460 Maybe they lease it to STMicroelectronics, they would make the chips, right? 153 00:08:24,460 --> 00:08:28,760 But ARM is the type of microprocessor, microcontroller that's in there, okay? 154 00:08:28,760 --> 00:08:34,040 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. 155 00:08:34,040 --> 00:08:36,120 But there are, for instance, Macs, right? 156 00:08:36,120 --> 00:08:39,740 Those M1, M4s, and all those, those are all ARM, right? 157 00:08:40,340 --> 00:08:43,220 Basically, everything in everybody's phone is going to be an ARM. 158 00:08:43,220 --> 00:08:46,780 Not everybody's, there's some that aren't, but most of them are going to be ARMs. 159 00:08:46,780 --> 00:08:50,180 Like, most of these devices use ARM microcontrollers, you know? 160 00:08:51,300 --> 00:09:00,540 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. 161 00:09:01,280 --> 00:09:01,820 Okay. 162 00:09:01,820 --> 00:09:04,160 Now, microcontrollers have peripherals. 163 00:09:04,160 --> 00:09:08,900 What I mean by this is, okay, this, I know you can't read the details of this. 164 00:09:08,900 --> 00:09:12,280 I took this out of a data sheet for a microcontroller I used to use for class. 165 00:09:12,420 --> 00:09:15,760 Now, up here, I'll just tell you, up here is the CPU, okay? 166 00:09:15,760 --> 00:09:18,720 This is the main processor, the ARM microcontroller, right? 167 00:09:18,720 --> 00:09:21,120 And that thing is what runs your code. 168 00:09:21,120 --> 00:09:23,460 So, it executes instructions, right? 169 00:09:23,800 --> 00:09:30,120 The rest of it is all, like, other stuff that connects to it and does useful things, okay? 170 00:09:30,120 --> 00:09:31,620 So, for instance, there's memories. 171 00:09:31,620 --> 00:09:32,660 I can't even read them. 172 00:09:32,760 --> 00:09:33,980 Memories and stuff like this. 173 00:09:34,020 --> 00:09:40,920 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? 174 00:09:41,260 --> 00:09:46,880 This, but the main thing is this CPU is connected by these two long buses, these buses, right? 175 00:09:46,940 --> 00:09:50,480 Connected by these buses to all these peripherals, what are called peripherals. 176 00:09:50,480 --> 00:09:54,360 Now, these peripherals are what do interesting stuff on microcontrollers. 177 00:09:54,360 --> 00:09:55,680 They do all kinds of things. 178 00:09:55,680 --> 00:09:57,880 Like, for instance, general purpose I.O., right? 179 00:09:57,880 --> 00:09:58,560 The pins. 180 00:09:58,560 --> 00:10:00,900 If you want to control the pins, that's a peripheral. 181 00:10:00,900 --> 00:10:04,020 Or if you want to communicate by UART, that's another peripheral. 182 00:10:04,020 --> 00:10:07,840 Or if you want to do analog to digital conversion, that's another peripheral, right? 183 00:10:07,840 --> 00:10:11,080 There are all these blocks are peripherals, okay? 184 00:10:11,080 --> 00:10:16,880 So, when you're coding, you know, some instructions, some things you do are the same, right? 185 00:10:16,880 --> 00:10:17,800 C is C. 186 00:10:17,800 --> 00:10:19,420 I'm assuming C right now, right? 187 00:10:19,420 --> 00:10:20,380 C is C. 188 00:10:20,380 --> 00:10:26,220 But the big difference with microcontroller programming is that you have to control these peripherals specifically. 189 00:10:26,220 --> 00:10:30,120 You have to tell them exactly what to do step by step, okay? 190 00:10:30,180 --> 00:10:37,600 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? 191 00:10:38,720 --> 00:10:39,820 Peripheral control. 192 00:10:39,820 --> 00:10:41,160 So, common peripherals, okay? 193 00:10:41,160 --> 00:10:50,640 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? 194 00:10:50,920 --> 00:10:53,380 So, embedded software directly controls peripherals, all right? 195 00:10:53,380 --> 00:10:54,280 I said that. 196 00:10:55,160 --> 00:10:55,780 Yeah. 197 00:10:55,820 --> 00:10:56,680 Yeah, okay. 198 00:10:56,780 --> 00:11:05,120 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? 199 00:11:06,080 --> 00:11:11,240 So, you can make some devices operate with a real operating system, like a full-on operating system. 200 00:11:11,240 --> 00:11:19,620 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. 201 00:11:19,620 --> 00:11:22,560 Like, I've seen many talks like this where they talk about attacking embedded systems. 202 00:11:22,560 --> 00:11:26,140 Maybe they use a router as an example, how to dump the firmware, whatever. 203 00:11:26,480 --> 00:11:32,520 And these devices, a lot of these devices have just Linux running on them, like a small Linux, right? 204 00:11:32,520 --> 00:11:35,440 And that's just running a full-on operating system, okay? 205 00:11:35,940 --> 00:11:37,300 So, you can do that. 206 00:11:37,300 --> 00:11:43,260 Now, the downside of that is that, you know, it's easy because it's running Linux, but there's overhead, right? 207 00:11:43,260 --> 00:11:45,860 You're running an operating system on top of the microcontroller. 208 00:11:45,980 --> 00:11:55,180 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? 209 00:11:55,180 --> 00:11:59,040 So, if you want to be really cheap, you might not want to use a full-on operating system. 210 00:11:59,360 --> 00:12:02,380 So, then sometimes people use bare metal. 211 00:12:02,380 --> 00:12:03,260 It's the other way. 212 00:12:03,320 --> 00:12:09,840 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? 213 00:12:09,880 --> 00:12:11,960 You control everything in detail. 214 00:12:11,960 --> 00:12:18,080 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? 215 00:12:18,080 --> 00:12:20,300 But if you're doing bare metal, then you don't, right? 216 00:12:20,300 --> 00:12:24,840 You have to really understand all the details of how to control the peripherals. 217 00:12:25,020 --> 00:12:27,940 And then there's this in-between, which is real-time operating systems. 218 00:12:27,940 --> 00:12:31,280 Real-time operating systems are basically stripped back operating systems. 219 00:12:31,800 --> 00:12:38,100 They don't have like a nice GUI or any of that stuff, but maybe they support multithreads, you know, threading. 220 00:12:38,100 --> 00:12:41,720 They support that and they also support scheduling algorithms. 221 00:12:41,820 --> 00:12:45,780 So, basically they're made to satisfy real-time deadlines, right? 222 00:12:45,780 --> 00:12:52,620 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? 223 00:12:52,620 --> 00:12:55,280 And you got to meet that deadline no matter what. 224 00:12:55,280 --> 00:13:01,940 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? 225 00:13:01,940 --> 00:13:04,940 So, they have scheduling algorithms that they use to support that. 226 00:13:05,600 --> 00:13:06,500 Okay. 227 00:13:06,500 --> 00:13:12,480 So, embedded systems are said to have a, if you're going to program one, you have what's called a toolchain, usually. 228 00:13:12,480 --> 00:13:16,720 Toolchain is basically an IDE and they're all sort of the same, right? 229 00:13:16,720 --> 00:13:19,480 I mean, that's just generic IDE looking thing, right? 230 00:13:19,480 --> 00:13:27,060 This particular one is ST microelectronics IDE, STM cube IDE, but they're all basically the same thing, okay? 231 00:13:27,060 --> 00:13:27,920 And you've seen them. 232 00:13:27,920 --> 00:13:32,340 Here's the code and here's all the files in the project and all that stuff, right? 233 00:13:32,460 --> 00:13:40,420 So, the one difference in an embedded system IDE is that you have a programmer that's attached to it. 234 00:13:40,420 --> 00:13:46,680 So, one thing you have to do is, like, once you compile the code, you actually cross-compile the code. 235 00:13:46,680 --> 00:13:52,520 So, compiling a code, normally, if I compile code on this machine, it'll be compiled to execute on this machine, right? 236 00:13:52,520 --> 00:13:53,720 On this microprocessor. 237 00:13:53,720 --> 00:13:58,080 But with an embedded system, you compile it on this machine to run on a different processor, right? 238 00:13:58,080 --> 00:13:59,720 That's called a cross-compiler. 239 00:13:59,720 --> 00:14:08,740 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. 240 00:14:08,840 --> 00:14:10,520 And that's what a programmer does. 241 00:14:10,700 --> 00:14:12,700 So, it's some programmer software. 242 00:14:12,700 --> 00:14:19,560 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. 243 00:14:20,160 --> 00:14:20,480 Okay. 244 00:14:20,480 --> 00:14:23,100 So, IDEs, though, they don't look that much different. 245 00:14:23,660 --> 00:14:30,060 Now, one, another sort of painful difference in embedded programming is datasheets. 246 00:14:30,060 --> 00:14:33,700 Here's a datasheet, or the reference manual, whatever they call it, okay? 247 00:14:33,720 --> 00:14:36,420 These datasheets are massive, okay? 248 00:14:36,420 --> 00:14:40,360 They describe everything that a component is supposed to do. 249 00:14:40,360 --> 00:14:44,620 Now, you can get datasheets on all kinds of integrated circuits, all kinds of components, right? 250 00:14:44,620 --> 00:14:46,620 But right now, I'm talking about the microcontroller. 251 00:14:46,620 --> 00:14:51,020 So, like, this is the microcontroller I'm going to use in class in the fall, actually. 252 00:14:51,060 --> 00:14:53,220 I'm just starting to learn it and use it in the fall. 253 00:14:53,220 --> 00:14:56,160 I was like, oh, let me use it in this talk so I can start getting comfortable with it. 254 00:14:56,200 --> 00:14:59,840 Its datasheet is 1,757 pages long, okay? 255 00:14:59,840 --> 00:15:02,780 That is a painful datasheet, right? 256 00:15:02,780 --> 00:15:09,180 And it describes every peripheral on there, how you use every peripheral, every little detail, okay? 257 00:15:09,240 --> 00:15:13,600 And you have to be familiar with a chunk of it, right? 258 00:15:13,600 --> 00:15:16,820 And learn how to search really well, okay? 259 00:15:16,820 --> 00:15:22,080 Like, you can't memorize all that, but you got to search, you got to remember to look at that datasheet, okay? 260 00:15:22,080 --> 00:15:26,600 And then sometimes, in the very worst case, the datasheet is incomplete, right? 261 00:15:26,600 --> 00:15:34,600 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? 262 00:15:34,600 --> 00:15:36,300 Maybe I missed it, right? 263 00:15:36,300 --> 00:15:37,800 Or it's wrong. 264 00:15:37,800 --> 00:15:38,720 That happens too. 265 00:15:38,720 --> 00:15:42,920 The datasheet will say something incorrect, and that's very painful, okay? 266 00:15:43,060 --> 00:15:50,140 And, you know, I use a lot of Google, because usually, whenever you find that, somebody else hopefully has run into the same issue. 267 00:15:50,520 --> 00:15:54,220 So, anyway, you have to get used to reading these datasheets, okay? 268 00:15:54,220 --> 00:15:55,400 Just in general. 269 00:15:56,220 --> 00:15:57,520 So, importance of datasheets. 270 00:15:57,520 --> 00:16:00,620 So, it is very easy to miss important information. 271 00:16:00,620 --> 00:16:02,680 So, as a broad example, right? 272 00:16:02,680 --> 00:16:08,880 Say I'm talking about my 1,700 page datasheet, and I want to do... it leads to bugs, which can be exploited. 273 00:16:08,880 --> 00:16:10,880 This is where a lot of bugs can happen, right? 274 00:16:10,980 --> 00:16:14,120 So, say I want to do UART communication, right? 275 00:16:14,120 --> 00:16:17,460 I want to communicate with another device by UART, which is protocol, right? 276 00:16:17,780 --> 00:16:20,800 So, there's a section in the datasheet on UART, right? 277 00:16:20,800 --> 00:16:21,500 Just on that. 278 00:16:21,500 --> 00:16:23,620 So, you're like, okay, let me read that whole section, right? 279 00:16:23,660 --> 00:16:26,540 Okay, based on that section, my code works. 280 00:16:26,540 --> 00:16:29,100 And you test it out, and you're like, okay, it works, right? 281 00:16:29,140 --> 00:16:35,760 But then you didn't notice that in this other section, 500 pages later, they were talking about reset, okay? 282 00:16:35,760 --> 00:16:39,160 And in reset condition, maybe UART works differently, right? 283 00:16:39,160 --> 00:16:44,680 There's like a special case that you missed, because it was far off in the datasheet, right? 284 00:16:44,680 --> 00:16:46,100 Very painful, okay ? 285 00:16:46,100 --> 00:16:47,300 This happens, right? 286 00:16:47,300 --> 00:16:57,100 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? 287 00:16:57,100 --> 00:17:00,220 Because it's very easy to put a bug into these things. 288 00:17:00,220 --> 00:17:08,860 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. 289 00:17:08,860 --> 00:17:10,160 They didn't win this year. 290 00:17:10,240 --> 00:17:23,800 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. 291 00:17:23,800 --> 00:17:28,520 They fuzzed the I2C drivers until they found such a vulnerability, and then they exploited it. 292 00:17:28,960 --> 00:17:32,360 So, anyway, data cheats are painful and important to understand. 293 00:17:33,440 --> 00:17:34,820 Peripheral control registers. 294 00:17:34,820 --> 00:17:35,200 Okay. 295 00:17:35,200 --> 00:17:40,040 So, when you're writing code, you have to control these peripherals and tell them what to do. 296 00:17:40,120 --> 00:17:43,160 So, peripherals are controlled through registers. 297 00:17:43,160 --> 00:17:47,900 Now, a register in a chip is just a storage element, you know? 298 00:17:47,900 --> 00:17:49,300 Like a 32-bit register. 299 00:17:49,300 --> 00:17:51,240 Typically, these are 32-bit devices. 300 00:17:51,240 --> 00:17:52,620 They've got a 32-bit register, right? 301 00:17:52,620 --> 00:17:54,800 It just stores 32 zeros and ones. 302 00:17:54,800 --> 00:18:02,800 And all of these peripherals, every peripheral has associated with it some registers that are used to control it and to observe it, right? 303 00:18:02,940 --> 00:18:15,760 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. 304 00:18:15,980 --> 00:18:16,220 Okay? 305 00:18:16,220 --> 00:18:17,940 That's how you do control. 306 00:18:18,540 --> 00:18:24,160 These registers are like the interface to all the peripherals on your microcontroller, okay? 307 00:18:24,160 --> 00:18:31,620 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. 308 00:18:31,620 --> 00:18:37,480 Oh, I see it's bit five of this register makes this start, and bit six puts it in this mode and all this. 309 00:18:37,480 --> 00:18:40,860 That's why the data sheet's, like, 1,700 pages long, okay? 310 00:18:40,900 --> 00:18:43,780 So, that's how you control them, through these registers. 311 00:18:44,060 --> 00:18:49,860 So, and if you... anything you want to do, drive a value onto a pin, or do A to D conversion, UART, or whatever. 312 00:18:50,480 --> 00:18:54,160 Now, so, as an example, right? 313 00:18:54,160 --> 00:19:01,080 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. 314 00:19:01,080 --> 00:19:06,320 It's the schematics inside a data sheet for a particular... for this STMicroelectronics chip, okay? 315 00:19:06,320 --> 00:19:09,860 And this schematic is showing me one pin in the GPIO. 316 00:19:09,860 --> 00:19:12,640 So, GPIO stands for General Purpose Input Output. 317 00:19:12,640 --> 00:19:14,200 That means the pins of the chip. 318 00:19:14,200 --> 00:19:17,240 If you drive to ones and zeros to turn lights on, or whatever, right? 319 00:19:17,240 --> 00:19:18,540 And you can read them, too. 320 00:19:18,540 --> 00:19:21,780 Maybe some of the device is driving a 0-1 output, you want to read it. 321 00:19:21,840 --> 00:19:24,640 So, this is, like, the hardware behind a pin. 322 00:19:24,640 --> 00:19:27,660 So, over here is the pin, in tiny letters, says IO pin, right? 323 00:19:27,660 --> 00:19:28,500 This is the pin. 324 00:19:28,520 --> 00:19:31,100 And then, this is all the logic associated with the pin. 325 00:19:31,100 --> 00:19:36,380 And then, over here, to the left, over here, is, like, the microcontroller, okay? 326 00:19:36,640 --> 00:19:41,720 So, and the only thing I want to highlight here is that they show some of these registers. 327 00:19:41,720 --> 00:19:43,540 I put them... I highlighted them in red. 328 00:19:43,540 --> 00:19:46,000 And they name them in the data sheet. 329 00:19:46,100 --> 00:19:49,800 GPIO... oh, and I'm talking about GPIO port A. 330 00:19:49,800 --> 00:19:51,040 There are many ports on these things. 331 00:19:51,040 --> 00:19:52,140 So, I'm talking about port A. 332 00:19:52,400 --> 00:19:56,620 IDR, GPIO-A-BSS-RR, and GPIO-A-ODR. 333 00:19:56,720 --> 00:19:59,160 So, like, IDR is the input data register. 334 00:19:59,220 --> 00:20:08,080 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. 335 00:20:08,080 --> 00:20:15,080 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. 336 00:20:15,160 --> 00:20:16,560 Pin 0, rather, you know? 337 00:20:16,560 --> 00:20:20,480 So, you read this register inside your code, right? 338 00:20:20,480 --> 00:20:22,480 And then this register is to set output bits. 339 00:20:22,480 --> 00:20:24,400 Say I want to set a particular output bit high. 340 00:20:24,400 --> 00:20:26,680 I set the appropriate bit in this register. 341 00:20:26,680 --> 00:20:29,260 And say I want to write all the output bits to something. 342 00:20:29,260 --> 00:20:33,720 I go to this ODR, output data register, and write all the pin outputs. 343 00:20:34,280 --> 00:20:39,160 So, the idea here is just that every peripheral has a set of registers. 344 00:20:39,160 --> 00:20:42,520 And you have to learn what all of them do, what they're all for. 345 00:20:44,400 --> 00:20:45,200 Okay. 346 00:20:45,940 --> 00:20:48,300 Now, registers are memory mapped. 347 00:20:48,540 --> 00:20:53,740 So, what that means is that in order to write to a register, you write to a memory address. 348 00:20:53,780 --> 00:21:01,780 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? 349 00:21:01,780 --> 00:21:08,060 In the datasheet, it will be like, GPIOA, output data register, is that address whatever, okay? 350 00:21:08,060 --> 00:21:13,220 And then all you do to write to that register is you write to that address, okay? 351 00:21:13,220 --> 00:21:15,620 And these addresses are in the datasheet. 352 00:21:15,760 --> 00:21:24,540 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? 353 00:21:24,560 --> 00:21:31,260 They usually, like, with these devices, they usually have, like, a header file that has them all defined for you. 354 00:21:31,280 --> 00:21:34,560 You know, most IDEs have that. 355 00:21:34,580 --> 00:21:42,180 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. 356 00:21:42,180 --> 00:21:44,840 Otherwise, you have to hash to find them explicitly in your code. 357 00:21:46,180 --> 00:21:48,500 By the way, if there's any questions, go ahead and raise your hand. 358 00:21:48,600 --> 00:21:52,580 I'm perfectly fine answering questions right in the middle, if that's fine with me. 359 00:21:52,580 --> 00:21:53,680 And I know I'm going fast. 360 00:21:53,680 --> 00:21:56,960 I always do that anyway, but anyway. 361 00:21:56,960 --> 00:21:58,160 All right. 362 00:21:58,560 --> 00:22:01,020 So, blinking an LED. 363 00:22:01,120 --> 00:22:05,380 So, this is the one I'm going to use in class, STMicroelectronicsBoard. 364 00:22:05,480 --> 00:22:09,000 And just... this is the main microcontroller. 365 00:22:09,000 --> 00:22:13,500 This is used for loading from... this is a USB connect interface. 366 00:22:13,840 --> 00:22:15,900 And say I want to blink an LED. 367 00:22:16,440 --> 00:22:18,140 Now, on this board... 368 00:22:18,140 --> 00:22:22,420 oh, I should mention here, there's a difference between the microcontroller and the board, okay? 369 00:22:22,420 --> 00:22:25,980 The microcontroller is this chip right here, okay? 370 00:22:25,980 --> 00:22:28,140 It has this data sheet and all that. 371 00:22:28,140 --> 00:22:31,700 The board is this whole thing, which has the microcontroller on it. 372 00:22:31,700 --> 00:22:35,140 And the reason I bring that up is because you need both to do this. 373 00:22:35,140 --> 00:22:43,080 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. 374 00:22:43,080 --> 00:22:47,440 And I'm going to have to know what pin is that LED connected to, right? 375 00:22:47,440 --> 00:22:51,540 So, now this board, like all boards, they have an LED built in, right? 376 00:22:51,540 --> 00:22:52,480 This has multiple. 377 00:22:52,480 --> 00:22:55,200 But that little red circle there, I circled the LED. 378 00:22:55,200 --> 00:22:58,120 You can't see it, but it's an LED built into the board. 379 00:22:58,140 --> 00:23:03,960 And I have to look at the board's data sheet, which is usually much easier, to say what pin is that connected to. 380 00:23:03,960 --> 00:23:09,060 So, looking at the board's data sheet, this LED is connected to port D, pin 14, okay? 381 00:23:09,060 --> 00:23:10,180 So, I know that. 382 00:23:10,360 --> 00:23:17,820 So, now my goal in writing this blinking LED code is to turn on... okay, well, let me skip that first line. 383 00:23:18,660 --> 00:23:24,440 I'm going to basically see the while loop, drive a 1 onto the pin, delay, drive a 0 onto the pin, delay. 384 00:23:24,440 --> 00:23:26,000 That's the basics, right? 385 00:23:26,000 --> 00:23:28,480 And that's a blinking LED. 386 00:23:28,740 --> 00:23:31,140 Now, before that, there's a couple of things I have to do. 387 00:23:31,220 --> 00:23:36,120 One thing is this first one, turn on the clock to the GPIO port, or D. 388 00:23:36,300 --> 00:23:43,780 So, what they do a lot with these peripherals to save power is they turn off the clock to these peripherals. 389 00:23:43,780 --> 00:23:44,800 So, there's a clock. 390 00:23:44,800 --> 00:23:48,560 A clock is a square wave that determines the rate at which events happen on the chip. 391 00:23:48,560 --> 00:23:51,060 If the clock is going, it is consuming power. 392 00:23:51,260 --> 00:23:55,040 So, they just shut off the clock to peripherals that are not in use by default. 393 00:23:55,260 --> 00:23:59,820 And so, you and your code have to turn on the clock to the peripheral before you can use it. 394 00:23:59,920 --> 00:24:01,040 So, you turn on its clock. 395 00:24:01,040 --> 00:24:02,060 You're going to have to do that. 396 00:24:02,100 --> 00:24:03,220 Again, there's some register. 397 00:24:03,220 --> 00:24:04,840 You set a bit, it turns on its clock. 398 00:24:05,240 --> 00:24:07,680 Then, you've got to set the port to an output pin. 399 00:24:07,680 --> 00:24:10,640 So, these pins, they can be inputs or outputs, okay? 400 00:24:10,640 --> 00:24:15,700 So, you're going to set this pin to an output so that you can drive outputs to it, okay? 401 00:24:15,700 --> 00:24:18,240 So, you have to do those two things first in your code. 402 00:24:18,260 --> 00:24:21,120 Then, you get into a while loop where you just do that, okay? 403 00:24:21,620 --> 00:24:27,940 So, just to show a little more detail, and we're going to do this by adjusting values of registers. 404 00:24:28,560 --> 00:24:29,440 So, okay. 405 00:24:29,440 --> 00:24:35,700 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? 406 00:24:35,700 --> 00:24:37,260 I don't expect you to understand all this. 407 00:24:37,260 --> 00:24:40,420 But, when you look in the data sheet, it has a description of every register. 408 00:24:40,420 --> 00:24:44,300 And I just went and zoomed into a piece of that, okay? 409 00:24:44,300 --> 00:24:45,600 So, there's this register. 410 00:24:45,860 --> 00:24:47,140 RCC, whatever. 411 00:24:47,220 --> 00:24:49,480 AHB is a bus name and all this, okay? 412 00:24:49,480 --> 00:24:52,700 This controls the clocks for the GPIO pins, okay? 413 00:24:52,700 --> 00:24:55,620 So, I've got to turn the clock on for a particular port. 414 00:24:55,620 --> 00:24:58,920 So, notice this register has got 0 through 15, right? 415 00:24:58,920 --> 00:25:00,060 Up there in the top. 416 00:25:00,320 --> 00:25:01,940 That's half the bits in the register. 417 00:25:01,940 --> 00:25:03,620 All the registers are 32 bits, right? 418 00:25:03,620 --> 00:25:05,520 So, I'm just looking at the first half. 419 00:25:05,560 --> 00:25:09,540 And if you zoom way in on this, it says GPIOD EN for enable. 420 00:25:09,860 --> 00:25:16,920 And then, in the data sheet, it will say, oh, pin 3 on this register enables the clock to GPIO pin 4D, okay? 421 00:25:16,920 --> 00:25:18,960 So, you've got to set that bit to a 1. 422 00:25:19,280 --> 00:25:22,040 Then, GPIOD mode register. 423 00:25:22,220 --> 00:25:29,700 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. 424 00:25:29,700 --> 00:25:32,980 So, the particular pin I'm interested in is pin 14, right? 425 00:25:32,980 --> 00:25:34,220 That's these two pins. 426 00:25:34,280 --> 00:25:35,540 Like, these two are 15. 427 00:25:35,540 --> 00:25:36,200 These two pins. 428 00:25:36,200 --> 00:25:38,960 And I have to set them to, like, 0, 1, if I recall. 429 00:25:38,980 --> 00:25:40,640 And that puts it into output mode. 430 00:25:41,080 --> 00:25:43,100 And then, over here, this is the output data register. 431 00:25:43,100 --> 00:25:52,800 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. 432 00:25:52,800 --> 00:25:55,020 It'll set the pin to a 1 or a 0, right? 433 00:25:55,040 --> 00:26:03,860 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? 434 00:26:04,680 --> 00:26:05,360 Okay. 435 00:26:05,360 --> 00:26:06,000 Question? 436 00:26:06,620 --> 00:26:07,300 Okay. 437 00:26:07,520 --> 00:26:09,540 So, here's my code for that. 438 00:26:09,540 --> 00:26:13,180 And I don't really expect you to follow all of it, but let me just say the structure of it. 439 00:26:14,420 --> 00:26:20,180 So, one thing is... so, there's a number of registers that I have to control, right? 440 00:26:20,280 --> 00:26:24,720 So, first thing I'm going to do, or somewhere in the code, I have to assign the addresses, right? 441 00:26:24,720 --> 00:26:26,820 Maybe I did that with hash defines at the top. 442 00:26:26,820 --> 00:26:27,960 In this code, I did it here. 443 00:26:27,960 --> 00:26:32,840 So, I said, this register equals, and I set it to this address, okay? 444 00:26:32,900 --> 00:26:36,980 And then... so, I set it to... I set these registers to their addresses, and then I set them to values. 445 00:26:36,980 --> 00:26:42,260 Star that equals a 1 shifted 3 over, because I want to set bit 3 high, and so on. 446 00:26:42,280 --> 00:26:43,800 So, I got... I do that. 447 00:26:43,800 --> 00:26:46,660 So, these are the initializations I was talking about, making an output register. 448 00:26:46,660 --> 00:26:48,500 I initialize the output to 0. 449 00:26:48,700 --> 00:26:50,200 Then, here's my while loop. 450 00:26:50,200 --> 00:26:53,040 I just say, set it to 0, set the pin to 0. 451 00:26:53,040 --> 00:26:55,440 Then, I have a loop, a dummy loop. 452 00:26:55,440 --> 00:27:00,460 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. 453 00:27:01,260 --> 00:27:02,600 So, that's the code. 454 00:27:02,600 --> 00:27:03,180 Question? 455 00:27:08,970 --> 00:27:09,850 No? 456 00:27:10,450 --> 00:27:13,910 So, I'll talk to you about... I'm curious. 457 00:27:14,050 --> 00:27:17,230 So, you know, I've, of course, been thinking about that too, right? 458 00:27:17,230 --> 00:27:21,450 Because, you know... and I'm mixed... 459 00:27:21,450 --> 00:27:23,330 I've mixed feelings on that, right? 460 00:27:23,810 --> 00:27:32,910 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? 461 00:27:32,910 --> 00:27:39,670 You're trusting the AI model, and if it messed up, then you mess up, and you don't even know why, right? 462 00:27:39,670 --> 00:27:40,590 So, I don't know. 463 00:27:40,590 --> 00:27:42,510 But still, I'm curious, okay? 464 00:27:42,510 --> 00:27:47,890 I'm curious, and I might use it, but you always have... it's just not safe, security-wise. 465 00:27:50,370 --> 00:27:51,250 Yeah. 466 00:27:53,090 --> 00:27:54,650 Yeah, I think so. 467 00:27:54,650 --> 00:27:55,630 I mean, I agree. 468 00:27:55,750 --> 00:27:58,430 I wonder if that'll change one day, but who knows? 469 00:27:59,390 --> 00:28:01,310 But, yeah, I believe it. 470 00:28:01,450 --> 00:28:02,390 So, okay. 471 00:28:02,390 --> 00:28:03,910 So, this is a Blinky. 472 00:28:03,910 --> 00:28:09,190 This is sort of the most low-level type of Blinky you could write, where you directly control these registers and their values. 473 00:28:09,350 --> 00:28:12,050 Now, that can be tedious, okay? 474 00:28:12,050 --> 00:28:19,110 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. 475 00:28:19,170 --> 00:28:23,590 Libraries, where they make things... you know, you don't have to worry about each individual register. 476 00:28:23,590 --> 00:28:25,970 You just call a library function, and it does stuff for you. 477 00:28:25,970 --> 00:28:30,670 So, most of the time, when people make these things, they often use these libraries, right? 478 00:28:30,670 --> 00:28:33,210 So, there are vendor-specific libraries. 479 00:28:33,250 --> 00:28:37,750 Like, I'm using this for STM microelectronics. 480 00:28:37,750 --> 00:28:39,370 They have their HAL library, right? 481 00:28:39,970 --> 00:28:41,090 STM32HAL. 482 00:28:41,250 --> 00:28:43,970 And different vendors have their own libraries. 483 00:28:43,970 --> 00:28:48,590 Plus, there are vendor-independent libraries, like CMSYS is a popular one. 484 00:28:48,970 --> 00:28:52,250 It's across ARM, platforms, right? 485 00:28:52,310 --> 00:28:55,390 And then, Arduino, Arduino itself. 486 00:28:55,510 --> 00:28:57,390 So, Arduino, there's a particular... 487 00:28:57,390 --> 00:29:05,490 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? 488 00:29:05,490 --> 00:29:06,730 So, you can use Arduino. 489 00:29:06,730 --> 00:29:10,170 Like, I know... they use it on... there's another class in my school. 490 00:29:10,170 --> 00:29:12,590 They use it on an ESP32, right? 491 00:29:12,590 --> 00:29:15,050 So, they... but they use Arduino libraries on that, right? 492 00:29:15,050 --> 00:29:16,810 Which is another set of libraries. 493 00:29:16,810 --> 00:29:18,850 So, it's sort of a high-level library. 494 00:29:18,850 --> 00:29:19,990 It makes things easier. 495 00:29:20,130 --> 00:29:22,070 But the... yeah, I think it's on the next slide. 496 00:29:22,070 --> 00:29:26,250 Yeah, the downside of these libraries is that they hide details, okay? 497 00:29:26,410 --> 00:29:29,010 So, with any library, okay? 498 00:29:29,010 --> 00:29:35,930 And so, anyway, here's an example of Blinky using the HAL STM32... oh, and they're also slow. 499 00:29:35,930 --> 00:29:36,770 They're also slow. 500 00:29:36,770 --> 00:29:44,170 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? 501 00:29:44,170 --> 00:29:48,170 If I just want to make a Blinky, it is much quicker to do it my way. 502 00:29:48,170 --> 00:29:50,030 Now, who cares with Blinky, right? 503 00:29:50,050 --> 00:29:51,830 But my way is a lot more efficient. 504 00:29:51,830 --> 00:29:54,890 I mean, when I say my way, going straight to the registry is a lot more efficient. 505 00:29:54,930 --> 00:29:55,870 Like this, okay? 506 00:29:55,870 --> 00:30:00,830 This basically, you know, they have a toggle pin, and they have a HAL delay, thousand, whatever. 507 00:30:01,610 --> 00:30:04,250 But, like, things like... where is it? 508 00:30:04,250 --> 00:30:04,890 HAL init. 509 00:30:04,890 --> 00:30:07,110 HAL init initializes all the peripherals. 510 00:30:07,110 --> 00:30:08,730 I don't need that, okay? 511 00:30:08,930 --> 00:30:12,730 So, they don't have, like, a HAL init just for the GPIO, right? 512 00:30:12,730 --> 00:30:13,630 Not that I know of. 513 00:30:13,630 --> 00:30:16,450 But you initialize all these peripherals, you don't need it. 514 00:30:16,790 --> 00:30:20,650 And I don't even... oh, this guy's for GPIO init, but you got to do the HAL init, too. 515 00:30:20,650 --> 00:30:22,470 I don't quite understand the relationship there. 516 00:30:22,490 --> 00:30:28,410 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? 517 00:30:28,510 --> 00:30:29,930 So, anyway, that's HAL. 518 00:30:29,930 --> 00:30:32,930 And then with Arduino, here's how you might write it. 519 00:30:32,930 --> 00:30:36,330 You set up in a loop, and digital write is their function. 520 00:30:37,490 --> 00:30:43,530 Now, you know, tradeoffs with the libraries, when you use libraries, the advantage is it makes everything easier. 521 00:30:43,590 --> 00:30:48,510 The disadvantage is that the libraries themselves might have exploitable bugs, okay? 522 00:30:48,510 --> 00:30:51,070 That's one security difficulty. 523 00:30:51,070 --> 00:30:53,550 But also, they're slow. 524 00:30:53,550 --> 00:30:55,070 They're generally slower, right? 525 00:30:55,070 --> 00:30:59,250 So, it depends on how efficient you really need to be, but they're generally slower. 526 00:30:59,250 --> 00:31:03,970 Most of the time, people use these libraries, though, in all honesty, because they do make things more convenient. 527 00:31:05,190 --> 00:31:05,870 Okay. 528 00:31:06,070 --> 00:31:06,630 Okay. 529 00:31:06,630 --> 00:31:08,110 Next bunch of the talk. 530 00:31:08,550 --> 00:31:12,010 Connecting the microcontroller to external devices, okay? 531 00:31:12,470 --> 00:31:15,750 So, you want to... so, it's not all about just programming the microcontroller. 532 00:31:15,750 --> 00:31:17,350 You got to connect to other things. 533 00:31:17,990 --> 00:31:20,450 So, analog interfacing, start with that. 534 00:31:20,450 --> 00:31:26,190 So, there are a lot of these little analog devices that you might want to control, or you might want to observe. 535 00:31:26,190 --> 00:31:28,630 So, like an LED, you might want to turn it off and on. 536 00:31:28,630 --> 00:31:30,770 A motor, you might want to drive it, right? 537 00:31:30,770 --> 00:31:33,330 And that's if it's an actuator, right? 538 00:31:33,510 --> 00:31:35,110 You're driving it to do something. 539 00:31:35,110 --> 00:31:42,530 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. 540 00:31:42,550 --> 00:31:43,970 This is just a few of them, right? 541 00:31:43,970 --> 00:31:46,010 Now, these are all simple ones, okay? 542 00:31:46,030 --> 00:31:49,130 Simple analog actuators and sensors. 543 00:31:49,330 --> 00:31:57,070 So, with those, you have to do a little bit of analog electronics, a little bit of analog electronics. 544 00:31:57,070 --> 00:31:59,890 Now, analog electronics are painful, okay? 545 00:31:59,890 --> 00:32:04,610 Analog electronics are hard in general, but this much you can do. 546 00:32:04,610 --> 00:32:07,390 So, like with me, I don't do analog electronics. 547 00:32:07,390 --> 00:32:08,230 I can do digital. 548 00:32:08,230 --> 00:32:14,710 Analog is going too far, but that's like a basic chunk of it that you need to know, and you just reuse, okay? 549 00:32:14,710 --> 00:32:20,790 In practice, embedded designers are not generally analog electronics professionals, usually. 550 00:32:21,250 --> 00:32:23,170 So, Ohm's law. 551 00:32:23,170 --> 00:32:25,710 Okay, this is really, really, like, simple. 552 00:32:25,990 --> 00:32:29,490 So, don't be intimidated, you may remember this from physics or something. 553 00:32:29,490 --> 00:32:30,590 V equals IR. 554 00:32:30,590 --> 00:32:33,470 So, voltage is like the electric pressure, right? 555 00:32:33,470 --> 00:32:36,150 I is the current, and R is resistance. 556 00:32:36,150 --> 00:32:38,230 So, think of this like water going through pipes. 557 00:32:38,230 --> 00:32:39,670 It's exactly the same thing. 558 00:32:39,690 --> 00:32:43,150 The pump is like the battery, the voltage source, right? 559 00:32:43,170 --> 00:32:45,450 So, it supplies pressure, generates pressure. 560 00:32:45,530 --> 00:32:48,090 So, in these pipes, the pipes are the wires. 561 00:32:48,150 --> 00:32:49,590 Current is current, right? 562 00:32:49,590 --> 00:32:51,850 The flow of electrons per unit time. 563 00:32:51,890 --> 00:32:55,390 And then resistance is anything that blocks the current. 564 00:32:55,390 --> 00:33:04,870 So, you know, junk, put some rocks in the pipe, or there are low resistance materials or something like that, or narrow wires. 565 00:33:05,110 --> 00:33:09,070 A wide wire has a lot less resistance than a narrow wire, and so on. 566 00:33:09,070 --> 00:33:11,030 So, anyway, V equals IR. 567 00:33:11,110 --> 00:33:14,890 This, you have to be a little familiar with it to use some of these devices. 568 00:33:15,230 --> 00:33:17,170 So, diodes and LEDs. 569 00:33:17,170 --> 00:33:20,210 So, I'm just going to talk about LEDs, because they're like a simple device, right? 570 00:33:20,470 --> 00:33:23,610 LED stands for light emitting diode. 571 00:33:23,610 --> 00:33:26,370 So, a diode symbol is just like this, right? 572 00:33:26,370 --> 00:33:29,770 A diode, it has one, two ends, an anode and cathode. 573 00:33:29,770 --> 00:33:31,090 They are not symmetrical, okay? 574 00:33:31,090 --> 00:33:35,270 And current flows from the anode to the cathode, flows straight through, okay? 575 00:33:35,330 --> 00:33:37,610 That's all it does, and current can't go backwards. 576 00:33:37,670 --> 00:33:38,770 Like, that's what a diode is. 577 00:33:38,770 --> 00:33:40,570 It's like a valve, can't go backwards. 578 00:33:40,690 --> 00:33:50,330 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? 579 00:33:50,330 --> 00:33:51,830 Below that, it doesn't flow. 580 00:33:52,470 --> 00:33:59,350 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? 581 00:33:59,350 --> 00:34:00,390 So, that's a diode. 582 00:34:00,390 --> 00:34:10,970 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? 583 00:34:11,290 --> 00:34:14,010 So, how do you do that? 584 00:34:14,010 --> 00:34:16,010 So, say I want to do that, right? 585 00:34:16,010 --> 00:34:20,890 I want to make my, I have an Arduino or whatever board, and I want to make a blinky example, right? 586 00:34:20,890 --> 00:34:23,390 So, I want to be able to light up an LED. 587 00:34:23,690 --> 00:34:31,290 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. 588 00:34:31,290 --> 00:34:33,910 The other side goes to ground, which is zero volts. 589 00:34:34,730 --> 00:34:38,910 And when I set this pin 13 high, then it's going to light up. 590 00:34:38,910 --> 00:34:41,490 When I set the pin low, it's not going to light up, okay? 591 00:34:41,510 --> 00:34:45,070 Now, note that I put this little resistor in the way, okay? 592 00:34:45,110 --> 00:34:48,650 Now, the reason I did that is so that I didn't blow up my diode, okay? 593 00:34:48,650 --> 00:34:52,170 Because these diodes, this is the one little analog electronics you have to know. 594 00:34:52,170 --> 00:34:55,510 These diodes are limited in the current that they can deal with. 595 00:34:55,510 --> 00:35:02,670 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? 596 00:35:02,670 --> 00:35:09,670 So, if I'm using a 3.3 volt device thing, like my board is 3.3 volts, right? 597 00:35:09,710 --> 00:35:12,190 If I'm using that, and I say, well, what's the current going through it? 598 00:35:12,190 --> 00:35:16,810 If I use about 330 ohms of resistance, then I get like 10 milliamps. 599 00:35:16,810 --> 00:35:18,270 That's safe, right? 600 00:35:18,270 --> 00:35:21,590 So, I need this resistor of 330, okay? 601 00:35:21,590 --> 00:35:23,270 That's like all you need to know, okay? 602 00:35:23,270 --> 00:35:26,750 You don't really need to know much more analog electronics than that. 603 00:35:27,010 --> 00:35:28,950 But yeah, I need a little circuit like that. 604 00:35:29,290 --> 00:35:33,450 Now, then once you get it, once you decide, okay, this is how I have to wire it together, right? 605 00:35:33,450 --> 00:35:34,450 Like this. 606 00:35:34,610 --> 00:35:36,530 Then you got to wire it together, right? 607 00:35:36,530 --> 00:35:37,370 Physically wire it. 608 00:35:37,370 --> 00:35:42,870 So, notice there's an Arduino or whatever board, and then there are two components, a resistor and a diode. 609 00:35:43,090 --> 00:35:48,530 So, I got to put them together, and usually do-it-yourselfers are going to put it together on a breadboard. 610 00:35:48,530 --> 00:35:50,970 Now, a breadboard is basically, it looks like this. 611 00:35:50,970 --> 00:35:52,090 It's got holes. 612 00:35:52,090 --> 00:35:53,830 These holes, stick wires in them, right? 613 00:35:53,830 --> 00:35:55,550 And it just sort of grips the wire. 614 00:35:55,770 --> 00:35:57,550 But you can pull it up, push it and pull it out. 615 00:35:57,550 --> 00:35:58,830 You can redo it. 616 00:35:59,130 --> 00:36:03,230 And so, these rows of five are all connected. 617 00:36:03,350 --> 00:36:05,410 So, all these pins are connected. 618 00:36:05,410 --> 00:36:06,570 All these pins are connected. 619 00:36:06,570 --> 00:36:09,030 But this row is not connected to this row, okay? 620 00:36:09,030 --> 00:36:12,390 So, the use of this is, say I want to connect a resistor to a diode. 621 00:36:12,390 --> 00:36:20,050 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? 622 00:36:20,050 --> 00:36:21,790 So, that's how you make connections. 623 00:36:21,810 --> 00:36:28,650 So, you can take this picture and connect them on a breadboard like this, okay? 624 00:36:28,810 --> 00:36:29,610 That's the idea. 625 00:36:29,610 --> 00:36:32,030 And in fact, here's a picture of that. 626 00:36:32,150 --> 00:36:34,150 So, I got, you can't read all the details. 627 00:36:34,150 --> 00:36:36,570 This is actually an Arduino over here. 628 00:36:36,670 --> 00:36:38,390 So, this is pin 13. 629 00:36:38,390 --> 00:36:41,230 It's connected to this row where there's a resistor. 630 00:36:41,290 --> 00:36:46,250 The other pin of the resistor goes into this row, which is connected to the diode. 631 00:36:46,250 --> 00:36:50,630 The other pin of the diode goes into this column, which is connected to ground, okay? 632 00:36:50,790 --> 00:36:59,010 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? 633 00:36:59,010 --> 00:37:01,430 Like, the relationship between it, you have to be able to do that, okay? 634 00:37:01,430 --> 00:37:04,710 But it's straightforward, you just practice it a little. 635 00:37:05,230 --> 00:37:05,890 Okay. 636 00:37:06,050 --> 00:37:09,570 So, that's, you know, simple electronics wiring, right? 637 00:37:09,670 --> 00:37:12,550 So, you do that, and then your program should work and blink the light. 638 00:37:14,250 --> 00:37:14,970 Okay. 639 00:37:15,490 --> 00:37:18,330 So, I was just talking about GPIO. 640 00:37:18,530 --> 00:37:22,710 GPIO is like the first thing you learn to use on your microcontroller. 641 00:37:22,870 --> 00:37:29,850 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? 642 00:37:29,890 --> 00:37:32,430 Can't teach them all now, but you learn how to use all of them. 643 00:37:32,430 --> 00:37:36,190 And each one of them has a set of registers devoted to it that describe its behavior. 644 00:37:36,950 --> 00:37:38,730 Another thing is synchronous protocols. 645 00:37:38,730 --> 00:37:49,190 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. 646 00:37:49,250 --> 00:37:51,030 Synchronous protocols are common. 647 00:37:51,030 --> 00:37:53,290 They're faster, they share a clock. 648 00:37:53,290 --> 00:38:00,750 Anyway, I can't go into details of the protocols, but FPI and I2C are the top ones, you know, that people use. 649 00:38:01,070 --> 00:38:02,550 And give you an example. 650 00:38:02,550 --> 00:38:05,890 Say I got like this, this is an Arduino, actually. 651 00:38:05,890 --> 00:38:09,930 And I only connected it to two components that I bought off of Adafruit or whatever, right? 652 00:38:10,010 --> 00:38:13,410 And these two components I know are I2C compatible. 653 00:38:13,410 --> 00:38:18,690 So when you look at the data sheet for these guys, it'll say, oh, this speaks I2C, this speaks I2C. 654 00:38:18,730 --> 00:38:21,050 So then you say, okay, I'm going to use I2C. 655 00:38:21,050 --> 00:38:24,070 So you wire it to the I2C pins of your Arduino. 656 00:38:24,290 --> 00:38:27,970 They're SDA and SCL, the two wires, two pins for I2C. 657 00:38:27,970 --> 00:38:30,730 SDA is a data line, SCL is a clock, right? 658 00:38:30,730 --> 00:38:34,670 And these guys, there's like a master and slaves. 659 00:38:34,910 --> 00:38:42,830 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? 660 00:38:44,250 --> 00:38:54,390 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. 661 00:38:54,390 --> 00:38:59,270 So there are certain registers like I2C1, CR1, and CR2. 662 00:38:59,270 --> 00:39:03,550 Control register one, this should say it too. 663 00:39:03,850 --> 00:39:14,230 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. 664 00:39:14,390 --> 00:39:17,610 Also, I2C DR, DR is its data register. 665 00:39:17,610 --> 00:39:24,630 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? 666 00:39:24,630 --> 00:39:31,850 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? 667 00:39:31,850 --> 00:39:36,730 And then on the receiving end, if I read from this DR register, I will receive whatever was sent, okay? 668 00:39:36,730 --> 00:39:40,870 So there's hardware built in that deals with all the details of the protocol. 669 00:39:42,570 --> 00:39:45,090 Okay, so, okay, good, make it. 670 00:39:45,090 --> 00:39:48,550 So, yeah, so the last part is debugging tools. 671 00:39:48,550 --> 00:39:52,690 So there are some different debugging tools when you're doing embedded design, right? 672 00:39:52,690 --> 00:39:55,510 So here's just my, some random design, okay? 673 00:39:55,510 --> 00:39:59,750 And it's got board and some components, some hardware components, all wired together, okay? 674 00:39:59,770 --> 00:40:02,350 Now, you probably use standard debuggers, right? 675 00:40:02,350 --> 00:40:05,050 You set a breakpoint, you step through the code and all that. 676 00:40:05,350 --> 00:40:11,230 So you can do, you can do that, right, with this, but that doesn't, that control, that works on the micro control. 677 00:40:11,230 --> 00:40:14,730 You can set a breakpoint, step through it, but what about all the rest of the devices, right? 678 00:40:14,730 --> 00:40:16,490 There are other things that you want to view. 679 00:40:16,550 --> 00:40:21,810 So it is very common in these designs to want to see the value on a wire. 680 00:40:21,810 --> 00:40:24,890 You might want to say, oh, is this high or is this low, okay? 681 00:40:24,890 --> 00:40:27,850 Random wire, very common to need to do that. 682 00:40:27,850 --> 00:40:29,050 You're like, I wonder what's being sent. 683 00:40:29,050 --> 00:40:30,510 Is it a one or a zero, right? 684 00:40:30,550 --> 00:40:31,790 So how do you do that? 685 00:40:31,790 --> 00:40:33,410 One way is with multimeters. 686 00:40:33,410 --> 00:40:35,670 So the first thing, you always have to have it. 687 00:40:35,830 --> 00:40:38,070 You gave some out, Sydney, yesterday, right? 688 00:40:38,190 --> 00:40:45,290 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. 689 00:40:45,470 --> 00:40:47,350 So you can tell if something is high or low. 690 00:40:47,350 --> 00:40:50,310 It can read the current, how much current is going through there if you need to know. 691 00:40:50,310 --> 00:40:52,550 It can read resistance between two points. 692 00:40:52,850 --> 00:40:54,330 It can read connectivity. 693 00:40:54,390 --> 00:40:56,730 So it'll like, they almost always have connectivity. 694 00:40:56,730 --> 00:40:59,070 So if these two pins are connected, it'll beep. 695 00:40:59,070 --> 00:41:01,530 So if you're like, oh, is this wire connected to this one? 696 00:41:01,530 --> 00:41:02,710 It'll beep, they are. 697 00:41:03,330 --> 00:41:05,070 And they have probes. 698 00:41:05,070 --> 00:41:10,150 So these two probes, like you take a black and a red probe, put them in like here and here, right? 699 00:41:10,170 --> 00:41:15,630 And then the other ends of these, you touch to the wires that you want to test the voltage on, for instance, okay? 700 00:41:15,690 --> 00:41:17,870 So multimeters are like basic tool. 701 00:41:17,990 --> 00:41:20,450 But the thing about multimeters is that they are very slow. 702 00:41:20,790 --> 00:41:28,910 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? 703 00:41:28,910 --> 00:41:32,450 So multimeters are only good for looking at signals that are constant. 704 00:41:32,450 --> 00:41:36,510 It's held high, like for half a second at least, or held low, half a second. 705 00:41:36,570 --> 00:41:38,850 Changing signals, you can't use a multimeter. 706 00:41:38,890 --> 00:41:41,190 So one thing you use is an oscilloscope. 707 00:41:41,190 --> 00:41:46,890 Now an oscilloscope, it basically, it'll have a screen and it just plots voltage over time, okay? 708 00:41:47,090 --> 00:41:52,690 Now oscilloscopes though, they're usually very few probes, two or four probes. 709 00:41:52,730 --> 00:41:57,090 So they can look at two signals, two wires at a time, or four wires at a time. 710 00:41:57,630 --> 00:42:00,610 And here's like an old one, an old analog scope. 711 00:42:00,930 --> 00:42:05,510 And now the analog scopes, they only work for repeating signals, okay? 712 00:42:05,510 --> 00:42:10,350 So the signal has to be like the same over and over, like a waveform, a sine wave or something. 713 00:42:10,350 --> 00:42:11,670 And it'll work for that, right? 714 00:42:11,670 --> 00:42:12,370 The old scopes. 715 00:42:12,370 --> 00:42:14,890 The new scopes, digital scopes, they're not like that. 716 00:42:14,890 --> 00:42:18,350 They can read, they can just sort of read it and capture it, right? 717 00:42:18,350 --> 00:42:20,730 Capture it at snapshot time and show it to you on the screen. 718 00:42:20,970 --> 00:42:23,830 But then you can say, oh, look at this time, it was high. 719 00:42:23,830 --> 00:42:25,510 Now at this time, it was low, right? 720 00:42:25,510 --> 00:42:27,390 And these things are very fast. 721 00:42:27,570 --> 00:42:35,150 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. 722 00:42:35,210 --> 00:42:36,970 And you can use an oscilloscope. 723 00:42:37,470 --> 00:42:42,770 Now oscilloscopes, one thing that they, one thing you need to do with oscilloscopes is do triggering, okay? 724 00:42:42,870 --> 00:42:47,670 So triggering is determining when to start recording. 725 00:42:47,670 --> 00:42:49,710 So these things, they have a buffer. 726 00:42:49,710 --> 00:42:52,270 I don't know, maybe say it has a two gigabyte buffer, okay? 727 00:42:52,310 --> 00:42:56,810 But for every, it's sampling, but it's got to be sampling like a lot faster than your signals. 728 00:42:56,810 --> 00:43:05,910 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. 729 00:43:05,910 --> 00:43:07,870 It'll fill up this buffer very quickly. 730 00:43:08,010 --> 00:43:11,110 So you need triggering to determine when to start recording, okay? 731 00:43:11,110 --> 00:43:13,470 To see what you want, right? 732 00:43:13,610 --> 00:43:16,050 So one way to do is manual triggering. 733 00:43:16,050 --> 00:43:17,650 You hit a button and it goes, okay? 734 00:43:17,650 --> 00:43:26,950 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? 735 00:43:27,110 --> 00:43:30,530 With oscilloscopes, another way triggers level triggering. 736 00:43:30,530 --> 00:43:34,250 So they repeatedly trigger whenever the signal reaches a certain level. 737 00:43:34,250 --> 00:43:38,690 When it goes above X amount of voltage, it triggers and it draws it, okay? 738 00:43:38,690 --> 00:43:40,010 That's another way to trigger. 739 00:43:40,390 --> 00:43:42,550 Also, there's one shot versus continuous triggering. 740 00:43:42,550 --> 00:43:46,330 So one shot means record once and just put that on the screen and hold it there. 741 00:43:46,690 --> 00:43:51,450 Continuous means record once, put it on the screen, record again, put it on the screen, over and over and over. 742 00:43:51,510 --> 00:43:53,990 And so for a repeating signal, that's useful. 743 00:43:53,990 --> 00:43:55,850 You can see if it's changing or what. 744 00:43:57,150 --> 00:43:58,630 Similar to an analog scope. 745 00:43:58,790 --> 00:44:01,430 Now, then another thing that's really useful is a logic analyzer. 746 00:44:01,430 --> 00:44:08,630 These cost even more, but the downside of a logic analyzer is that they are only digital. 747 00:44:08,650 --> 00:44:10,170 See, an oscilloscope is an analog device. 748 00:44:10,170 --> 00:44:11,870 It'll measure analog voltage. 749 00:44:12,130 --> 00:44:14,450 An oscilloscope is either zero or one, okay? 750 00:44:14,450 --> 00:44:15,310 It's only going to show that. 751 00:44:15,310 --> 00:44:18,190 So it's less information, but they have a lot more pins. 752 00:44:18,190 --> 00:44:20,510 They'll have like 32 pins, 64 pins. 753 00:44:20,510 --> 00:44:23,490 So you can see a whole bus at a time, right? 754 00:44:23,490 --> 00:44:26,070 A whole big bus, which is useful, but expensive. 755 00:44:26,070 --> 00:44:27,730 They cost a lot of money. 756 00:44:27,730 --> 00:44:32,230 Or you can get the cheap one, like I do, which has like 10 pins or something, right? 757 00:44:32,230 --> 00:44:34,770 And it's like USB connection to my device. 758 00:44:34,770 --> 00:44:35,090 Okay. 759 00:44:35,090 --> 00:44:35,890 Question? 760 00:44:35,950 --> 00:44:36,410 No? 761 00:44:36,410 --> 00:44:36,650 Okay. 762 00:44:36,650 --> 00:44:36,910 Yeah. 763 00:44:37,250 --> 00:44:40,470 So anyway, these are useful like that. 764 00:44:40,710 --> 00:44:43,090 And they're actually, they're usually very smart too. 765 00:44:43,090 --> 00:44:44,510 They know protocol. 766 00:44:44,510 --> 00:44:45,850 So like they know I2C. 767 00:44:45,850 --> 00:44:47,470 So they'll just mark it up for you. 768 00:44:47,470 --> 00:44:49,350 You know, it's pretty useful actually. 769 00:44:49,750 --> 00:44:53,150 Here's one that I have, a USB logic analyzer. 770 00:44:53,150 --> 00:44:55,090 So it's connected by USB to my laptop. 771 00:44:55,090 --> 00:44:59,870 You download a free app and you can do stuff with it, record and stuff like that. 772 00:44:59,890 --> 00:45:02,510 And it's got a lot more wires that you can use to probe. 773 00:45:03,130 --> 00:45:05,090 And that's about it. 774 00:45:05,510 --> 00:45:11,770 You could download the slides if you want to download the slides and let me know if there's any questions. 775 00:45:19,830 --> 00:45:24,090 We do have time for about three to four questions and I'll hand you the mic. 776 00:45:24,810 --> 00:45:25,710 Go ahead. 777 00:45:31,410 --> 00:45:36,810 I work with a firmware team for whom the idea of cybersecurity is completely new. 778 00:45:37,130 --> 00:45:42,830 What is the best way to establish rapport with them on cybersecurity? 779 00:45:42,830 --> 00:45:46,610 Because they hear cybersecurity, they say, doesn't belong to me. 780 00:45:46,610 --> 00:45:53,990 I make devices, but you know, we're kind of notorious for, I'm an industrial control system. 781 00:45:53,990 --> 00:45:56,630 So that it's a new field for us. 782 00:45:56,630 --> 00:45:56,910 Yeah. 783 00:45:56,910 --> 00:46:04,570 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. 784 00:46:04,570 --> 00:46:06,110 I do that in my class, right? 785 00:46:06,110 --> 00:46:09,790 Like to entice the students and show them how important it is. 786 00:46:09,790 --> 00:46:11,530 Like, you know, it's easy to find, right? 787 00:46:11,530 --> 00:46:12,750 Especially around here. 788 00:46:12,950 --> 00:46:13,410 You know what I'm saying? 789 00:46:13,410 --> 00:46:16,550 You could get like a list of events and just show it to them. 790 00:46:16,610 --> 00:46:23,390 You could also make them participate in that MITRE embedded capture the flag. 791 00:46:23,510 --> 00:46:30,810 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. 792 00:46:30,810 --> 00:46:33,970 And then six more weeks, you get to attack everybody else's system. 793 00:46:33,970 --> 00:46:40,690 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. 794 00:46:40,690 --> 00:46:46,610 And then you give it to, then you trade it to everybody and everybody else attacks and you get points and stuff like that. 795 00:46:46,610 --> 00:46:57,990 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. 796 00:46:58,050 --> 00:47:01,050 Like if they hide some details, so like with the CMU guys, right? 797 00:47:01,150 --> 00:47:06,310 They said, yeah, we found vulnerabilities in this I2C driver and we did this and that with it, right? 798 00:47:06,310 --> 00:47:09,610 I'm like, I'm thinking, how did they find these vulnerabilities? 799 00:47:09,630 --> 00:47:12,130 And they didn't say, they had to do fuzzing. 800 00:47:12,130 --> 00:47:14,650 In my conclusion, they had to fuzz it, you know? 801 00:47:14,650 --> 00:47:17,610 Because it's not like they eyeballed it and were like, aha. 802 00:47:17,610 --> 00:47:19,690 I mean, I would be really shocked if they did that. 803 00:47:19,690 --> 00:47:22,170 But anyway, maybe that, I don't know. 804 00:47:22,810 --> 00:47:23,290 Yeah. 805 00:47:26,780 --> 00:47:29,560 So I don't work in industry, right? 806 00:47:29,560 --> 00:47:31,920 So I don't really have to vet anything. 807 00:47:32,120 --> 00:47:36,220 But I do in Bad Catch the Flag, I have them fuzz the libraries. 808 00:47:37,540 --> 00:47:40,280 I teach them, I do have the lecture material on fuzzing. 809 00:47:40,280 --> 00:47:45,620 I'm like, okay, fuzz each one of these that you're going to use because of that CMU attack, actually. 810 00:47:45,640 --> 00:47:46,920 But that's what I do. 811 00:47:46,920 --> 00:47:50,360 No, no, I just have them do it from scratch. 812 00:47:50,860 --> 00:47:55,720 Yeah, I just have them write their own code for fuzzing from scratch, yeah. 813 00:47:59,360 --> 00:48:02,440 Thank you, Professor Harris. 814 00:48:02,540 --> 00:48:05,780 I'm very interested in your topic. 815 00:48:05,800 --> 00:48:09,740 You mentioned this devices to do the diagnostics and stuff, right? 816 00:48:09,740 --> 00:48:18,760 But maybe this is something with security diagnostics or geo tag debugging, some stuff that should be covered? 817 00:48:18,760 --> 00:48:20,680 Sorry, yeah, I didn't show that. 818 00:48:20,680 --> 00:48:21,980 You're absolutely right. 819 00:48:22,300 --> 00:48:24,160 So that certainly exists. 820 00:48:24,160 --> 00:48:25,940 So this I didn't go into. 821 00:48:25,940 --> 00:48:30,660 So generally debugging, like setting breakpoints and all that is harder on an embedded system. 822 00:48:30,660 --> 00:48:35,780 Because when you set a breakpoint, you change the memory value, right? 823 00:48:35,780 --> 00:48:38,300 But these things, a lot of these embedded systems run in firmware. 824 00:48:38,300 --> 00:48:43,680 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? 825 00:48:43,680 --> 00:48:46,880 So a lot of times people will use JTAG debugger. 826 00:48:46,880 --> 00:48:49,060 I just sort of didn't cover it as a whole. 827 00:48:49,060 --> 00:48:58,480 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. 828 00:48:58,480 --> 00:49:02,440 Actually, so I have a paper where we follow the branches to see if malware is running, right? 829 00:49:02,440 --> 00:49:05,800 Because you know, if malware is running, it'll branch to the wrong location. 830 00:49:05,800 --> 00:49:11,000 Some, you know, somebody did a buffer overflow and change the return address pointer, it'll jump somewhere weird, right? 831 00:49:11,000 --> 00:49:19,760 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. 832 00:49:20,100 --> 00:49:21,220 So those exist. 833 00:49:21,220 --> 00:49:21,980 Those exist. 834 00:49:21,980 --> 00:49:23,360 I just didn't talk about it. 835 00:49:23,760 --> 00:49:24,720 Those are useful. 836 00:49:24,840 --> 00:49:26,120 They cost a lot of money, though. 837 00:49:26,120 --> 00:49:26,880 That's the problem. 838 00:49:26,880 --> 00:49:30,580 They cost a lot of money, like Lauterbach, thousands of dollars for one of these things. 839 00:49:30,580 --> 00:49:32,560 But embedded... yeah, go ahead. 840 00:49:32,840 --> 00:49:34,400 Yeah, that's right. 841 00:49:35,040 --> 00:49:37,040 I'm assuming no more questions. 842 00:49:37,720 --> 00:49:38,940 Okay, thanks.