start	end	text
0	2280	I'm talking about embedded system design.
2280	4680	So this is really rather tutorial, right?
4680	7140	This isn't like a new security invention.
7140	10200	This is just basically how to build an embedded system.
10200	15560	And this is useful information if you somehow wanted to attack a system , an embedded system, or defend a system.
15600	23060	It's a good idea to know how to develop them and , you know, how the development is different than just traditional software.
23440	29980	I'm Professor from University of California, Irvine, and I teach this stuff sort of regularly.
30000	32720	And this is going to be very compressed, right?
32720	35240	I mean, it's only, you know, 50 minutes or something.
35480	39020	So it's not like I could summarize the whole thing, but I'm going to touch on everything.
39020	40980	And then you can also download the slides if you want to.
40980	43920	I have like a QR code at the end if you wanted to.
43920	47580	And you could pursue some of these topics more, you know, later if you wanted to.
48220	50080	Okay, so what's an embedded system?
50360	54960	An embedded system is basically a computer that doesn't look like a computer, okay?
54960	59500	So like, yeah, a phone, let's say, or the projector, right?
59500	61020	The projector is a good example.
61020	65500	All you see, you know, there's computation going on inside it, but the interface isn't the same, right?
65500	67600	I don't have to write code directly on it.
67600	72420	So to work with it, I press some buttons on it or click some buttons on here, you know?
72440	75760	So as an example, typical embedded device, like a car, right?
75760	79820	You got a car, old car on the left, and a new car.
79820	84660	Now, the interface is basically the same, like the driving interface is the same, right?
84660	90300	But the new car has like 60 plus processes in it doing all kinds of internal control.
90360	94720	So there's a lot of computation going on, but you as a user, you don't have to deal with that directly.
94720	97800	So you have to code for each one of these microcontrollers, right?
97800	102960	They're all just doing stuff in the background, making things better, but the interface to you is nice and simple.
103080	106060	And so that's basically what an embedded device is.
107340	109860	Related buzzwords, I just like to define these.
109980	113640	You maybe have heard of cyber-physical systems, or you definitely heard of Internet of Things.
113640	115880	These are all basically the same thing.
115940	118420	Cyber-physical is sort of an older term.
118420	122820	It focuses on industrial systems most of the time, right?
123260	127560	With big sensors and actuators, like, I don't know, a plant or something like that.
128040	131040	And Internet of Things has that word internet in it.
131040	134060	So it focuses on the networking abilities of it.
134060	139660	Now, in truth, nowadays most embedded systems are networked anyway, so there's not really much distinction.
139660	141380	IoT is really an embedded system.
141380	148120	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.
148820	151100	So they're all similar concepts.
151400	155640	So main idea is sort of at a high level, the design...
155640	160400	one difference in designing that versus designing regular software is being efficient, right?
160400	171680	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?
171680	172520	Like, when you turn...
172520	175120	when they turn in an assignment, it's like, okay, it worked, right?
175120	176820	I tested it out a little bit.
176840	179040	Barely... they don't really know how to test, but I tested it out.
179040	179860	It worked.
179880	182120	But, you know, did it work fast?
182120	184420	You know, was it... how much memory did it use?
184420	188200	And in a language like Python, you have no idea about those type of things, right?
188200	190080	Like, the memory, you have no idea, right?
190680	196480	So... but with embedded systems, you have to be efficient, because people... these manufacturers are cheap, cheap, cheap.
196480	198840	Like, they don't want to spend anything on these devices.
198840	208780	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.
208780	209520	That would be stupid.
209520	211300	It costs way too much, right?
211300	212600	They would never do that.
212600	215120	They would get the cheapest possible microcontroller.
215160	216380	They'd be like, what's the cheapest thing?
216380	218800	You know, I could save 10 cents if I got this cheaper one.
218800	219860	Let's go for that.
219860	220380	You know what I mean?
220380	221700	It's always efficiency.
221700	223280	So, efficiency is really important.
223340	224440	And there's lots of constraints.
224440	228020	Design costs, performance, you know, power.
228020	229040	Power is a big constraint.
229040	230240	How much power is it using?
230260	239500	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.
239500	243100	You know, you don't have to... you're not thinking, oh, what is the memory that this thing is requiring?
243100	245860	Well, with embedded systems, you really are, like, all the time.
247260	247800	Okay.
248000	249180	Hardware and software.
249180	253100	So, embedded systems have hardware and they have software components, right?
253140	256220	So, that's actually the badge from last year.
256580	258460	You know, it's a little video game thing.
258480	259740	And it's hardware and software.
259740	261560	So, there's like a microcontroller in there.
261560	262560	There's a little screen.
262560	263520	There's some speakers.
263520	264040	There's a bunch...
264040	265500	I don't know what other devices are in there.
265500	267240	Lights, LEDs, that type of thing.
267260	271540	And they have to be controlled by some software running on the microcontroller, right?
271540	275340	So, you have to consider hardware as well as software and design them together.
275660	277860	So, this is not what you do in normal software, right?
277860	284580	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?
284600	286060	Generally not, right?
286100	288700	You're not... like, what is the speaker they're going to use, right?
288700	293220	But when they designed this, they knew exactly, like, okay, this is the speaker that we're going to use.
293220	294520	This is the cheap monitor.
294520	296620	And that changed the way they wrote the code.
296620	301020	So, you have to think about the hardware side of it when you're doing the design, too.
303240	304040	Okay.
304180	305080	Outline of the talk.
305080	309660	I might not be able to finish all these slides just because, you know, there's only so much time.
309800	311360	But three things.
311360	314380	So, first, I'll talk about working with the microcontroller.
314620	317620	Then connecting the microcontroller to external devices.
317620	319860	So, work with the microcontroller's coding, right?
319960	321040	Software, pretty much.
321040	324780	Then connecting it to hardware devices, other things you want to talk to.
324780	326180	And then debugging tools.
326180	329420	Because debugging is different in embedded systems, too.
329960	330180	Okay.
330180	333100	So, microcontrollers are just these little integrated circuits.
333380	334440	And you've seen them.
334460	338780	Generally microcontrollers, I mean, people have definitions of these things.
338780	342080	But generally, they're just, like, cheaper microprocessors, okay?
342600	346440	And you can control everything directly, right?
346440	350460	Meaning all the hardware on the chip, the programmer can control.
350460	352120	And I'll go through what I mean by that.
352120	359580	Normally, you can't control a lot of things on regular microcontrollers, microprocessors, you can't control, okay?
359580	362020	Like, say you want to print something on the screen, right?
362020	363700	You call print, right?
364080	366860	But print asks the operating system to do the control.
367080	368920	Basically, it calls a system call.
368920	374440	The system calls that, checks it out, calls the driver, and the driver puts it on the screen, you know?
374440	380020	So, with microcontrollers, the programmer is doing that directly themselves, okay?
381540	384100	Yeah, so, how do you program one of these things?
384100	385580	So, you have to program them.
385780	392980	So, you write your code on some development environment, like a laptop, and eventually you've got to put it onto the microcontroller.
392980	404100	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.
404100	406980	This is a really old-fashioned one, but same idea, right?
406980	408960	And you can do it that way.
409920	413840	And in fact, that's how it's really done in products, right?
413920	418640	Because the other way is like this, which is much more common if you're going to do it yourself.
418800	420220	It's built into the board.
420220	423420	So, say you buy a board like this, or an Arduino, or whatever.
423420	425800	This is a board we use in class, right?
425840	429360	And this board, it has the programming hardware built into it, okay?
429360	439200	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.
439200	440580	This one deals with the programming.
440580	444040	It takes the USB, transfers it into this guy.
444040	447860	It has a bootloader running on it, and it programs it, okay?
447880	454340	So, this is like what do-it-yourselfers use, but this hardware here is excess.
454720	458100	Like, you don't really need that once you deploy the device, right?
458100	462280	So , in real devices, they do it this way, and then all they're deploying is this.
462280	465280	This is useful, though, in practice for regular people.
466580	467140	Okay.
467140	468420	So, ARM.
468420	474240	So, ARM is the brand of microcontroller that is the most common, okay?
474240	479700	So, you know, Intel and AMD, Intel-class machines dominate microprocessors, right?
479700	485440	Well, in microcontrollers, Intel has, like, no... they don't make anything that anybody uses, really, right?
485640	487700	Instead, ARM makes them.
487700	492860	Now, ARM, what they do is they lease the design.
492860	494460	So, they don't make silicon, right?
494460	495520	They don't make the chip.
495520	498600	They lease the designs to other companies who make the chips.
498600	501160	So, maybe they lease it to TI, TI makes chips.
501200	504460	Maybe they lease it to STMicroelectronics, they would make the chips, right?
504460	508760	But ARM is the type of microprocessor, microcontroller that's in there, okay?
508760	514040	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.
514040	516120	But there are, for instance, Macs, right?
516120	519740	Those M1, M4s, and all those, those are all ARM, right?
520340	523220	Basically, everything in everybody's phone is going to be an ARM.
523220	526780	Not everybody's, there's some that aren't, but most of them are going to be ARMs.
526780	530180	Like, most of these devices use ARM microcontrollers, you know?
531300	540540	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.
541280	541820	Okay.
541820	544160	Now, microcontrollers have peripherals.
544160	548900	What I mean by this is, okay, this, I know you can't read the details of this.
548900	552280	I took this out of a data sheet for a microcontroller I used to use for class.
552420	555760	Now, up here, I'll just tell you, up here is the CPU, okay?
555760	558720	This is the main processor, the ARM microcontroller, right?
558720	561120	And that thing is what runs your code.
561120	563460	So, it executes instructions, right?
563800	570120	The rest of it is all, like, other stuff that connects to it and does useful things, okay?
570120	571620	So, for instance, there's memories.
571620	572660	I can't even read them.
572760	573980	Memories and stuff like this.
574020	580920	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?
581260	586880	This, but the main thing is this CPU is connected by these two long buses, these buses, right?
586940	590480	Connected by these buses to all these peripherals, what are called peripherals.
590480	594360	Now, these peripherals are what do interesting stuff on microcontrollers.
594360	595680	They do all kinds of things.
595680	597880	Like, for instance, general purpose I.O., right?
597880	598560	The pins.
598560	600900	If you want to control the pins, that's a peripheral.
600900	604020	Or if you want to communicate by UART, that's another peripheral.
604020	607840	Or if you want to do analog to digital conversion, that's another peripheral, right?
607840	611080	There are all these blocks are peripherals, okay?
611080	616880	So, when you're coding, you know, some instructions, some things you do are the same, right?
616880	617800	C is C.
617800	619420	I'm assuming C right now, right?
619420	620380	C is C.
620380	626220	But the big difference with microcontroller programming is that you have to control these peripherals specifically.
626220	630120	You have to tell them exactly what to do step by step, okay?
630180	637600	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?
638720	639820	Peripheral control.
639820	641160	So, common peripherals, okay?
641160	650640	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?
650920	653380	So, embedded software directly controls peripherals, all right?
653380	654280	I said that.
655160	655780	Yeah.
655820	656680	Yeah, okay.
656780	665120	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?
666080	671240	So, you can make some devices operate with a real operating system, like a full-on operating system.
671240	679620	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.
679620	682560	Like, I've seen many talks like this where they talk about attacking embedded systems.
682560	686140	Maybe they use a router as an example, how to dump the firmware, whatever.
686480	692520	And these devices, a lot of these devices have just Linux running on them, like a small Linux, right?
692520	695440	And that's just running a full-on operating system, okay?
695940	697300	So, you can do that.
697300	703260	Now, the downside of that is that, you know, it's easy because it's running Linux, but there's overhead, right?
703260	705860	You're running an operating system on top of the microcontroller.
705980	715180	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?
715180	719040	So, if you want to be really cheap, you might not want to use a full-on operating system.
719360	722380	So, then sometimes people use bare metal.
722380	723260	It's the other way.
723320	729840	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?
729880	731960	You control everything in detail.
731960	738080	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?
738080	740300	But if you're doing bare metal, then you don't, right?
740300	744840	You have to really understand all the details of how to control the peripherals.
745020	747940	And then there's this in-between, which is real-time operating systems.
747940	751280	Real-time operating systems are basically stripped back operating systems.
751800	758100	They don't have like a nice GUI or any of that stuff, but maybe they support multithreads, you know, threading.
758100	761720	They support that and they also support scheduling algorithms.
761820	765780	So, basically they're made to satisfy real-time deadlines, right?
765780	772620	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?
772620	775280	And you got to meet that deadline no matter what.
775280	781940	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?
781940	784940	So, they have scheduling algorithms that they use to support that.
785600	786500	Okay.
786500	792480	So, embedded systems are said to have a, if you're going to program one, you have what's called a toolchain, usually.
792480	796720	Toolchain is basically an IDE and they're all sort of the same, right?
796720	799480	I mean, that's just generic IDE looking thing, right?
799480	807060	This particular one is ST microelectronics IDE, STM cube IDE, but they're all basically the same thing, okay?
807060	807920	And you've seen them.
807920	812340	Here's the code and here's all the files in the project and all that stuff, right?
812460	820420	So, the one difference in an embedded system IDE is that you have a programmer that's attached to it.
820420	826680	So, one thing you have to do is, like, once you compile the code, you actually cross-compile the code.
826680	832520	So, compiling a code, normally, if I compile code on this machine, it'll be compiled to execute on this machine, right?
832520	833720	On this microprocessor.
833720	838080	But with an embedded system, you compile it on this machine to run on a different processor, right?
838080	839720	That's called a cross-compiler.
839720	848740	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.
848840	850520	And that's what a programmer does.
850700	852700	So, it's some programmer software.
852700	859560	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.
860160	860480	Okay.
860480	863100	So, IDEs, though, they don't look that much different.
863660	870060	Now, one, another sort of painful difference in embedded programming is datasheets.
870060	873700	Here's a datasheet, or the reference manual, whatever they call it, okay?
873720	876420	These datasheets are massive, okay?
876420	880360	They describe everything that a component is supposed to do.
880360	884620	Now, you can get datasheets on all kinds of integrated circuits, all kinds of components, right?
884620	886620	But right now, I'm talking about the microcontroller.
886620	891020	So, like, this is the microcontroller I'm going to use in class in the fall, actually.
891060	893220	I'm just starting to learn it and use it in the fall.
893220	896160	I was like, oh, let me use it in this talk so I can start getting comfortable with it.
896200	899840	Its datasheet is 1,757 pages long, okay?
899840	902780	That is a painful datasheet, right?
902780	909180	And it describes every peripheral on there, how you use every peripheral, every little detail, okay?
909240	913600	And you have to be familiar with a chunk of it, right?
913600	916820	And learn how to search really well, okay?
916820	922080	Like, you can't memorize all that, but you got to search, you got to remember to look at that datasheet, okay?
922080	926600	And then sometimes, in the very worst case, the datasheet is incomplete, right?
926600	934600	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?
934600	936300	Maybe I missed it, right?
936300	937800	Or it's wrong.
937800	938720	That happens too.
938720	942920	The datasheet will say something incorrect, and that's very painful, okay?
943060	950140	And, you know, I use a lot of Google, because usually, whenever you find that, somebody else hopefully has run into the same issue.
950520	954220	So, anyway, you have to get used to reading these datasheets, okay?
954220	955400	Just in general.
956220	957520	So, importance of datasheets.
957520	960620	So, it is very easy to miss important information.
960620	962680	So, as a broad example, right?
962680	968880	Say I'm talking about my 1,700 page datasheet, and I want to do... it leads to bugs, which can be exploited.
968880	970880	This is where a lot of bugs can happen, right?
970980	974120	So, say I want to do UART communication, right?
974120	977460	I want to communicate with another device by UART, which is protocol, right?
977780	980800	So, there's a section in the datasheet on UART, right?
980800	981500	Just on that.
981500	983620	So, you're like, okay, let me read that whole section, right?
983660	986540	Okay, based on that section, my code works.
986540	989100	And you test it out, and you're like, okay, it works, right?
989140	995760	But then you didn't notice that in this other section, 500 pages later, they were talking about reset, okay?
995760	999160	And in reset condition, maybe UART works differently, right?
999160	1004680	There's like a special case that you missed, because it was far off in the datasheet, right?
1004680	1006100	Very painful, okay ?
1006100	1007300	This happens, right?
1007300	1017100	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?
1017100	1020220	Because it's very easy to put a bug into these things.
1020220	1028860	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.
1028860	1030160	They didn't win this year.
1030240	1043800	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.
1043800	1048520	They fuzzed the I2C drivers until they found such a vulnerability, and then they exploited it.
1048960	1052360	So, anyway, data cheats are painful and important to understand.
1053440	1054820	Peripheral control registers.
1054820	1055200	Okay.
1055200	1060040	So, when you're writing code, you have to control these peripherals and tell them what to do.
1060120	1063160	So, peripherals are controlled through registers.
1063160	1067900	Now, a register in a chip is just a storage element, you know?
1067900	1069300	Like a 32-bit register.
1069300	1071240	Typically, these are 32-bit devices.
1071240	1072620	They've got a 32-bit register, right?
1072620	1074800	It just stores 32 zeros and ones.
1074800	1082800	And all of these peripherals, every peripheral has associated with it some registers that are used to control it and to observe it, right?
1082940	1095760	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.
1095980	1096220	Okay?
1096220	1097940	That's how you do control.
1098540	1104160	These registers are like the interface to all the peripherals on your microcontroller, okay?
1104160	1111620	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.
1111620	1117480	Oh, I see it's bit five of this register makes this start, and bit six puts it in this mode and all this.
1117480	1120860	That's why the data sheet's, like, 1,700 pages long, okay?
1120900	1123780	So, that's how you control them, through these registers.
1124060	1129860	So, and if you... anything you want to do, drive a value onto a pin, or do A to D conversion, UART, or whatever.
1130480	1134160	Now, so, as an example, right?
1134160	1141080	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.
1141080	1146320	It's the schematics inside a data sheet for a particular... for this STMicroelectronics chip, okay?
1146320	1149860	And this schematic is showing me one pin in the GPIO.
1149860	1152640	So, GPIO stands for General Purpose Input Output.
1152640	1154200	That means the pins of the chip.
1154200	1157240	If you drive to ones and zeros to turn lights on, or whatever, right?
1157240	1158540	And you can read them, too.
1158540	1161780	Maybe some of the device is driving a 0-1 output, you want to read it.
1161840	1164640	So, this is, like, the hardware behind a pin.
1164640	1167660	So, over here is the pin, in tiny letters, says IO pin, right?
1167660	1168500	This is the pin.
1168520	1171100	And then, this is all the logic associated with the pin.
1171100	1176380	And then, over here, to the left, over here, is, like, the microcontroller, okay?
1176640	1181720	So, and the only thing I want to highlight here is that they show some of these registers.
1181720	1183540	I put them... I highlighted them in red.
1183540	1186000	And they name them in the data sheet.
1186100	1189800	GPIO... oh, and I'm talking about GPIO port A.
1189800	1191040	There are many ports on these things.
1191040	1192140	So, I'm talking about port A.
1192400	1196620	IDR, GPIO-A-BSS-RR, and GPIO-A-ODR.
1196720	1199160	So, like, IDR is the input data register.
1199220	1208080	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.
1208080	1215080	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.
1215160	1216560	Pin 0, rather, you know?
1216560	1220480	So, you read this register inside your code, right?
1220480	1222480	And then this register is to set output bits.
1222480	1224400	Say I want to set a particular output bit high.
1224400	1226680	I set the appropriate bit in this register.
1226680	1229260	And say I want to write all the output bits to something.
1229260	1233720	I go to this ODR, output data register, and write all the pin outputs.
1234280	1239160	So, the idea here is just that every peripheral has a set of registers.
1239160	1242520	And you have to learn what all of them do, what they're all for.
1244400	1245200	Okay.
1245940	1248300	Now, registers are memory mapped.
1248540	1253740	So, what that means is that in order to write to a register, you write to a memory address.
1253780	1261780	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?
1261780	1268060	In the datasheet, it will be like, GPIOA, output data register, is that address whatever, okay?
1268060	1273220	And then all you do to write to that register is you write to that address, okay?
1273220	1275620	And these addresses are in the datasheet.
1275760	1284540	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?
1284560	1291260	They usually, like, with these devices, they usually have, like, a header file that has them all defined for you.
1291280	1294560	You know, most IDEs have that.
1294580	1302180	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.
1302180	1304840	Otherwise, you have to hash to find them explicitly in your code.
1306180	1308500	By the way, if there's any questions, go ahead and raise your hand.
1308600	1312580	I'm perfectly fine answering questions right in the middle, if that's fine with me.
1312580	1313680	And I know I'm going fast.
1313680	1316960	I always do that anyway, but anyway.
1316960	1318160	All right.
1318560	1321020	So, blinking an LED.
1321120	1325380	So, this is the one I'm going to use in class, STMicroelectronicsBoard.
1325480	1329000	And just... this is the main microcontroller.
1329000	1333500	This is used for loading from... this is a USB connect interface.
1333840	1335900	And say I want to blink an LED.
1336440	1338140	Now, on this board...
1338140	1342420	oh, I should mention here, there's a difference between the microcontroller and the board, okay?
1342420	1345980	The microcontroller is this chip right here, okay?
1345980	1348140	It has this data sheet and all that.
1348140	1351700	The board is this whole thing, which has the microcontroller on it.
1351700	1355140	And the reason I bring that up is because you need both to do this.
1355140	1363080	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.
1363080	1367440	And I'm going to have to know what pin is that LED connected to, right?
1367440	1371540	So, now this board, like all boards, they have an LED built in, right?
1371540	1372480	This has multiple.
1372480	1375200	But that little red circle there, I circled the LED.
1375200	1378120	You can't see it, but it's an LED built into the board.
1378140	1383960	And I have to look at the board's data sheet, which is usually much easier, to say what pin is that connected to.
1383960	1389060	So, looking at the board's data sheet, this LED is connected to port D, pin 14, okay?
1389060	1390180	So, I know that.
1390360	1397820	So, now my goal in writing this blinking LED code is to turn on... okay, well, let me skip that first line.
1398660	1404440	I'm going to basically see the while loop, drive a 1 onto the pin, delay, drive a 0 onto the pin, delay.
1404440	1406000	That's the basics, right?
1406000	1408480	And that's a blinking LED.
1408740	1411140	Now, before that, there's a couple of things I have to do.
1411220	1416120	One thing is this first one, turn on the clock to the GPIO port, or D.
1416300	1423780	So, what they do a lot with these peripherals to save power is they turn off the clock to these peripherals.
1423780	1424800	So, there's a clock.
1424800	1428560	A clock is a square wave that determines the rate at which events happen on the chip.
1428560	1431060	If the clock is going, it is consuming power.
1431260	1435040	So, they just shut off the clock to peripherals that are not in use by default.
1435260	1439820	And so, you and your code have to turn on the clock to the peripheral before you can use it.
1439920	1441040	So, you turn on its clock.
1441040	1442060	You're going to have to do that.
1442100	1443220	Again, there's some register.
1443220	1444840	You set a bit, it turns on its clock.
1445240	1447680	Then, you've got to set the port to an output pin.
1447680	1450640	So, these pins, they can be inputs or outputs, okay?
1450640	1455700	So, you're going to set this pin to an output so that you can drive outputs to it, okay?
1455700	1458240	So, you have to do those two things first in your code.
1458260	1461120	Then, you get into a while loop where you just do that, okay?
1461620	1467940	So, just to show a little more detail, and we're going to do this by adjusting values of registers.
1468560	1469440	So, okay.
1469440	1475700	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?
1475700	1477260	I don't expect you to understand all this.
1477260	1480420	But, when you look in the data sheet, it has a description of every register.
1480420	1484300	And I just went and zoomed into a piece of that, okay?
1484300	1485600	So, there's this register.
1485860	1487140	RCC, whatever.
1487220	1489480	AHB is a bus name and all this, okay?
1489480	1492700	This controls the clocks for the GPIO pins, okay?
1492700	1495620	So, I've got to turn the clock on for a particular port.
1495620	1498920	So, notice this register has got 0 through 15, right?
1498920	1500060	Up there in the top.
1500320	1501940	That's half the bits in the register.
1501940	1503620	All the registers are 32 bits, right?
1503620	1505520	So, I'm just looking at the first half.
1505560	1509540	And if you zoom way in on this, it says GPIOD EN for enable.
1509860	1516920	And then, in the data sheet, it will say, oh, pin 3 on this register enables the clock to GPIO pin 4D, okay?
1516920	1518960	So, you've got to set that bit to a 1.
1519280	1522040	Then, GPIOD mode register.
1522220	1529700	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.
1529700	1532980	So, the particular pin I'm interested in is pin 14, right?
1532980	1534220	That's these two pins.
1534280	1535540	Like, these two are 15.
1535540	1536200	These two pins.
1536200	1538960	And I have to set them to, like, 0, 1, if I recall.
1538980	1540640	And that puts it into output mode.
1541080	1543100	And then, over here, this is the output data register.
1543100	1552800	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.
1552800	1555020	It'll set the pin to a 1 or a 0, right?
1555040	1563860	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?
1564680	1565360	Okay.
1565360	1566000	Question?
1566620	1567300	Okay.
1567520	1569540	So, here's my code for that.
1569540	1573180	And I don't really expect you to follow all of it, but let me just say the structure of it.
1574420	1580180	So, one thing is... so, there's a number of registers that I have to control, right?
1580280	1584720	So, first thing I'm going to do, or somewhere in the code, I have to assign the addresses, right?
1584720	1586820	Maybe I did that with hash defines at the top.
1586820	1587960	In this code, I did it here.
1587960	1592840	So, I said, this register equals, and I set it to this address, okay?
1592900	1596980	And then... so, I set it to... I set these registers to their addresses, and then I set them to values.
1596980	1602260	Star that equals a 1 shifted 3 over, because I want to set bit 3 high, and so on.
1602280	1603800	So, I got... I do that.
1603800	1606660	So, these are the initializations I was talking about, making an output register.
1606660	1608500	I initialize the output to 0.
1608700	1610200	Then, here's my while loop.
1610200	1613040	I just say, set it to 0, set the pin to 0.
1613040	1615440	Then, I have a loop, a dummy loop.
1615440	1620460	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.
1621260	1622600	So, that's the code.
1622600	1623180	Question?
1628970	1629850	No?
1630450	1633910	So, I'll talk to you about... I'm curious.
1634050	1637230	So, you know, I've, of course, been thinking about that too, right?
1637230	1641450	Because, you know... and I'm mixed...
1641450	1643330	I've mixed feelings on that, right?
1643810	1652910	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?
1652910	1659670	You're trusting the AI model, and if it messed up, then you mess up, and you don't even know why, right?
1659670	1660590	So, I don't know.
1660590	1662510	But still, I'm curious, okay?
1662510	1667890	I'm curious, and I might use it, but you always have... it's just not safe, security-wise.
1670370	1671250	Yeah.
1673090	1674650	Yeah, I think so.
1674650	1675630	I mean, I agree.
1675750	1678430	I wonder if that'll change one day, but who knows?
1679390	1681310	But, yeah, I believe it.
1681450	1682390	So, okay.
1682390	1683910	So, this is a Blinky.
1683910	1689190	This is sort of the most low-level type of Blinky you could write, where you directly control these registers and their values.
1689350	1692050	Now, that can be tedious, okay?
1692050	1699110	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.
1699170	1703590	Libraries, where they make things... you know, you don't have to worry about each individual register.
1703590	1705970	You just call a library function, and it does stuff for you.
1705970	1710670	So, most of the time, when people make these things, they often use these libraries, right?
1710670	1713210	So, there are vendor-specific libraries.
1713250	1717750	Like, I'm using this for STM microelectronics.
1717750	1719370	They have their HAL library, right?
1719970	1721090	STM32HAL.
1721250	1723970	And different vendors have their own libraries.
1723970	1728590	Plus, there are vendor-independent libraries, like CMSYS is a popular one.
1728970	1732250	It's across ARM, platforms, right?
1732310	1735390	And then, Arduino, Arduino itself.
1735510	1737390	So, Arduino, there's a particular...
1737390	1745490	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?
1745490	1746730	So, you can use Arduino.
1746730	1750170	Like, I know... they use it on... there's another class in my school.
1750170	1752590	They use it on an ESP32, right?
1752590	1755050	So, they... but they use Arduino libraries on that, right?
1755050	1756810	Which is another set of libraries.
1756810	1758850	So, it's sort of a high-level library.
1758850	1759990	It makes things easier.
1760130	1762070	But the... yeah, I think it's on the next slide.
1762070	1766250	Yeah, the downside of these libraries is that they hide details, okay?
1766410	1769010	So, with any library, okay?
1769010	1775930	And so, anyway, here's an example of Blinky using the HAL STM32... oh, and they're also slow.
1775930	1776770	They're also slow.
1776770	1784170	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?
1784170	1788170	If I just want to make a Blinky, it is much quicker to do it my way.
1788170	1790030	Now, who cares with Blinky, right?
1790050	1791830	But my way is a lot more efficient.
1791830	1794890	I mean, when I say my way, going straight to the registry is a lot more efficient.
1794930	1795870	Like this, okay?
1795870	1800830	This basically, you know, they have a toggle pin, and they have a HAL delay, thousand, whatever.
1801610	1804250	But, like, things like... where is it?
1804250	1804890	HAL init.
1804890	1807110	HAL init initializes all the peripherals.
1807110	1808730	I don't need that, okay?
1808930	1812730	So, they don't have, like, a HAL init just for the GPIO, right?
1812730	1813630	Not that I know of.
1813630	1816450	But you initialize all these peripherals, you don't need it.
1816790	1820650	And I don't even... oh, this guy's for GPIO init, but you got to do the HAL init, too.
1820650	1822470	I don't quite understand the relationship there.
1822490	1828410	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?
1828510	1829930	So, anyway, that's HAL.
1829930	1832930	And then with Arduino, here's how you might write it.
1832930	1836330	You set up in a loop, and digital write is their function.
1837490	1843530	Now, you know, tradeoffs with the libraries, when you use libraries, the advantage is it makes everything easier.
1843590	1848510	The disadvantage is that the libraries themselves might have exploitable bugs, okay?
1848510	1851070	That's one security difficulty.
1851070	1853550	But also, they're slow.
1853550	1855070	They're generally slower, right?
1855070	1859250	So, it depends on how efficient you really need to be, but they're generally slower.
1859250	1863970	Most of the time, people use these libraries, though, in all honesty, because they do make things more convenient.
1865190	1865870	Okay.
1866070	1866630	Okay.
1866630	1868110	Next bunch of the talk.
1868550	1872010	Connecting the microcontroller to external devices, okay?
1872470	1875750	So, you want to... so, it's not all about just programming the microcontroller.
1875750	1877350	You got to connect to other things.
1877990	1880450	So, analog interfacing, start with that.
1880450	1886190	So, there are a lot of these little analog devices that you might want to control, or you might want to observe.
1886190	1888630	So, like an LED, you might want to turn it off and on.
1888630	1890770	A motor, you might want to drive it, right?
1890770	1893330	And that's if it's an actuator, right?
1893510	1895110	You're driving it to do something.
1895110	1902530	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.
1902550	1903970	This is just a few of them, right?
1903970	1906010	Now, these are all simple ones, okay?
1906030	1909130	Simple analog actuators and sensors.
1909330	1917070	So, with those, you have to do a little bit of analog electronics, a little bit of analog electronics.
1917070	1919890	Now, analog electronics are painful, okay?
1919890	1924610	Analog electronics are hard in general, but this much you can do.
1924610	1927390	So, like with me, I don't do analog electronics.
1927390	1928230	I can do digital.
1928230	1934710	Analog is going too far, but that's like a basic chunk of it that you need to know, and you just reuse, okay?
1934710	1940790	In practice, embedded designers are not generally analog electronics professionals, usually.
1941250	1943170	So, Ohm's law.
1943170	1945710	Okay, this is really, really, like, simple.
1945990	1949490	So, don't be intimidated, you may remember this from physics or something.
1949490	1950590	V equals IR.
1950590	1953470	So, voltage is like the electric pressure, right?
1953470	1956150	I is the current, and R is resistance.
1956150	1958230	So, think of this like water going through pipes.
1958230	1959670	It's exactly the same thing.
1959690	1963150	The pump is like the battery, the voltage source, right?
1963170	1965450	So, it supplies pressure, generates pressure.
1965530	1968090	So, in these pipes, the pipes are the wires.
1968150	1969590	Current is current, right?
1969590	1971850	The flow of electrons per unit time.
1971890	1975390	And then resistance is anything that blocks the current.
1975390	1984870	So, you know, junk, put some rocks in the pipe, or there are low resistance materials or something like that, or narrow wires.
1985110	1989070	A wide wire has a lot less resistance than a narrow wire, and so on.
1989070	1991030	So, anyway, V equals IR.
1991110	1994890	This, you have to be a little familiar with it to use some of these devices.
1995230	1997170	So, diodes and LEDs.
1997170	2000210	So, I'm just going to talk about LEDs, because they're like a simple device, right?
2000470	2003610	LED stands for light emitting diode.
2003610	2006370	So, a diode symbol is just like this, right?
2006370	2009770	A diode, it has one, two ends, an anode and cathode.
2009770	2011090	They are not symmetrical, okay?
2011090	2015270	And current flows from the anode to the cathode, flows straight through, okay?
2015330	2017610	That's all it does, and current can't go backwards.
2017670	2018770	Like, that's what a diode is.
2018770	2020570	It's like a valve, can't go backwards.
2020690	2030330	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?
2030330	2031830	Below that, it doesn't flow.
2032470	2039350	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?
2039350	2040390	So, that's a diode.
2040390	2050970	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?
2051290	2054010	So, how do you do that?
2054010	2056010	So, say I want to do that, right?
2056010	2060890	I want to make my, I have an Arduino or whatever board, and I want to make a blinky example, right?
2060890	2063390	So, I want to be able to light up an LED.
2063690	2071290	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.
2071290	2073910	The other side goes to ground, which is zero volts.
2074730	2078910	And when I set this pin 13 high, then it's going to light up.
2078910	2081490	When I set the pin low, it's not going to light up, okay?
2081510	2085070	Now, note that I put this little resistor in the way, okay?
2085110	2088650	Now, the reason I did that is so that I didn't blow up my diode, okay?
2088650	2092170	Because these diodes, this is the one little analog electronics you have to know.
2092170	2095510	These diodes are limited in the current that they can deal with.
2095510	2102670	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?
2102670	2109670	So, if I'm using a 3.3 volt device thing, like my board is 3.3 volts, right?
2109710	2112190	If I'm using that, and I say, well, what's the current going through it?
2112190	2116810	If I use about 330 ohms of resistance, then I get like 10 milliamps.
2116810	2118270	That's safe, right?
2118270	2121590	So, I need this resistor of 330, okay?
2121590	2123270	That's like all you need to know, okay?
2123270	2126750	You don't really need to know much more analog electronics than that.
2127010	2128950	But yeah, I need a little circuit like that.
2129290	2133450	Now, then once you get it, once you decide, okay, this is how I have to wire it together, right?
2133450	2134450	Like this.
2134610	2136530	Then you got to wire it together, right?
2136530	2137370	Physically wire it.
2137370	2142870	So, notice there's an Arduino or whatever board, and then there are two components, a resistor and a diode.
2143090	2148530	So, I got to put them together, and usually do-it-yourselfers are going to put it together on a breadboard.
2148530	2150970	Now, a breadboard is basically, it looks like this.
2150970	2152090	It's got holes.
2152090	2153830	These holes, stick wires in them, right?
2153830	2155550	And it just sort of grips the wire.
2155770	2157550	But you can pull it up, push it and pull it out.
2157550	2158830	You can redo it.
2159130	2163230	And so, these rows of five are all connected.
2163350	2165410	So, all these pins are connected.
2165410	2166570	All these pins are connected.
2166570	2169030	But this row is not connected to this row, okay?
2169030	2172390	So, the use of this is, say I want to connect a resistor to a diode.
2172390	2180050	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?
2180050	2181790	So, that's how you make connections.
2181810	2188650	So, you can take this picture and connect them on a breadboard like this, okay?
2188810	2189610	That's the idea.
2189610	2192030	And in fact, here's a picture of that.
2192150	2194150	So, I got, you can't read all the details.
2194150	2196570	This is actually an Arduino over here.
2196670	2198390	So, this is pin 13.
2198390	2201230	It's connected to this row where there's a resistor.
2201290	2206250	The other pin of the resistor goes into this row, which is connected to the diode.
2206250	2210630	The other pin of the diode goes into this column, which is connected to ground, okay?
2210790	2219010	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?
2219010	2221430	Like, the relationship between it, you have to be able to do that, okay?
2221430	2224710	But it's straightforward, you just practice it a little.
2225230	2225890	Okay.
2226050	2229570	So, that's, you know, simple electronics wiring, right?
2229670	2232550	So, you do that, and then your program should work and blink the light.
2234250	2234970	Okay.
2235490	2238330	So, I was just talking about GPIO.
2238530	2242710	GPIO is like the first thing you learn to use on your microcontroller.
2242870	2249850	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?
2249890	2252430	Can't teach them all now, but you learn how to use all of them.
2252430	2256190	And each one of them has a set of registers devoted to it that describe its behavior.
2256950	2258730	Another thing is synchronous protocols.
2258730	2269190	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.
2269250	2271030	Synchronous protocols are common.
2271030	2273290	They're faster, they share a clock.
2273290	2280750	Anyway, I can't go into details of the protocols, but FPI and I2C are the top ones, you know, that people use.
2281070	2282550	And give you an example.
2282550	2285890	Say I got like this, this is an Arduino, actually.
2285890	2289930	And I only connected it to two components that I bought off of Adafruit or whatever, right?
2290010	2293410	And these two components I know are I2C compatible.
2293410	2298690	So when you look at the data sheet for these guys, it'll say, oh, this speaks I2C, this speaks I2C.
2298730	2301050	So then you say, okay, I'm going to use I2C.
2301050	2304070	So you wire it to the I2C pins of your Arduino.
2304290	2307970	They're SDA and SCL, the two wires, two pins for I2C.
2307970	2310730	SDA is a data line, SCL is a clock, right?
2310730	2314670	And these guys, there's like a master and slaves.
2314910	2322830	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?
2324250	2334390	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.
2334390	2339270	So there are certain registers like I2C1, CR1, and CR2.
2339270	2343550	Control register one, this should say it too.
2343850	2354230	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.
2354390	2357610	Also, I2C DR, DR is its data register.
2357610	2364630	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?
2364630	2371850	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?
2371850	2376730	And then on the receiving end, if I read from this DR register, I will receive whatever was sent, okay?
2376730	2380870	So there's hardware built in that deals with all the details of the protocol.
2382570	2385090	Okay, so, okay, good, make it.
2385090	2388550	So, yeah, so the last part is debugging tools.
2388550	2392690	So there are some different debugging tools when you're doing embedded design, right?
2392690	2395510	So here's just my, some random design, okay?
2395510	2399750	And it's got board and some components, some hardware components, all wired together, okay?
2399770	2402350	Now, you probably use standard debuggers, right?
2402350	2405050	You set a breakpoint, you step through the code and all that.
2405350	2411230	So you can do, you can do that, right, with this, but that doesn't, that control, that works on the micro control.
2411230	2414730	You can set a breakpoint, step through it, but what about all the rest of the devices, right?
2414730	2416490	There are other things that you want to view.
2416550	2421810	So it is very common in these designs to want to see the value on a wire.
2421810	2424890	You might want to say, oh, is this high or is this low, okay?
2424890	2427850	Random wire, very common to need to do that.
2427850	2429050	You're like, I wonder what's being sent.
2429050	2430510	Is it a one or a zero, right?
2430550	2431790	So how do you do that?
2431790	2433410	One way is with multimeters.
2433410	2435670	So the first thing, you always have to have it.
2435830	2438070	You gave some out, Sydney, yesterday, right?
2438190	2445290	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.
2445470	2447350	So you can tell if something is high or low.
2447350	2450310	It can read the current, how much current is going through there if you need to know.
2450310	2452550	It can read resistance between two points.
2452850	2454330	It can read connectivity.
2454390	2456730	So it'll like, they almost always have connectivity.
2456730	2459070	So if these two pins are connected, it'll beep.
2459070	2461530	So if you're like, oh, is this wire connected to this one?
2461530	2462710	It'll beep, they are.
2463330	2465070	And they have probes.
2465070	2470150	So these two probes, like you take a black and a red probe, put them in like here and here, right?
2470170	2475630	And then the other ends of these, you touch to the wires that you want to test the voltage on, for instance, okay?
2475690	2477870	So multimeters are like basic tool.
2477990	2480450	But the thing about multimeters is that they are very slow.
2480790	2488910	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?
2488910	2492450	So multimeters are only good for looking at signals that are constant.
2492450	2496510	It's held high, like for half a second at least, or held low, half a second.
2496570	2498850	Changing signals, you can't use a multimeter.
2498890	2501190	So one thing you use is an oscilloscope.
2501190	2506890	Now an oscilloscope, it basically, it'll have a screen and it just plots voltage over time, okay?
2507090	2512690	Now oscilloscopes though, they're usually very few probes, two or four probes.
2512730	2517090	So they can look at two signals, two wires at a time, or four wires at a time.
2517630	2520610	And here's like an old one, an old analog scope.
2520930	2525510	And now the analog scopes, they only work for repeating signals, okay?
2525510	2530350	So the signal has to be like the same over and over, like a waveform, a sine wave or something.
2530350	2531670	And it'll work for that, right?
2531670	2532370	The old scopes.
2532370	2534890	The new scopes, digital scopes, they're not like that.
2534890	2538350	They can read, they can just sort of read it and capture it, right?
2538350	2540730	Capture it at snapshot time and show it to you on the screen.
2540970	2543830	But then you can say, oh, look at this time, it was high.
2543830	2545510	Now at this time, it was low, right?
2545510	2547390	And these things are very fast.
2547570	2555150	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.
2555210	2556970	And you can use an oscilloscope.
2557470	2562770	Now oscilloscopes, one thing that they, one thing you need to do with oscilloscopes is do triggering, okay?
2562870	2567670	So triggering is determining when to start recording.
2567670	2569710	So these things, they have a buffer.
2569710	2572270	I don't know, maybe say it has a two gigabyte buffer, okay?
2572310	2576810	But for every, it's sampling, but it's got to be sampling like a lot faster than your signals.
2576810	2585910	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.
2585910	2587870	It'll fill up this buffer very quickly.
2588010	2591110	So you need triggering to determine when to start recording, okay?
2591110	2593470	To see what you want, right?
2593610	2596050	So one way to do is manual triggering.
2596050	2597650	You hit a button and it goes, okay?
2597650	2606950	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?
2607110	2610530	With oscilloscopes, another way triggers level triggering.
2610530	2614250	So they repeatedly trigger whenever the signal reaches a certain level.
2614250	2618690	When it goes above X amount of voltage, it triggers and it draws it, okay?
2618690	2620010	That's another way to trigger.
2620390	2622550	Also, there's one shot versus continuous triggering.
2622550	2626330	So one shot means record once and just put that on the screen and hold it there.
2626690	2631450	Continuous means record once, put it on the screen, record again, put it on the screen, over and over and over.
2631510	2633990	And so for a repeating signal, that's useful.
2633990	2635850	You can see if it's changing or what.
2637150	2638630	Similar to an analog scope.
2638790	2641430	Now, then another thing that's really useful is a logic analyzer.
2641430	2648630	These cost even more, but the downside of a logic analyzer is that they are only digital.
2648650	2650170	See, an oscilloscope is an analog device.
2650170	2651870	It'll measure analog voltage.
2652130	2654450	An oscilloscope is either zero or one, okay?
2654450	2655310	It's only going to show that.
2655310	2658190	So it's less information, but they have a lot more pins.
2658190	2660510	They'll have like 32 pins, 64 pins.
2660510	2663490	So you can see a whole bus at a time, right?
2663490	2666070	A whole big bus, which is useful, but expensive.
2666070	2667730	They cost a lot of money.
2667730	2672230	Or you can get the cheap one, like I do, which has like 10 pins or something, right?
2672230	2674770	And it's like USB connection to my device.
2674770	2675090	Okay.
2675090	2675890	Question?
2675950	2676410	No?
2676410	2676650	Okay.
2676650	2676910	Yeah.
2677250	2680470	So anyway, these are useful like that.
2680710	2683090	And they're actually, they're usually very smart too.
2683090	2684510	They know protocol.
2684510	2685850	So like they know I2C.
2685850	2687470	So they'll just mark it up for you.
2687470	2689350	You know, it's pretty useful actually.
2689750	2693150	Here's one that I have, a USB logic analyzer.
2693150	2695090	So it's connected by USB to my laptop.
2695090	2699870	You download a free app and you can do stuff with it, record and stuff like that.
2699890	2702510	And it's got a lot more wires that you can use to probe.
2703130	2705090	And that's about it.
2705510	2711770	You could download the slides if you want to download the slides and let me know if there's any questions.
2719830	2724090	We do have time for about three to four questions and I'll hand you the mic.
2724810	2725710	Go ahead.
2731410	2736810	I work with a firmware team for whom the idea of cybersecurity is completely new.
2737130	2742830	What is the best way to establish rapport with them on cybersecurity?
2742830	2746610	Because they hear cybersecurity, they say, doesn't belong to me.
2746610	2753990	I make devices, but you know, we're kind of notorious for, I'm an industrial control system.
2753990	2756630	So that it's a new field for us.
2756630	2756910	Yeah.
2756910	2764570	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.
2764570	2766110	I do that in my class, right?
2766110	2769790	Like to entice the students and show them how important it is.
2769790	2771530	Like, you know, it's easy to find, right?
2771530	2772750	Especially around here.
2772950	2773410	You know what I'm saying?
2773410	2776550	You could get like a list of events and just show it to them.
2776610	2783390	You could also make them participate in that MITRE embedded capture the flag.
2783510	2790810	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.
2790810	2793970	And then six more weeks, you get to attack everybody else's system.
2793970	2800690	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.
2800690	2806610	And then you give it to, then you trade it to everybody and everybody else attacks and you get points and stuff like that.
2806610	2817990	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.
2818050	2821050	Like if they hide some details, so like with the CMU guys, right?
2821150	2826310	They said, yeah, we found vulnerabilities in this I2C driver and we did this and that with it, right?
2826310	2829610	I'm like, I'm thinking, how did they find these vulnerabilities?
2829630	2832130	And they didn't say, they had to do fuzzing.
2832130	2834650	In my conclusion, they had to fuzz it, you know?
2834650	2837610	Because it's not like they eyeballed it and were like, aha.
2837610	2839690	I mean, I would be really shocked if they did that.
2839690	2842170	But anyway, maybe that, I don't know.
2842810	2843290	Yeah.
2846780	2849560	So I don't work in industry, right?
2849560	2851920	So I don't really have to vet anything.
2852120	2856220	But I do in Bad Catch the Flag, I have them fuzz the libraries.
2857540	2860280	I teach them, I do have the lecture material on fuzzing.
2860280	2865620	I'm like, okay, fuzz each one of these that you're going to use because of that CMU attack, actually.
2865640	2866920	But that's what I do.
2866920	2870360	No, no, I just have them do it from scratch.
2870860	2875720	Yeah, I just have them write their own code for fuzzing from scratch, yeah.
2879360	2882440	Thank you, Professor Harris.
2882540	2885780	I'm very interested in your topic.
2885800	2889740	You mentioned this devices to do the diagnostics and stuff, right?
2889740	2898760	But maybe this is something with security diagnostics or geo tag debugging, some stuff that should be covered?
2898760	2900680	Sorry, yeah, I didn't show that.
2900680	2901980	You're absolutely right.
2902300	2904160	So that certainly exists.
2904160	2905940	So this I didn't go into.
2905940	2910660	So generally debugging, like setting breakpoints and all that is harder on an embedded system.
2910660	2915780	Because when you set a breakpoint, you change the memory value, right?
2915780	2918300	But these things, a lot of these embedded systems run in firmware.
2918300	2923680	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?
2923680	2926880	So a lot of times people will use JTAG debugger.
2926880	2929060	I just sort of didn't cover it as a whole.
2929060	2938480	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.
2938480	2942440	Actually, so I have a paper where we follow the branches to see if malware is running, right?
2942440	2945800	Because you know, if malware is running, it'll branch to the wrong location.
2945800	2951000	Some, you know, somebody did a buffer overflow and change the return address pointer, it'll jump somewhere weird, right?
2951000	2959760	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.
2960100	2961220	So those exist.
2961220	2961980	Those exist.
2961980	2963360	I just didn't talk about it.
2963760	2964720	Those are useful.
2964840	2966120	They cost a lot of money, though.
2966120	2966880	That's the problem.
2966880	2970580	They cost a lot of money, like Lauterbach, thousands of dollars for one of these things.
2970580	2972560	But embedded... yeah, go ahead.
2972840	2974400	Yeah, that's right.
2975040	2977040	I'm assuming no more questions.
2977720	2978940	Okay, thanks.
