WEBVTT

00:00.000 --> 00:09.000
All right, we have our second talk ready for the day.

00:09.000 --> 00:16.000
This is Marcell, this wheeler is going to talk about rust with risk five, which is very

00:16.000 --> 00:19.000
exciting and new topics.

00:19.000 --> 00:23.000
So, yeah, please give it up.

00:23.000 --> 00:30.000
Good morning, folks.

00:30.000 --> 00:34.000
No, I think it's fine.

00:34.000 --> 00:39.000
I'm not wrong.

00:39.000 --> 00:49.000
I'm Marcell, I joined Coat Think in 2024, and I'm a senior software engineer there.

00:49.000 --> 00:56.000
I've right in, I first show you the hardware with the microcontroller I'm using here.

00:56.000 --> 01:03.000
It's actually from a Chinese company, Nanjing, Queen Heng, microelectronics.

01:03.000 --> 01:09.000
Those guys are basically behind the WCH, the Winchip Head brand.

01:09.000 --> 01:18.000
They're founded in 2004, and so this control is a 32-bit channel purpose risk five, microcontroller.

01:19.000 --> 01:23.000
And it has a Queen K, 32-bit risk five.

01:23.000 --> 01:30.000
They call it V2A, processor, which supports a two-level D-pin drop nesting,

01:30.000 --> 01:38.000
and it can run up to 48 megahertz, has 2K SRAM 16K flash.

01:38.000 --> 01:45.000
And the cool thing is it can be run from 3.3 or 5 volts,

01:45.000 --> 01:53.000
so it has a white multi-chranged there, and also supports multiple low power modes,

01:53.000 --> 01:57.000
sleep standby, all that good stuff.

01:57.000 --> 02:04.000
Then it has some peripherals included, like, you see there,

02:05.000 --> 02:10.000
user, d-square-c-s-s-p-i-s of like that.

02:10.000 --> 02:18.000
Some timers, it has up to 18 GP-i-os, they also call it IO ports,

02:18.000 --> 02:25.000
and in the table down here you see what actual port numbers you can get.

02:25.000 --> 02:32.000
Also, it is industrial grade minus 40 to 85 degrees.

02:32.000 --> 02:38.000
And I also checked there are English data sheets available, actually pretty comprehensive.

02:38.000 --> 02:42.000
So from that point of view, also quite good.

02:42.000 --> 02:46.000
Let's have a look at the core that runs in this chip.

02:46.000 --> 02:50.000
It actually implements the RV32 EMC.

02:50.000 --> 02:53.000
Instruction set.

02:53.000 --> 03:01.000
E is an alternative extension for all this, like real chip, low power chips.

03:01.000 --> 03:06.000
And it's almost identical to the regular one, the RV32i,

03:06.000 --> 03:11.000
but it's missing 16 of the general purpose registers.

03:11.000 --> 03:18.000
So that is the big difference that they do that, I guess, for cost-reason.

03:18.000 --> 03:22.000
This extension is still kind of influx.

03:22.000 --> 03:27.000
That's also why official support for it is not fully there.

03:27.000 --> 03:36.000
So you have to, like, on the wrong side, you have to use nightly stuff.

03:36.000 --> 03:39.000
I'm not going to go through more of the details.

03:39.000 --> 03:44.000
There is also an English manual available for the core itself.

03:44.000 --> 03:48.000
This is the hardware, I have here.

03:48.000 --> 03:53.000
They call it an EVT engineering validation test port.

03:53.000 --> 03:58.000
So it has USB-C, just to power it.

03:58.000 --> 04:06.000
And alternatively, in my case here, I actually power it by the debug probe.

04:06.000 --> 04:09.000
Also the schematic's available.

04:09.000 --> 04:17.000
The debug probe is a little USB tunnel that actually it has two modes,

04:17.000 --> 04:23.000
even, it has a so-called RV mode for risk-5, debugging and downloading.

04:23.000 --> 04:29.000
And it alternatively would also support the ARM SWDJ tag mode.

04:29.000 --> 04:32.000
So that's the same probe.

04:32.000 --> 04:39.000
You actually have to run another firmware on it, but it could run in both boats.

04:39.000 --> 04:45.000
For the rust side, you can use a W link.

04:45.000 --> 04:50.000
It's the command line tool in rust that you can run with it.

04:50.000 --> 04:55.000
But of course, much more familiar for the embedded guys.

04:55.000 --> 04:59.000
It's usually used probe RS, which also supports it.

04:59.000 --> 05:03.000
It's the Factor embedded tool kit.

05:04.000 --> 05:09.000
And yeah, it's cheap micros, not the full kit.

05:09.000 --> 05:16.000
With the board on this probe, you can get for like seven and a half bucks on all the express.

05:16.000 --> 05:20.000
This is when you plug in the probe.

05:20.000 --> 05:28.000
So it also has a separate TTIACM-0, so it can do like a separate serial port.

05:28.000 --> 05:35.000
That is kind of can be quite handy when you debugging stuff.

05:35.000 --> 05:39.000
There are also other similar ports available, very cheap.

05:39.000 --> 05:42.000
For example, the 10-star robot stuff.

05:42.000 --> 05:45.000
It's more like a Raspberry Pi pick up things.

05:45.000 --> 05:52.000
10-C-style, or a little bit more advance, for example, the one from Mini2.

05:52.000 --> 06:03.000
That one has actually the UART directly integrated, so you have on the USB-C also the UART.

06:03.000 --> 06:05.000
So how does the embedded tooling look like?

06:05.000 --> 06:11.000
There is this W link, command line tool that allows you to flash firmware,

06:11.000 --> 06:18.000
and basically steps through and look at your target.

06:18.000 --> 06:23.000
Read right the registers, stuff like that.

06:23.000 --> 06:26.000
This is how you install it.

06:26.000 --> 06:29.000
You just call it installed W link.

06:29.000 --> 06:33.000
Then you can list your probes that you have connected.

06:33.000 --> 06:40.000
You can get the status from your chips, stuff like that.

06:40.000 --> 06:45.000
And you can look at the status of basically dump all the registers.

06:45.000 --> 06:58.000
And here you can see the terminal purpose registers X0 to X15, so we only have 16 of them.

06:58.000 --> 07:03.000
Then progress, it's basically the fact to standard.

07:03.000 --> 07:08.000
When you do embedded stuff with RAS node, it's very user friendly.

07:08.000 --> 07:15.000
And yeah, it supports, basically it's direct integration with cargo node,

07:15.000 --> 07:18.000
so you can call it cargo flash.

07:18.000 --> 07:24.000
And if you have it configured, you can basically just run cargo run on your host target,

07:24.000 --> 07:28.000
and it does all that behind the scenes node.

07:28.000 --> 07:35.000
So you install it's called probars tools.

07:36.000 --> 07:42.000
So embedded RAS, there is a RAS embedded device working group.

07:42.000 --> 07:49.000
They basically build an economic and composable ecosystem for us developers

07:49.000 --> 07:52.000
to work on embedded with RAS.

07:52.000 --> 07:58.000
It has basically two important parts are the peripheral access grades,

07:58.000 --> 08:04.000
so that's basically how would you access hardware peripheral registers,

08:04.000 --> 08:08.000
so that is basically the way that is standard nowadays.

08:08.000 --> 08:12.000
It uses machine readable hardware definition,

08:12.000 --> 08:17.000
and that is called system view description, SVD format.

08:17.000 --> 08:22.000
And then there is tooling, it's called SVD to RAS,

08:22.000 --> 08:27.000
that basically automatically converts that then for API,

08:27.000 --> 08:30.000
so you can access your peripherals.

08:31.000 --> 08:37.000
And in the winchy pad case, this is distributed as part of the eclipse,

08:37.000 --> 08:43.000
derived ID, their own ID, it's called Mount River Studio,

08:43.000 --> 08:50.000
and in that ID, when you install that, you then get all this SVD files.

08:50.000 --> 08:57.000
And basically, yeah, we took the SVD files and generated through SVD to RAS,

08:57.000 --> 09:01.000
and you get all that tooling.

09:01.000 --> 09:05.000
And then, of course, there is also the hardware abstraction layer,

09:05.000 --> 09:11.000
so on top of that, you basically define traits

09:11.000 --> 09:14.000
that for common peripheral functionality this way,

09:14.000 --> 09:18.000
you can then really use a high-level drivers

09:18.000 --> 09:21.000
that can depend on that stuff.

09:21.000 --> 09:24.000
So you get interfaces for different peripheral types,

09:24.000 --> 09:28.000
like GPS, time, and spaces, things like that,

09:28.000 --> 09:32.000
that's your hardware has not.

09:32.000 --> 09:37.000
And of course, trying to make sure that those abstractions

09:37.000 --> 09:41.000
are like zero costs, so there isn't much overhead,

09:41.000 --> 09:46.000
and also that it models the differences of certain chips

09:46.000 --> 09:51.000
reasonably well.

09:51.000 --> 09:58.000
Okay, then what does that mean in the WCHCH32v-003 case?

09:58.000 --> 10:04.000
If you want to use that with Rust, there is an embedded hull,

10:04.000 --> 10:10.000
so this hardware abstraction layer available as part of the CH32RS project

10:10.000 --> 10:13.000
that you find that on GitHub.

10:13.000 --> 10:19.000
Actually, I also have all the resources in the slide at the end of the tick.

10:20.000 --> 10:26.000
So that is the same project where also that WCHCH tooling came from.

10:26.000 --> 10:33.000
And like I mentioned earlier, it requires Rust nightly,

10:33.000 --> 10:38.000
the embedded hull stuff, because it uses some features

10:38.000 --> 10:42.000
that are not yet in regular kind of stable.

10:42.000 --> 10:45.000
So that's how you configure that.

10:45.000 --> 10:50.000
And then you also need the sources of standard library

10:50.000 --> 10:54.000
to build some core pieces later on.

10:59.000 --> 11:05.000
Then one thing you need is, do you need the target specification file

11:05.000 --> 11:08.000
for your controller?

11:08.000 --> 11:17.000
Okay, it's this risk-532EC on-down health stuff,

11:17.000 --> 11:21.000
not this is basically not integrated yet.

11:21.000 --> 11:29.000
That is like I mentioned earlier, this kind of simpler variant

11:29.000 --> 11:37.000
of the risk-5 stuff that you can basically force that on your side

11:37.000 --> 11:39.000
with an abstraction JSON file, not.

11:39.000 --> 11:43.000
So here is specify what architecture it is,

11:43.000 --> 11:49.000
and what the data layout is, and all these kind of details.

11:49.000 --> 11:55.000
So one day maybe that in the future that will be basically integrated

11:55.000 --> 12:02.000
and you would not have to manually do that like that, not.

12:02.000 --> 12:07.000
Then you also use a cargo configuration file,

12:07.000 --> 12:13.000
where you then specify that you actually want to use this special target.

12:13.000 --> 12:18.000
So here you point to that JSON, different from before.

12:18.000 --> 12:25.000
And then also here you can tell it when it would run stuff,

12:25.000 --> 12:30.000
that it uses pro-barrass and which chip it's going to use there.

12:30.000 --> 12:40.000
So that's how you link, make the link basically to the hardware again.

12:40.000 --> 12:47.000
Then you have also some dependencies and profile settings in your cargo tomel.

12:47.000 --> 12:56.000
So you basically have to use there, for example, the crate for that core,

12:56.000 --> 13:01.000
not the crinkierty and crinkiest stuff.

13:01.000 --> 13:07.000
Then we use embedded hull, remember that actually got the one O release.

13:07.000 --> 13:11.000
I think some a little bit more than a year ago.

13:11.000 --> 13:15.000
And that's basically that.

13:15.000 --> 13:23.000
And now let's have a look how you can, for example, link an LED.

13:24.000 --> 13:27.000
That's the finally do that.

13:27.000 --> 13:35.000
It uses the delay, how that you can later do, for example, a delay.

