WEBVTT

00:00.000 --> 00:13.760
Thank you. Good afternoon. As Paul said, my name is Eric. Short version. McGeeck, I used

00:13.760 --> 00:18.960
quite a few different systems over the years. However, I've only started doing embedded

00:18.960 --> 00:24.960
software development less than a year ago. It started when Apple back in May published

00:24.960 --> 00:31.680
the opening of the embedded Swift GitHub repository with the examples to go look at that.

00:31.680 --> 00:38.720
So, if you want to talk embedded Swift, let's talk Swift. Swift was introduced in 2014.

00:38.720 --> 00:43.680
First, as a successor to Objective C, for developing for the Apple platforms.

00:43.680 --> 00:47.360
That very soon afterwards, it was made up in sales. It was available on Linux.

00:48.000 --> 00:52.960
Nowadays, it's available on macOS, several folders of Linux, Windows.

00:53.840 --> 00:59.520
It's used for scripting, for server-side development, for serverless function

00:59.520 --> 01:04.640
implementation, or some of the talk this afternoon will be short. But in terms of embedded

01:04.640 --> 01:10.800
systems, there was very little. There was just a few community project, but that's it.

01:11.600 --> 01:18.720
So, why is that? Well, it's good embedded. Embedded systems are all over daily lives.

01:18.720 --> 01:22.720
Yet it's quite difficult to find a definition. We might say that it's

01:22.720 --> 01:29.840
dedicated hardware for specific functionality, yet it doesn't go well everything. So, in this case,

01:29.840 --> 01:37.360
what we'll say is that it is also hardware is limited functionality. So, a Raspberry Pi,

01:37.360 --> 01:46.320
or an Apple Watch, wouldn't qualify as embedded in this scope. So, let's further compare

01:46.400 --> 01:53.440
and see the limitations and compare on our F52840, which is a mid-level microcontroll chip,

01:53.440 --> 01:57.200
to an Apple Watch series zero. So, the original one from many 10 years ago.

01:58.080 --> 02:03.200
If you look at the processor, we got a single core 30-to-bit versus a single core 64-bit,

02:03.200 --> 02:09.760
no big deal. Clock speed, we're talking 64 megahertz versus 420 megahertz. So, we'll already see

02:09.760 --> 02:18.000
an 8 times difference there. In terms of RAM, we're talking 266 kilo-bite versus 512 mega-bites.

02:18.000 --> 02:24.560
So, that's 2,000 times difference. And in flash, we're talking 1 mega-bite versus 8 kilo-bite. So,

02:24.560 --> 02:29.920
that's 8,000x. So, different beasts. So, we see that if we want to bring swift

02:29.920 --> 02:34.640
to the limited systems, we need to reduce the runtime overhead, we need to reduce the

02:34.640 --> 02:41.600
limited footprint and the total activity group code size. And so, embedded swift is Apple's

02:41.600 --> 02:46.480
official answer to this problem. It's a subset of swift, not the dialect. So, it is swift,

02:46.480 --> 02:52.480
but with some limitations. And basically, it adds a compilation mode that adds constraint

02:52.480 --> 02:57.920
to achieve the way that you should go, is that I just mentioned. How does it do it? Well,

02:58.000 --> 03:04.800
do you see basically everything that's dynamic at runtime? So, there is no dynamic reflection,

03:04.800 --> 03:11.280
no existential types, the generic instantiation at runtime is not possible. Of course, no

03:11.280 --> 03:18.320
objective to interrupt, but it is runtime and do dynamic code loading. Also, at runtime,

03:18.320 --> 03:25.920
all I agree is quite minim, mostly concerned about memory, allocation and management. There is no need

03:26.080 --> 03:32.160
to bundle the metadata either, because the runtime wouldn't use it. The swift style library

03:32.160 --> 03:38.000
also has some limitations. So, no credible available in embedded space. And then the compiler

03:38.000 --> 03:44.160
will perform aggressive debt code stripping. How does it look in practice? Well, we add

03:44.800 --> 03:49.520
three flags to the combination first, the target, which brought are we compounding to,

03:50.080 --> 03:55.520
then we enable the embedded feature, which is still experimental to this day, and we have

03:55.520 --> 04:04.400
the WMO flag, which is for optimization. And as of 50, the manual puts it, so embedded swift

04:04.400 --> 04:10.240
is a compilation mode that would, basically, as a sick compiler would do project, project,

04:10.240 --> 04:15.600
produce object files that would later be linked with the rest of your code, so that would be

04:15.600 --> 04:21.920
see assembly or the libraries that you're using. And that linking is done by the target to

04:21.920 --> 04:26.560
be changed, so it's very little about embedded swift is concerned with the linking.

04:28.400 --> 04:33.280
Enough talking, let's see that, let's get started. So, if you want to get started, you need to pick

04:33.280 --> 04:42.640
a board, the embedded swift examples from Apple, Duke of the Civil Birds, with risk 5 or ARM architecture,

04:42.640 --> 04:48.320
the help source and project on the panic played or the future zero, etc. Just pick one,

04:48.320 --> 04:52.240
don't do as I did, and buy everything that's available, you just pick one of them.

04:54.000 --> 04:59.200
For reasons that are not really relevant to this talk, I went with Nordics, so we connect this chip.

05:00.080 --> 05:04.560
And then when you do that, I would recommend that the fourth thing you do is install the target

05:04.560 --> 05:10.480
to change the target libraries without thinking about swift at this stage. So, just make sure that

05:10.560 --> 05:18.640
you can compile and build and flush your board. In the case of the RF Connectors Decay,

05:18.640 --> 05:26.560
this comes also with a handy video studio code extension. And so, use that and use some of their

05:26.560 --> 05:32.560
examples and make sure that you can build and flush the board in this works. And then you can move

05:32.560 --> 05:38.160
to the embedded swift examples. I would start from the repository that Apple published. You go

05:38.160 --> 05:44.720
there and you find the project that is appropriate for your board. It is the help of the embedded

05:44.720 --> 05:51.520
works of blinking and LED for the RF chip. And one of the fourth thing that you really will tell

05:51.520 --> 05:58.320
you is to download the latest 90 tuition of swift. So, you go to the website and that's the same

05:59.200 --> 06:04.240
side that I showed you, but there is a section below that says development snapshots and that's the

06:04.240 --> 06:10.880
one you will want because the current mainstream doesn't yet flush the boards. And then you

06:10.880 --> 06:17.440
follow the really file typing all the commands, making sure that you select the tool shown that

06:17.440 --> 06:25.920
you just installed. And if everything goes well, you go to blinking LED. Hey! And so,

06:26.160 --> 06:34.320
I don't know about you, but typing these kinds of commands in a terminal is not the ideal

06:34.320 --> 06:39.920
development. So, one of the next step that I did was make sure that I set up a purple environment.

06:40.800 --> 06:46.240
And there's a bit of jumping through hoops, but basically it's using the RF connected SDK

06:46.240 --> 06:51.840
in the SDS code, the swift extension in the SDS code. And so, I can do code completion and I can

06:51.840 --> 06:58.960
use a single click, build flash, and I can connect to the board and see the console logs of the board.

06:58.960 --> 07:06.240
So, that makes for much easier experience. With that in place, we can start growing from the

07:06.240 --> 07:12.720
embedics with the examples and creating a project from there. So, let's take a look at the embedics with

07:12.720 --> 07:19.440
examples. It's time like a normal C file is the main function, etc. So, like swift files is the main

07:19.440 --> 07:25.040
function, but then it got GPIO pink of your DTE LED zero, which is not really swift, which is

07:25.840 --> 07:31.280
as it's coming from. Well, from the bridging header that's H, which is a stand-up C header,

07:31.280 --> 07:38.960
header file, which is used by the swift C interrupt interrupt. So, and then we can see that it includes

07:38.960 --> 07:45.920
the header files for the SDK. So, ZF here is a written-up and existing on which RF connect is based.

07:46.000 --> 07:51.840
And we see the static variable declared in C, or LED zero, which basically represents the

07:51.840 --> 07:57.280
beginning to which the LED is connected. So, that makes a bit more sense. But still, it doesn't

07:57.280 --> 08:02.160
look very swift to me, that's just using swift as a blue curve to see. That's not what we want.

08:03.440 --> 08:10.000
So, what we would like is encapsulate those sequels into a swift struct. So, that's what we do.

08:10.000 --> 08:16.400
We just have an initializer. And as you can see, we are using some unsafe something,

08:16.400 --> 08:22.400
unsafe portal, and there is a 10-F unsafe type in swift to do money and money management.

08:22.400 --> 08:26.800
And when you do embedded system, you will need to get acquainted with those.

08:26.800 --> 08:32.160
And then we have just a method to toggle the LED, and we can rewrite or main curve into

08:32.160 --> 08:40.160
something that is much more swift. Once it is skipped, until now, is error management.

08:40.160 --> 08:45.760
So, let's do that. We create a name to represent the L, and we make the initializer

08:45.760 --> 08:53.360
throwing, and we get a compilation L. Fortunately, the compiler is quite explicit. It says that

08:54.560 --> 09:00.960
we have a close, close, and close is the same as true, any L. Any is an extension,

09:00.960 --> 09:08.160
an extension, an edge part, so we need to do something. 14 here, so we have 66 introduced the

09:08.160 --> 09:15.680
type throw, so we just declare the type that we throw, and it fixes our issue. And you just keep

09:15.680 --> 09:22.800
going like that, encapsulating what you need from the SDK. And until you get to something like this,

09:22.800 --> 09:28.240
for instance, where we have a button that uses generic, generic specification that compiles down

09:28.240 --> 09:34.960
us fine. We have a training trader to do the handler, and so we can we can go further like that.

09:34.960 --> 09:40.560
And I did go a bit further, we said a project, there are all open source, so if you want to go

09:40.560 --> 09:46.720
on GitHub, you can find the helpful for all of them, and you can explore what it is. So that's an

09:46.800 --> 09:56.160
arch reactor. And contact each other there, please reach out, and you can also try to post

09:56.160 --> 10:02.000
quite often on the board on the blog. Thank you very much.

