FAQ - 21:53 : Is `RefCell` really needed with `Mutex`? Doesn't `Mutex` already provide interior mutability? - The `critical_section::Mutex` is a bit different from the `std::sync::Mutex` in that the former does not provide interior mutability, for reasons described here: docs.rs/critical-section/1.1.3/critical_section/struct.Mutex.html#design
I've been programming for decades, but I'm quite new to Rust. Having watched about half of your videos so far, I really like how you don't just jump right to the end-state offloading all the inner workings to a library. Instead, you start from first principals and work-up a basic implementation that clearly demonstrates the concept before showing the library short-cut. This kind of teaching really helps developers grow from committers to _contributors_! ☺ Look forward to seeing more!
After developing for years C/C++ in anger for embedded, I can see now why people talk good about rust. A lot of verbosity, but things make sense. And it seems like it won't give you nightmares at night while you wonder if your medical unit will kill somebody some day because you had a dangling pointer!
Ha. Like complete novice in embedded that seems to me like endless pulsing pain. I can say I'll take that pointer and heck I'll take the road. Metal oxidation forms let me begin.
This comprehensive guide delves deeply into Rust programming, covering all the techniques used in this program. Great job!, I’ll try out this code on my end.
Loved that it is Project based explanation. I now understand how concurrent programming work. I was struggling with the concept for months really. Im a in high school student so this is very useful video. Thank you.
I just recently watched your other videos and when I discovered that they were from 5+ months ago and you only had 3 others I was so sad. So imagine my surprise and absolute joy to find that there is a new video now. I'm so glad you're still continuing with these videos I find them imeasurably helpful and I am captivated by the way you present and discuss topics. Please never stop, your content is amazing!
Very nice video, I am thinking about using Embassy for some new embedded projects at work but was a little queasy on using something (async/await) that I did not fully understand. This video gave me a lot of insight and (slightly) more confidence. Thank you for taking the time to make such a great resource!
Best Embedded Rust out there so far. For me a tick fast in some places due to not being to familiar with the embedded eco system in general but its probably smarter to pick up those skills with C first
This is awesome! Ive recently been working on an async executor using C++ coroutines for embedded systems at work, so it was really neat to see some of the parallels.
I'm just here to appreciate the copy of Linux Programming Interface sitting on your table in the back. 😂 Seriously, though, love this content and happy to see you're back to it. Just ordered a Micro:bit finally to follow along.
I remember when first learning about futures and async, I somehow completely missed the concept of wakers and was really confused until I finally learned about them and it all clicked into place :D
I think the approach to teaching async is often top-down, but I much prefer bottom-up: us low-level folks like to know what's going on at the lowest layers, and if you're coming from C then you're likely already familiar with state-machines, so this seems natural.
At 38:37 you may be able to use the mutex directly without the refcell since mutexes already implements mutually exclusive access so you already get a mutable reference. RefCell should ne used when you want to have mutability from an immutable setting (ex. Immutable ref to mutable ref) EDIT: Sorry, after some research this is the mutex of the critical section crate that confusingly does not provide interior mutability for better performance 0_o. Embedded rust is quite weird. Thanks for the great video! I'll surely recommend it to teach advanced embedded rust!
Thanks very much about this video, I haven't seen yet but I know is going to be a lot of good information, all your videos it is really helpfull, thanks for this channel.
I'm looking forward to the next videos where Embassy is assumed! It's somewhat interesting seeing the journey through different ways to do this, and I can see why someone would learn things this way. However it seems to be a video about why async is useful by showing how everything else is worse. The video builds A, replaces it with B, replaces it with C, where A, B, & C do the same thing. An alternative is building A, then go on to A' and A'' where each step adds new functionality using the same system (eg. start with 1 button & 1 LED, add movement, then add blinking, all with async). On the other hand, I've come across async in other languages and in rust web server libraries, and I never tried running or even fully grokking the code, so I thought "Oh cool, async for embedded" rather than "What's async? Why would I need it?" Embassy sounds great! I hope the five minute outro is a sign of things to come.
Fantastic video! Async and embedded rust are something I've been meaning to get more comfortable with, and this is about as concise as the combination of those two things can be! One thing I noticed though while watching was that you used a Mutex, and I'm pretty sure Mutex has interior mutability on its own, so the RefCell isn't necessary. I could be mistaken, like I said, this isn't really my wheelhouse, but it just popped out to me.
Thanks! The `critical-section` crate's `Mutex` doesn't provide interior mutability, for reasons described here: docs.rs/critical-section/1.1.3/critical_section/struct.Mutex.html#design
Keyframes in Final Cut Pro, just changing position. The default behavior seems to have a nice acceleration/deceleration ramp at the beginning and end, which is nice..
Sir... Can you make another dedicated Video Tutorial for STM32 discovery development with RUST? A Complete guideline will be also ok. And This video was really helpful for beginners. Thank you!
I was really confused by the Mutex pattern until I looked at the docs. The critical_section::Mutex does not offer interior mutability like the std::sync::Mutex.
I'm a 4th year IT student of course I know so little about all these, but the async and concurrent code in esp32 sucks that it can't escape a loop and just blocks all these, I don't know how to do that, so I might be excited with these.
I'm not sure I understand why you use an ISR in the timer. Why not configure the RTC's prescaler of 32 (1000 Hz) ? Doing so, you get millisecond accuracy and an overflow only every 50 days. Thanks for the video!
The RTC's low power oscillator frequency is 32,768 Hz, so a prescaler of 32 would get you 1,024 Hz, which might be OK for tracking system time if you can tolerate the error. But even then, the counter register is only 24-bits (counting up to 16,777,216), which is an overflow every 4.66 hours, so you still need somewhere to keep track of overflows. Alternatively, you could keep the native frequency and use one of the CC registers to count up to ~1ms (32 ticks, so still some error) and just increment a single 64-bit tick counter value in memory.
@@therustybits Thanks for your answer. What I don't understand is why you need more than a few seconds before overflow. With the unsigned integer overflow rule, the following code is garantee to work: u32 elapsed = now() - start; if elapsed >= 100 { do_something(); } Anyway, thanks for sharing !
I'm using "Oh My Zsh" to manage my zsh config, and have added `zsh-autosuggestions` (github.com/zsh-users/zsh-autosuggestions) and `zsh-syntax-highlighting` (github.com/zsh-users/zsh-syntax-highlighting). Basically just followed @typecraft_dev's video th-cam.com/video/wNQpDWLs4To/w-d-xo.html
The `critical_section::Mutex` is a bit different from the `std::sync::Mutex` in that it does not provide interior mutability, for reasons described here: docs.rs/critical-section/1.1.3/critical_section/struct.Mutex.html#design
Im curious, is async aproach good for lets say real time audio. For guitar amps or pedals.. When you have audio thread that is highest priority, and must not be blocked ever. Is classical RTOS aproach better than?
In `embassy`, you can run multiple executors even in a single-core system, with lower priority tasks running on the default thread-mode executor, and higher-priority tasks running in interrupt executor(s) (running in ISRs). For extremely time-sensitive stuff, you can always run your own ISR logic in tandem with the normal async executor, or use a framework like RTIC that is usually better-suited for that type of thing. A long way of saying.. it depends 😀
It is a RTOS implemented on RUST? I only can find some old (dead) projects and some FreeRTOS wrappers... 🤔because the Embassy framework is most an event oriented framework.
An RTOS is a bit of a different animal than what we build in this video, which is more like a stripped down version of embassy. And you’re right, AFAIK there aren’t many RTOS efforts in Rust at the moment. For real-time stuff there’s RTIC, but that works much differently than something like FreeRTOS.
I see that you convert a Result type to an Option type in several lines of code using the the .ok function but not using the resulting value. Why convert the Result into an Option without using the value?
I believe this is in reference to the calls to drive the LED: the `embedded-hal`'s `OutputPin` trait methods `set_low()`/`set_high()`/`toggle()` are specified to return a `Result`, but because this is effectively just a write to memory, the implementation in the HAL always returns `Ok(())`. This is the case for the `nrf52833-hal` used by the `microbit-v2` BSP, but I suppose maybe its possible in some other hardware that has to do something more complicated than an MMIO write might fail, so having that flexibility of returning a `Result` in the trait definition is probably a good thing, although having to deal with it in the vast majority of use-cases is a bit unfortunate..
I doubt that! I knew literally nothing about async a few months ago, and now I know.. slightly more! Seriously though, learning anything new is a process, you just need to stick with it 🙂
I aprreciate the work put into this video. But when I tried following it myself I found the explanations to be too advanced to the point where I couldn't make sense of anything and I got really discoureaged by the experience.
Hiding things under abstractions can get you in trouble in the type of code I write so C is preferred, however I see this being very useful as a embedded C++ replacement. I might incorporate futures into my own systems in C/asm.
Pieces of this video went right over my head due to inexperience, but this talk [th-cam.com/video/H7NtzyP9q8E/w-d-xo.htmlsi=eeVPFC9iHGsHWivR] by the Embassy creator helped clear things a lot more.
Please turn off the editor suggestions when typing the code. It's difficult to follow the code with the rust analyzer suggestions popping up. Especially at the accelerated render of the video
There is an extremely popular (and excellent) book “Zero to Production in Rust” by Luca Palmieri, and so this title is a play on that, though the “learn by doing” style is similar. Like Luca, my assumption is that you’ve read the Rust Book (link in description) and so have some familiarity with the concepts and now want to seem them in action. But yeah, if I also had to teach all the underlying concepts this video would be 10x longer.
FAQ
- 21:53 : Is `RefCell` really needed with `Mutex`? Doesn't `Mutex` already provide interior mutability?
- The `critical_section::Mutex` is a bit different from the `std::sync::Mutex` in that the former does not provide interior mutability, for reasons described here: docs.rs/critical-section/1.1.3/critical_section/struct.Mutex.html#design
This is the exact kind of top to bottom project breakdown that can onboard people very quickly 10/10 video.
I've been programming for decades, but I'm quite new to Rust. Having watched about half of your videos so far, I really like how you don't just jump right to the end-state offloading all the inner workings to a library. Instead, you start from first principals and work-up a basic implementation that clearly demonstrates the concept before showing the library short-cut.
This kind of teaching really helps developers grow from committers to _contributors_! ☺
Look forward to seeing more!
After developing for years C/C++ in anger for embedded, I can see now why people talk good about rust. A lot of verbosity, but things make sense. And it seems like it won't give you nightmares at night while you wonder if your medical unit will kill somebody some day because you had a dangling pointer!
Arena allocators.
@@thegrandnil764 ha, if only
Ha.
Like complete novice in embedded that seems to me like endless pulsing pain.
I can say I'll take that pointer and heck I'll take the road. Metal oxidation forms let me begin.
Now this is *content*.
I’m now half way through the genius „Zero2Prod in Rust“ book. You should *absolutely* write one but for embedded in Rust.
Zero to Production is a fantastic book; I don't think I have it in me to write one though 😅
In my case, the video series is the book/course...
@@therustybits you can write it, can you create a crate for extending cargo for managing embedded development. like we have platformIO
This comprehensive guide delves deeply into Rust programming, covering all the techniques used in this program.
Great job!, I’ll try out this code on my end.
Loved that it is Project based explanation. I now understand how concurrent programming work. I was struggling with the concept for months really. Im a in high school student so this is very useful video. Thank you.
I just recently watched your other videos and when I discovered that they were from 5+ months ago and you only had 3 others I was so sad. So imagine my surprise and absolute joy to find that there is a new video now. I'm so glad you're still continuing with these videos I find them imeasurably helpful and I am captivated by the way you present and discuss topics. Please never stop, your content is amazing!
Excellent. I'll be rewatching this to understand how Embassy works "under the hood".
Great video! Low level async and embedded, two of my high interest topics at the moment!
Thanks!
Damn this is some quality explanation! Answered a lot of questions I had related to embedded. Keep it up man!
You made me sit down and think how concurrent tasks are usually implemented using state machines, thanks for this amazing work!
Very nice video, I am thinking about using Embassy for some new embedded projects at work but was a little queasy on using something (async/await) that I did not fully understand. This video gave me a lot of insight and (slightly) more confidence. Thank you for taking the time to make such a great resource!
Best Embedded Rust out there so far. For me a tick fast in some places due to not being to familiar with the embedded eco system in general but its probably smarter to pick up those skills with C first
Amazing work, was waiting your next video, perfect as always
Wooo new video! Love the content and super useful topic!🎉🎉
Duuuuuude so sick!! Thanks for this!
Ahhhh, I just finally manage to make it using rtic and interrupts and here we go new pattern 😂😂
As always thank you!
Thrilling to try it
This is awesome! Ive recently been working on an async executor using C++ coroutines for embedded systems at work, so it was really neat to see some of the parallels.
This is a really good tutorial. Thank you so much for making quality education video.
Picking embassy going forward is a very good choice.
Excellent! Very well explained!
Waiting for a 1 hour Video was so worth it!
Oooooo NICE! A new video from my new favourite Rust channel! Can't wait to watch it this evening!
Yeah, new video! Just yesterday I was leaving a message asking for one, and here we go!!!
Dude! loving the execution and format of videos. Looking forward to the next rusty bit
fabulous video (again!) - many thanks for sharing!
I watched the whole video. PLEASE consider doing a complete tutorial for Rust. I like the way you explain things.
Awesome! the world needs rust content like this 11/10
Very great video and visuals during the discussion! 🎉
Excellent video as usual. I definitely need to find some time and do my homework.
I'm just here to appreciate the copy of Linux Programming Interface sitting on your table in the back. 😂 Seriously, though, love this content and happy to see you're back to it. Just ordered a Micro:bit finally to follow along.
I remember when first learning about futures and async, I somehow completely missed the concept of wakers and was really confused until I finally learned about them and it all clicked into place :D
I think the approach to teaching async is often top-down, but I much prefer bottom-up: us low-level folks like to know what's going on at the lowest layers, and if you're coming from C then you're likely already familiar with state-machines, so this seems natural.
At 38:37 you may be able to use the mutex directly without the refcell since mutexes already implements mutually exclusive access so you already get a mutable reference. RefCell should ne used when you want to have mutability from an immutable setting (ex. Immutable ref to mutable ref)
EDIT: Sorry, after some research this is the mutex of the critical section crate that confusingly does not provide interior mutability for better performance 0_o. Embedded rust is quite weird.
Thanks for the great video! I'll surely recommend it to teach advanced embedded rust!
Thanks very much about this video, I haven't seen yet but I know is going to be a lot of good information, all your videos it is really helpfull, thanks for this channel.
i'm glad you're back
Instant sub. So good!
some of your points map to react incredibly well, interestingly
Amazing video, great job! It is very very helpful!
The video I was waiting for
I'm looking forward to the next videos where Embassy is assumed!
It's somewhat interesting seeing the journey through different ways to do this, and I can see why someone would learn things this way. However it seems to be a video about why async is useful by showing how everything else is worse. The video builds A, replaces it with B, replaces it with C, where A, B, & C do the same thing. An alternative is building A, then go on to A' and A'' where each step adds new functionality using the same system (eg. start with 1 button & 1 LED, add movement, then add blinking, all with async). On the other hand, I've come across async in other languages and in rust web server libraries, and I never tried running or even fully grokking the code, so I thought "Oh cool, async for embedded" rather than "What's async? Why would I need it?"
Embassy sounds great! I hope the five minute outro is a sign of things to come.
you should probably test each change on the hardware to make the video more interesting by showing the effect of the change
Ah yep, good call... did that in blinky but forgot in this one. Next time!
When is coming your video of embassy? :)
Thanks for this amazing video explain everything inside of the logic of the embassy framework.
Fantastic video! Async and embedded rust are something I've been meaning to get more comfortable with, and this is about as concise as the combination of those two things can be!
One thing I noticed though while watching was that you used a Mutex, and I'm pretty sure Mutex has interior mutability on its own, so the RefCell isn't necessary.
I could be mistaken, like I said, this isn't really my wheelhouse, but it just popped out to me.
Thanks! The `critical-section` crate's `Mutex` doesn't provide interior mutability, for reasons described here: docs.rs/critical-section/1.1.3/critical_section/struct.Mutex.html#design
@@therustybits D'oh, that's on me for not noticing it wasn't the std Mutex. That makes sense.
Lets GOoooo. love your soft voice😊😊.
Looking forward to the atomic ordering video!
Great video!
Love this so much ❤
Thank you for the great tutorials.
Great video, thanks! Btw, what software do you use to create text animations?
Keyframes in Final Cut Pro, just changing position. The default behavior seems to have a nice acceleration/deceleration ramp at the beginning and end, which is nice..
Thanks@@therustybits, the quality of your videos is excellent! Please keep up the great work!
What still blows my mind about Rust's async is that, in essence, it's identical to the original code, just smarter.
Automatically generated state-machines FTW
@@therustybits The even more fun part is I got to do this transition for real from state machines in a super loop to asynchronous rust at my work!
He is back from the hiatus
Jackpot!
This is great 👍
babe wake up, an hour long got posted
So babe can be polled?
Walker getters is stabilized now!
Rust pull 129919 btw
Sweet!
Sir... Can you make another dedicated Video Tutorial for STM32 discovery development with RUST? A Complete guideline will be also ok. And This video was really helpful for beginners. Thank you!
I was really confused by the Mutex pattern until I looked at the docs. The critical_section::Mutex does not offer interior mutability like the std::sync::Mutex.
big W
in english, it's usually pronounced few-jit which doesn't quite match the original latin "tempus fugit" - generally translated as "time flies"
My favorite part about Rust .. rewritting something you just wrote lol
This is the way 😅
Actually 🔥
Thanks
I'm a 4th year IT student of course I know so little about all these, but the async and concurrent code in esp32 sucks that it can't escape a loop and just blocks all these, I don't know how to do that, so I might be excited with these.
I'm not sure I understand why you use an ISR in the timer.
Why not configure the RTC's prescaler of 32 (1000 Hz) ? Doing so, you get millisecond accuracy and an overflow only every 50 days.
Thanks for the video!
The RTC's low power oscillator frequency is 32,768 Hz, so a prescaler of 32 would get you 1,024 Hz, which might be OK for tracking system time if you can tolerate the error. But even then, the counter register is only 24-bits (counting up to 16,777,216), which is an overflow every 4.66 hours, so you still need somewhere to keep track of overflows. Alternatively, you could keep the native frequency and use one of the CC registers to count up to ~1ms (32 ticks, so still some error) and just increment a single 64-bit tick counter value in memory.
@@therustybits Thanks for your answer. What I don't understand is why you need more than a few seconds before overflow.
With the unsigned integer overflow rule, the following code is garantee to work:
u32 elapsed = now() - start;
if elapsed >= 100 { do_something(); }
Anyway, thanks for sharing !
Could I ask what a tool/plugin do you use to make your vscode's integrated terminal so powerful?
I'm using "Oh My Zsh" to manage my zsh config, and have added `zsh-autosuggestions` (github.com/zsh-users/zsh-autosuggestions) and `zsh-syntax-highlighting` (github.com/zsh-users/zsh-syntax-highlighting). Basically just followed @typecraft_dev's video th-cam.com/video/wNQpDWLs4To/w-d-xo.html
Is the RefCell needed inside the mutex??
The `critical_section::Mutex` is a bit different from the `std::sync::Mutex` in that it does not provide interior mutability, for reasons described here: docs.rs/critical-section/1.1.3/critical_section/struct.Mutex.html#design
Im curious, is async aproach good for lets say real time audio. For guitar amps or pedals.. When you have audio thread that is highest priority, and must not be blocked ever. Is classical RTOS aproach better than?
In `embassy`, you can run multiple executors even in a single-core system, with lower priority tasks running on the default thread-mode executor, and higher-priority tasks running in interrupt executor(s) (running in ISRs). For extremely time-sensitive stuff, you can always run your own ISR logic in tandem with the normal async executor, or use a framework like RTIC that is usually better-suited for that type of thing. A long way of saying.. it depends 😀
What is the name of the book on the table?
"The Linux Programming Interface" by Michael Kerrisk
Will there be an stm32 version of this video?
No: while the code is specific to the nRF series of controllers, the concepts are applicable to any microcontroller.
It is a RTOS implemented on RUST? I only can find some old (dead) projects and some FreeRTOS wrappers... 🤔because the Embassy framework is most an event oriented framework.
An RTOS is a bit of a different animal than what we build in this video, which is more like a stripped down version of embassy. And you’re right, AFAIK there aren’t many RTOS efforts in Rust at the moment. For real-time stuff there’s RTIC, but that works much differently than something like FreeRTOS.
wow
What code editor do you use?
VS Code; check out this video for full setup: th-cam.com/video/TOAynddiu5M/w-d-xo.html
A bit fast, but very good.
I see that you convert a Result type to an Option type in several lines of code using the the .ok function but not using the resulting value. Why convert the Result into an Option without using the value?
I believe this is in reference to the calls to drive the LED: the `embedded-hal`'s `OutputPin` trait methods `set_low()`/`set_high()`/`toggle()` are specified to return a `Result`, but because this is effectively just a write to memory, the implementation in the HAL always returns `Ok(())`. This is the case for the `nrf52833-hal` used by the `microbit-v2` BSP, but I suppose maybe its possible in some other hardware that has to do something more complicated than an MMIO write might fail, so having that flexibility of returning a `Result` in the trait definition is probably a good thing, although having to deal with it in the vast majority of use-cases is a bit unfortunate..
Here a comment for the algorithm, because you are still criminally low on subscribers!
For the algorithm! 🙌
My dude rewrote embassy in one hour
This looks like an awesome video, sadly I'm too stupid for it 😔
I doubt that! I knew literally nothing about async a few months ago, and now I know.. slightly more! Seriously though, learning anything new is a process, you just need to stick with it 🙂
@@therustybits Heh, I think I needed to hear that, thanks! I'll try my best to absorb more about the basic concepts and come back to this :)
I aprreciate the work put into this video. But when I tried following it myself I found the explanations to be too advanced to the point where I couldn't make sense of anything and I got really discoureaged by the experience.
I assume it was a joke, but "fugit" is likely from "tempus fugit" (latin for "time flies") and would probably be pronounced "foojit".
Hiding things under abstractions can get you in trouble in the type of code I write so C is preferred, however I see this being very useful as a embedded C++ replacement.
I might incorporate futures into my own systems in C/asm.
Pieces of this video went right over my head due to inexperience, but this talk [th-cam.com/video/H7NtzyP9q8E/w-d-xo.htmlsi=eeVPFC9iHGsHWivR] by the Embassy creator helped clear things a lot more.
Please turn off the editor suggestions when typing the code. It's difficult to follow the code with the rust analyzer suggestions popping up. Especially at the accelerated render of the video
Thanks for the feedback! In future videos I’ll be more selective about when RA is enabled.
Do you really explain for "from zero" sort of learners?
There is an extremely popular (and excellent) book “Zero to Production in Rust” by Luca Palmieri, and so this title is a play on that, though the “learn by doing” style is similar. Like Luca, my assumption is that you’ve read the Rust Book (link in description) and so have some familiarity with the concepts and now want to seem them in action. But yeah, if I also had to teach all the underlying concepts this video would be 10x longer.
@@therustybits Thanks, I felt like a homo erectus around the middle of the tutorial 😂.