13:35.000 --> 13:40.000
So you can blink it in a certain timed way, not.

13:40.000 --> 13:45.000
You also use the cheap IO abstraction.

13:46.000 --> 13:51.000
And of course, as the hardware abstraction layer itself,

13:51.000 --> 13:55.000
you use the CH32 flavor pair of.

13:55.000 --> 13:59.000
And also specified the panning called stuff.

13:59.000 --> 14:05.000
So basically on the microcontroller, you cannot do much more as just halt.

14:05.000 --> 14:10.000
If you would hit some kind of a panic situation not.

14:10.000 --> 14:16.000
Then for the crinkierty core, you basically specify the entry point.

14:16.000 --> 14:24.000
So that your main basically, yeah, is the entry point for the microcontroller, not.

14:24.000 --> 14:31.000
And here you just configure the hardware abstraction layer.

14:31.000 --> 14:35.000
And you assign the peripherals.

14:35.000 --> 14:40.000
And then you can basically specify an output pin.

14:40.000 --> 14:43.000
So the LED is an output pin.

14:43.000 --> 14:47.000
And you can give it the actual port there.

14:47.000 --> 14:49.000
So it's the port D6.

14:49.000 --> 14:55.000
So that will be a particular pin of your microcontroller, not what levels you want.

14:55.000 --> 15:00.000
And then basically you go into your main loop.

15:00.000 --> 15:02.000
That is very bare metal.

15:02.000 --> 15:06.000
And you can do all your work in the main loop there.

15:06.000 --> 15:09.000
In this case, we just toggle the LED.

15:09.000 --> 15:13.000
And we wait another second.

15:13.000 --> 15:16.000
OK.

15:16.000 --> 15:20.000
That would look like when you run it.

15:20.000 --> 15:23.000
Like I said, you can just cargo around and under the hood.

15:23.000 --> 15:31.000
We'll do all that called ProBoris and through the debug probe.

15:31.000 --> 15:39.000
It basically erases the flash, flashes it in and runs it in.

15:39.000 --> 15:42.000
Then the last piece, of course, you don't really want to do that.

15:42.000 --> 15:44.000
Maybe on the command line.

15:44.000 --> 15:46.000
But you want it in a ID.

15:46.000 --> 15:51.000
So let's have a look how one can do that.

15:51.000 --> 15:54.000
For example, with VS code.

15:54.000 --> 15:59.000
Of course, if you want to use VS code for rough development,

15:59.000 --> 16:01.000
you install a few things.

16:01.000 --> 16:07.000
Like for example, the Rostanalyzer and for the embedded stuff.

16:07.000 --> 16:13.000
There is also an extension for the ProBoris debugger.

16:13.000 --> 16:19.000
And then I hit a few more issues, of course.

16:19.000 --> 16:22.000
I'm actually on a Fedora Silver blue.

16:22.000 --> 16:29.000
So this is an atomic distribution node, where you usually run stuff in flat packs.

16:29.000 --> 16:33.000
So it runs in a sandbox environment.

16:33.000 --> 16:42.000
And of course, then you have the problem when you now want to run things like the debug probe.

16:42.000 --> 16:45.000
There is no connection, basically.

16:45.000 --> 16:50.000
The sandbox cannot get to that host tools, not.

16:50.000 --> 16:52.000
How can that be done?

16:52.000 --> 16:56.000
That's basically where the dev containers come in handy.

16:56.000 --> 17:05.000
So VS code has a mode, where you basically can, in the background, spawn a container,

17:05.000 --> 17:10.000
and anything that VS code would do on your host.

17:10.000 --> 17:14.000
It does it basically in that container.

17:14.000 --> 17:20.000
So this way you can have your whole environment.

17:20.000 --> 17:24.000
Basically, for example, in the toolbox container in my case,

17:24.000 --> 17:27.000
I usually use a toolbox container.

17:27.000 --> 17:31.000
You can have that all configured the way to your liking, not,

17:31.000 --> 17:35.000
including the tools that I mentioned earlier,

17:35.000 --> 17:39.000
that you install it all in that toolbox container.

17:39.000 --> 17:44.000
And then in VS code, you can configure that.

17:44.000 --> 17:49.000
You have to configure Docker path and the Docker socket path.

17:49.000 --> 17:54.000
Like I show here in the settings chasin for the Docker path,

17:54.000 --> 18:00.000
I basically use a wrapper script that potman hosting.

18:00.000 --> 18:05.000
And as the socket path, you use the potman socket.

18:05.000 --> 18:09.000
And one thousand there, that's just the user ID.

18:09.000 --> 18:15.000
So should you use another one, you would have to adjust it accordingly.

18:15.000 --> 18:22.000
And then like I said, the wrapper script is just basically calling flatpack spawn.

18:22.000 --> 18:26.000
That's basically the way you can, from the sandbox,

18:26.000 --> 18:30.000
from spawn stuff, not.

18:30.000 --> 18:34.000
And then another piece of the puzzle is, of course,

18:34.000 --> 18:38.000
that the permission that you can actually access,

18:38.000 --> 18:42.000
you reuse be stuff, not from the container.

18:42.000 --> 18:48.000
One way to go about that, usually is, why are the so-called block dev in Linux,

18:48.000 --> 18:53.000
not? So you have to find out in VS code,

18:53.000 --> 18:57.000
when that content runs, what actually user,

18:57.000 --> 19:01.000
it runs as not on the native host site.

19:01.000 --> 19:05.000
And you can do that, for example, by when you're in VS code,

19:05.000 --> 19:10.000
in the terminal there, that runs in that dev container.

19:10.000 --> 19:14.000
You can spawn a sleep thousand, not like I show here.

19:14.000 --> 19:20.000
And then outside, you can have a look with the, with PS,

19:21.000 --> 19:24.000
what number that is using, not.

19:24.000 --> 19:28.000
And then you can, in your Etsy group, just configure that

19:28.000 --> 19:34.000
for the, to give it block dev access, not.

19:34.000 --> 19:39.000
Alternatively, one thing you can do, you can run the whole container

19:39.000 --> 19:43.000
privileged, not.

19:43.000 --> 19:48.000
And the way you can do that is, for the dev container stuff,

19:48.000 --> 19:52.000
also find in, in VS code, in the configuration,

19:52.000 --> 19:55.000
a JSON file for that, not.

19:55.000 --> 19:59.000
And in that, you can, on the bottom, you see that,

19:59.000 --> 20:07.000
you can use privileged and disable all the security label stuff.

20:07.000 --> 20:11.000
I mean, it's kind of a little bit harsh, but that way,

20:11.000 --> 20:15.000
if you have any kind of hardware stuff that you would want to access,

20:16.000 --> 20:19.000
do it that way, you know.

20:19.000 --> 20:23.000
Okay, that's basically it, and I always, at the end,

20:23.000 --> 20:27.000
also show a quick live demo.

20:27.000 --> 20:30.000
In this case, you can maybe see it here.

20:30.000 --> 20:34.000
I have one of these tunnels configured, and it is connected

20:34.000 --> 20:39.000
to such a controller, and it has a little LED, not.

20:39.000 --> 20:41.000
So let's have a look.

20:41.000 --> 20:46.000
I had a VS code, unfortunately, it might be a little bit small,

20:46.000 --> 20:52.000
but on the left side, you basically, in this case,

20:52.000 --> 20:55.000
in, you have the dev container.

20:55.000 --> 20:59.000
So it all, basically, runs now in the background

20:59.000 --> 21:04.000
that dev container, that you also get the output down here.

21:04.000 --> 21:09.000
And I have now, basically, the code here.

21:10.000 --> 21:14.000
I suggest that it actually one can see that it also

21:14.000 --> 21:15.000
something changes.

21:15.000 --> 21:18.000
I changed the delay to 10 seconds.

21:18.000 --> 21:22.000
So right now, the LED is not like perceived blinking,

21:22.000 --> 21:25.000
because it's very slowly blinking, basically.

