From Zero to Async in Embedded Rust

  Рет қаралды 28,791

The Rusty Bits

The Rusty Bits

Күн бұрын

Пікірлер: 122
@therustybits
@therustybits 2 ай бұрын
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
@danjadave
@danjadave 3 күн бұрын
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!
@Kaptime
@Kaptime 3 ай бұрын
This is the exact kind of top to bottom project breakdown that can onboard people very quickly 10/10 video.
@jackkendall6420
@jackkendall6420 3 ай бұрын
Now this is *content*.
@FernandoMumbach
@FernandoMumbach 3 ай бұрын
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!
@thegrandnil764
@thegrandnil764 3 ай бұрын
Arena allocators.
@FernandoMumbach
@FernandoMumbach 3 ай бұрын
@@thegrandnil764 ha, if only
@НиколаевВасилий-н3б
@НиколаевВасилий-н3б 3 ай бұрын
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.
@Eekhoornz
@Eekhoornz 28 күн бұрын
You made me sit down and think how concurrent tasks are usually implemented using state machines, thanks for this amazing work!
@FedynaPavlo
@FedynaPavlo 3 ай бұрын
I’m now half way through the genius „Zero2Prod in Rust“ book. You should *absolutely* write one but for embedded in Rust.
@therustybits
@therustybits 3 ай бұрын
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...
@vikaspoddar001
@vikaspoddar001 2 ай бұрын
@@therustybits you can write it, can you create a crate for extending cargo for managing embedded development. like we have platformIO
@anandmoon5701
@anandmoon5701 3 ай бұрын
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.
@JordanRobinson-w6w
@JordanRobinson-w6w 3 ай бұрын
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!
@indierusty
@indierusty 3 ай бұрын
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.
@jan_the_man
@jan_the_man 3 ай бұрын
Damn this is some quality explanation! Answered a lot of questions I had related to embedded. Keep it up man!
@farukhalilagic2070
@farukhalilagic2070 2 ай бұрын
Thanks!
@J-Kimble
@J-Kimble 3 ай бұрын
Great video! Low level async and embedded, two of my high interest topics at the moment!
@namr2000
@namr2000 2 ай бұрын
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!
@Sillyvan
@Sillyvan 3 ай бұрын
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
@mehmethekimolu
@mehmethekimolu 3 ай бұрын
Amazing work, was waiting your next video, perfect as always
@Jon4as
@Jon4as 3 ай бұрын
Waiting for a 1 hour Video was so worth it!
@jvcrules
@jvcrules 3 ай бұрын
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.
@MaxWeninger
@MaxWeninger 3 ай бұрын
Picking embassy going forward is a very good choice.
@indierusty
@indierusty 3 ай бұрын
This is a really good tutorial. Thank you so much for making quality education video.
@topper2kuk
@topper2kuk 2 ай бұрын
Dude! loving the execution and format of videos. Looking forward to the next rusty bit
@MrMassaraksh
@MrMassaraksh 3 ай бұрын
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
@irlshrek
@irlshrek 3 ай бұрын
Duuuuuude so sick!! Thanks for this!
@thaejsooriya3313
@thaejsooriya3313 3 ай бұрын
Wooo new video! Love the content and super useful topic!🎉🎉
@IvanDeMarino
@IvanDeMarino 3 ай бұрын
Yeah, new video! Just yesterday I was leaving a message asking for one, and here we go!!!
@JeroenL111
@JeroenL111 3 ай бұрын
Excellent! Very well explained!
@teuluPaul
@teuluPaul 3 ай бұрын
fabulous video (again!) - many thanks for sharing!
@marcopaolovaleriovezzoli5776
@marcopaolovaleriovezzoli5776 3 ай бұрын
Excellent video as usual. I definitely need to find some time and do my homework.
@descriptionsuchandsuch4709
@descriptionsuchandsuch4709 3 ай бұрын
Oooooo NICE! A new video from my new favourite Rust channel! Can't wait to watch it this evening!
@HybridRobotix
@HybridRobotix 18 күн бұрын
I watched the whole video. PLEASE consider doing a complete tutorial for Rust. I like the way you explain things.
@thelethalmoo
@thelethalmoo 3 ай бұрын
Awesome! the world needs rust content like this 11/10
@lorenzorossi2000
@lorenzorossi2000 3 ай бұрын
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!
@evertonoriente7150
@evertonoriente7150 3 ай бұрын
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.
@unaimillian
@unaimillian 3 ай бұрын
Very great video and visuals during the discussion! 🎉
@ThomasLockney
@ThomasLockney 3 ай бұрын
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.
@trejohnson7677
@trejohnson7677 3 ай бұрын
some of your points map to react incredibly well, interestingly
@maexlich
@maexlich 3 ай бұрын
Amazing video, great job! It is very very helpful!
@auggiebuerkle6660
@auggiebuerkle6660 3 ай бұрын
i'm glad you're back
@oof-software
@oof-software 3 ай бұрын
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
@therustybits
@therustybits 3 ай бұрын
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.
@driedurchin
@driedurchin 3 ай бұрын
Instant sub. So good!
@jorgegomezreus7019
@jorgegomezreus7019 3 ай бұрын
The video I was waiting for
@nathanbanks2354
@nathanbanks2354 3 ай бұрын
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.
@PlayerOne1999
@PlayerOne1999 3 ай бұрын
Lets GOoooo. love your soft voice😊😊.
@daniellarson6279
@daniellarson6279 3 ай бұрын
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.
@therustybits
@therustybits 3 ай бұрын
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
@daniellarson6279
@daniellarson6279 3 ай бұрын
@@therustybits D'oh, that's on me for not noticing it wasn't the std Mutex. That makes sense.
@Iswimandrun
@Iswimandrun 3 ай бұрын
Thank you for the great tutorials.
@danielprimostuart
@danielprimostuart 3 ай бұрын
Looking forward to the atomic ordering video!
@matpala2
@matpala2 3 ай бұрын
Great video!
@cunningham.s_law
@cunningham.s_law 3 ай бұрын
you should probably test each change on the hardware to make the video more interesting by showing the effect of the change
@therustybits
@therustybits 3 ай бұрын
Ah yep, good call... did that in blinky but forgot in this one. Next time!
@evertonoriente7150
@evertonoriente7150 2 ай бұрын
When is coming your video of embassy? :) Thanks for this amazing video explain everything inside of the logic of the embassy framework.
@borkomne
@borkomne 3 ай бұрын
Great video, thanks! Btw, what software do you use to create text animations?
@therustybits
@therustybits 3 ай бұрын
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..
@borkomne
@borkomne 3 ай бұрын
Thanks@@therustybits, the quality of your videos is excellent! Please keep up the great work!
@driedurchin
@driedurchin 3 ай бұрын
What still blows my mind about Rust's async is that, in essence, it's identical to the original code, just smarter.
@therustybits
@therustybits 3 ай бұрын
Automatically generated state-machines FTW
@driedurchin
@driedurchin 3 ай бұрын
@@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!
@commissariomontanaro2931
@commissariomontanaro2931 3 ай бұрын
babe wake up, an hour long got posted
@johnwu5908
@johnwu5908 3 ай бұрын
So babe can be polled?
@vikaspoddar001
@vikaspoddar001 3 ай бұрын
He is back from the hiatus
@krauterbaguette3645
@krauterbaguette3645 3 ай бұрын
Love this so much ❤
@NotherPleb
@NotherPleb 3 ай бұрын
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.
@10e999
@10e999 3 ай бұрын
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!
@therustybits
@therustybits 3 ай бұрын
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.
@10e999
@10e999 3 ай бұрын
​@@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 !
@justinliu7788
@justinliu7788 3 ай бұрын
Walker getters is stabilized now!
@justinliu7788
@justinliu7788 3 ай бұрын
Rust pull 129919 btw
@therustybits
@therustybits 3 ай бұрын
Sweet!
@The_Nova_Glow
@The_Nova_Glow 3 ай бұрын
Jackpot!
@thearrow4624
@thearrow4624 3 ай бұрын
Could I ask what a tool/plugin do you use to make your vscode's integrated terminal so powerful?
@therustybits
@therustybits 3 ай бұрын
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 kzbin.info/www/bejne/rX-0oXeNgdhnitE
@takeiteasyeh
@takeiteasyeh Ай бұрын
My favorite part about Rust .. rewritting something you just wrote lol
@therustybits
@therustybits 29 күн бұрын
This is the way 😅
@JulianBolivarGaleno74
@JulianBolivarGaleno74 2 ай бұрын
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.
@therustybits
@therustybits 2 ай бұрын
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.
@christopherpetersen342
@christopherpetersen342 2 ай бұрын
in english, it's usually pronounced few-jit which doesn't quite match the original latin "tempus fugit" - generally translated as "time flies"
@orrenjenkins289
@orrenjenkins289 2 ай бұрын
Is the RefCell needed inside the mutex??
@therustybits
@therustybits 2 ай бұрын
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
@markocvejic6416
@markocvejic6416 11 күн бұрын
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?
@therustybits
@therustybits 11 күн бұрын
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 😀
@skydandelion2560
@skydandelion2560 2 ай бұрын
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!
@erentas7391
@erentas7391 3 ай бұрын
What is the name of the book on the table?
@therustybits
@therustybits 3 ай бұрын
"The Linux Programming Interface" by Michael Kerrisk
@timvw01
@timvw01 3 ай бұрын
This is great 👍
@roiborromeo7921
@roiborromeo7921 3 ай бұрын
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.
@tommasoclini9902
@tommasoclini9902 3 ай бұрын
Will there be an stm32 version of this video?
@therustybits
@therustybits 3 ай бұрын
No: while the code is specific to the nRF series of controllers, the concepts are applicable to any microcontroller.
@elijahpo3800
@elijahpo3800 3 ай бұрын
What code editor do you use?
@therustybits
@therustybits 3 ай бұрын
VS Code; check out this video for full setup: kzbin.info/www/bejne/ioCkqqGamc6oa68
@samuelhomberg9075
@samuelhomberg9075 3 ай бұрын
Here a comment for the algorithm, because you are still criminally low on subscribers!
@therustybits
@therustybits 3 ай бұрын
For the algorithm! 🙌
@chris-duncan-arauz
@chris-duncan-arauz 29 күн бұрын
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?
@therustybits
@therustybits 29 күн бұрын
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..
@orhundev
@orhundev 3 ай бұрын
big W
@AdarshKumar370
@AdarshKumar370 3 ай бұрын
Thanks
@UsatiyNyan
@UsatiyNyan 3 ай бұрын
Actually 🔥
@billytalentrocks345
@billytalentrocks345 3 ай бұрын
A bit fast, but very good.
@mateusztocha9260
@mateusztocha9260 3 ай бұрын
wow
@urmok6iv
@urmok6iv 26 күн бұрын
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.
@JeffHanke
@JeffHanke 3 ай бұрын
I assume it was a joke, but "fugit" is likely from "tempus fugit" (latin for "time flies") and would probably be pronounced "foojit".
@ederbarrero5585
@ederbarrero5585 3 ай бұрын
This looks like an awesome video, sadly I'm too stupid for it 😔
@therustybits
@therustybits 3 ай бұрын
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 🙂
@ederbarrero5585
@ederbarrero5585 3 ай бұрын
@@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 :)
@pierreyao7221
@pierreyao7221 2 ай бұрын
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
@therustybits
@therustybits 2 ай бұрын
Thanks for the feedback! In future videos I’ll be more selective about when RA is enabled.
@jad.k.haddad
@jad.k.haddad 3 ай бұрын
My dude rewrote embassy in one hour
@clivedsouza6213
@clivedsouza6213 22 күн бұрын
Pieces of this video went right over my head due to inexperience, but this talk [kzbin.info/www/bejne/fmixpa2vhZ6kbqcsi=eeVPFC9iHGsHWivR] by the Embassy creator helped clear things a lot more.
@thegrandnil764
@thegrandnil764 3 ай бұрын
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.
@imanidioli
@imanidioli 3 ай бұрын
Do you really explain for "from zero" sort of learners?
@therustybits
@therustybits 3 ай бұрын
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.
@imanidioli
@imanidioli 3 ай бұрын
@@therustybits Thanks, I felt like a homo erectus around the middle of the tutorial 😂.
Async Rust in Embedded Systems with Embassy - Dario Nieuwenhuis
36:16
Rust Nederland (RustNL)
Рет қаралды 8 М.
Rust Functions Are Weird (But Be Glad)
19:52
Logan Smith
Рет қаралды 143 М.
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
The SQLite Rewrite In Rust
22:15
ThePrimeTime
Рет қаралды 148 М.
but what is 'a lifetime?
12:20
leddoo
Рет қаралды 81 М.
Async Rust Is A Bad Language | Prime Reacts
28:46
ThePrimeTime
Рет қаралды 109 М.
rust runs on EVERYTHING (no operating system, just Rust)
18:10
Low Level
Рет қаралды 364 М.
Blinking an LED: Embedded Rust ecosystem explored
17:14
The Rusty Bits
Рет қаралды 24 М.
Async Rust: the good, the bad, and the ugly - Steve Klabnik
46:20
All Things Open
Рет қаралды 16 М.
Rust's Most Important Containers 📦 10 Useful Patterns
17:11
Code to the Moon
Рет қаралды 130 М.
Introducing Clay - High Performance UI Layout in C
35:19
Nic Barker
Рет қаралды 59 М.
Oxidize Conference: How Rust makes Oxide possible
50:18
Oxidize Conference
Рет қаралды 6 М.
Async Rust Is The Bane Of My Existence | Prime Reacts
35:36
ThePrimeTime
Рет қаралды 109 М.
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН