1 00:00:01,280 --> 00:00:03,679 hello my name is dave robbins and i'm 2 00:00:03,679 --> 00:00:06,240 giving a talk called getting naughty 3 00:00:06,240 --> 00:00:08,880 on the can bus with the car hacking 4 00:00:08,880 --> 00:00:10,559 village badge 5 00:00:10,559 --> 00:00:12,719 so welcome to las vegas 6 00:00:12,719 --> 00:00:15,599 uh the home of the 30 cocktail these 7 00:00:15,599 --> 00:00:17,760 days it's kind of strange uh the badge 8 00:00:17,760 --> 00:00:19,680 here i got i'll talk more about what 9 00:00:19,680 --> 00:00:21,359 that is but uh 10 00:00:21,359 --> 00:00:23,840 this is the badge and uh 11 00:00:23,840 --> 00:00:25,599 go to the next slide what is uh what are 12 00:00:25,599 --> 00:00:27,039 we gonna talk about 13 00:00:27,039 --> 00:00:29,119 i'm just gonna briefly talk about me and 14 00:00:29,119 --> 00:00:31,039 i'm going to talk about 15 00:00:31,039 --> 00:00:32,800 the company that 16 00:00:32,800 --> 00:00:35,920 i run i'm the ceo and 17 00:00:35,920 --> 00:00:37,120 i'm going to talk a bit a little bit 18 00:00:37,120 --> 00:00:38,719 about the badge so just give you the 19 00:00:38,719 --> 00:00:40,399 basics so if you don't really want a lot 20 00:00:40,399 --> 00:00:42,000 of detail you can just skip out after 21 00:00:42,000 --> 00:00:43,200 that 22 00:00:43,200 --> 00:00:44,960 we're going to talk about the pi pico 23 00:00:44,960 --> 00:00:47,920 which is the the cpu or the the board 24 00:00:47,920 --> 00:00:50,160 computer board that's used in the batch 25 00:00:50,160 --> 00:00:51,280 we're going to talk 26 00:00:51,280 --> 00:00:53,680 briefly about the can bus 27 00:00:53,680 --> 00:00:55,840 which is the technology used for 28 00:00:55,840 --> 00:00:59,840 networking and many industrial 29 00:00:59,840 --> 00:01:02,480 machines including vehicles 30 00:01:02,480 --> 00:01:04,559 we're going to talk about 31 00:01:04,559 --> 00:01:06,320 how we could generate and receive can 32 00:01:06,320 --> 00:01:07,280 data 33 00:01:07,280 --> 00:01:08,240 and then we're going to talk about a 34 00:01:08,240 --> 00:01:10,240 couple methods that we can do 35 00:01:10,240 --> 00:01:12,799 some of them that you really wasn't easy 36 00:01:12,799 --> 00:01:15,200 to do before uh this this 37 00:01:15,200 --> 00:01:16,320 new part 38 00:01:16,320 --> 00:01:18,640 uh i'll show you the 39 00:01:18,640 --> 00:01:20,640 software that comes with the badge 40 00:01:20,640 --> 00:01:22,799 there's actually a serial console 41 00:01:22,799 --> 00:01:25,759 and then i'll talk about uh other 42 00:01:25,759 --> 00:01:27,200 software for the badge and then 43 00:01:27,200 --> 00:01:29,200 hopefully some conclusions 44 00:01:29,200 --> 00:01:30,960 uh related to that 45 00:01:30,960 --> 00:01:32,079 i've been 46 00:01:32,079 --> 00:01:34,159 doing this kind of stuff for over 30 47 00:01:34,159 --> 00:01:35,840 years 48 00:01:35,840 --> 00:01:38,000 it's kind of my passion computers 49 00:01:38,000 --> 00:01:39,759 electronics i originally was a hardware 50 00:01:39,759 --> 00:01:40,799 person 51 00:01:40,799 --> 00:01:42,640 but there's just so much software with 52 00:01:42,640 --> 00:01:44,479 microcontrollers you had to learn that 53 00:01:44,479 --> 00:01:46,720 and i did every kind of software 54 00:01:46,720 --> 00:01:48,799 starting out with assembly code back in 55 00:01:48,799 --> 00:01:50,479 the day 56 00:01:50,479 --> 00:01:52,840 you know c code 57 00:01:52,840 --> 00:01:56,320 python i did gpu programming which is 58 00:01:56,320 --> 00:01:57,759 really interesting 59 00:01:57,759 --> 00:02:01,840 i did fpga programming embedded software 60 00:02:01,840 --> 00:02:05,520 linux programming etc etc so and we do 61 00:02:05,520 --> 00:02:06,719 all that 62 00:02:06,719 --> 00:02:09,119 at our work 63 00:02:09,119 --> 00:02:12,480 i started uh trumpet control systems 64 00:02:12,480 --> 00:02:14,640 in my college dorm room in ann arbor 65 00:02:14,640 --> 00:02:16,879 michigan in 1994 and we've been just 66 00:02:16,879 --> 00:02:18,640 supporting the 67 00:02:18,640 --> 00:02:20,640 vehicle electronics 68 00:02:20,640 --> 00:02:22,800 industry in the detroit area and then 69 00:02:22,800 --> 00:02:24,720 eventually globally 70 00:02:24,720 --> 00:02:27,120 and then i am a dog person but i'm too 71 00:02:27,120 --> 00:02:29,280 busy to have a dog so i also do i'm a 72 00:02:29,280 --> 00:02:31,360 part-time dog watcher 73 00:02:31,360 --> 00:02:33,519 so now i'll talk about intrepid control 74 00:02:33,519 --> 00:02:35,040 systems 75 00:02:35,040 --> 00:02:36,959 we're a company we were founded 76 00:02:36,959 --> 00:02:39,040 almost 30 years ago 77 00:02:39,040 --> 00:02:41,760 we provide test tools for automotive 78 00:02:41,760 --> 00:02:44,640 we're around the can hacking a lot 79 00:02:44,640 --> 00:02:46,480 related to can but we do way more than 80 00:02:46,480 --> 00:02:47,440 can 81 00:02:47,440 --> 00:02:49,040 automotive ethernet is getting bigger 82 00:02:49,040 --> 00:02:51,760 than can now for future vehicles 83 00:02:51,760 --> 00:02:54,879 intrepid is a global company around 200 84 00:02:54,879 --> 00:02:58,560 people offices in asia three in china 85 00:02:58,560 --> 00:03:01,519 japan korea india and then europe we 86 00:03:01,519 --> 00:03:03,360 have 87 00:03:03,360 --> 00:03:04,480 germany 88 00:03:04,480 --> 00:03:07,680 and coliseum and then in uk 89 00:03:07,680 --> 00:03:10,879 we are a partner for the oem so a lot of 90 00:03:10,879 --> 00:03:13,120 the equipment we develop is basically on 91 00:03:13,120 --> 00:03:15,040 their specification and we're kind of 92 00:03:15,040 --> 00:03:16,720 like farther 93 00:03:16,720 --> 00:03:18,239 our new products or stuff that will 94 00:03:18,239 --> 00:03:20,640 appear in in production like three to 95 00:03:20,640 --> 00:03:22,480 five years out so some of our new 96 00:03:22,480 --> 00:03:24,080 products like ethernet and things like 97 00:03:24,080 --> 00:03:26,799 that uh in car hacking village you know 98 00:03:26,799 --> 00:03:28,640 2026 99 00:03:28,640 --> 00:03:30,799 that you know that technology will be 100 00:03:30,799 --> 00:03:32,560 working on that almost looking combined 101 00:03:32,560 --> 00:03:34,159 with the packet hackability village 102 00:03:34,159 --> 00:03:36,000 because it's really a lot of the same 103 00:03:36,000 --> 00:03:38,080 technology 104 00:03:38,080 --> 00:03:39,840 we've been working on cyber security 105 00:03:39,840 --> 00:03:41,599 tools for a long time 106 00:03:41,599 --> 00:03:43,840 foundational 107 00:03:43,840 --> 00:03:46,480 oems wanted to be able to benchmark 108 00:03:46,480 --> 00:03:48,239 other companies so 109 00:03:48,239 --> 00:03:50,720 we we developed a lot of tools for 110 00:03:50,720 --> 00:03:52,640 benchmarking 111 00:03:52,640 --> 00:03:54,480 including uh you know just figuring out 112 00:03:54,480 --> 00:03:56,319 how cars work so that that we've been 113 00:03:56,319 --> 00:03:57,840 doing that for a long time and that 114 00:03:57,840 --> 00:04:00,000 happens to have a use case in cyber 115 00:04:00,000 --> 00:04:02,239 security just figuring out how a system 116 00:04:02,239 --> 00:04:04,959 works and its flaws 117 00:04:04,959 --> 00:04:07,040 the aftermarket is a similar type of 118 00:04:07,040 --> 00:04:08,879 industry where people want to install a 119 00:04:08,879 --> 00:04:10,480 new radio and to 120 00:04:10,480 --> 00:04:12,239 take out the factory radio and like in 121 00:04:12,239 --> 00:04:14,080 the can buses as well so they have to 122 00:04:14,080 --> 00:04:16,320 figure out how to make all that work 123 00:04:16,320 --> 00:04:17,918 you might have heard some of our main 124 00:04:17,918 --> 00:04:20,798 products vehicle spy is common 125 00:04:20,798 --> 00:04:22,720 in the industry value can is our low 126 00:04:22,720 --> 00:04:25,840 cost can can fd and then neoli 127 00:04:25,840 --> 00:04:28,400 interfaces which we continue to evolve 128 00:04:28,400 --> 00:04:31,440 so the latest one the neobi fire 3 has 129 00:04:31,440 --> 00:04:34,639 16 can fd channels and 2 gigabyte 130 00:04:34,639 --> 00:04:36,639 ethernet so 131 00:04:36,639 --> 00:04:39,440 intrepid is way more than can bus we do 132 00:04:39,440 --> 00:04:42,560 every protocol in the vehicle can bus is 133 00:04:42,560 --> 00:04:44,400 the most fun though because it's it's 134 00:04:44,400 --> 00:04:45,840 it's you know 135 00:04:45,840 --> 00:04:47,600 it's not too hard to learn and you can 136 00:04:47,600 --> 00:04:49,840 get a lot done a lot of hacking hacking 137 00:04:49,840 --> 00:04:52,080 done with it 138 00:04:52,080 --> 00:04:54,000 okay i'm gonna give a demonstration of 139 00:04:54,000 --> 00:04:56,880 the badge right now so i'm gonna switch 140 00:04:56,880 --> 00:04:57,919 to 141 00:04:57,919 --> 00:04:59,759 the full screen 142 00:04:59,759 --> 00:05:04,320 okay so what we have here is uh 143 00:05:04,960 --> 00:05:06,000 the most 144 00:05:06,000 --> 00:05:07,919 interesting part here is this is the pi 145 00:05:07,919 --> 00:05:09,360 pico right here 146 00:05:09,360 --> 00:05:11,360 and this is the cpu 147 00:05:11,360 --> 00:05:14,320 and the usb interface for the badge the 148 00:05:14,320 --> 00:05:16,960 pi pico has gpio around it and we're 149 00:05:16,960 --> 00:05:19,039 using some of the gpio and we actually 150 00:05:19,039 --> 00:05:21,600 connect it to a can physical layer here 151 00:05:21,600 --> 00:05:23,600 this can physical layer it's from 152 00:05:23,600 --> 00:05:25,600 microchip 153 00:05:25,600 --> 00:05:28,160 it's capable of can fd as well although 154 00:05:28,160 --> 00:05:29,759 we're not doing any can fd with the 155 00:05:29,759 --> 00:05:31,120 badge 156 00:05:31,120 --> 00:05:33,600 that's basically something that 157 00:05:33,600 --> 00:05:35,600 based on the talk you could do can fd 158 00:05:35,600 --> 00:05:37,280 based on 159 00:05:37,280 --> 00:05:40,320 what i talk about there's two buttons 160 00:05:40,320 --> 00:05:42,240 and then there's two switches one of the 161 00:05:42,240 --> 00:05:44,639 switch turns on and off the power 162 00:05:44,639 --> 00:05:46,240 for the the 163 00:05:46,240 --> 00:05:47,520 battery 164 00:05:47,520 --> 00:05:49,520 the battery is just 165 00:05:49,520 --> 00:05:52,479 used to kind of flash an led while it's 166 00:05:52,479 --> 00:05:54,400 not plugged into usb but most of the 167 00:05:54,400 --> 00:05:57,759 batch features only run on usb 168 00:05:57,759 --> 00:06:00,160 uh so so basically we have some just 169 00:06:00,160 --> 00:06:02,160 regular leds that are just powered off 170 00:06:02,160 --> 00:06:04,479 usb and then these are actually 171 00:06:04,479 --> 00:06:07,520 controlled by the cpu 172 00:06:07,520 --> 00:06:09,759 one of the switches doesn't do anything 173 00:06:09,759 --> 00:06:12,000 the there's then there's two buttons 174 00:06:12,000 --> 00:06:13,440 and there's you can hear that there's a 175 00:06:13,440 --> 00:06:15,360 buzzer on the back 176 00:06:15,360 --> 00:06:17,840 uh the badge itself has a slip screen 177 00:06:17,840 --> 00:06:19,280 that kind of explains a lot and then 178 00:06:19,280 --> 00:06:21,120 there's a qr code that links to our 179 00:06:21,120 --> 00:06:23,520 website with it has more information 180 00:06:23,520 --> 00:06:25,280 just a heads up some of the silk screen 181 00:06:25,280 --> 00:06:26,960 has errata in terms of what pens 182 00:06:26,960 --> 00:06:28,720 connected to what 183 00:06:28,720 --> 00:06:31,759 so for example the buzzer says gp19 it's 184 00:06:31,759 --> 00:06:34,479 actually gp20 so if you do 185 00:06:34,479 --> 00:06:36,639 sit down and write some software for it 186 00:06:36,639 --> 00:06:38,960 python or c plus or basic or whatever 187 00:06:38,960 --> 00:06:43,198 your poison is i'll go ahead and do that 188 00:06:44,080 --> 00:06:46,319 but what it does with when you just plug 189 00:06:46,319 --> 00:06:48,639 it in is you can push the button and 190 00:06:48,639 --> 00:06:50,479 it'll start a countdown 191 00:06:50,479 --> 00:06:52,000 and then what that's going to do is it's 192 00:06:52,000 --> 00:06:54,479 going to launch a kill on the can bus so 193 00:06:54,479 --> 00:06:56,000 it's actually going to generate canned 194 00:06:56,000 --> 00:06:58,319 messages out of this connector 195 00:06:58,319 --> 00:07:01,199 which you would wire in which i'll show 196 00:07:01,199 --> 00:07:04,000 a wiring setup i got later 197 00:07:04,000 --> 00:07:06,080 uh so just to give you an example 198 00:07:06,080 --> 00:07:08,240 there's a there's if you hold one button 199 00:07:08,240 --> 00:07:10,160 it does one kill another button does 200 00:07:10,160 --> 00:07:12,639 another kill you hold both it does 201 00:07:12,639 --> 00:07:15,039 a third kill and i'll explain what those 202 00:07:15,039 --> 00:07:16,880 kills are are later but we'll just go 203 00:07:16,880 --> 00:07:20,080 ahead and try one 204 00:07:22,370 --> 00:07:24,319 [Music] 205 00:07:24,319 --> 00:07:26,240 now you can see this led illuminate this 206 00:07:26,240 --> 00:07:28,800 is the actual can bus activity so we're 207 00:07:28,800 --> 00:07:31,599 sending out uh canned messages right now 208 00:07:31,599 --> 00:07:33,599 and the idea is that we're we're either 209 00:07:33,599 --> 00:07:34,479 doing 210 00:07:34,479 --> 00:07:35,440 a 211 00:07:35,440 --> 00:07:37,680 type of denial of service or sending uh 212 00:07:37,680 --> 00:07:39,199 incorrect frames 213 00:07:39,199 --> 00:07:41,440 um 214 00:07:41,919 --> 00:07:43,280 and there's actually three different 215 00:07:43,280 --> 00:07:46,240 kills which i'll show you later but this 216 00:07:46,240 --> 00:07:47,599 is 217 00:07:47,599 --> 00:07:49,599 uh never gonna let you talk so i think 218 00:07:49,599 --> 00:07:51,919 this is generating zero frames which if 219 00:07:51,919 --> 00:07:54,000 you generate continuous zero frames 220 00:07:54,000 --> 00:07:55,360 that's the highest priority message it 221 00:07:55,360 --> 00:07:57,120 will disable the canvas 222 00:07:57,120 --> 00:07:58,879 now if you go plug this into your card 223 00:07:58,879 --> 00:08:00,240 things go bad 224 00:08:00,240 --> 00:08:02,639 don't call me okay because 225 00:08:02,639 --> 00:08:05,199 uh older cars that weren't necessarily 226 00:08:05,199 --> 00:08:06,240 tested 227 00:08:06,240 --> 00:08:08,479 to be like attacked so 228 00:08:08,479 --> 00:08:10,639 use at your own risk or rent a car i 229 00:08:10,639 --> 00:08:12,400 don't even know but the first time i 230 00:08:12,400 --> 00:08:14,400 plugged into like a 231 00:08:14,400 --> 00:08:17,520 an old ford uh not with this badge but i 232 00:08:17,520 --> 00:08:21,039 just had the can bus uh uh speedrun and 233 00:08:21,039 --> 00:08:22,639 the whole car just shut down and i had 234 00:08:22,639 --> 00:08:25,199 to just disconnect the battery and reset 235 00:08:25,199 --> 00:08:27,520 the whole car so it's so you know your 236 00:08:27,520 --> 00:08:29,759 mileage will vary i'm interested to see 237 00:08:29,759 --> 00:08:31,680 what people in the community plug this 238 00:08:31,680 --> 00:08:33,200 thing into 239 00:08:33,200 --> 00:08:35,200 so that's the basics of the badge i'll 240 00:08:35,200 --> 00:08:37,519 i'll demonstrate the usb software a lot 241 00:08:37,519 --> 00:08:39,519 later 242 00:08:39,519 --> 00:08:41,760 so this right here are some screenshots 243 00:08:41,760 --> 00:08:43,679 of the usb console so if you plug this 244 00:08:43,679 --> 00:08:45,360 in 245 00:08:45,360 --> 00:08:47,839 to linux or mac or whatever and you open 246 00:08:47,839 --> 00:08:50,200 up a serial console to 247 00:08:50,200 --> 00:08:53,440 ttyscs whatever whatever usb the serial 248 00:08:53,440 --> 00:08:54,480 port it is 249 00:08:54,480 --> 00:08:57,200 this will show up and it'll allow you to 250 00:08:57,200 --> 00:08:59,600 set up configure the badge the kills 251 00:08:59,600 --> 00:09:01,839 with the buttons are predefined kills 252 00:09:01,839 --> 00:09:04,720 and then the mess the menus allow you to 253 00:09:04,720 --> 00:09:06,640 can figure out exactly what you want to 254 00:09:06,640 --> 00:09:09,760 do first let's talk about the pi pico 255 00:09:09,760 --> 00:09:12,240 what is the raspberry pi pico uh 256 00:09:12,240 --> 00:09:14,399 traditionally the raspberry pi uh 257 00:09:14,399 --> 00:09:16,640 foundation has been building single 258 00:09:16,640 --> 00:09:18,560 board computers that are based on linux 259 00:09:18,560 --> 00:09:21,200 and then the raspberry pi pico is the 260 00:09:21,200 --> 00:09:23,600 first single board computer that is just 261 00:09:23,600 --> 00:09:26,160 a microcontroller so the microcontroller 262 00:09:26,160 --> 00:09:30,320 runs almost no os or little or no ls 263 00:09:30,320 --> 00:09:32,880 it's lower cost lower power it's a lot 264 00:09:32,880 --> 00:09:35,040 different than the raspberry pi 265 00:09:35,040 --> 00:09:36,480 now you might hear something called 266 00:09:36,480 --> 00:09:39,279 rp2040 267 00:09:39,279 --> 00:09:41,120 to clear the confusion is the raspberry 268 00:09:41,120 --> 00:09:43,120 pi pico is the name for the single board 269 00:09:43,120 --> 00:09:44,320 computer 270 00:09:44,320 --> 00:09:46,080 the microprocessor or the 271 00:09:46,080 --> 00:09:47,920 microcontroller on the board is the 272 00:09:47,920 --> 00:09:50,160 rp2040 273 00:09:50,160 --> 00:09:51,040 now 274 00:09:51,040 --> 00:09:53,440 with the raspberry pi they didn't sell 275 00:09:53,440 --> 00:09:55,279 the processor independently it's just 276 00:09:55,279 --> 00:09:57,600 you buy the board and then 277 00:09:57,600 --> 00:09:59,200 you can't buy the chip and make your own 278 00:09:59,200 --> 00:10:00,160 board 279 00:10:00,160 --> 00:10:01,760 but that's different with the raspberry 280 00:10:01,760 --> 00:10:03,120 pi pico 281 00:10:03,120 --> 00:10:05,839 now the pico board cost between four and 282 00:10:05,839 --> 00:10:08,880 six dollars and they just released a ver 283 00:10:08,880 --> 00:10:11,279 the six dollar version last i think last 284 00:10:11,279 --> 00:10:13,839 month and it includes wi-fi so you can 285 00:10:13,839 --> 00:10:17,200 do wi-fi type projects with this that 286 00:10:17,200 --> 00:10:19,360 connect to an access point or act like 287 00:10:19,360 --> 00:10:22,959 an access point so it's pretty cool 288 00:10:22,959 --> 00:10:25,200 for six dollars how much you get 289 00:10:25,200 --> 00:10:27,680 the board itself is programmed and it's 290 00:10:27,680 --> 00:10:30,480 support supported by raspberry pi it's c 291 00:10:30,480 --> 00:10:32,880 and c plus plus and python 292 00:10:32,880 --> 00:10:34,079 so there's a 293 00:10:34,079 --> 00:10:36,000 i believe a micro python there's yeah 294 00:10:36,000 --> 00:10:39,279 micro python port for raspberry pi or 295 00:10:39,279 --> 00:10:40,560 pico 296 00:10:40,560 --> 00:10:43,120 uh which you can write uh 297 00:10:43,120 --> 00:10:46,880 you know quickly write scripts the board 298 00:10:46,880 --> 00:10:49,200 it has the raspberry pi community behind 299 00:10:49,200 --> 00:10:50,720 it so i think that's what's most 300 00:10:50,720 --> 00:10:53,279 interesting to me is that getting 301 00:10:53,279 --> 00:10:55,360 support and finding other people that 302 00:10:55,360 --> 00:10:56,959 did things 303 00:10:56,959 --> 00:10:59,360 the initial release was last year and i 304 00:10:59,360 --> 00:11:01,680 think maybe it didn't get as much 305 00:11:01,680 --> 00:11:03,600 attention as it should have 306 00:11:03,600 --> 00:11:05,519 because it didn't have wireless so now 307 00:11:05,519 --> 00:11:06,880 that it has wireless it'll be really 308 00:11:06,880 --> 00:11:09,200 interesting to see how this board does 309 00:11:09,200 --> 00:11:11,040 take off 310 00:11:11,040 --> 00:11:13,440 the tools are all free so like if you've 311 00:11:13,440 --> 00:11:16,240 been in the embedded systems area for a 312 00:11:16,240 --> 00:11:18,240 long time 313 00:11:18,240 --> 00:11:20,399 it's tools are a pain to get are very 314 00:11:20,399 --> 00:11:23,279 expensive i mean at work we paid 315 00:11:23,279 --> 00:11:25,040 you know ten thousand dollars for a c 316 00:11:25,040 --> 00:11:27,440 compiler just you know for the power pc 317 00:11:27,440 --> 00:11:29,279 because that's that was all that was 318 00:11:29,279 --> 00:11:30,959 available at the time 319 00:11:30,959 --> 00:11:33,440 but these tools are all free gcc 320 00:11:33,440 --> 00:11:36,000 uh visual studio code and then even a 321 00:11:36,000 --> 00:11:37,519 hardware debugger 322 00:11:37,519 --> 00:11:40,160 you can use a pi pico to beat debug 323 00:11:40,160 --> 00:11:42,480 another pi pico so 324 00:11:42,480 --> 00:11:43,680 so you can use the four dollar pie 325 00:11:43,680 --> 00:11:45,760 pickle to debug the other one which you 326 00:11:45,760 --> 00:11:47,120 got to have a debugger if you're doing 327 00:11:47,120 --> 00:11:48,800 any serious work 328 00:11:48,800 --> 00:11:50,240 but the most 329 00:11:50,240 --> 00:11:52,160 interesting feature of this board and 330 00:11:52,160 --> 00:11:53,519 the only reason i 331 00:11:53,519 --> 00:11:54,839 learned about it is because it's 332 00:11:54,839 --> 00:11:57,920 available availability 333 00:11:57,920 --> 00:12:00,800 of any type of microprocessor 334 00:12:00,800 --> 00:12:03,279 chips right now is is so important 335 00:12:03,279 --> 00:12:05,440 and right now at least 336 00:12:05,440 --> 00:12:07,279 right now you can you can get these in 337 00:12:07,279 --> 00:12:08,959 thousands of quantities 338 00:12:08,959 --> 00:12:10,800 for projects so like at the for the 339 00:12:10,800 --> 00:12:11,839 badge we 340 00:12:11,839 --> 00:12:14,639 we bought reels of these uh months and 341 00:12:14,639 --> 00:12:16,399 months ago so we made sure that we had 342 00:12:16,399 --> 00:12:18,639 all the parts we needed 343 00:12:18,639 --> 00:12:19,839 the 344 00:12:19,839 --> 00:12:22,320 the badge hosts the rp 1210 345 00:12:22,320 --> 00:12:24,240 microcontroller 346 00:12:24,240 --> 00:12:26,399 which is 347 00:12:26,399 --> 00:12:27,839 when it first came out i looked at it 348 00:12:27,839 --> 00:12:29,839 and i just dismissed it as another metoo 349 00:12:29,839 --> 00:12:31,040 product 350 00:12:31,040 --> 00:12:32,160 but since 351 00:12:32,160 --> 00:12:34,480 it was hard for us to source well last 352 00:12:34,480 --> 00:12:36,560 year all we did was redesign our project 353 00:12:36,560 --> 00:12:39,040 products that work for availability of 354 00:12:39,040 --> 00:12:40,240 components 355 00:12:40,240 --> 00:12:42,240 which was not not the most interesting 356 00:12:42,240 --> 00:12:44,079 work but we learned a lot 357 00:12:44,079 --> 00:12:46,399 so this year i took a look at what was 358 00:12:46,399 --> 00:12:48,800 available and 359 00:12:48,800 --> 00:12:52,800 this part is super available and it's 70 360 00:12:52,800 --> 00:12:54,880 cents if you buy the full reel and you 361 00:12:54,880 --> 00:12:57,279 can buy it directly from raspberry pi 362 00:12:57,279 --> 00:13:01,040 so i took a look at it and i was 363 00:13:01,040 --> 00:13:03,040 pretty impressed with what it what it 364 00:13:03,040 --> 00:13:05,120 had first of all 365 00:13:05,120 --> 00:13:08,240 cortex m0 who cares but there's a new 366 00:13:08,240 --> 00:13:09,200 trend 367 00:13:09,200 --> 00:13:11,120 to have like microcontrollers that have 368 00:13:11,120 --> 00:13:13,279 multi-cores and it opens up some 369 00:13:13,279 --> 00:13:15,360 interesting applications including the 370 00:13:15,360 --> 00:13:18,000 one that i'm talking about today 371 00:13:18,000 --> 00:13:19,200 but the most 372 00:13:19,200 --> 00:13:21,440 i think breakthrough thing that this 373 00:13:21,440 --> 00:13:24,000 part has is it has eight bit bang 374 00:13:24,000 --> 00:13:26,880 processors called a pio and i feel like 375 00:13:26,880 --> 00:13:29,839 there's so many problems in my career 376 00:13:29,839 --> 00:13:31,920 in about it that are solved with this 377 00:13:31,920 --> 00:13:35,279 it's uh it's just a total breakthrough 378 00:13:35,279 --> 00:13:36,959 uh and it's it's a game changer 379 00:13:36,959 --> 00:13:38,959 especially on such a part 380 00:13:38,959 --> 00:13:41,839 uh that's so low cost and low power 381 00:13:41,839 --> 00:13:42,720 which 382 00:13:42,720 --> 00:13:45,680 before the really only option was fpga 383 00:13:45,680 --> 00:13:46,880 which is 384 00:13:46,880 --> 00:13:48,800 a very complicated very complicated 385 00:13:48,800 --> 00:13:49,920 tools 386 00:13:49,920 --> 00:13:50,720 very 387 00:13:50,720 --> 00:13:52,880 hungry power hungry very expensive so 388 00:13:52,880 --> 00:13:54,639 it's kind of it's a game changer for the 389 00:13:54,639 --> 00:13:55,680 industry 390 00:13:55,680 --> 00:13:58,000 another thing is it's very fast 125 391 00:13:58,000 --> 00:14:00,240 megahertz and that's a clock rate of 8 392 00:14:00,240 --> 00:14:01,680 nanoseconds 393 00:14:01,680 --> 00:14:03,360 so you can do a lot 394 00:14:03,360 --> 00:14:05,680 and you know things like bit bang 395 00:14:05,680 --> 00:14:08,480 canvas at 500 kilohertz is our 396 00:14:08,480 --> 00:14:09,279 is 397 00:14:09,279 --> 00:14:10,720 well i'm not going to give it away but 398 00:14:10,720 --> 00:14:13,519 it could be possible 399 00:14:13,519 --> 00:14:15,120 there are videos online where people 400 00:14:15,120 --> 00:14:18,240 overclocked it to over 300 megahertz so 401 00:14:18,240 --> 00:14:20,399 feel free to 402 00:14:20,399 --> 00:14:22,240 check those out and then use it you know 403 00:14:22,240 --> 00:14:23,760 use that your own 404 00:14:23,760 --> 00:14:24,800 uh 405 00:14:24,800 --> 00:14:26,720 you know use that your own 406 00:14:26,720 --> 00:14:28,959 experience so if you if you overclock it 407 00:14:28,959 --> 00:14:30,399 and you test it and everything it works 408 00:14:30,399 --> 00:14:32,480 that's great so if you want to bit bang 409 00:14:32,480 --> 00:14:33,920 things at uh 410 00:14:33,920 --> 00:14:35,519 you know 300 megahertz would be like 411 00:14:35,519 --> 00:14:36,240 three 412 00:14:36,240 --> 00:14:38,399 three or four nanoseconds or you know 413 00:14:38,399 --> 00:14:40,240 under four nanoseconds 414 00:14:40,240 --> 00:14:42,399 go ahead and do that 415 00:14:42,399 --> 00:14:45,199 it has usb uh which is really useful uh 416 00:14:45,199 --> 00:14:47,199 for boot loading and 417 00:14:47,199 --> 00:14:49,839 connecting to a pc it's 12 megabit which 418 00:14:49,839 --> 00:14:50,639 is 419 00:14:50,639 --> 00:14:53,600 disappointing uh because the thing is is 420 00:14:53,600 --> 00:14:55,600 that the pio engine can move so much 421 00:14:55,600 --> 00:14:57,360 data it just doesn't have anywhere to go 422 00:14:57,360 --> 00:14:59,040 it can't go up to a pc 423 00:14:59,040 --> 00:15:02,000 uh but it's a 70 cent part so that's 424 00:15:02,000 --> 00:15:02,880 that 425 00:15:02,880 --> 00:15:05,519 it's really great at pwm channels 426 00:15:05,519 --> 00:15:08,000 using the pio and the pf pwm you can 427 00:15:08,000 --> 00:15:10,839 generate a p pwm on every pin of this 428 00:15:10,839 --> 00:15:11,920 device uh 429 00:15:11,920 --> 00:15:13,760 so like things like uh 430 00:15:13,760 --> 00:15:14,800 uh 431 00:15:14,800 --> 00:15:16,240 robotics applications where you're 432 00:15:16,240 --> 00:15:18,720 controlling servos or uh you know you 433 00:15:18,720 --> 00:15:20,959 have a bunch of leds that you wanna 434 00:15:20,959 --> 00:15:22,959 dim and you know full color leds it's 435 00:15:22,959 --> 00:15:24,240 really awesome 436 00:15:24,240 --> 00:15:26,079 and it's got like the standard digital 437 00:15:26,079 --> 00:15:27,839 peripherals and 438 00:15:27,839 --> 00:15:29,519 the pin mapping is real flexible so 439 00:15:29,519 --> 00:15:30,639 that's really useful when you're 440 00:15:30,639 --> 00:15:31,920 designing boards 441 00:15:31,920 --> 00:15:32,959 uh 442 00:15:32,959 --> 00:15:35,680 it does not have onboard flash so it 443 00:15:35,680 --> 00:15:38,880 actually has to load code from a serial 444 00:15:38,880 --> 00:15:40,720 flash at boot up 445 00:15:40,720 --> 00:15:41,759 which is 446 00:15:41,759 --> 00:15:43,519 not so great if you're used to 447 00:15:43,519 --> 00:15:45,279 microcontroller and there's no code 448 00:15:45,279 --> 00:15:47,199 protection so like if you design 449 00:15:47,199 --> 00:15:48,639 something with this it would be very 450 00:15:48,639 --> 00:15:51,360 easy to copy 451 00:15:52,560 --> 00:15:56,320 and voila this part is on the defcon 30 452 00:15:56,320 --> 00:15:59,440 badge so this part right here is rp2040 453 00:15:59,440 --> 00:16:00,480 so 454 00:16:00,480 --> 00:16:02,160 i'm not really sure why they chose it 455 00:16:02,160 --> 00:16:04,320 i'm really interested to learn 456 00:16:04,320 --> 00:16:05,440 but 457 00:16:05,440 --> 00:16:07,440 i would guess having it available is 458 00:16:07,440 --> 00:16:10,560 probably maybe a good reason 459 00:16:10,560 --> 00:16:12,320 and i'm really excited to learn more 460 00:16:12,320 --> 00:16:15,600 about this badge this week 461 00:16:17,040 --> 00:16:19,040 and of course on the back of the badge 462 00:16:19,040 --> 00:16:21,440 is the raspberry pi pico and it's just 463 00:16:21,440 --> 00:16:22,720 soldered down 464 00:16:22,720 --> 00:16:25,440 and you can we actually place this 465 00:16:25,440 --> 00:16:27,839 with our machines our smt machine so it 466 00:16:27,839 --> 00:16:29,440 came on a reel it's placed right on the 467 00:16:29,440 --> 00:16:30,399 board 468 00:16:30,399 --> 00:16:32,240 and our guys did a really good job where 469 00:16:32,240 --> 00:16:33,279 the pins 470 00:16:33,279 --> 00:16:35,440 if you look at the pin hole pins they 471 00:16:35,440 --> 00:16:37,199 are totally open so you can put a pin 472 00:16:37,199 --> 00:16:39,279 header through the defcon badge and you 473 00:16:39,279 --> 00:16:41,279 can use the rest of the i o so think 474 00:16:41,279 --> 00:16:42,880 outside the badge 475 00:16:42,880 --> 00:16:44,720 use it you know write some code use the 476 00:16:44,720 --> 00:16:46,480 other pins to do stuff 477 00:16:46,480 --> 00:16:47,440 and 478 00:16:47,440 --> 00:16:48,560 have fun 479 00:16:48,560 --> 00:16:49,680 all right so now i'm going to talk a 480 00:16:49,680 --> 00:16:52,000 little bit about can bus 481 00:16:52,000 --> 00:16:54,880 it's very popular and it's kind of a 482 00:16:54,880 --> 00:16:57,680 huge focus of the car hacking village uh 483 00:16:57,680 --> 00:16:59,759 the can bus also 484 00:16:59,759 --> 00:17:00,720 um 485 00:17:00,720 --> 00:17:03,680 used in many other particles so like a 486 00:17:03,680 --> 00:17:05,199 boat if you have a boat there's 487 00:17:05,199 --> 00:17:06,720 something called nema 488 00:17:06,720 --> 00:17:10,000 i think 2000 and uh that uses the can 489 00:17:10,000 --> 00:17:12,559 bus so we were talking about like all 490 00:17:12,559 --> 00:17:14,240 the different ways you 491 00:17:14,240 --> 00:17:15,599 we can make different badges like we 492 00:17:15,599 --> 00:17:16,959 could have boat kill 493 00:17:16,959 --> 00:17:18,559 all they use on airplanes you have 494 00:17:18,559 --> 00:17:21,919 airplane kill which no one like that uh 495 00:17:21,919 --> 00:17:24,480 no one like that name because we don't 496 00:17:24,480 --> 00:17:26,000 you know we don't want to get picked up 497 00:17:26,000 --> 00:17:29,440 by the nsa at dot com but anyway the can 498 00:17:29,440 --> 00:17:31,280 bus is used everywhere and all these 499 00:17:31,280 --> 00:17:33,120 attacks would work on that 500 00:17:33,120 --> 00:17:35,919 uh what is the basic when was can bus 501 00:17:35,919 --> 00:17:38,160 created who cares i mean really who 502 00:17:38,160 --> 00:17:39,120 cares 503 00:17:39,120 --> 00:17:40,240 uh 504 00:17:40,240 --> 00:17:42,080 it's been around forever it's gonna be 505 00:17:42,080 --> 00:17:43,440 around 506 00:17:43,440 --> 00:17:46,160 forevermore too so everyone listen to 507 00:17:46,160 --> 00:17:47,679 this when you're on your deathbed you're 508 00:17:47,679 --> 00:17:49,280 going to look over it 509 00:17:49,280 --> 00:17:50,880 at that machine keeping you alive and 510 00:17:50,880 --> 00:17:53,440 it's probably running can bus so 511 00:17:53,440 --> 00:17:56,000 and it's it's just a great uh 512 00:17:56,000 --> 00:17:58,400 inexpensive cheap protocol it's it's 513 00:17:58,400 --> 00:18:00,559 very robust and of course when people 514 00:18:00,559 --> 00:18:02,720 say what does that mean it's like 515 00:18:02,720 --> 00:18:04,880 you can really configure it all around 516 00:18:04,880 --> 00:18:07,360 it still probably will work and 517 00:18:07,360 --> 00:18:08,720 which is a terrible way to design a 518 00:18:08,720 --> 00:18:10,480 system ideally you design the system 519 00:18:10,480 --> 00:18:12,799 correctly and then whatever happens in 520 00:18:12,799 --> 00:18:13,919 the field 521 00:18:13,919 --> 00:18:15,760 you know it still works but i've i've 522 00:18:15,760 --> 00:18:18,080 seen systems over the years where they 523 00:18:18,080 --> 00:18:20,559 just take that robustness and use it as 524 00:18:20,559 --> 00:18:22,320 a feature 525 00:18:22,320 --> 00:18:24,400 um why do they make the can bus who 526 00:18:24,400 --> 00:18:26,720 cares who you know go find go find 527 00:18:26,720 --> 00:18:28,640 another video online to learn about why 528 00:18:28,640 --> 00:18:30,240 they created it but we're going to talk 529 00:18:30,240 --> 00:18:32,720 about the what and the how and this is 530 00:18:32,720 --> 00:18:35,520 just a basic 531 00:18:35,520 --> 00:18:37,520 can network uh where we have two wires 532 00:18:37,520 --> 00:18:40,160 can high and can low 533 00:18:40,160 --> 00:18:41,679 i like to think that we invented the 534 00:18:41,679 --> 00:18:44,080 colors for can high and can low but i 535 00:18:44,080 --> 00:18:45,919 just remembered uh 536 00:18:45,919 --> 00:18:47,520 you know at the beginning 537 00:18:47,520 --> 00:18:50,000 we always said yellow is like the sun 538 00:18:50,000 --> 00:18:52,480 and green is like the grass but i don't 539 00:18:52,480 --> 00:18:54,480 it's been so long i don't remember 540 00:18:54,480 --> 00:18:57,679 but each end of the network uh is uh 541 00:18:57,679 --> 00:19:00,000 terminated so uh 542 00:19:00,000 --> 00:19:02,000 can needs a termination because it only 543 00:19:02,000 --> 00:19:05,120 drives the can bus uh in one direction 544 00:19:05,120 --> 00:19:06,559 and then it relies on the network 545 00:19:06,559 --> 00:19:08,880 capacitance to pull it back down 546 00:19:08,880 --> 00:19:11,600 so without that uh you your your bits 547 00:19:11,600 --> 00:19:13,039 will be all messed up 548 00:19:13,039 --> 00:19:15,120 and uh we actually have a feature in our 549 00:19:15,120 --> 00:19:17,760 product where we generate a pulse on can 550 00:19:17,760 --> 00:19:21,600 and based on the the the the fall time 551 00:19:21,600 --> 00:19:23,520 of the transceiver back to recessive you 552 00:19:23,520 --> 00:19:25,679 can automatically determine 553 00:19:25,679 --> 00:19:29,120 if the network is terminated 554 00:19:30,880 --> 00:19:33,200 what does the bus actually look like 555 00:19:33,200 --> 00:19:35,360 so if you connected an oscilloscope to 556 00:19:35,360 --> 00:19:36,320 the bus 557 00:19:36,320 --> 00:19:39,200 there are two signals can high and can 558 00:19:39,200 --> 00:19:41,200 low 559 00:19:41,200 --> 00:19:44,080 and can high whenever uh there's a 560 00:19:44,080 --> 00:19:47,280 there's a dominant bit it goes high and 561 00:19:47,280 --> 00:19:49,840 can low goes low so it's a differential 562 00:19:49,840 --> 00:19:51,760 bus so the receiver actually measures 563 00:19:51,760 --> 00:19:54,000 the difference between the two lines 564 00:19:54,000 --> 00:19:55,600 and the difference is real important 565 00:19:55,600 --> 00:19:58,640 because in a vehicle the ground is used 566 00:19:58,640 --> 00:20:00,799 to carry current for all the different 567 00:20:00,799 --> 00:20:02,400 parts the chassis 568 00:20:02,400 --> 00:20:04,240 so what happens is whenever currents are 569 00:20:04,240 --> 00:20:06,000 flowing to the ground there'll be an ir 570 00:20:06,000 --> 00:20:07,679 drop which will change the voltage at 571 00:20:07,679 --> 00:20:08,880 the ecu 572 00:20:08,880 --> 00:20:11,760 and if it goes you know if you're using 573 00:20:11,760 --> 00:20:13,840 the ground as a reference 574 00:20:13,840 --> 00:20:15,200 you can have some real interesting 575 00:20:15,200 --> 00:20:17,280 problems like when only certain motors 576 00:20:17,280 --> 00:20:18,320 go off 577 00:20:18,320 --> 00:20:21,200 you lose communication so 578 00:20:21,200 --> 00:20:23,120 having a differential network is a huge 579 00:20:23,120 --> 00:20:25,520 benefit 580 00:20:25,520 --> 00:20:27,520 now uh how do we get to this protocol 581 00:20:27,520 --> 00:20:29,600 well on the badge the 582 00:20:29,600 --> 00:20:32,080 i'm sorry the the the fi 583 00:20:32,080 --> 00:20:34,559 on the badge this little part 584 00:20:34,559 --> 00:20:37,120 uh that can cost you know between 30 585 00:20:37,120 --> 00:20:39,360 cents and and well last year people were 586 00:20:39,360 --> 00:20:41,440 selling them for eight dollars 587 00:20:41,440 --> 00:20:44,480 uh but that part for microchip it 588 00:20:44,480 --> 00:20:46,480 generate it takes in a digital logic 589 00:20:46,480 --> 00:20:47,520 signal 590 00:20:47,520 --> 00:20:49,360 and then it generates the actual 591 00:20:49,360 --> 00:20:50,880 physical layer 592 00:20:50,880 --> 00:20:51,840 system 593 00:20:51,840 --> 00:20:54,320 so with the pi pico we'll be generating 594 00:20:54,320 --> 00:20:56,480 this digital signal and the phi will 595 00:20:56,480 --> 00:20:59,200 generate that 596 00:21:00,480 --> 00:21:02,000 what's important when you configure the 597 00:21:02,000 --> 00:21:02,960 network 598 00:21:02,960 --> 00:21:04,559 now 599 00:21:04,559 --> 00:21:06,960 when you first look at can and they show 600 00:21:06,960 --> 00:21:09,280 you this this diagram it's just like you 601 00:21:09,280 --> 00:21:11,120 immediately have like 602 00:21:11,120 --> 00:21:13,039 you need like aspirin or you know 603 00:21:13,039 --> 00:21:14,799 ibuprofen immediately just gives you a 604 00:21:14,799 --> 00:21:17,520 headache and like who cares about tying 605 00:21:17,520 --> 00:21:19,039 content whatever 606 00:21:19,039 --> 00:21:20,960 the main important thing about this is 607 00:21:20,960 --> 00:21:22,720 the bit time and that's the length of 608 00:21:22,720 --> 00:21:24,480 the actual bit 609 00:21:24,480 --> 00:21:25,919 and then the sample point those are the 610 00:21:25,919 --> 00:21:27,760 two things that care so if you got those 611 00:21:27,760 --> 00:21:30,400 correct uh the can bus will work now the 612 00:21:30,400 --> 00:21:33,120 sample point is when the digital logic 613 00:21:33,120 --> 00:21:35,360 actually looks at the bit to determine 614 00:21:35,360 --> 00:21:36,480 if it's 615 00:21:36,480 --> 00:21:38,720 one or zero okay 616 00:21:38,720 --> 00:21:40,720 uh so 617 00:21:40,720 --> 00:21:42,480 what happens is you can have it wrong 618 00:21:42,480 --> 00:21:44,720 but then on certain networks if you wire 619 00:21:44,720 --> 00:21:47,360 it a certain way 620 00:21:47,360 --> 00:21:49,679 you won't you'll get errors and there's 621 00:21:49,679 --> 00:21:52,159 actually a attack by 622 00:21:52,159 --> 00:21:53,440 by 623 00:21:53,440 --> 00:21:54,880 canis labs that you can do with the 624 00:21:54,880 --> 00:21:56,320 badge called the janus attack which 625 00:21:56,320 --> 00:21:57,679 messes with this 626 00:21:57,679 --> 00:21:59,200 which i'll have more information about 627 00:21:59,200 --> 00:22:01,760 that later 628 00:22:02,880 --> 00:22:03,679 so 629 00:22:03,679 --> 00:22:05,120 what do we want to do with the badge we 630 00:22:05,120 --> 00:22:08,400 want to generate can bus frames 631 00:22:08,400 --> 00:22:10,240 so now i'm going to talk about how we're 632 00:22:10,240 --> 00:22:11,600 going to do that 633 00:22:11,600 --> 00:22:14,320 what's really awesome and i probably 634 00:22:14,320 --> 00:22:16,080 didn't realize this at the start when i 635 00:22:16,080 --> 00:22:19,200 looked at this part and having two cpu 636 00:22:19,200 --> 00:22:21,600 cores and embedded system is is really 637 00:22:21,600 --> 00:22:23,280 useful because 638 00:22:23,280 --> 00:22:24,400 normally 639 00:22:24,400 --> 00:22:26,640 bit banging is just not possible because 640 00:22:26,640 --> 00:22:29,200 you have a you have a core and it's like 641 00:22:29,200 --> 00:22:32,080 it's got to handle usb or you know or it 642 00:22:32,080 --> 00:22:33,919 has to uh 643 00:22:33,919 --> 00:22:35,679 you know process some data or something 644 00:22:35,679 --> 00:22:37,360 like that and you can kind of 645 00:22:37,360 --> 00:22:39,600 do some stuff with interrupts but it's 646 00:22:39,600 --> 00:22:43,200 uh it's never really deterministic and 647 00:22:43,200 --> 00:22:45,360 you know you can stop everything and bit 648 00:22:45,360 --> 00:22:46,880 bang and that does work 649 00:22:46,880 --> 00:22:48,480 we've did some stuff with that but if 650 00:22:48,480 --> 00:22:50,080 you do if you have to bit bang for too 651 00:22:50,080 --> 00:22:51,919 long it kind of you know things stop 652 00:22:51,919 --> 00:22:54,880 working so for example like usb on this 653 00:22:54,880 --> 00:22:58,320 on this badge it's interrupt driven so 654 00:22:58,320 --> 00:23:00,080 if you don't service it 655 00:23:00,080 --> 00:23:02,159 uh it will actually disconnect from usb 656 00:23:02,159 --> 00:23:03,440 so it's kind of annoying when you're 657 00:23:03,440 --> 00:23:06,240 using a debugger 658 00:23:06,400 --> 00:23:09,280 but having a separate cpu core allows 659 00:23:09,280 --> 00:23:11,678 you to 660 00:23:12,080 --> 00:23:13,360 do these 661 00:23:13,360 --> 00:23:15,280 bit banging and still have your full 662 00:23:15,280 --> 00:23:18,000 application running uh so you'll notice 663 00:23:18,000 --> 00:23:20,080 when i sent the cam messages with the 664 00:23:20,080 --> 00:23:21,200 badge 665 00:23:21,200 --> 00:23:23,679 it sent the cam messages and the leds 666 00:23:23,679 --> 00:23:25,600 flash and everything else still works so 667 00:23:25,600 --> 00:23:28,080 it's pretty cool 668 00:23:28,080 --> 00:23:30,640 now um you could have a second core but 669 00:23:30,640 --> 00:23:32,480 like how does it use 670 00:23:32,480 --> 00:23:35,679 how do they work together and 671 00:23:35,679 --> 00:23:38,480 with the rp 2040 they did a really good 672 00:23:38,480 --> 00:23:39,520 job of 673 00:23:39,520 --> 00:23:41,760 allowing it to operate independently if 674 00:23:41,760 --> 00:23:43,520 you use it correctly 675 00:23:43,520 --> 00:23:45,120 uh so there's 676 00:23:45,120 --> 00:23:46,960 there's uh 677 00:23:46,960 --> 00:23:48,799 essential for bit banging is you want to 678 00:23:48,799 --> 00:23:50,400 be able to be deterministic that means 679 00:23:50,400 --> 00:23:52,480 when you write the software it's exactly 680 00:23:52,480 --> 00:23:54,640 going to have that that many cycles and 681 00:23:54,640 --> 00:23:56,400 that timing and everything 682 00:23:56,400 --> 00:23:59,760 and uh they did so so the way you do it 683 00:23:59,760 --> 00:24:01,919 on this part is uh they have a feature 684 00:24:01,919 --> 00:24:03,760 called single cycle i o which i'll 685 00:24:03,760 --> 00:24:05,039 explain 686 00:24:05,039 --> 00:24:07,279 there's something called a bus matrix 687 00:24:07,279 --> 00:24:08,159 with 688 00:24:08,159 --> 00:24:10,480 sram and then they have fifos between 689 00:24:10,480 --> 00:24:12,960 the cores so they can communicate so 690 00:24:12,960 --> 00:24:14,799 i'll talk a little bit about that and 691 00:24:14,799 --> 00:24:16,679 all this all these diagrams are from the 692 00:24:16,679 --> 00:24:19,440 rp2040 data sheet so you can 693 00:24:19,440 --> 00:24:22,000 learn more it's really fun now there's 694 00:24:22,000 --> 00:24:23,039 other 695 00:24:23,039 --> 00:24:26,559 uh cpus that have dual cores out there 696 00:24:26,559 --> 00:24:30,159 uh so so nxp has a microchip has them 697 00:24:30,159 --> 00:24:32,240 i would say i can't tell you if they're 698 00:24:32,240 --> 00:24:33,919 done deterministically although 699 00:24:33,919 --> 00:24:36,320 microchip does have a ds pick core uh 700 00:24:36,320 --> 00:24:38,480 which i used to program and i love but 701 00:24:38,480 --> 00:24:40,400 it's only 16 bit they have a dual core 702 00:24:40,400 --> 00:24:41,919 now that runs at 703 00:24:41,919 --> 00:24:44,880 10 nanoseconds 704 00:24:44,960 --> 00:24:47,600 here we go single cycle i o so normally 705 00:24:47,600 --> 00:24:49,440 with an arm processor 706 00:24:49,440 --> 00:24:51,440 uh what happens is 707 00:24:51,440 --> 00:24:53,039 they they have load and store 708 00:24:53,039 --> 00:24:54,720 instructions meaning 709 00:24:54,720 --> 00:24:58,000 that's the only way memory uh is changed 710 00:24:58,000 --> 00:25:00,720 but it's through these instructions 711 00:25:00,720 --> 00:25:02,880 which require access to the bus and they 712 00:25:02,880 --> 00:25:05,600 als they're always multi-cycle so 713 00:25:05,600 --> 00:25:06,720 you 714 00:25:06,720 --> 00:25:08,960 to do a load it will have to go on the 715 00:25:08,960 --> 00:25:10,000 bus 716 00:25:10,000 --> 00:25:12,320 and then and then the i o itself is 717 00:25:12,320 --> 00:25:14,320 memory mapped so it will be a specific 718 00:25:14,320 --> 00:25:17,600 address they have to go to to change 719 00:25:17,600 --> 00:25:21,360 now with the cortex m0 plus 720 00:25:21,360 --> 00:25:23,279 they have this feature called single 721 00:25:23,279 --> 00:25:25,279 cycle i o so 722 00:25:25,279 --> 00:25:27,360 the logic in the core actually looks at 723 00:25:27,360 --> 00:25:29,279 what address that you're running to and 724 00:25:29,279 --> 00:25:32,320 if it happens to be a specific address 725 00:25:32,320 --> 00:25:34,799 it will it can change that logic with 726 00:25:34,799 --> 00:25:36,480 one cycle so the load and store 727 00:25:36,480 --> 00:25:39,360 instructions for those address 728 00:25:39,360 --> 00:25:42,799 take part eight nanoseconds so you can 729 00:25:42,799 --> 00:25:45,200 actually uh there's a there's a register 730 00:25:45,200 --> 00:25:47,840 that will allow you to toggle a gpio 731 00:25:47,840 --> 00:25:50,240 and you could just have uh inline code 732 00:25:50,240 --> 00:25:52,559 that will that you can generate uh clock 733 00:25:52,559 --> 00:25:54,880 pulse every eight nanoseconds so you can 734 00:25:54,880 --> 00:25:56,480 you can bit paying 735 00:25:56,480 --> 00:25:59,360 things you know up to 65 62 megahertz 736 00:25:59,360 --> 00:26:01,440 you know 62 and a half or half the clock 737 00:26:01,440 --> 00:26:02,480 rate 738 00:26:02,480 --> 00:26:04,640 so it's a really cool feature for a bit 739 00:26:04,640 --> 00:26:06,720 banging now do you really need this to 740 00:26:06,720 --> 00:26:08,559 do can because like if you look at the 741 00:26:08,559 --> 00:26:10,400 eight nanoseconds compared to like a 742 00:26:10,400 --> 00:26:12,960 standard can bit time at 500 kilobits 743 00:26:12,960 --> 00:26:14,400 which is 744 00:26:14,400 --> 00:26:17,200 two microseconds that's you know that's 745 00:26:17,200 --> 00:26:18,880 you do you need single cycle aisle for 746 00:26:18,880 --> 00:26:20,720 that i don't think so but like if you 747 00:26:20,720 --> 00:26:22,720 want if you want to do a faster protocol 748 00:26:22,720 --> 00:26:25,200 like maybe canon d 749 00:26:25,200 --> 00:26:26,960 then you want to have as you know you 750 00:26:26,960 --> 00:26:28,400 want to be able to save every 751 00:26:28,400 --> 00:26:30,880 instruction 752 00:26:32,559 --> 00:26:35,039 now this is the other part so the cpu 753 00:26:35,039 --> 00:26:37,039 just exists in the part and it needs 754 00:26:37,039 --> 00:26:40,080 access to ram and it needs access to i o 755 00:26:40,080 --> 00:26:44,080 so the single cycle i o takes care of 756 00:26:44,080 --> 00:26:45,120 the i o 757 00:26:45,120 --> 00:26:47,200 now the other part is you need ram and 758 00:26:47,200 --> 00:26:49,679 you need ram for your stack you need ram 759 00:26:49,679 --> 00:26:51,039 for your code because 760 00:26:51,039 --> 00:26:53,360 this is a processor 761 00:26:53,360 --> 00:26:55,279 that 762 00:26:55,279 --> 00:26:56,880 you know 763 00:26:56,880 --> 00:26:59,760 there's no flash or anything and 764 00:26:59,760 --> 00:27:00,720 so 765 00:27:00,720 --> 00:27:04,159 when you go to access the ram 766 00:27:04,159 --> 00:27:06,000 if you have to share the ram with 767 00:27:06,000 --> 00:27:07,279 another core 768 00:27:07,279 --> 00:27:08,960 that's a problem because 769 00:27:08,960 --> 00:27:11,760 depending on priorities who gets it and 770 00:27:11,760 --> 00:27:14,720 cycles so the trick is is they created 771 00:27:14,720 --> 00:27:16,320 this thing called the bus matrix which 772 00:27:16,320 --> 00:27:17,840 is actually kind of hard to see right 773 00:27:17,840 --> 00:27:20,159 here but it's basically a logic 774 00:27:20,159 --> 00:27:22,480 a logic device that 775 00:27:22,480 --> 00:27:23,600 um 776 00:27:23,600 --> 00:27:25,440 there's there's certain masters which in 777 00:27:25,440 --> 00:27:28,159 this case is there's three uh there's 778 00:27:28,159 --> 00:27:28,880 the 779 00:27:28,880 --> 00:27:30,159 the core one 780 00:27:30,159 --> 00:27:32,480 or core zero which is the first four it 781 00:27:32,480 --> 00:27:33,760 gets kind of confusing and then there's 782 00:27:33,760 --> 00:27:36,240 a second core core one 783 00:27:36,240 --> 00:27:39,039 and then dma and they all access they go 784 00:27:39,039 --> 00:27:42,960 into this little box called the matrix 785 00:27:42,960 --> 00:27:44,799 and then there's all these 786 00:27:44,799 --> 00:27:46,559 things that hang off of it and the 787 00:27:46,559 --> 00:27:49,200 beauty of the matrix is as long as 788 00:27:49,200 --> 00:27:51,760 you're not accessing the same 789 00:27:51,760 --> 00:27:54,880 uh preferable at the same time or the 790 00:27:54,880 --> 00:27:56,720 or the 791 00:27:56,720 --> 00:27:58,559 um i don't know what the best let's just 792 00:27:58,559 --> 00:28:00,480 call it peripheral 793 00:28:00,480 --> 00:28:03,520 that there will be no weights for that 794 00:28:03,520 --> 00:28:04,720 that uh 795 00:28:04,720 --> 00:28:09,039 resource so for example if core 796 00:28:09,039 --> 00:28:12,480 core zero is talking to this sram and 797 00:28:12,480 --> 00:28:14,320 then core one is talking to another 798 00:28:14,320 --> 00:28:16,799 asram amp 799 00:28:16,799 --> 00:28:19,918 there won't be any blocking 800 00:28:20,159 --> 00:28:24,880 uh so that allows the core to run 801 00:28:25,200 --> 00:28:27,440 allows the core to run witho without any 802 00:28:27,440 --> 00:28:29,279 blocking so it gives you a deterministic 803 00:28:29,279 --> 00:28:31,120 clock rate for the core now it's 804 00:28:31,120 --> 00:28:33,440 important to know if you use this part 805 00:28:33,440 --> 00:28:35,760 that depending on what address you ask 806 00:28:35,760 --> 00:28:38,000 these srams 807 00:28:38,000 --> 00:28:41,200 they're striped so uh if like you might 808 00:28:41,200 --> 00:28:42,880 take one address but the next address 809 00:28:42,880 --> 00:28:45,840 will be on this sram it's actually a 810 00:28:45,840 --> 00:28:47,840 cool thing because it allows 811 00:28:47,840 --> 00:28:50,159 if you're running code out of the sram 812 00:28:50,159 --> 00:28:52,559 from both parts they'll they'll 813 00:28:52,559 --> 00:28:54,000 they'll not always 814 00:28:54,000 --> 00:28:55,679 block each other 815 00:28:55,679 --> 00:28:57,279 you know so that's interesting but like 816 00:28:57,279 --> 00:28:59,279 if you're going for determinism 817 00:28:59,279 --> 00:29:02,240 you can't use that striped feature so in 818 00:29:02,240 --> 00:29:04,240 the code that i wrote uses one of the 819 00:29:04,240 --> 00:29:06,960 one of the 4k srams so all the code and 820 00:29:06,960 --> 00:29:08,960 the stack all go in there 821 00:29:08,960 --> 00:29:10,399 okay so this is basically a summary of 822 00:29:10,399 --> 00:29:12,880 what i just said 823 00:29:12,880 --> 00:29:15,120 we use this independent sram 824 00:29:15,120 --> 00:29:16,960 we're calling it they call it scratch x 825 00:29:16,960 --> 00:29:19,120 actually in the code and then the second 826 00:29:19,120 --> 00:29:21,360 core another thing i want to mention 827 00:29:21,360 --> 00:29:24,240 that i might have skipped is uh 828 00:29:24,240 --> 00:29:26,480 on this first part here there's actually 829 00:29:26,480 --> 00:29:27,919 a fifo 830 00:29:27,919 --> 00:29:29,679 and this allows you to communicate 831 00:29:29,679 --> 00:29:32,320 between the chords and that does that's 832 00:29:32,320 --> 00:29:34,640 also deterministic so 833 00:29:34,640 --> 00:29:36,880 uh core one there's a fifo that goes in 834 00:29:36,880 --> 00:29:39,279 one direction and then chord zero has 835 00:29:39,279 --> 00:29:42,000 the opposite so core 0 can write to the 836 00:29:42,000 --> 00:29:45,360 fifo and not block and then core 1 can 837 00:29:45,360 --> 00:29:47,440 read that fifo you can check if 838 00:29:47,440 --> 00:29:49,760 something's there and use it or not and 839 00:29:49,760 --> 00:29:52,720 that's how we actually trigger the can 840 00:29:52,720 --> 00:29:54,559 transmission so i'm going to stop and 841 00:29:54,559 --> 00:29:56,799 i'm going to do a code demo of of the 842 00:29:56,799 --> 00:29:59,360 cpu uh bitbang so 843 00:29:59,360 --> 00:30:01,440 uh this is this is going to be visual 844 00:30:01,440 --> 00:30:03,840 studio itself uh so i'm going to let it 845 00:30:03,840 --> 00:30:06,480 stop i'm back and i'm going to show the 846 00:30:06,480 --> 00:30:09,279 code for generating the can 847 00:30:09,279 --> 00:30:10,559 message 848 00:30:10,559 --> 00:30:13,520 this is visual studio 22 and i have a 849 00:30:13,520 --> 00:30:16,080 plug-in called visual gdb which has some 850 00:30:16,080 --> 00:30:17,360 tools 851 00:30:17,360 --> 00:30:19,520 for 852 00:30:20,880 --> 00:30:23,120 it has some tools for 853 00:30:23,120 --> 00:30:26,880 using uh visual studio 2022 actually all 854 00:30:26,880 --> 00:30:28,960 the previous versions uh with for 855 00:30:28,960 --> 00:30:31,200 embedded process that's pretty good 856 00:30:31,200 --> 00:30:32,320 uh 857 00:30:32,320 --> 00:30:34,159 i'm having some issues with the debugger 858 00:30:34,159 --> 00:30:36,640 between the two parts but let's go ahead 859 00:30:36,640 --> 00:30:38,559 and look at this 860 00:30:38,559 --> 00:30:41,279 so this this this particular uh 861 00:30:41,279 --> 00:30:43,679 file is called uh 862 00:30:43,679 --> 00:30:46,720 can message builder 863 00:30:46,720 --> 00:30:48,840 and this is 864 00:30:48,840 --> 00:30:50,080 uh the 865 00:30:50,080 --> 00:30:52,240 [Music] 866 00:30:52,240 --> 00:30:54,559 uh the i'll show you the first step so 867 00:30:54,559 --> 00:30:57,519 basically what comes happens is there's 868 00:30:57,519 --> 00:30:59,760 an init uh function here 869 00:30:59,760 --> 00:31:02,159 and it looks at what the type of kill it 870 00:31:02,159 --> 00:31:04,480 is so the arbitrary kill and then it 871 00:31:04,480 --> 00:31:06,000 will uh 872 00:31:06,000 --> 00:31:07,519 load 873 00:31:07,519 --> 00:31:10,000 some settings in the kill 874 00:31:10,000 --> 00:31:11,919 and there is a 875 00:31:11,919 --> 00:31:14,799 function called create can message bits 876 00:31:14,799 --> 00:31:18,760 so we're going to look at that 877 00:31:20,480 --> 00:31:22,880 uh so there's this object called 878 00:31:22,880 --> 00:31:25,200 can which is actual it takes the canned 879 00:31:25,200 --> 00:31:27,600 message and creates ones and zeros based 880 00:31:27,600 --> 00:31:30,399 on the information so we're loading the 881 00:31:30,399 --> 00:31:33,360 can id 882 00:31:33,360 --> 00:31:35,519 the different pieces 883 00:31:35,519 --> 00:31:38,000 of the extended frame the data 884 00:31:38,000 --> 00:31:39,440 and then there's calls this function 885 00:31:39,440 --> 00:31:42,399 called canned bits 886 00:31:43,600 --> 00:31:45,919 so what it does is it goes through here 887 00:31:45,919 --> 00:31:48,000 and it checks the bits and then adds 888 00:31:48,000 --> 00:31:50,640 them to an array 889 00:31:50,640 --> 00:31:52,159 and 890 00:31:52,159 --> 00:31:54,240 i tried to do can fd but it's it's not 891 00:31:54,240 --> 00:31:56,559 supported 892 00:31:56,559 --> 00:31:58,559 but if you it just goes through the 893 00:31:58,559 --> 00:32:00,320 different fields of the can protocol and 894 00:32:00,320 --> 00:32:02,320 generates the bits and then if we go 895 00:32:02,320 --> 00:32:05,200 look at this function 896 00:32:05,279 --> 00:32:06,960 uh it's kind of interesting it actually 897 00:32:06,960 --> 00:32:10,480 does the crc and the the bit stuffing of 898 00:32:10,480 --> 00:32:11,919 can which i'm not going to explain in 899 00:32:11,919 --> 00:32:14,080 this video but that's a key part of key 900 00:32:14,080 --> 00:32:17,918 parts of the can protocol 901 00:32:19,760 --> 00:32:21,519 so that generates the actual ones and 902 00:32:21,519 --> 00:32:23,679 zeros and then 903 00:32:23,679 --> 00:32:25,760 we come back to where we started there's 904 00:32:25,760 --> 00:32:29,559 this build can message 905 00:32:29,919 --> 00:32:33,120 and what we have here is there's this 906 00:32:33,120 --> 00:32:35,840 class called arm so normally you would 907 00:32:35,840 --> 00:32:38,159 use an assembler which is a separate 908 00:32:38,159 --> 00:32:39,760 source file 909 00:32:39,760 --> 00:32:42,240 but i've written a 910 00:32:42,240 --> 00:32:44,960 c plus class that dynamically generates 911 00:32:44,960 --> 00:32:47,600 the cortex m0 instructions 912 00:32:47,600 --> 00:32:50,480 now there's only like 30 instructions 913 00:32:50,480 --> 00:32:52,640 in the cortex m0 914 00:32:52,640 --> 00:32:53,919 which is 915 00:32:53,919 --> 00:32:55,440 why i thought it wouldn't be hard to 916 00:32:55,440 --> 00:32:58,000 just dynamically generate messages 917 00:32:58,000 --> 00:33:00,240 and it wasn't too bad 918 00:33:00,240 --> 00:33:01,760 uh 919 00:33:01,760 --> 00:33:03,760 the the instructions have derivatives so 920 00:33:03,760 --> 00:33:05,360 i only really implemented the ones i'm 921 00:33:05,360 --> 00:33:07,679 using uh so it'll probably grow over 922 00:33:07,679 --> 00:33:09,919 time what's really cool about the cortex 923 00:33:09,919 --> 00:33:13,440 m0 is the instructions are binary 924 00:33:13,440 --> 00:33:17,039 compatible with all the cortex m so m 925 00:33:17,039 --> 00:33:19,200 stands for microcontroller so 926 00:33:19,200 --> 00:33:20,960 some of the more popular ones are cortex 927 00:33:20,960 --> 00:33:23,120 m3 or iv uh 928 00:33:23,120 --> 00:33:24,480 that have like more advanced 929 00:33:24,480 --> 00:33:27,440 instructions and floating point in m7 as 930 00:33:27,440 --> 00:33:29,919 well they're out there so this code 931 00:33:29,919 --> 00:33:31,760 technically will work 932 00:33:31,760 --> 00:33:33,760 on those processors 933 00:33:33,760 --> 00:33:36,559 of course the delays are different 934 00:33:36,559 --> 00:33:38,159 uh because the they're designed 935 00:33:38,159 --> 00:33:39,600 differently so some of them have like 936 00:33:39,600 --> 00:33:41,679 dedicated ram or they have a different 937 00:33:41,679 --> 00:33:43,760 number of stages and pipelines so things 938 00:33:43,760 --> 00:33:46,080 take longer but anyway 939 00:33:46,080 --> 00:33:47,679 uh what we're doing the first thing 940 00:33:47,679 --> 00:33:49,600 we're doing is we're initializing the 941 00:33:49,600 --> 00:33:51,039 program at the address of that 942 00:33:51,039 --> 00:33:53,519 particular sram now the key part about a 943 00:33:53,519 --> 00:33:56,960 cortex m part is the addresses that you 944 00:33:56,960 --> 00:33:59,200 call have to have a one in them 945 00:33:59,200 --> 00:34:01,200 otherwise they you get a hard fault 946 00:34:01,200 --> 00:34:02,480 because one is 947 00:34:02,480 --> 00:34:05,919 the the the first bit says it's a thumb 948 00:34:05,919 --> 00:34:08,000 or arm instruction and the cortex m only 949 00:34:08,000 --> 00:34:09,040 supports 950 00:34:09,040 --> 00:34:10,079 uh 951 00:34:10,079 --> 00:34:10,879 thumb 952 00:34:10,879 --> 00:34:12,639 so so that's a weird thing i had to 953 00:34:12,639 --> 00:34:15,520 learn lots of lots of crashing and hard 954 00:34:15,520 --> 00:34:16,719 to debug 955 00:34:16,719 --> 00:34:19,199 one of the problems i have with this 956 00:34:19,199 --> 00:34:21,119 with my setup right now is the second 957 00:34:21,119 --> 00:34:23,599 core is really difficult to debug uh so 958 00:34:23,599 --> 00:34:26,239 there's the the tools don't 959 00:34:26,239 --> 00:34:29,119 that i have and i looked for i i haven't 960 00:34:29,119 --> 00:34:31,440 seen any really great solutions to debug 961 00:34:31,440 --> 00:34:34,399 both chords which is kind of a bummer uh 962 00:34:34,399 --> 00:34:37,280 so anyway uh we're basically generating 963 00:34:37,280 --> 00:34:40,079 arm assembly here move immediate logical 964 00:34:40,079 --> 00:34:42,000 shift rush here 965 00:34:42,000 --> 00:34:43,359 uh 966 00:34:43,359 --> 00:34:45,440 and then there's literals 967 00:34:45,440 --> 00:34:49,119 this is kind of interesting 968 00:34:49,119 --> 00:34:51,199 arm is a 16-bit instruction set so it 969 00:34:51,199 --> 00:34:53,359 can only load uh small 970 00:34:53,359 --> 00:34:55,679 constants so the way they do it is they 971 00:34:55,679 --> 00:34:57,599 actually just in the code itself they'll 972 00:34:57,599 --> 00:34:59,200 have the 32-bit constant and then 973 00:34:59,200 --> 00:35:01,599 they'll load that from memory uh so 974 00:35:01,599 --> 00:35:03,440 that's the assembler actually already 975 00:35:03,440 --> 00:35:07,359 does that but like we do it dynamically 976 00:35:07,359 --> 00:35:08,560 so 977 00:35:08,560 --> 00:35:09,280 back 978 00:35:09,280 --> 00:35:12,240 going through the uh code here here's 979 00:35:12,240 --> 00:35:14,480 where we actually generate the code for 980 00:35:14,480 --> 00:35:16,800 generating can so we have the can we 981 00:35:16,800 --> 00:35:18,480 have the bit buffer which is just ones 982 00:35:18,480 --> 00:35:20,160 and zeros at this point 983 00:35:20,160 --> 00:35:22,480 and we either generate a set instruction 984 00:35:22,480 --> 00:35:24,320 or a clear instruction 985 00:35:24,320 --> 00:35:25,440 uh so 986 00:35:25,440 --> 00:35:27,040 what with the clear instruction it's 987 00:35:27,040 --> 00:35:29,520 just storing uh data to the the memory 988 00:35:29,520 --> 00:35:32,640 location where it controls the uh output 989 00:35:32,640 --> 00:35:34,800 so there's a different address for clear 990 00:35:34,800 --> 00:35:35,920 versus set 991 00:35:35,920 --> 00:35:37,760 uh and then there's a it does a branch 992 00:35:37,760 --> 00:35:39,359 and link which is basically calling a 993 00:35:39,359 --> 00:35:40,560 subroutine 994 00:35:40,560 --> 00:35:43,839 uh to a delay so based on your bit time 995 00:35:43,839 --> 00:35:46,400 the delay uh will be different 996 00:35:46,400 --> 00:35:49,040 and i'll show you basically that at the 997 00:35:49,040 --> 00:35:50,800 end here we actually build a delay 998 00:35:50,800 --> 00:35:52,560 function 999 00:35:52,560 --> 00:35:55,119 and depending on what you're doing 1000 00:35:55,119 --> 00:35:56,480 you're generating you're gonna you're 1001 00:35:56,480 --> 00:35:58,400 gonna build a delay for your bit period 1002 00:35:58,400 --> 00:35:59,920 and then you'll to build a delay for a 1003 00:35:59,920 --> 00:36:01,440 consecutive message and that's called 1004 00:36:01,440 --> 00:36:03,280 the inner frame period so we'll go to 1005 00:36:03,280 --> 00:36:05,520 this 1006 00:36:06,960 --> 00:36:08,960 so here 1007 00:36:08,960 --> 00:36:11,599 you pass in the number of the the delay 1008 00:36:11,599 --> 00:36:15,520 in nanoseconds and then it generates a 1009 00:36:15,520 --> 00:36:17,920 cycle accurate delay on with an 1010 00:36:17,920 --> 00:36:19,280 assembler 1011 00:36:19,280 --> 00:36:21,440 now how did i get this perfect 1012 00:36:21,440 --> 00:36:23,440 i used an oscilloscope and i verified it 1013 00:36:23,440 --> 00:36:24,720 so 1014 00:36:24,720 --> 00:36:26,400 step one calculate 1015 00:36:26,400 --> 00:36:29,200 it step two it didn't make sense step 1016 00:36:29,200 --> 00:36:31,280 three you go back and trying to figure 1017 00:36:31,280 --> 00:36:33,520 out what went wrong and eventually that 1018 00:36:33,520 --> 00:36:35,760 the the instructions or the the 1019 00:36:35,760 --> 00:36:38,720 knowledge matched the actual uh um the 1020 00:36:38,720 --> 00:36:40,800 code so 1021 00:36:40,800 --> 00:36:42,320 what's cool is the difference between 1022 00:36:42,320 --> 00:36:44,480 cortex m0 plus and the other core all 1023 00:36:44,480 --> 00:36:46,320 the other cortex sounds it has two 1024 00:36:46,320 --> 00:36:48,640 staged pipeline so that means that the 1025 00:36:48,640 --> 00:36:51,520 branches take two cycles versus three on 1026 00:36:51,520 --> 00:36:53,119 all the other cortex m so if you want to 1027 00:36:53,119 --> 00:36:54,720 port this code that would be definitely 1028 00:36:54,720 --> 00:36:57,520 a consideration 1029 00:36:58,320 --> 00:37:01,200 but the end result is 1030 00:37:01,200 --> 00:37:03,920 the main core software calls a function 1031 00:37:03,920 --> 00:37:06,920 called 1032 00:37:10,400 --> 00:37:13,680 sorry that's the wrong source code 1033 00:37:13,680 --> 00:37:14,880 start 1034 00:37:14,880 --> 00:37:16,480 and then we'll call this thing called 1035 00:37:16,480 --> 00:37:19,119 send message 1036 00:37:21,599 --> 00:37:24,480 and all this does is if the fifo is 1037 00:37:24,480 --> 00:37:27,520 ready it pushes a value into the fifo 1038 00:37:27,520 --> 00:37:31,280 and then the second core 1039 00:37:34,720 --> 00:37:37,040 um this is process core one 1040 00:37:37,040 --> 00:37:38,800 um it just uh 1041 00:37:38,800 --> 00:37:40,800 basically runs the program and sends a 1042 00:37:40,800 --> 00:37:43,040 message 1043 00:37:43,040 --> 00:37:44,880 and it doesn't show where it's checking 1044 00:37:44,880 --> 00:37:46,560 the fifo so i actually have to go to a 1045 00:37:46,560 --> 00:37:48,400 different source file 1046 00:37:48,400 --> 00:37:51,200 for that so 1047 00:37:55,280 --> 00:37:56,880 so here's the actual 1048 00:37:56,880 --> 00:37:59,520 source for the mean is checking the fifo 1049 00:37:59,520 --> 00:38:00,880 and then if it does it calls that 1050 00:38:00,880 --> 00:38:04,560 function that will trigger the the send 1051 00:38:04,560 --> 00:38:06,960 so this is the actual initialization for 1052 00:38:06,960 --> 00:38:09,280 the code 1053 00:38:09,280 --> 00:38:11,760 and uh this is where you start the core 1054 00:38:11,760 --> 00:38:14,960 so the first core starts the second core 1055 00:38:14,960 --> 00:38:19,079 and that generates scan messages 1056 00:38:19,200 --> 00:38:22,320 okay so uh now 1057 00:38:22,320 --> 00:38:23,920 you might not understand that code but 1058 00:38:23,920 --> 00:38:24,880 the main 1059 00:38:24,880 --> 00:38:27,040 purpose of the presentation is the time 1060 00:38:27,040 --> 00:38:29,200 kind of give you clues 1061 00:38:29,200 --> 00:38:32,079 and give you the idea in your head that 1062 00:38:32,079 --> 00:38:34,000 it's definitely possible to bit bang 1063 00:38:34,000 --> 00:38:36,000 digital protocols that 1064 00:38:36,000 --> 00:38:38,240 in the past i think we're too fast to do 1065 00:38:38,240 --> 00:38:39,520 that so 1066 00:38:39,520 --> 00:38:43,599 uh for example a can frame is uh 1067 00:38:43,599 --> 00:38:45,680 typically the 500 kilobits that's it's 1068 00:38:45,680 --> 00:38:49,680 the bit time is is 200 or 2 000 1069 00:38:49,680 --> 00:38:52,400 nanoseconds so with the eight nanosecond 1070 00:38:52,400 --> 00:38:55,520 clock rate you have 250 instructions 1071 00:38:55,520 --> 00:38:58,960 between each bit uh that the cpu can use 1072 00:38:58,960 --> 00:39:00,720 to to 1073 00:39:00,720 --> 00:39:02,480 to deal with can so 1074 00:39:02,480 --> 00:39:04,560 it just opens up some some really cool 1075 00:39:04,560 --> 00:39:06,240 opportunities 1076 00:39:06,240 --> 00:39:09,200 for for can hacking now of course now we 1077 00:39:09,200 --> 00:39:11,200 want to receive can bus frames so how 1078 00:39:11,200 --> 00:39:12,560 can we do that 1079 00:39:12,560 --> 00:39:14,720 and uh 1080 00:39:14,720 --> 00:39:16,560 this gave me a chance to talk about the 1081 00:39:16,560 --> 00:39:18,240 bit bang processor 1082 00:39:18,240 --> 00:39:21,520 uh so the bit bang processor is is a 1083 00:39:21,520 --> 00:39:24,160 revolutionary and it's a huge part huge 1084 00:39:24,160 --> 00:39:26,240 uh uh 1085 00:39:26,240 --> 00:39:28,720 it's it's a huge piece of this part so 1086 00:39:28,720 --> 00:39:30,720 it's such an important part it's got its 1087 00:39:30,720 --> 00:39:33,440 own section and the data sheet it's got 1088 00:39:33,440 --> 00:39:35,119 it takes up a huge part of the die area 1089 00:39:35,119 --> 00:39:37,440 but it's really just super capable 1090 00:39:37,440 --> 00:39:39,520 and what it is is there's actually two 1091 00:39:39,520 --> 00:39:42,800 of them um and the two pio modules each 1092 00:39:42,800 --> 00:39:45,839 have four bit bang processors uh and the 1093 00:39:45,839 --> 00:39:47,680 four bit bank processor share some 1094 00:39:47,680 --> 00:39:49,280 resources and then have their own 1095 00:39:49,280 --> 00:39:51,839 independent resources as well uh and 1096 00:39:51,839 --> 00:39:53,599 it's what's kind of cool uh that you can 1097 00:39:53,599 --> 00:39:55,440 just waste that the the bit bang 1098 00:39:55,440 --> 00:39:57,440 processors can kind of start at the same 1099 00:39:57,440 --> 00:39:59,520 time and since they're all cycle 1100 00:39:59,520 --> 00:40:01,359 accurate you can do a lot of really cool 1101 00:40:01,359 --> 00:40:04,240 uh coordination between the two 1102 00:40:04,240 --> 00:40:06,480 but it's very complicated it's not 1103 00:40:06,480 --> 00:40:08,160 complicated it's actually very simple 1104 00:40:08,160 --> 00:40:09,200 but it's 1105 00:40:09,200 --> 00:40:10,960 how to use it for a period of 1106 00:40:10,960 --> 00:40:12,480 application you just have to sit down 1107 00:40:12,480 --> 00:40:14,240 and look at the instructions and see how 1108 00:40:14,240 --> 00:40:16,319 it works 1109 00:40:16,319 --> 00:40:17,839 but i did this 1110 00:40:17,839 --> 00:40:20,880 just a very simple crappy uh can receive 1111 00:40:20,880 --> 00:40:22,160 so 1112 00:40:22,160 --> 00:40:23,760 what does it have it has eight different 1113 00:40:23,760 --> 00:40:26,160 instructions doesn't sound like a lot uh 1114 00:40:26,160 --> 00:40:27,920 but low number of instructions are good 1115 00:40:27,920 --> 00:40:29,920 because it maybe gives you that allows 1116 00:40:29,920 --> 00:40:32,480 you to do an understanding of it uh it's 1117 00:40:32,480 --> 00:40:36,160 got fifos uh to communicate with the cpu 1118 00:40:36,160 --> 00:40:38,880 uh so basically the cpu will 1119 00:40:38,880 --> 00:40:41,839 throw data in the fifo and and read data 1120 00:40:41,839 --> 00:40:43,520 out so for example for if you were doing 1121 00:40:43,520 --> 00:40:45,280 can transmission you would put those 1122 00:40:45,280 --> 00:40:47,839 those bits from can into that fifo and 1123 00:40:47,839 --> 00:40:50,160 then the the bit bank processor would 1124 00:40:50,160 --> 00:40:53,119 read them out send them for this example 1125 00:40:53,119 --> 00:40:55,040 with the receive 1126 00:40:55,040 --> 00:40:57,200 i sample the bus and then i slide the 1127 00:40:57,200 --> 00:40:59,119 bits into the fifo for the cpu to 1128 00:40:59,119 --> 00:41:00,560 re-read 1129 00:41:00,560 --> 00:41:03,119 there's there's 32 instructions only and 1130 00:41:03,119 --> 00:41:05,440 they're shared within the pio by all the 1131 00:41:05,440 --> 00:41:06,640 pios 1132 00:41:06,640 --> 00:41:08,800 so the can receive core i'm going to 1133 00:41:08,800 --> 00:41:10,640 show 1134 00:41:10,640 --> 00:41:13,119 or the code um it's it's i don't it's 1135 00:41:13,119 --> 00:41:15,520 it's uh it takes like say 10 1136 00:41:15,520 --> 00:41:17,520 instructions or something 1137 00:41:17,520 --> 00:41:19,359 all those state machines could run 1138 00:41:19,359 --> 00:41:21,680 simultaneously with those instructions 1139 00:41:21,680 --> 00:41:23,440 so if you wanted to capture you know 1140 00:41:23,440 --> 00:41:25,440 eight can channels at the same time you 1141 00:41:25,440 --> 00:41:27,359 can do that because it's just it all 1142 00:41:27,359 --> 00:41:31,680 works in parallel pretty pretty amazing 1143 00:41:31,760 --> 00:41:34,480 uh what are the instructions uh jump 1144 00:41:34,480 --> 00:41:36,160 uh the jump it's a conditional jump or 1145 00:41:36,160 --> 00:41:37,680 non-conditional jump and it can jump 1146 00:41:37,680 --> 00:41:40,800 anywhere in those 32 uh instructions uh 1147 00:41:40,800 --> 00:41:42,720 it can jump on eye open it can jump on 1148 00:41:42,720 --> 00:41:44,160 there's some scratch registers or 1149 00:41:44,160 --> 00:41:46,000 accumulators 1150 00:41:46,000 --> 00:41:47,440 stuff like that 1151 00:41:47,440 --> 00:41:50,400 oh wait wait for wade is waiting for 1152 00:41:50,400 --> 00:41:53,200 usually a pin uh to change state uh so 1153 00:41:53,200 --> 00:41:54,880 for can we're waiting for that start of 1154 00:41:54,880 --> 00:41:56,800 frame uh so as soon as that goes low 1155 00:41:56,800 --> 00:41:58,480 then it signals the start of a new cam 1156 00:41:58,480 --> 00:42:00,079 frame 1157 00:42:00,079 --> 00:42:03,440 in uh n is in and out are just like usb 1158 00:42:03,440 --> 00:42:04,880 where they're they're the direction to 1159 00:42:04,880 --> 00:42:06,960 the host so in means it's going to the 1160 00:42:06,960 --> 00:42:08,560 cpu and out it means it's coming from 1161 00:42:08,560 --> 00:42:11,599 the cpu so in is is basically shifting 1162 00:42:11,599 --> 00:42:13,839 data in 1163 00:42:13,839 --> 00:42:16,960 into a shift register uh and then out is 1164 00:42:16,960 --> 00:42:20,240 out or from pins into a shift register 1165 00:42:20,240 --> 00:42:22,079 and then out is out from a shift writer 1166 00:42:22,079 --> 00:42:23,440 two pins 1167 00:42:23,440 --> 00:42:25,520 so if you're doing can transmission use 1168 00:42:25,520 --> 00:42:27,920 out can reception be used in 1169 00:42:27,920 --> 00:42:29,520 push push 1170 00:42:29,520 --> 00:42:31,520 moves data from 1171 00:42:31,520 --> 00:42:33,280 one of the registers either the shift 1172 00:42:33,280 --> 00:42:35,839 register the or the 1173 00:42:35,839 --> 00:42:38,160 scratch register into the fifo and then 1174 00:42:38,160 --> 00:42:40,960 pull pulls a data value out 1175 00:42:40,960 --> 00:42:41,839 move 1176 00:42:41,839 --> 00:42:43,760 move just moves data between the 1177 00:42:43,760 --> 00:42:46,160 different parts uh different registers 1178 00:42:46,160 --> 00:42:48,880 in the part and the irq it generates 1179 00:42:48,880 --> 00:42:50,800 interrupt for the processor which we 1180 00:42:50,800 --> 00:42:53,440 actually use for the can reception 1181 00:42:53,440 --> 00:42:56,000 and then set will actually set i o pins 1182 00:42:56,000 --> 00:42:59,200 or set values of the scratch registers 1183 00:42:59,200 --> 00:43:01,200 okay so now uh we're going to do a 1184 00:43:01,200 --> 00:43:03,440 demonstration of 1185 00:43:03,440 --> 00:43:06,240 the receive code for canvas 1186 00:43:06,240 --> 00:43:09,920 okay so we're back to the visual studio 1187 00:43:09,920 --> 00:43:14,079 and this is in a class called knrx 1188 00:43:14,160 --> 00:43:15,680 so just like 1189 00:43:15,680 --> 00:43:17,680 there was a class that was created for 1190 00:43:17,680 --> 00:43:20,800 generating cortex m0 instructions 1191 00:43:20,800 --> 00:43:22,720 there's also an assembler that you can 1192 00:43:22,720 --> 00:43:25,520 write assembly code for the pio 1193 00:43:25,520 --> 00:43:27,520 but i wrote a class that just generates 1194 00:43:27,520 --> 00:43:29,520 the pio it's very simple 1195 00:43:29,520 --> 00:43:31,440 and i i want to dynamically change them 1196 00:43:31,440 --> 00:43:33,599 in code and honestly the assembler it 1197 00:43:33,599 --> 00:43:36,079 just is 1198 00:43:36,079 --> 00:43:37,680 it's easier to use code the only 1199 00:43:37,680 --> 00:43:39,440 downside is that 1200 00:43:39,440 --> 00:43:40,800 you have to have this code in your 1201 00:43:40,800 --> 00:43:43,040 project so the some assembler that i 1202 00:43:43,040 --> 00:43:45,040 wrote is extra code in your project 1203 00:43:45,040 --> 00:43:46,640 where the assembler if you just use 1204 00:43:46,640 --> 00:43:47,520 theirs 1205 00:43:47,520 --> 00:43:49,599 uh it just it just works just like a c 1206 00:43:49,599 --> 00:43:51,520 compiler which is it's actually really 1207 00:43:51,520 --> 00:43:53,680 cool um how they did that so when you 1208 00:43:53,680 --> 00:43:55,040 learn more about it but we're just going 1209 00:43:55,040 --> 00:43:56,480 to go through this code 1210 00:43:56,480 --> 00:43:59,200 uh the can receive and the badge is is 1211 00:43:59,200 --> 00:44:00,720 kind of not a very good one it didn't 1212 00:44:00,720 --> 00:44:02,560 have a lot of time to work on it 1213 00:44:02,560 --> 00:44:04,400 but i just want to demonstrate the pio 1214 00:44:04,400 --> 00:44:08,160 engine so it only works at one specific 1215 00:44:08,160 --> 00:44:10,720 bit rate which is 500 kilobits so the 1216 00:44:10,720 --> 00:44:12,160 first thing you're do you're gonna do is 1217 00:44:12,160 --> 00:44:15,760 set up the clock period of the pio 1218 00:44:15,760 --> 00:44:18,000 now it can run at eight nanoseconds but 1219 00:44:18,000 --> 00:44:20,240 there's advantages if you can use a 1220 00:44:20,240 --> 00:44:22,240 small closer clock rate which i'll 1221 00:44:22,240 --> 00:44:24,480 explain so this actually sets it up so 1222 00:44:24,480 --> 00:44:26,800 you have 32 1223 00:44:26,800 --> 00:44:30,640 different clocks per bit okay 1224 00:44:30,640 --> 00:44:32,560 so the first thing we do we initialize 1225 00:44:32,560 --> 00:44:34,800 the uh pio engine 1226 00:44:34,800 --> 00:44:36,640 and then we're gonna set up the fifos 1227 00:44:36,640 --> 00:44:38,400 the fifos are configurable there's a lot 1228 00:44:38,400 --> 00:44:40,079 of cool things you can do with them uh 1229 00:44:40,079 --> 00:44:41,680 but two of the features that i use in 1230 00:44:41,680 --> 00:44:45,200 this is there's a four word so 32 bits 1231 00:44:45,200 --> 00:44:46,960 for 32-bit 1232 00:44:46,960 --> 00:44:49,599 uh word fifo on in and out but you can 1233 00:44:49,599 --> 00:44:51,359 actually join them so they can be all in 1234 00:44:51,359 --> 00:44:52,960 or all out so i actually joined those 1235 00:44:52,960 --> 00:44:57,040 32-bit fifos which means there's uh 1236 00:44:57,040 --> 00:44:58,720 250 or 1237 00:44:58,720 --> 00:45:01,520 yeah 32 times 8 bits 1238 00:45:01,520 --> 00:45:04,160 and that's actually smaller than a can 1239 00:45:04,160 --> 00:45:06,960 for any can frame so you can actually 1240 00:45:06,960 --> 00:45:08,319 uh 1241 00:45:08,319 --> 00:45:10,240 use the fifo to gener to capture an 1242 00:45:10,240 --> 00:45:12,880 entire cam frame which is pretty cool 1243 00:45:12,880 --> 00:45:15,359 uh without any cpu intervention so we 1244 00:45:15,359 --> 00:45:17,280 set the pins we're only using one pin 1245 00:45:17,280 --> 00:45:19,040 this is the rx pin off the can 1246 00:45:19,040 --> 00:45:20,560 transceiver 1247 00:45:20,560 --> 00:45:23,839 then we start the uh the assembler we 1248 00:45:23,839 --> 00:45:25,599 start encoding 1249 00:45:25,599 --> 00:45:27,920 i'm not going to talk about wrap target 1250 00:45:27,920 --> 00:45:30,160 but we add a label so for jumps you need 1251 00:45:30,160 --> 00:45:32,079 labels so this is just like in the 1252 00:45:32,079 --> 00:45:33,760 assembler the first thing we're going to 1253 00:45:33,760 --> 00:45:35,920 do is we're going to 1254 00:45:35,920 --> 00:45:38,240 set up a uh inner frame timeout so this 1255 00:45:38,240 --> 00:45:40,800 is how we detect when detect when the 1256 00:45:40,800 --> 00:45:42,560 can message is done is there's a certain 1257 00:45:42,560 --> 00:45:45,760 number of bits in between the messages 1258 00:45:45,760 --> 00:45:46,960 then we're going to go ahead and sit 1259 00:45:46,960 --> 00:45:50,000 ahead and wait for can to go low 1260 00:45:50,000 --> 00:45:52,160 so this false means low 1261 00:45:52,160 --> 00:45:54,560 so this is the weight instruction 1262 00:45:54,560 --> 00:45:56,240 now each instruction can have its own 1263 00:45:56,240 --> 00:45:58,560 delay so if i look in there each 1264 00:45:58,560 --> 00:46:00,880 instruction can have its own delay 1265 00:46:00,880 --> 00:46:02,480 so that means after the instruction 1266 00:46:02,480 --> 00:46:04,400 executes it will actually wait this 1267 00:46:04,400 --> 00:46:05,680 amount of time to go to the next 1268 00:46:05,680 --> 00:46:06,880 instruction 1269 00:46:06,880 --> 00:46:09,280 so that's where the time determinism of 1270 00:46:09,280 --> 00:46:12,400 of the state machine is extremely useful 1271 00:46:12,400 --> 00:46:14,240 so what we're doing here is we're just 1272 00:46:14,240 --> 00:46:17,440 waiting for the sample point to be 75 1273 00:46:17,440 --> 00:46:19,280 and then what that is is 1274 00:46:19,280 --> 00:46:21,920 since i set up 32 clocks 1275 00:46:21,920 --> 00:46:25,920 it's 24 clocks to the sample point 1276 00:46:25,920 --> 00:46:28,079 uh so here we go we're just gonna fall 1277 00:46:28,079 --> 00:46:29,920 into this and then we do a jump and we 1278 00:46:29,920 --> 00:46:32,960 do a bit a jump based on the can rx to 1279 00:46:32,960 --> 00:46:34,960 determine if it's high or low now what's 1280 00:46:34,960 --> 00:46:37,200 weird about the jump instruction it only 1281 00:46:37,200 --> 00:46:38,960 will jump on a high so you have to 1282 00:46:38,960 --> 00:46:41,119 design your code uh if you wanted you 1283 00:46:41,119 --> 00:46:42,240 wanted to do something when it's low 1284 00:46:42,240 --> 00:46:43,680 then you gotta just jump somewhere else 1285 00:46:43,680 --> 00:46:45,920 but it totally works it just uses 1286 00:46:45,920 --> 00:46:48,480 another instruction it's all uh so if it 1287 00:46:48,480 --> 00:46:51,200 doesn't jump canon is low 1288 00:46:51,200 --> 00:46:54,240 when can is low we refresh the timeout 1289 00:46:54,240 --> 00:46:55,760 and we're storing this into this y 1290 00:46:55,760 --> 00:46:57,440 scratch register 1291 00:46:57,440 --> 00:47:00,400 and then we we call the instruction to 1292 00:47:00,400 --> 00:47:02,319 sample the can line and put it and that 1293 00:47:02,319 --> 00:47:03,839 puts it into the 1294 00:47:03,839 --> 00:47:06,880 the shift register 1295 00:47:07,119 --> 00:47:10,560 and then we just jump um always back to 1296 00:47:10,560 --> 00:47:13,680 checking the can line now 1297 00:47:13,680 --> 00:47:15,280 how why am i checking the cam line 1298 00:47:15,280 --> 00:47:16,960 immediately i'm actually not because in 1299 00:47:16,960 --> 00:47:19,680 this in instruction we're waiting 1300 00:47:19,680 --> 00:47:20,880 32 1301 00:47:20,880 --> 00:47:21,680 uh 1302 00:47:21,680 --> 00:47:24,160 clocks so 30 clocks is one whole bit and 1303 00:47:24,160 --> 00:47:26,319 i subtract away four because there's 1304 00:47:26,319 --> 00:47:28,960 actu each instruction takes one clock so 1305 00:47:28,960 --> 00:47:31,280 basically i took away the the clocks of 1306 00:47:31,280 --> 00:47:32,880 the instruction and then resampled the 1307 00:47:32,880 --> 00:47:33,920 bit 1308 00:47:33,920 --> 00:47:36,240 if can is high 1309 00:47:36,240 --> 00:47:39,280 which is idle bus we sampled a bit and 1310 00:47:39,280 --> 00:47:41,599 then we jump but in this jump we 1311 00:47:41,599 --> 00:47:43,440 actually decrement the y scratch 1312 00:47:43,440 --> 00:47:45,440 register 1313 00:47:45,440 --> 00:47:48,400 so what this does is it it will if if y 1314 00:47:48,400 --> 00:47:49,920 is zero it will 1315 00:47:49,920 --> 00:47:52,800 it will not jump 1316 00:47:52,800 --> 00:47:55,359 if not it jumps and then decrements y so 1317 00:47:55,359 --> 00:47:57,599 it's kind of a post decrement 1318 00:47:57,599 --> 00:47:58,400 if 1319 00:47:58,400 --> 00:48:01,040 y is zero at this point then we fall 1320 00:48:01,040 --> 00:48:02,720 through the loop to this 1321 00:48:02,720 --> 00:48:06,400 and then we we flush the fifo so the 1322 00:48:06,400 --> 00:48:08,800 fifo will automatically flush when it 1323 00:48:08,800 --> 00:48:11,520 fills 32 bits but since the can is not 1324 00:48:11,520 --> 00:48:13,440 going to end on a 32-bit boundary we 1325 00:48:13,440 --> 00:48:15,599 have to flush that data in 1326 00:48:15,599 --> 00:48:17,440 and then we we actually generate an 1327 00:48:17,440 --> 00:48:21,119 interrupt to the processor okay 1328 00:48:21,119 --> 00:48:23,359 and then this just goes back to 1329 00:48:23,359 --> 00:48:24,880 the weight which is waiting for the 1330 00:48:24,880 --> 00:48:26,640 starter frame so this thing is just 1331 00:48:26,640 --> 00:48:29,119 going to run and any time it sees the 1332 00:48:29,119 --> 00:48:30,559 start of frame it's going to sample the 1333 00:48:30,559 --> 00:48:33,520 can bus until it's idle and then it will 1334 00:48:33,520 --> 00:48:35,599 put that data in the fifo 1335 00:48:35,599 --> 00:48:36,400 now 1336 00:48:36,400 --> 00:48:38,559 i call this a crappy can decoder because 1337 00:48:38,559 --> 00:48:40,559 it's missing a key feature of can and 1338 00:48:40,559 --> 00:48:42,720 that's called resynchronization 1339 00:48:42,720 --> 00:48:46,078 so whenever there's a 1340 00:48:46,800 --> 00:48:49,040 a dominant edge whenever the can is 1341 00:48:49,040 --> 00:48:51,520 driven by the transceiver 1342 00:48:51,520 --> 00:48:53,599 uh you're supposed to check the the 1343 00:48:53,599 --> 00:48:55,920 timer synchronization so like if you if 1344 00:48:55,920 --> 00:48:58,480 you know a lot about you are you you are 1345 00:48:58,480 --> 00:49:00,480 time the the receiver since it's an 1346 00:49:00,480 --> 00:49:02,400 asynchronous protocol it has to derive 1347 00:49:02,400 --> 00:49:05,040 its own the sample clock from the bits 1348 00:49:05,040 --> 00:49:07,200 so can what it does is anytime there's a 1349 00:49:07,200 --> 00:49:09,280 high to low transition it it does what's 1350 00:49:09,280 --> 00:49:11,040 called a resynchronization 1351 00:49:11,040 --> 00:49:13,040 uh where where it compares to where it 1352 00:49:13,040 --> 00:49:15,040 thought the edge was and then adjust its 1353 00:49:15,040 --> 00:49:17,359 clock now i didn't do any of that is it 1354 00:49:17,359 --> 00:49:19,040 possible to do absolutely it's possible 1355 00:49:19,040 --> 00:49:20,960 to do it's just more work and i didn't 1356 00:49:20,960 --> 00:49:23,520 have time to do that in this this this 1357 00:49:23,520 --> 00:49:24,400 uh 1358 00:49:24,400 --> 00:49:25,520 example 1359 00:49:25,520 --> 00:49:27,839 and and and honestly with the pio 1360 00:49:27,839 --> 00:49:30,319 received it can totally work the only 1361 00:49:30,319 --> 00:49:32,160 problem with receive is 1362 00:49:32,160 --> 00:49:34,480 uh acknowledgment so like 1363 00:49:34,480 --> 00:49:36,480 the the pio i don't think can keep track 1364 00:49:36,480 --> 00:49:39,280 of which bit is which and decode um but 1365 00:49:39,280 --> 00:49:41,280 maybe maybe a handshaking with a cb you 1366 00:49:41,280 --> 00:49:42,960 can do that but like knowing where to 1367 00:49:42,960 --> 00:49:44,960 set the galaxy bit is is definitely 1368 00:49:44,960 --> 00:49:46,800 going to be the biggest challenge now 1369 00:49:46,800 --> 00:49:47,839 normally 1370 00:49:47,839 --> 00:49:49,280 if you're just connecting to existing 1371 00:49:49,280 --> 00:49:50,319 bus you don't care about the 1372 00:49:50,319 --> 00:49:52,160 acknowledgement or you're just spying so 1373 00:49:52,160 --> 00:49:54,319 definitely pio for receive totally could 1374 00:49:54,319 --> 00:49:55,359 work 1375 00:49:55,359 --> 00:49:57,680 and transmit really is very simple you 1376 00:49:57,680 --> 00:50:00,000 generate the bits and then you just 1377 00:50:00,000 --> 00:50:01,920 compare uh that's the sample point is 1378 00:50:01,920 --> 00:50:04,400 that the bit that i said set 1379 00:50:04,400 --> 00:50:06,559 um is it the same if it's the same then 1380 00:50:06,559 --> 00:50:08,079 your trans your transmitter if you're 1381 00:50:08,079 --> 00:50:09,839 not then you just stop transmitting so 1382 00:50:09,839 --> 00:50:11,280 that i think that would be very easy to 1383 00:50:11,280 --> 00:50:13,920 do with pio 1384 00:50:13,920 --> 00:50:16,160 so let's look at the other 1385 00:50:16,160 --> 00:50:18,240 functions in this so how does the cpu 1386 00:50:18,240 --> 00:50:20,559 actually get access to that data 1387 00:50:20,559 --> 00:50:22,079 so 1388 00:50:22,079 --> 00:50:26,000 every so often this the cpu 1389 00:50:26,000 --> 00:50:27,520 this main loop we'll call process and 1390 00:50:27,520 --> 00:50:29,040 what it does is it looks at the message 1391 00:50:29,040 --> 00:50:31,760 data count um 1392 00:50:31,760 --> 00:50:33,760 and then it just it just parses them and 1393 00:50:33,760 --> 00:50:36,480 it changes the bits it destuffs them so 1394 00:50:36,480 --> 00:50:38,480 can bit stuffing and then it builds a 1395 00:50:38,480 --> 00:50:41,040 can message now where does this thing 1396 00:50:41,040 --> 00:50:42,400 get filled up there's actually an 1397 00:50:42,400 --> 00:50:43,920 interrupt that's called 1398 00:50:43,920 --> 00:50:46,480 uh so we have an interrupt call back 1399 00:50:46,480 --> 00:50:47,920 here 1400 00:50:47,920 --> 00:50:50,000 and then that is called here and we 1401 00:50:50,000 --> 00:50:52,559 actually read the read the fifo into 1402 00:50:52,559 --> 00:50:55,119 this temporary data section 1403 00:50:55,119 --> 00:50:56,960 which is basically then eventually 1404 00:50:56,960 --> 00:50:59,280 processed by the main core which is this 1405 00:50:59,280 --> 00:51:00,720 code 1406 00:51:00,720 --> 00:51:03,119 so just this is just an example of it 1407 00:51:03,119 --> 00:51:04,960 can be done uh 1408 00:51:04,960 --> 00:51:07,440 and we'll go back to any ending this 1409 00:51:07,440 --> 00:51:10,559 presentation the demo 1410 00:51:11,839 --> 00:51:15,200 we have our picoscope up here 1411 00:51:15,200 --> 00:51:17,440 and uh 1412 00:51:17,440 --> 00:51:20,640 i'm just do some quick settings so 1413 00:51:20,640 --> 00:51:22,720 first of all channel a i have a 10x 1414 00:51:22,720 --> 00:51:25,040 probe 1415 00:51:25,359 --> 00:51:28,240 and i want the range to be 1416 00:51:28,240 --> 00:51:30,480 plus or minus five so we can 1417 00:51:30,480 --> 00:51:31,920 see the voltage 1418 00:51:31,920 --> 00:51:35,040 and i have the probe here and i'm 1419 00:51:35,040 --> 00:51:37,680 going to touch the 1420 00:51:37,680 --> 00:51:40,559 uh touch the i o pin of the can 1421 00:51:40,559 --> 00:51:42,720 transceiver all right so it looks like 1422 00:51:42,720 --> 00:51:44,240 we got a good 1423 00:51:44,240 --> 00:51:46,079 waveform there uh so what i'm going to 1424 00:51:46,079 --> 00:51:49,680 do is i'm going to run one of the kills 1425 00:51:50,160 --> 00:51:51,520 i don't have another camera on the badge 1426 00:51:51,520 --> 00:51:53,920 just because i ran out of usb ports 1427 00:51:53,920 --> 00:51:55,520 uh so what we're going to do is we're 1428 00:51:55,520 --> 00:51:57,200 going to zoom in here 1429 00:51:57,200 --> 00:52:01,040 and this is just generating error frames 1430 00:52:02,480 --> 00:52:04,559 i'm going to set up the trigger 1431 00:52:04,559 --> 00:52:06,640 and this little diamond is the trigger 1432 00:52:06,640 --> 00:52:08,240 point you can move it wherever you want 1433 00:52:08,240 --> 00:52:09,680 so we're just 1434 00:52:09,680 --> 00:52:12,399 put it right there 1435 00:52:17,599 --> 00:52:18,960 so we're basically just changing the 1436 00:52:18,960 --> 00:52:20,240 horizontal and i'll go ahead and stop 1437 00:52:20,240 --> 00:52:22,479 that 1438 00:52:24,240 --> 00:52:28,400 and we have our curse cursors here 1439 00:52:28,400 --> 00:52:30,000 now 1440 00:52:30,000 --> 00:52:32,319 this is the logic waveform so outside of 1441 00:52:32,319 --> 00:52:33,760 the transceiver 1442 00:52:33,760 --> 00:52:35,599 and we're going to go ahead and 1443 00:52:35,599 --> 00:52:38,079 look at measure this 1444 00:52:38,079 --> 00:52:40,319 and you can see we're at uh almost 1445 00:52:40,319 --> 00:52:43,119 exactly 16 microseconds so a 2 1446 00:52:43,119 --> 00:52:45,440 microsecond bit time is 1447 00:52:45,440 --> 00:52:47,280 is uh that's that's going to be eight 1448 00:52:47,280 --> 00:52:49,520 eight pulses okay so 1449 00:52:49,520 --> 00:52:53,520 that's what we're generating with the uh 1450 00:52:53,920 --> 00:52:56,480 with the uh that's the uh 1451 00:52:56,480 --> 00:52:58,640 your cans in jeopardy kill 1452 00:52:58,640 --> 00:53:01,119 uh and then kill with zeros let's go 1453 00:53:01,119 --> 00:53:02,640 ahead and do that 1454 00:53:02,640 --> 00:53:05,119 um you can do it from the usb prompt or 1455 00:53:05,119 --> 00:53:07,520 it's just more fun to do with the badge 1456 00:53:07,520 --> 00:53:08,400 you know 1457 00:53:08,400 --> 00:53:10,240 all right so go ahead and run that and 1458 00:53:10,240 --> 00:53:14,839 i'll turn the trigger back on and 1459 00:53:17,599 --> 00:53:19,920 yes 1460 00:53:23,520 --> 00:53:27,240 so can message 1461 00:53:33,119 --> 00:53:35,520 all right so you can see it's generating 1462 00:53:35,520 --> 00:53:37,760 um so this is the idle bus and then this 1463 00:53:37,760 --> 00:53:40,559 is basically canid 0. 1464 00:53:40,559 --> 00:53:42,240 the picoscope has some canned decoding 1465 00:53:42,240 --> 00:53:44,640 features and that's really cool uh but i 1466 00:53:44,640 --> 00:53:46,480 don't have time to show that right now 1467 00:53:46,480 --> 00:53:49,520 and then finally the random kill 1468 00:53:49,520 --> 00:53:52,720 uh which is not not as much 1469 00:53:52,720 --> 00:53:54,559 that is exciting 1470 00:53:54,559 --> 00:53:58,240 hold both buttons for the random kill 1471 00:54:01,200 --> 00:54:02,960 now this one generates random delays 1472 00:54:02,960 --> 00:54:07,079 between the messages as well 1473 00:54:12,400 --> 00:54:14,720 um just random size message random can 1474 00:54:14,720 --> 00:54:15,520 id 1475 00:54:15,520 --> 00:54:17,599 um it will actually generate errors once 1476 00:54:17,599 --> 00:54:20,160 in a while as well 1477 00:54:20,160 --> 00:54:21,760 all right 1478 00:54:21,760 --> 00:54:25,920 okay so that's the the predefined kills 1479 00:54:25,920 --> 00:54:28,000 and let's go ahead and uh i'll talk 1480 00:54:28,000 --> 00:54:30,240 about the software uh first of all uh 1481 00:54:30,240 --> 00:54:32,160 there's a version number uh i think 1482 00:54:32,160 --> 00:54:34,160 we're releasing five or six 1483 00:54:34,160 --> 00:54:36,640 uh six has the power management features 1484 00:54:36,640 --> 00:54:38,880 to run off the battery so 1485 00:54:38,880 --> 00:54:41,040 that might be the one you get 1486 00:54:41,040 --> 00:54:41,839 uh 1487 00:54:41,839 --> 00:54:43,440 it shows how many message bits you're 1488 00:54:43,440 --> 00:54:45,920 generating uh and it tells you the time 1489 00:54:45,920 --> 00:54:48,559 so this you know standard can messages 1490 00:54:48,559 --> 00:54:50,799 like 250 microseconds 1491 00:54:50,799 --> 00:54:52,559 and that's this particular message right 1492 00:54:52,559 --> 00:54:54,799 here 1493 00:54:55,119 --> 00:54:57,200 uh there's 16 stuff bits 1494 00:54:57,200 --> 00:54:58,960 so it's kind of a waste and can has to 1495 00:54:58,960 --> 00:55:00,400 generate these stuff bits so depending 1496 00:55:00,400 --> 00:55:01,920 on the data in the message it's either 1497 00:55:01,920 --> 00:55:03,839 going to be shorter or longer 1498 00:55:03,839 --> 00:55:05,680 the bit period so this is the actual 1499 00:55:05,680 --> 00:55:09,760 baud rate uh so 200 nanoseconds uh 1500 00:55:09,760 --> 00:55:11,440 and then transmit count is how many 1501 00:55:11,440 --> 00:55:13,200 you're going to send when the kill is 1502 00:55:13,200 --> 00:55:15,040 issued and that's just for the arbitrary 1503 00:55:15,040 --> 00:55:17,200 kill that's this one down here 1504 00:55:17,200 --> 00:55:20,000 uh and then you can actually generate an 1505 00:55:20,000 --> 00:55:21,920 inner frame period that's nanosecond 1506 00:55:21,920 --> 00:55:23,760 accurate as well so if you wanted to do 1507 00:55:23,760 --> 00:55:26,240 like 10 milliseconds between the message 1508 00:55:26,240 --> 00:55:28,640 uh response uh that lets you 1509 00:55:28,640 --> 00:55:31,599 see can messages 1510 00:55:31,599 --> 00:55:33,680 can ramp the cam data so that will 1511 00:55:33,680 --> 00:55:36,000 change the data and mccann message 1512 00:55:36,000 --> 00:55:38,720 uh or enter frame uh then ramp the inner 1513 00:55:38,720 --> 00:55:40,000 frame period 1514 00:55:40,000 --> 00:55:42,640 uh that's the the width between the 1515 00:55:42,640 --> 00:55:44,559 message you can ramp you can actually 1516 00:55:44,559 --> 00:55:46,640 ramp the bit period so if you wanted to 1517 00:55:46,640 --> 00:55:50,240 send you know 500 kilobits 1518 00:55:50,240 --> 00:55:51,920 and then mess with the bit timing to see 1519 00:55:51,920 --> 00:55:54,319 how an ecu responds you can do that and 1520 00:55:54,319 --> 00:55:57,040 then ramp can id well change to can id 1521 00:55:57,040 --> 00:55:58,319 so 1522 00:55:58,319 --> 00:55:59,440 these are the different settings so 1523 00:55:59,440 --> 00:56:00,799 let's go ahead and change the can 1524 00:56:00,799 --> 00:56:03,359 message so this is a canned message 1525 00:56:03,359 --> 00:56:05,119 configuration 1526 00:56:05,119 --> 00:56:07,920 you can change the can id 1527 00:56:07,920 --> 00:56:11,680 the length of the frame the bytes 1528 00:56:11,680 --> 00:56:15,839 you can add invalid crc invalid r0 which 1529 00:56:15,839 --> 00:56:17,200 is a 1530 00:56:17,200 --> 00:56:19,040 common issue that with a lot of can 1531 00:56:19,040 --> 00:56:20,640 controllers it wasn't defined what to do 1532 00:56:20,640 --> 00:56:21,839 about that 1533 00:56:21,839 --> 00:56:23,119 uh you can change the inner frame 1534 00:56:23,119 --> 00:56:24,880 separation time and the end of frame 1535 00:56:24,880 --> 00:56:26,319 separation time so if you want to 1536 00:56:26,319 --> 00:56:27,599 violate that 1537 00:56:27,599 --> 00:56:29,680 that rule where you send a message 1538 00:56:29,680 --> 00:56:31,839 earlier uh you can do that 1539 00:56:31,839 --> 00:56:33,920 generate an airframe this just generates 1540 00:56:33,920 --> 00:56:36,079 that airframe that you saw in the 1541 00:56:36,079 --> 00:56:39,520 in the in the um jeopardy uh kill 1542 00:56:39,520 --> 00:56:41,359 and also you can have an extended cam 1543 00:56:41,359 --> 00:56:43,119 frame with 29-bit ids and that's what's 1544 00:56:43,119 --> 00:56:45,440 used in uh trucking and industrial 1545 00:56:45,440 --> 00:56:48,240 applications a lot boats uh remote frame 1546 00:56:48,240 --> 00:56:50,319 this is a frame that no one really uses 1547 00:56:50,319 --> 00:56:52,960 but you know why not see what happens 1548 00:56:52,960 --> 00:56:55,200 so i'm gonna go ahead and and uh 1549 00:56:55,200 --> 00:56:58,880 generate a different can frame so 1550 00:56:58,880 --> 00:57:01,839 i'll hit three and then 1551 00:57:01,839 --> 00:57:05,920 enter in some different bytes 1552 00:57:08,799 --> 00:57:12,079 uh you see we changed the message 1553 00:57:12,079 --> 00:57:13,839 and then i'll quit and then what i'll go 1554 00:57:13,839 --> 00:57:15,839 ahead and do is i'm going to kill 1555 00:57:15,839 --> 00:57:18,000 the boss here with uh 1556 00:57:18,000 --> 00:57:20,000 okay so we can see the scope 1557 00:57:20,000 --> 00:57:22,640 and i'm going to hold the scroll probe 1558 00:57:22,640 --> 00:57:25,200 on the handship 1559 00:57:25,200 --> 00:57:27,359 and then i'll go ahead and 1560 00:57:27,359 --> 00:57:29,119 okay 1561 00:57:29,119 --> 00:57:31,520 and then you went ahead and generated a 1562 00:57:31,520 --> 00:57:33,520 lot of messages so 1563 00:57:33,520 --> 00:57:35,760 let me slow down the scope 1564 00:57:35,760 --> 00:57:38,960 and i'll do the kill again 1565 00:57:38,960 --> 00:57:40,319 and there you go there's there's your 1566 00:57:40,319 --> 00:57:43,200 message now what's cool about the 555 is 1567 00:57:43,200 --> 00:57:45,280 uh messages is that it's shorter i don't 1568 00:57:45,280 --> 00:57:46,400 know if you know 1569 00:57:46,400 --> 00:57:48,079 because it has a lot less stuff bits you 1570 00:57:48,079 --> 00:57:49,680 don't need stuff bits if every other bit 1571 00:57:49,680 --> 00:57:51,680 is different 1572 00:57:51,680 --> 00:57:52,480 uh 1573 00:57:52,480 --> 00:57:55,359 so let's do something i'll let's let's 1574 00:57:55,359 --> 00:57:57,520 i'll i'll uh 1575 00:57:57,520 --> 00:58:01,119 send i'm uh the kill 1576 00:58:04,000 --> 00:58:08,000 and we'll we'll ramp the the can data 1577 00:58:08,000 --> 00:58:10,160 so i'll select uh 1578 00:58:10,160 --> 00:58:11,200 six 1579 00:58:11,200 --> 00:58:12,640 and then there's different patterns you 1580 00:58:12,640 --> 00:58:15,119 can generate uh walking ones is pretty 1581 00:58:15,119 --> 00:58:16,160 cool 1582 00:58:16,160 --> 00:58:18,079 and that where it just 1583 00:58:18,079 --> 00:58:20,240 shifts a one through the can data every 1584 00:58:20,240 --> 00:58:23,240 frame 1585 00:58:34,480 --> 00:58:36,240 did you catch that this is where the 1586 00:58:36,240 --> 00:58:38,240 vehicle spy tool will come in handy to 1587 00:58:38,240 --> 00:58:41,119 see actually what it's doing 1588 00:58:41,119 --> 00:58:42,400 now just to show some of the other 1589 00:58:42,400 --> 00:58:44,240 features i'm not going to demo 1590 00:58:44,240 --> 00:58:45,359 uh 1591 00:58:45,359 --> 00:58:46,640 the uh 1592 00:58:46,640 --> 00:58:49,520 the can response refrigeration and what 1593 00:58:49,520 --> 00:58:51,680 this does is you can set up a can id and 1594 00:58:51,680 --> 00:58:53,920 that will trigger the arbitrary kill so 1595 00:58:53,920 --> 00:58:54,880 you can 1596 00:58:54,880 --> 00:58:58,240 transmit arbitrary kill so when it gets 1597 00:58:58,240 --> 00:59:01,599 342 it will trigger the kill 1598 00:59:01,599 --> 00:59:03,359 there is a bug with this version where 1599 00:59:03,359 --> 00:59:05,040 it actually kills the badge so it's kind 1600 00:59:05,040 --> 00:59:06,079 of like 1601 00:59:06,079 --> 00:59:08,400 suicide feature i guess 1602 00:59:08,400 --> 00:59:10,240 so the kill kills itself 1603 00:59:10,240 --> 00:59:12,160 uh but you can res you can just power 1604 00:59:12,160 --> 00:59:14,240 cycle the badge and it will it will do 1605 00:59:14,240 --> 00:59:16,640 it um and then there's a can monitor can 1606 00:59:16,640 --> 00:59:18,799 monitor is actually using the pio code i 1607 00:59:18,799 --> 00:59:21,520 just showed and it's uh you know it only 1608 00:59:21,520 --> 00:59:23,680 really decodes the can id at this point 1609 00:59:23,680 --> 00:59:25,119 and there's some issues with the data 1610 00:59:25,119 --> 00:59:27,599 but the data is correct it's just the 1611 00:59:27,599 --> 00:59:29,599 the decoding uh transiting the bit 1612 00:59:29,599 --> 00:59:31,440 stream into the can messages there's a 1613 00:59:31,440 --> 00:59:32,720 bug in it 1614 00:59:32,720 --> 00:59:34,240 anyway uh 1615 00:59:34,240 --> 00:59:36,480 that's pretty much the badge and uh if 1616 00:59:36,480 --> 00:59:37,920 you have any questions 1617 00:59:37,920 --> 00:59:40,079 i'm gonna be at the deaf or a def con 1618 00:59:40,079 --> 00:59:42,720 village on friday all day uh i might be 1619 00:59:42,720 --> 00:59:44,400 there some saturday i'm not sure 1620 00:59:44,400 --> 00:59:46,160 depending on what else is going on okay 1621 00:59:46,160 --> 00:59:47,599 just wrapping up here 1622 00:59:47,599 --> 00:59:49,040 uh 1623 00:59:49,040 --> 00:59:51,920 there's a company called canis labs 1624 00:59:51,920 --> 00:59:54,720 that had uh came up with the idea of 1625 00:59:54,720 --> 00:59:57,839 using the raspberry pi pico with can and 1626 00:59:57,839 --> 01:00:00,960 they made a couple of products one 1627 01:00:00,960 --> 01:00:03,200 is just the raspberry pi pico connected 1628 01:00:03,200 --> 01:00:04,799 to a transceiver 1629 01:00:04,799 --> 01:00:06,960 that's called can hack and then another 1630 01:00:06,960 --> 01:00:08,720 one it actually connects to a microchip 1631 01:00:08,720 --> 01:00:10,799 can controller so it can do 1632 01:00:10,799 --> 01:00:12,400 can bus and they have an api but they 1633 01:00:12,400 --> 01:00:16,400 support python very well uh the the cto 1634 01:00:16,400 --> 01:00:19,680 of canis labs uh ken dr ken tindall 1635 01:00:19,680 --> 01:00:23,599 uh he uh has ported their software and 1636 01:00:23,599 --> 01:00:25,920 he's did a number of talks about cyber 1637 01:00:25,920 --> 01:00:27,200 security online that are pretty 1638 01:00:27,200 --> 01:00:29,520 interesting in a lot of attacks 1639 01:00:29,520 --> 01:00:32,000 but he designed those attacks into his 1640 01:00:32,000 --> 01:00:34,640 pi pico code 1641 01:00:34,640 --> 01:00:37,200 what's awesome is that the his can hack 1642 01:00:37,200 --> 01:00:39,839 board is basically identical it's the pi 1643 01:00:39,839 --> 01:00:42,720 pico connected to a can pin so he ported 1644 01:00:42,720 --> 01:00:45,119 his software to the badge and it's 1645 01:00:45,119 --> 01:00:46,559 available for download so you can 1646 01:00:46,559 --> 01:00:48,400 generate different attacks from a camera 1647 01:00:48,400 --> 01:00:51,119 or a python replica so i encourage you 1648 01:00:51,119 --> 01:00:53,280 to learn more about 1649 01:00:53,280 --> 01:00:54,079 that 1650 01:00:54,079 --> 01:00:56,240 port as well as the different attacks 1651 01:00:56,240 --> 01:00:59,280 that badge can do uh so he's got some 1652 01:00:59,280 --> 01:01:01,440 research that he's done with it 1653 01:01:01,440 --> 01:01:03,440 so so please check that out it's really 1654 01:01:03,440 --> 01:01:06,000 really cool and a real great bonus for 1655 01:01:06,000 --> 01:01:08,640 for the badge 1656 01:01:09,520 --> 01:01:12,160 and finally uh conclusions 1657 01:01:12,160 --> 01:01:14,240 the rp2040 1658 01:01:14,240 --> 01:01:15,839 take a look at super interesting the 1659 01:01:15,839 --> 01:01:18,480 dual core cpu and the bit bang engine 1660 01:01:18,480 --> 01:01:19,920 the high clock rate which you can 1661 01:01:19,920 --> 01:01:21,680 probably overclock you probably do a lot 1662 01:01:21,680 --> 01:01:24,319 of uh destruction to digital protocols 1663 01:01:24,319 --> 01:01:26,480 everything's really digital protocol 1664 01:01:26,480 --> 01:01:29,520 uh now so like wireless all it is is 1665 01:01:29,520 --> 01:01:31,920 digital protocols you know in there and 1666 01:01:31,920 --> 01:01:33,839 they're on a carrier 1667 01:01:33,839 --> 01:01:36,240 and uh what's what's interesting about 1668 01:01:36,240 --> 01:01:38,240 engineering and where cyber security 1669 01:01:38,240 --> 01:01:40,400 happens is 1670 01:01:40,400 --> 01:01:42,559 people are testing things 1671 01:01:42,559 --> 01:01:45,520 but they don't test it to the point 1672 01:01:45,520 --> 01:01:47,200 where they need to it might be just 1673 01:01:47,200 --> 01:01:48,880 impossible it's just hard enough to get 1674 01:01:48,880 --> 01:01:50,480 things working these days so you ship 1675 01:01:50,480 --> 01:01:51,599 the product 1676 01:01:51,599 --> 01:01:53,440 and then maybe 10 years go by and then 1677 01:01:53,440 --> 01:01:54,960 you come around with something like this 1678 01:01:54,960 --> 01:01:56,799 and then you you interact with the 1679 01:01:56,799 --> 01:01:58,720 protocol in a way no one ever thought 1680 01:01:58,720 --> 01:02:01,039 and you can discover some interesting 1681 01:02:01,039 --> 01:02:03,359 you know zero days and things like that 1682 01:02:03,359 --> 01:02:04,960 so i think this is a real interesting 1683 01:02:04,960 --> 01:02:06,400 tool for any protocol 1684 01:02:06,400 --> 01:02:09,599 this is just an example on the can bus 1685 01:02:09,599 --> 01:02:10,640 so 1686 01:02:10,640 --> 01:02:12,400 you can use that cpu cycle accurate 1687 01:02:12,400 --> 01:02:16,400 eight nanoseconds you know or or less 1688 01:02:16,400 --> 01:02:17,839 and you don't have it's not like 1689 01:02:17,839 --> 01:02:20,319 cumbersome like an fpga 1690 01:02:20,319 --> 01:02:23,359 so you can do a lot of cool stuff and uh 1691 01:02:23,359 --> 01:02:25,440 can you do can bus with rp 2040 1692 01:02:25,440 --> 01:02:27,680 absolutely 1693 01:02:27,680 --> 01:02:28,960 uh 1694 01:02:28,960 --> 01:02:29,680 two 1695 01:02:29,680 --> 01:02:31,920 500 kilobit can bus you have 250 1696 01:02:31,920 --> 01:02:34,960 instructions between bits 1697 01:02:34,960 --> 01:02:36,480 now you would have to do it the exactly 1698 01:02:36,480 --> 01:02:39,920 opposite way as i did it so what i did 1699 01:02:39,920 --> 01:02:41,839 i used the cpu to do transmission 1700 01:02:41,839 --> 01:02:43,680 because the arbitrary transmission was 1701 01:02:43,680 --> 01:02:45,680 the main feature of the badge and then i 1702 01:02:45,680 --> 01:02:49,280 used the pio to do reception 1703 01:02:49,280 --> 01:02:51,520 actually the opposite will work or use 1704 01:02:51,520 --> 01:02:53,599 cpu to do reception because then you can 1705 01:02:53,599 --> 01:02:56,319 do things like decode the can bus data 1706 01:02:56,319 --> 01:02:58,319 length 1707 01:02:58,319 --> 01:02:59,760 generate the 1708 01:02:59,760 --> 01:03:00,559 uh 1709 01:03:00,559 --> 01:03:02,640 generate the uh 1710 01:03:02,640 --> 01:03:04,240 acknowledgement in the proper location 1711 01:03:04,240 --> 01:03:06,000 things like that which you really need 1712 01:03:06,000 --> 01:03:07,520 you really need to keep track of numbers 1713 01:03:07,520 --> 01:03:10,000 and do some math uh but the pio 1714 01:03:10,000 --> 01:03:12,720 absolutely can do transmission uh 1715 01:03:12,720 --> 01:03:13,839 and they they're 1716 01:03:13,839 --> 01:03:16,000 they're totally independent processes so 1717 01:03:16,000 --> 01:03:18,000 you can transmit with 1718 01:03:18,000 --> 01:03:19,920 the 1719 01:03:19,920 --> 01:03:20,720 um 1720 01:03:20,720 --> 01:03:22,880 with the pio while you're receiving with 1721 01:03:22,880 --> 01:03:25,920 the cpu and you can do arbitration by 1722 01:03:25,920 --> 01:03:26,720 just 1723 01:03:26,720 --> 01:03:28,240 checking the bits if you put it on the 1724 01:03:28,240 --> 01:03:30,640 bus not there he stopped so it's totally 1725 01:03:30,640 --> 01:03:33,280 possible uh um i don't i don't know 1726 01:03:33,280 --> 01:03:36,000 about can fd i i uh there's some bit 1727 01:03:36,000 --> 01:03:38,559 time changes and stuff like that 1728 01:03:38,559 --> 01:03:41,119 i i would have to say you know i only 1729 01:03:41,119 --> 01:03:42,640 spent like a few days with this and 1730 01:03:42,640 --> 01:03:44,240 there's a lot of creative ways to use 1731 01:03:44,240 --> 01:03:47,359 the cpu and to use pio 1732 01:03:47,359 --> 01:03:48,960 so i think 1733 01:03:48,960 --> 01:03:50,880 you know someone with a lot of time and 1734 01:03:50,880 --> 01:03:53,200 talent probably could do a lot with this 1735 01:03:53,200 --> 01:03:54,960 anyway in the hopefully the conclusion 1736 01:03:54,960 --> 01:03:56,720 is a chv badge 1737 01:03:56,720 --> 01:03:58,880 that intrepid has designed 1738 01:03:58,880 --> 01:04:01,200 uh it's pretty awesome and maybe i would 1739 01:04:01,200 --> 01:04:02,400 like to think it was one of the best 1740 01:04:02,400 --> 01:04:05,359 badges at least in terms of functionally 1741 01:04:05,359 --> 01:04:07,680 what it can do uh and it's a great value 1742 01:04:07,680 --> 01:04:09,760 so i hope you get pick one up we made a 1743 01:04:09,760 --> 01:04:12,400 ton of them in our factory and uh in 1744 01:04:12,400 --> 01:04:15,200 troy uh so please uh 1745 01:04:15,200 --> 01:04:17,119 take a look and uh i would be great to 1746 01:04:17,119 --> 01:04:19,119 meet you in person and answer any of 1747 01:04:19,119 --> 01:04:22,640 your questions in the village 1748 01:04:22,799 --> 01:04:25,280 or contact me on twitter or linkedin and 1749 01:04:25,280 --> 01:04:27,359 um if you're super talented you know a 1750 01:04:27,359 --> 01:04:29,760 trap is always hiring so that's that and 1751 01:04:29,760 --> 01:04:31,119 put the plug in 1752 01:04:31,119 --> 01:04:34,880 but enjoy uh con enjoy vegas and 1753 01:04:34,880 --> 01:04:38,160 have a good trip home