21:25.000 --> 21:29.000
I change it back to one second, and I can just, in VS code,

21:29.000 --> 21:31.000
hit the wrong button here.

21:31.000 --> 21:36.000
One can see down here that it calls pro bar S,

21:36.000 --> 21:39.000
and basically downloads the stuff.

21:39.000 --> 21:43.000
And we can now see that the LED is blinking in,

21:43.000 --> 21:47.000
like, one second cadence.

21:47.000 --> 21:48.000
OK?

21:48.000 --> 21:51.000
That's basically it.

21:51.000 --> 21:56.000
And we have a few minutes for questions if there are any.

21:56.000 --> 21:58.000
So go ahead.

21:59.000 --> 22:08.000
Thank you.

22:08.000 --> 22:12.000
Any questions?

22:12.000 --> 22:15.000
Can you try for a minute?

22:15.000 --> 22:19.000
Yeah, that's a good question, of course.

22:19.000 --> 22:24.000
On some of the stuff I ran before, we use

22:24.000 --> 22:29.000
something stuff, but I have to admit on this one, I have not tried it.

22:29.000 --> 22:35.000
But yeah, I think it's mainly the space reason.

22:35.000 --> 22:40.000
I have a very basic question, like you're using delay here.

22:40.000 --> 22:43.000
Is the micro control sleeping when you're using delay?

22:43.000 --> 22:45.000
Is it on?

22:45.000 --> 22:51.000
When you use delay, is it sleeping or not?

22:51.000 --> 22:53.000
At a delay, how?

22:53.000 --> 22:56.000
That's a good question.

22:56.000 --> 22:57.000
Yeah?

22:57.000 --> 23:03.000
I think it will probably do, what is it?

23:03.000 --> 23:12.000
The WMI thing here, that will basically sleep, not.

23:12.000 --> 23:17.000
It's not that complicated, not.

23:17.000 --> 23:26.000
That.

23:26.000 --> 23:28.000
The entry point that you have.

23:28.000 --> 23:32.000
Normally, I think I recall that the entry point is from the

23:32.000 --> 23:36.000
Crayed Risk VRT, and you are using something else.

23:36.000 --> 23:38.000
Why is that?

23:38.000 --> 23:41.000
Like the decoration above the main.

23:41.000 --> 23:43.000
Ah, we can go back, sorry.

23:43.000 --> 23:56.000
Which one do you mean?

23:56.000 --> 24:03.000
At the entry point, well, it is basically the reason it's done is that

24:03.000 --> 24:08.000
Embedded hull can maybe do some set-up stuff, and then it will

24:08.000 --> 24:11.000
call your main stuff, you know what I mean?

24:11.000 --> 24:15.000
So the might be some kind of code that runs before, and that's how

24:15.000 --> 24:18.000
we complicated that one.

24:18.000 --> 24:26.000
Oh, that time, I'm not sure, I would have to check.

24:26.000 --> 24:31.000
Why do you need the mic?

24:31.000 --> 24:36.000
Yeah, I think it's because.

24:36.000 --> 24:38.000
Yeah, so that.

24:38.000 --> 24:40.000
Ah, yeah, of course.

24:40.000 --> 24:44.000
Why we use this JSON file for the target?

24:44.000 --> 24:45.000
Yeah.

24:45.000 --> 24:46.000
That's like I explained.

24:46.000 --> 24:49.000
It uses this kind of special.

24:49.000 --> 24:53.000
It's not a RBE32I.

24:53.000 --> 25:08.000
Yeah, I mean, to be honest, I'm not sure.

25:08.000 --> 25:11.000
Maybe it's now in, basically.

25:11.000 --> 25:13.000
It didn't use to be in there.

25:13.000 --> 25:15.000
Like I even mentioned.

25:15.000 --> 25:19.000
Months that is in there, you would not have to do that anymore.

25:19.000 --> 25:22.000
But that is how you can override it, basically.

25:23.000 --> 25:24.000
Okay.

25:24.000 --> 25:26.000
I think that's all the time we have.

25:26.000 --> 25:28.000
Thank you very much.

