100% disagree with your opening statement. The Rasberry pi is now impossible to buy. What should cost $50 is now selling for $190. All of you illegal rom downloading boi's who wanted emulation jacked up the prices. Way to go pirate. Way to ruin it for everyone else.
@@orangehatmusic225 Lockdowns had *nothing* to do with it? Seems a little short-sighted there; chips of all types were affected, including the car my dad wanted to buy. Pirates STEAL ITEMS. Like Assange recently said, he didn't steal anything; he made a copy. Verbs matter. Ever hear "Possession is nine tenths of the law"? When people copy software, the original possessor does not lose their possession. It's more like lighting a candle from another candle. Separately, the esp32 is like $5, a 240x240 color screen is another $5, and PictoBlox is like MIT's Scratch, for the smaller devices. Or the Orange Pi, for $117. So: I 100% disagree with your 100% disagreement. :)
I knew literally nothing about embedded systems and barely anything about Rust 18 minutes ago, and now it feels like it's a very acheivable thing to learn thanks to this demonstration. You're clearly a gifted teacher, fantastic video.
Same here. I have a background in web dev, but allost everything was new to me here. Yet, I‘ve understood pretty much everything and learned a ton. But honestly speaking, I will probably never learn this type of low-level programming. Just seems way too much effort to get something done when there are easier albeit less efficient tools/languages to use. Nice to be able to peek into this world though
@@LowLevelTV how do I compile for the 64bit version (aarch64) objcopy does not work and i could not find my Problem. (I put AARCH64 in the linker script instead of ARM.eabi)
The great thing about your videos is the pace and "constant" narration. It feels like there isn't a single second in the video where you're not explaining what you're currently doing. That makes it very easy to not lose focus and attention as a viewer
@@LowLevelTV I agree. You really talk about every detail which is so important. The viewer has no questions, and you make no assumptions about what the viewer knows. I hope to watch more like this in the future :D
It's awesome that he does that, agreed! Just a few videos of this nature and we're downloading helicopter flight manuals between words of dialogue! :) (Matrix reference; as we age, our references get stale, like moldy bread one can use to cure disease or have interesting visions with.)
13:39 I would hope nobody would be mad. Unsafe code is basically the only way this can be done. It's just a fact. There's a reason rust has the unsafe keyword, because it's sometimes needed. :) Also, thanks for the video. It's very enlightening!
Could probably be abstracted into a safe interface (or however it's called). Like a struct (with the PIN number) with methods or even plain functions (one for turning a hard-coded PIN on and the other for turning it off). But in the end the unsafe has be be somewhere.
Safe code is slower code, as there has to be a lot of hash inserts and checks and when you are processing movement, electrical spikes and wave forms, a lot of interrupts that are happening in the higher kilohertz range, such as signal processing, your program isn't gong to be looking at the web directly and should reject anything unexpected.
I started working on an operating system in rust. I never went that far with it but it works. Can boot both legacy bios mode and modern efi style. Though only in qemu on efi. Don’t have video output properly working on any real efi hardware I have. But with bios boot it works with a text mode console. Boots into long mode and all but no memory protection
You can make a `build.rs` file like this ```rust fn main() { println!("cargo:rerun-if-changed=./linker.ld"); } ``` to hint to cargo that a change in that file should also result in a rebuild
Thanks for Everything you do LLL, Seriously your videos have invigorated my spirit and inspired me to learn more about computer systems and lower level langs. C and Go are becoming my favorite languages to write my code. I'm gonna try writing some rust today!. Thanks again! Keep up the great work!
@@LowLevelTV Haha, that's interesting because my takeaway was that low level programming is so different that I know less about it than I thought :). I could probably follow along, but I'm SOL the second something goes wrong.
Cool, I like it! I don't know any Rust, so this was a good guide on how building Rust for bare metal works. For those who want to go further; If you want to be remotely efficient, you'd use a timer interrupt instead of the nop loops. Then you leave the timer to do it's thing, and whenever the time you've chosen happens, it will call your interrupt routine, which toggles the bit. Then you can do something else in between, instead of wasting cycles in a nop loop. That is, you can do simple round-robin multitasking etc using just interrupt routines and timers. Doesn't matter for just blinking an LED of course, but interrupts are key to do more complex things on bare metal.
I really like how you explain not only how to do things, but how to look for things yourself (e.g. the broadcom datasheet or the rpi firmware). I already have a bit of experience in embedded programming but I'm sure this helps beginners a lot. And more importantly, it makes the whole field feel less magic and scary than just saying "this address controls this LED because I know it".
So glad I found this channel, I have been writing code for a long time and wanted to jump into some low level stuff to improve my wider understanding esp. embedded systems etc. You cover fundamentals so well and easily digestible. Thanks for this!
You should configure the internal timers to trigger an interrupt every millisecond to increment a counter. Then reference that counter to to get more precise timing on when the LEDs turn on and off.
I am absolutely watching your channel from now on.This is the most I have ever learned from a programming video. I've been trying to learn how to be a low level developer for years. Since high school. WOW. It's quick. It's on point. And I can follow it. I love how you just filled in several gaps learning in only a few minutes. I could have stayed in college, and I am not knocking anyone who does, but I have a short attention span. Thanks for this. Don't even remember how I stumbled here.
Me as a web developer trying to learn more low level programming during most of this, "Funny words magic man." But really great video, and has helped me a ton.
The CPU must be running very slow for us to see that LED blink that slowly. 50000 nop operations is nothing for a modern CPU, and we shouldn’t be able to see the LED normally if it ran at the full speed.
@@SqueakyNeb even arduino.. the processor is running at more than 10MHZ ! I guess utilising all the hardware and allocating cores and instructions sets to execute programs must be no easy job ig. Although having even remotely close to raw access to a processor's capabilities and being able to control all the io and all interfaces like a boss.. is fascinating! Might just become true thanks to the people who developed tools to flash sd cards or rpi with such a powerful.. self made os.
I just started watching your videos yesterday and in every one you've had full facial hair, the beanie and glasses. Then this one autoplays and I'm like "wait...is this the same guy?" you look so different without all of those "modifiers" haha
This was really interesting. It would be great to see 2 things: 1) A list of references of sources you read to understand each part of this problem including the tools to generate the image that was capable of being loaded into the PI. i.e. a learning path. 2) An approach where you halted the processor putting it into a low power mode until the hardware timer triggered an interrupt allowing you to advance the state of the LED. The spinning for a delay makes this a bad start outside of proving that something could be done.
I just found the channel and I loved the video. One thing that it makes me thing was: if is it possible to build a kernel with Rust, then running appa on top of it would be possible too. The possibilities to embed are endless
Using `global_asm` to change the link section of a function is not supported (since top-level items may be reordered arbitrarily, so it might not apply to what you want it to. The intended way to change the section a function is in is with the link_section attribute, e.g. #[link_section = ".text._start"] pub extern "C" fn _start() { loop {} }
Such high quality content, thank you! Hoping in the future you can find the time to create a whole course on embedded Rust, I'd sign up in a heartbeat.
>write a kernel to blink an LED annd there goes all of the respect: either you’re overselling whatever program you’re going to write as a ‘kernel’ or you don’t really know what you’re talking about
It seems like Rust is really gaining momentum at the moment. I've switched from learning web dev with JavaScript to focusing now solely on Rust, not for any particular field, I just want to really get to grips with Rust. I'm taking a gamble but it feels like a really good investment.
Thanks for such a great introduction! My one question is just about the naming? Is _start convention or arbitrary? Should the entrypoint always be prefixed by an underscore? Is the name main forbidden?
Hey! Awesome video. As a viewer, I'd like to suggest increasing the font size (zooming the UI) to be clearer to read in small screens. Furthermore, as a concept in video making, it's better to avoid non-flat color elements like your transparent/medium opacity terminal. The video encoder has to sacrifice quality in texts (code) to embrace all details on screen (the diverse details in your wallpaper)
I realized after I rendered and uploaded that the font quality wasn't great :(. I'm transitioning my videos to 4K in the future to avoid this. Thanks for watching!
Actually, if its static then it doesn't detract any quality at all - Tom Scott did a great video about video quality, bit rate, and moving vs stationary details.
@@AbelShields Agreed, translucency is perfectly fine when static, which in this case 99.999% of the time it is; potentially even more 9s when considering the video is 60fps and the proportion of the screen that updates is quite small. The encoder/decoder will *absolutely not choke* on this sort of content. To the video encoder, there is no difference here between a terminal with a translucent background, and a terminal with an opaque, washed out background image. Translucency only matters due to the complexity of attempting to compress something that is changing in extremely unpredictable ways, which translucent objects overlapping and moving on top of a moving background tend to cause. I really like the flair the translucent terminal gives; please don't change it @Low Level Learning ! Though of course, please go to 4K to make the text nice and crisp :)
While not totally unsafe, but definitely more safe, you should wrap only the unsafe parts of the code. Have small subroutines that are entirely unsafe and call them from safe code. Pin-enable, pin-on, and pin-off (maybe the no-op if that requires unsafe as well) should all be their own functions that get called by the main loop which would realistically also be calling some kind of computational code that you definitely want to be checked
I was wondering this myself. There must be a way without using unsafe blocks. I know they’re trying to use rust in the Linux kernel, and kernel device work is almost all about writing bits to raw pointers. Surely rust in the kernel isn’t just all unsafe blocks.
@@Grstearns this is exactly how you're supposed to do unsafe code. Make it as small as possible so that it's easy to read and verify (by humans) that it does only the thing it's supposed to do.
If you are writing a kernal and it bootstraps in that is the effective OS. You can do that with any compiled language, C,C++ ... How do you think Operating Systems are created? If anyone wants to learn a lot more grab a book called "developing your own 32 bit operating system" You can use the same methods to create a 64 bit system or a lot more.
really good video thank you! Im really confused, how can a file start at position 0x000..8000? what does that mean? Isnt each position incremented for each byte of data we have, and files start at position 0x0?
The file gets loaded at that address by the RP bootloader. We need to make sure the code we write is aware of that, otherwise offsets may be wrong in the code. Theoretically we could compile the code "position-independent" to get around this, but that's not always easy.
@@LowLevelTV ahhh its like an offset? so we have other data before that position (0x0 ..0x008000) and that file is loaded after all that content exactly at position 0x00..800
@@jordixboy at address 0x00000000 is the start of the bootloader (it's own vector table). and the 0x8000 offset is to be future proof (so the bootloader can grow/be replaced by another one without exceeding the reserved max size)
I'll give it a gold star for devising the most complicated way so far to flash and LED with a microcontroller. One wonders how many lines of code does it take to add two and two. More than the number of electricians to fit a lightbulb I'd say.
That's what we did on the university, but I was never good enough to actually get a job in embedded, so I just write Python stuff... Good luck to anyone pursuing this as a career choice. This is however a great hobby and great for home automation, maybe starting your startup...
I don't do rust, but still super useful information. I just got a pico W to do bare metal programming (and learning "properly" ARM assembly at the same time). next step is using a hardware timer instead of a loop?
Negative numbers are actually postitive, but with 1. For instance, 8-bit signed integer 2 would be 00000010 in binary, and negative 2 would be bitwise_not(2) + 1 = 11111101 + 1 = 11111110. When they are combined, it is equal to 100000000, and 1 gets truncated because its 8 bit. 2 - 2 = 0.
It's fantastic to have so much knowledge packed into such a short video, BUT this knowledge should not even be necessary! How one even gathers all this info on their own? That would probably take a few more hours to explain :) I think this video clearly demonstrates how abnormal is the current state of software development: * Half the story was about how to *disable* features. * We needed a linker configuration, which was *not* in Rust, but some whatever file format, AND it was just as long as the final program. * It also had to be copy-pasted, because it isn't intuitive enough to remember. * Nothing in the 1st half was related to LED blinking. * At the end of the 2nd half, we had to *download and trust* 3 binary files, ~3 *million* bytes in total, with "magic" file names, to run this ~200 byte (NOT *kilobyte*, just *byte*) example program. * Finally, we had to *disable* a feature, again, because we are not even utilizing the full 64bit capabilities of the hardware.
How do you learn this information starting at 2:14? This just feels like some sort of esoteric knowledge that one has to dig really deep to find. Not at all intuitive. But then again maybe I feel like this because of my limited knowledge of computer hardware.
My question is: why are all these initial settings wrong? Like is there a case where you do baremetal coding on ARM and want to have all the extra data in the beginning of the code? I'm sure there's reasons why the things are done like this initially, but I don't know the whole picture.
It depends how the core starts up (is there a bootloader, which address does the CPU jump to on reset etc.) this depends on the manufacturer and/or whoever made the bootloader (if one is used). Unless you use a compiler specifically made for a specific target processor, you will need a linker script even for other languages like C, C++ etc. because the compiler doesn't know how the processor works outside the instruction set.
It's just an arbitrary amount. NOP = no operation, which is used to make the program sleep. If it's blinking too fast, make it more. If it's too slow, reduce the number.
It looks really good.... I just wish you could get something with RISC-V that was as cheap as a Blue Pill .... RISC-V is better than ARM..... anything is better than ST Microelectronics..... but that Blue Pill is everso cheap!
.... oh, pardon me, I was thinking about the Lo-Five.... But, again, the price compared to a Raspberry Pi is kinda shocking. Without them getting the price down, despite any superiority of design, I don't see how RISC-V will ever compete with ARM.
Well it is not that bad if the program memory can be loaded from an external SD card. If not then you need some kind of gateway into the built in flash, usually board producer provides these.. custom boards it is on you.
It's an incremental counter, imagine a for loop that does nothing but counts i from 0 to 50000 then exits, basically every timer is built like that, to count time you need a frequency clock to time ratio if you want to count seconds precisely.
Can someone explain the syntax he used for assigning the values to the memory addresses? Im just getting into this stuff and I am confused as to why bit shifting is necessary and what its actually doing there
I was trying this on a raspi zero v1.3 (because that's one I have lying around) But it's not booting properly (7 green flashes) I figured it probably wouldn't work but I'd just try. Where would I even start to figure out the changes I should make?
1. Very humble request sir, Can you make videos on how to find and learn things, for example how to get the neccessary information required to do xyz task, like the kernel and program you wrote to blink an led using rust, suppose If someone just thought about it and just wants to do a basic thing , how can they achieve it 2. Grapichs and ML/DL processing chip, something like running a stereo vision camera on a edge device which is not a SoC like raspberry pi, performs good, can run basic depth perception, or use an FPGA , a custom ARM chip for product development 🙏🙏🙏🙏🙏🙏 Please
Not a rust guy here, just older guy who used to do Turbo Pascal with Inline Assembler 30 years ago. Anyway, I wonder which constructs stops modern compiler, e.g. from optimizing away the nops?! Is anything inside asm never optimized (would be reasonable), or anything inside unsafe, or is it that Raspberry PI CPU don't make such optimiziations, or is because we never called an optimiziation pendant like the -O3? Maybe the question is dumb, but I'm so used to just add a MOV AX, 50_000 // not sure what's the 32/64 bit accumulator register pendant for Raspberry PI WAIT_LOOP: NOP DEC AX JNZ WAIT_LOOP so just doing the loop inside assembler on your own, where I might be concerned that a for _ in range(50_000) { asm("nop") } might be really optimized away by a compiler/LLVM?! Also, I noticed the generated loop in the assembler is a bit longer than my intuitive expectation. Is it because it doesn't use a register for the counter, or what did I miss here? Is it again because optimizations are not active?! I thought rust is good at detecting when to use registers is possible (it can't only be FORTRAN that gets it right, is it). Of course, as we are waiting here anyway, it's purely academic, but just trying to understand modern embedded systems with old fashioned half knowledge :-) A bit similar would be the question what stops the compiler from rearranging the lines. It's clear, that the lines with the volatile addresses can't be rearranged, but not so clear why the for waiting loop might not be rearranged as they don't touch the volatiles and also semantically don't do anything. Is it just me who don't understand optimizations or is it again because they are deactivated (with which instruction - there is no explicit release semantic visible like you would add in C)?! Anyway, great video, makes appetite to try it out on my own - still have to buy a Raspberry :-)
Hey! I'm trying to call Rust Functions from C environment using the static library generation in Rust for the Cortex-M0+ target which is thumbv6m-none-eabi in Rust...The Linker in the C environment always throws some missing sections error like "section .ARM.exidx.text._start isn't included by the sections map". When i add this section..it throws more and more sections continuously. Appreciate any help
Thank you so much for this video - that’s really cool! I have done something similar in C++ but to see this in Rust is awesome! A follow up question if that’s okay please: let’s say you wanted to write a Rust application to run on Linux on a RPi 3B, what would you prefer: using the /dev/gpio* interface, or actually tweaking memory mapped addresses? What does the Rust code look like there: obviously you don’t need to bother with no_main right? Would love to see an example - if you or anyone has done it please.
Thank you for the well made video! Which command can I use on windows to extract the binary from the elf file? I use the Visual Studio C++ Build Tools.
Does this not work on Raspberry Pi 3A? I didn't have any 3B+ laying around and so I did it on the 3A. LED came on but won't blink. Re-reviewed my work like 8 times hoping to find something I did wrong.
I have grasped many info from explanation. Some of them were completely new to me. I'll appreciate if you were able to zoom just to the area where lines of code are written, specially the IDE. Thanks,,
wanna get good at programming? check out lowlevel.academy and use code THREADS20 for 20% off lifetime access. or dont. im not a cop
Please do another tutorial on this stuff. It's really interesting.
Can you please Zoom in on the code. It's not readable on mobile screen.
100% disagree with your opening statement. The Rasberry pi is now impossible to buy. What should cost $50 is now selling for $190. All of you illegal rom downloading boi's who wanted emulation jacked up the prices. Way to go pirate. Way to ruin it for everyone else.
@@orangehatmusic225 Lockdowns had *nothing* to do with it? Seems a little short-sighted there; chips of all types were affected, including the car my dad wanted to buy.
Pirates STEAL ITEMS. Like Assange recently said, he didn't steal anything; he made a copy. Verbs matter. Ever hear "Possession is nine tenths of the law"? When people copy software, the original possessor does not lose their possession. It's more like lighting a candle from another candle.
Separately, the esp32 is like $5, a 240x240 color screen is another $5, and PictoBlox is like MIT's Scratch, for the smaller devices.
Or the Orange Pi, for $117.
So: I 100% disagree with your 100% disagreement. :)
Rust really runs on everything, even on my local iron river bridge!
I knew literally nothing about embedded systems and barely anything about Rust 18 minutes ago, and now it feels like it's a very acheivable thing to learn thanks to this demonstration. You're clearly a gifted teacher, fantastic video.
Welcome aboard!
@@LowLevelTV no pun intended :D haha
Now you can update your resume. :)
Same here. I have a background in web dev, but allost everything was new to me here. Yet, I‘ve understood pretty much everything and learned a ton. But honestly speaking, I will probably never learn this type of low-level programming. Just seems way too much effort to get something done when there are easier albeit less efficient tools/languages to use. Nice to be able to peek into this world though
@@LowLevelTV how do I compile for the 64bit version (aarch64) objcopy does not work and i could not find my Problem.
(I put AARCH64 in the linker script instead of ARM.eabi)
The great thing about your videos is the pace and "constant" narration. It feels like there isn't a single second in the video where you're not explaining what you're currently doing. That makes it very easy to not lose focus and attention as a viewer
Wow, thanks!
very true
@@LowLevelTV I agree. You really talk about every detail which is so important. The viewer has no questions, and you make no assumptions about what the viewer knows. I hope to watch more like this in the future :D
Really like that you use documentation as a reference to explain. Lots of tutorials skip the fact that documentation is there to help.
It's awesome that he does that, agreed! Just a few videos of this nature and we're downloading helicopter flight manuals between words of dialogue! :) (Matrix reference; as we age, our references get stale, like moldy bread one can use to cure disease or have interesting visions with.)
The amount of effort on this video to make it only 18 min is insane if you are a bit familiar with embedded system, thanks for it LLL
Much appreciated!
Thanks!
MARK! My guy. Thank you so much for this generous Super Thanks. I hope this video helped you in your embedded development journey.
as a recovering TS dev I'm watching this in complete awe! Thanks for explaining what you're doing, it leaves me with hope ;)
13:39 I would hope nobody would be mad. Unsafe code is basically the only way this can be done. It's just a fact. There's a reason rust has the unsafe keyword, because it's sometimes needed. :) Also, thanks for the video. It's very enlightening!
It is just same as writing C inside rust with more wording of course.
@@devrim-oguz unsafe rust is not C
Could probably be abstracted into a safe interface (or however it's called). Like a struct (with the PIN number) with methods or even plain functions (one for turning a hard-coded PIN on and the other for turning it off). But in the end the unsafe has be be somewhere.
Safe code is slower code, as there has to be a lot of hash inserts and checks and when you are processing movement, electrical spikes and wave forms, a lot of interrupts that are happening in the higher kilohertz range, such as signal processing, your program isn't gong to be looking at the web directly and should reject anything unexpected.
@@tsclly2377 safe code is not slower than unsafe code
I started working on an operating system in rust. I never went that far with it but it works. Can boot both legacy bios mode and modern efi style. Though only in qemu on efi. Don’t have video output properly working on any real efi hardware I have. But with bios boot it works with a text mode console. Boots into long mode and all but no memory protection
You can make a `build.rs` file like this
```rust
fn main() {
println!("cargo:rerun-if-changed=./linker.ld");
}
```
to hint to cargo that a change in that file should also result in a rebuild
Great suggestion, I think you also need to set that build script in the Cargo.toml mainfest of your crate
Thanks for Everything you do LLL, Seriously your videos have invigorated my spirit and inspired me to learn more about computer systems and lower level langs. C and Go are becoming my favorite languages to write my code. I'm gonna try writing some rust today!. Thanks again! Keep up the great work!
Wow, thank you! I'm so happy to hear the videos inspire you :)
@@LowLevelTV Haha, that's interesting because my takeaway was that low level programming is so different that I know less about it than I thought :). I could probably follow along, but I'm SOL the second something goes wrong.
Cool, I like it!
I don't know any Rust, so this was a good guide on how building Rust for bare metal works.
For those who want to go further;
If you want to be remotely efficient, you'd use a timer interrupt instead of the nop loops.
Then you leave the timer to do it's thing, and whenever the time you've chosen happens, it will call your interrupt routine, which toggles the bit.
Then you can do something else in between, instead of wasting cycles in a nop loop.
That is, you can do simple round-robin multitasking etc using just interrupt routines and timers.
Doesn't matter for just blinking an LED of course, but interrupts are key to do more complex things on bare metal.
The panic handler function is for Rust panics. Not hardware faults. And #[panic_handler] is not called an option, it's called an attribute.
Calm down buddy
@@marcuskissinger3842 Not sure where the impression I wasn't calm when writing that came from, I just have a neutral tone.
@@VisualEhrmanntraut yeah but just relax
I really like how you explain not only how to do things, but how to look for things yourself (e.g. the broadcom datasheet or the rpi firmware). I already have a bit of experience in embedded programming but I'm sure this helps beginners a lot. And more importantly, it makes the whole field feel less magic and scary than just saying "this address controls this LED because I know it".
Grazie.
Thanks man, it took some adjustments to make it run in u-boot on a cortex-a9, but I figured it out eventually. Very helpful tutorial.
Absolutely killing it with how you're presenting. I'm not really a fan of Rust but I couldn't stop watching.
So glad I found this channel, I have been writing code for a long time and wanted to jump into some low level stuff to improve my wider understanding esp. embedded systems etc. You cover fundamentals so well and easily digestible. Thanks for this!
You should configure the internal timers to trigger an interrupt every millisecond to increment a counter. Then reference that counter to to get more precise timing on when the LEDs turn on and off.
osdev mindset
I am absolutely watching your channel from now on.This is the most I have ever learned from a programming video. I've been trying to learn how to be a low level developer for years. Since high school. WOW. It's quick. It's on point. And I can follow it. I love how you just filled in several gaps learning in only a few minutes. I could have stayed in college, and I am not knocking anyone who does, but I have a short attention span. Thanks for this. Don't even remember how I stumbled here.
Fantastic video, very very informative. Hope to see more content on RUST for embedded systems from Low Level Learning
More to come!
With all the soft soft tutorials that exist on YT, yours just created that "light bulb illumination" mont in my head. Thanks for taking the
This is reallz interesting. What are your plans on next courses for your platform? Will the current mini course get updates and more content?
Current mini course will probably stay in its current state while I work on the full AVR course. Thanks for watching!
Me as a web developer trying to learn more low level programming during most of this, "Funny words magic man." But really great video, and has helped me a ton.
Great video but can you please increase the font size of visual studio code? It's hard to read code. Thanks.
Yeah I'm sorry I realized this after I uploaded. I edit on a 4K monitor, didn't realize it was so small on YT.
The CPU must be running very slow for us to see that LED blink that slowly. 50000 nop operations is nothing for a modern CPU, and we shouldn’t be able to see the LED normally if it ran at the full speed.
Yeah that should be flashing at like 10KHz or thereabouts. ???
@@SqueakyNeb even arduino.. the processor is running at more than 10MHZ !
I guess utilising all the hardware and allocating cores and instructions sets to execute programs must be no easy job ig.
Although having even remotely close to raw access to a processor's capabilities and being able to control all the io and all interfaces like a boss.. is fascinating!
Might just become true thanks to the people who developed tools to flash sd cards or rpi with such a powerful.. self made os.
Nice. Finally no more annoying unavoidable Linux boot log messages in a console. Just a pure code and an awesome blinking ;)
I just started watching your videos yesterday and in every one you've had full facial hair, the beanie and glasses. Then this one autoplays and I'm like "wait...is this the same guy?" you look so different without all of those "modifiers" haha
this is incredible, thanks for sharing this knowledge
This was really interesting. It would be great to see 2 things:
1) A list of references of sources you read to understand each part of this problem including the tools to generate the image that was capable of being loaded into the PI. i.e. a learning path.
2) An approach where you halted the processor putting it into a low power mode until the hardware timer triggered an interrupt allowing you to advance the state of the LED. The spinning for a delay makes this a bad start outside of proving that something could be done.
I just found the channel and I loved the video. One thing that it makes me thing was: if is it possible to build a kernel with Rust, then running appa on top of it would be possible too. The possibilities to embed are endless
thankyou. someone who shows the meat of a topic, no fluff and just the right amount of fat. great contribution. cheers.
Wow seeing arm assembler at the end there really took me back to my assembler days of programming the first acorn risc machines…
7:23 you can also add an `include = [“linker script”]` section to the Cargo.toml file. I can’t remember if it’s in [workspace] or [profile] though
Using `global_asm` to change the link section of a function is not supported (since top-level items may be reordered arbitrarily, so it might not apply to what you want it to.
The intended way to change the section a function is in is with the link_section attribute, e.g. #[link_section = ".text._start"] pub extern "C" fn _start() { loop {} }
Such high quality content, thank you!
Hoping in the future you can find the time to create a whole course on embedded Rust, I'd sign up in a heartbeat.
>write a kernel to blink an LED
annd there goes all of the respect: either you’re overselling whatever program you’re going to write as a ‘kernel’ or you don’t really know what you’re talking about
the absolute best programming video I've seen in years
It seems like Rust is really gaining momentum at the moment. I've switched from learning web dev with JavaScript to focusing now solely on Rust, not for any particular field, I just want to really get to grips with Rust. I'm taking a gamble but it feels like a really good investment.
Excellent vid man. Been a while since I've done any embedded programming. Very cool seeing how to do this low-level stuff on a pi 😎👍
I wish RPi 4s were $35 once again...
Same :(
Hohoho... there are so many things I like about this video. If this is anything to go by, I'm gonna make time and binge watch tf out of this channel.
Welcome!
Superb quality by all means. Instant subscribe without a moment of hesitation.
Thanks for such a great introduction! My one question is just about the naming? Is _start convention or arbitrary? Should the entrypoint always be prefixed by an underscore? Is the name main forbidden?
_start is the Linux convention for the entry point to a binary. Not a requirement to call it that, although some compilers expect it
You are a living god among n, a legend worthy of praise. What you've uploaded here, will echo into eternity!
Hey! Awesome video.
As a viewer, I'd like to suggest increasing the font size (zooming the UI) to be clearer to read in small screens. Furthermore, as a concept in video making, it's better to avoid non-flat color elements like your transparent/medium opacity terminal. The video encoder has to sacrifice quality in texts (code) to embrace all details on screen (the diverse details in your wallpaper)
I realized after I rendered and uploaded that the font quality wasn't great :(. I'm transitioning my videos to 4K in the future to avoid this. Thanks for watching!
Actually, if its static then it doesn't detract any quality at all - Tom Scott did a great video about video quality, bit rate, and moving vs stationary details.
@@AbelShields Agreed, translucency is perfectly fine when static, which in this case 99.999% of the time it is; potentially even more 9s when considering the video is 60fps and the proportion of the screen that updates is quite small. The encoder/decoder will *absolutely not choke* on this sort of content.
To the video encoder, there is no difference here between a terminal with a translucent background, and a terminal with an opaque, washed out background image. Translucency only matters due to the complexity of attempting to compress something that is changing in extremely unpredictable ways, which translucent objects overlapping and moving on top of a moving background tend to cause.
I really like the flair the translucent terminal gives; please don't change it @Low Level Learning ! Though of course, please go to 4K to make the text nice and crisp :)
You were right guys. I forgot about it. Thanks for the correction!
Thanks for the fantastic tutorial! Could you show a good example of controlling GPIO without "unsafe"?
I don’t think you can, since you’re writing to uninitialised memory addresses, a massive safe rust nono
@@jovianarsenic6893 I'm pretty sure they do it in a safe way in some of the STM32 crates.... but I could be mistaken.
While not totally unsafe, but definitely more safe, you should wrap only the unsafe parts of the code. Have small subroutines that are entirely unsafe and call them from safe code. Pin-enable, pin-on, and pin-off (maybe the no-op if that requires unsafe as well) should all be their own functions that get called by the main loop which would realistically also be calling some kind of computational code that you definitely want to be checked
I was wondering this myself. There must be a way without using unsafe blocks. I know they’re trying to use rust in the Linux kernel, and kernel device work is almost all about writing bits to raw pointers. Surely rust in the kernel isn’t just all unsafe blocks.
@@Grstearns this is exactly how you're supposed to do unsafe code. Make it as small as possible so that it's easy to read and verify (by humans) that it does only the thing it's supposed to do.
If you are writing a kernal and it bootstraps in that is the effective OS. You can do that with any compiled language, C,C++ ... How do you think Operating Systems are created?
If anyone wants to learn a lot more grab a book called "developing your own 32 bit operating system" You can use the same methods to create a 64 bit system or a lot more.
Can you increase the font size in vscode? Its pretty hard to read. The font size in the terminal is very good
Fantastic video! Really wish they covered this in my software engineering degree. No time to learn like the present!
Never in my life i haven’t seen so unexpected transition, “let’s blink LED with your own kernel”
Amazing content! Congrats dude!
really good video thank you! Im really confused, how can a file start at position 0x000..8000? what does that mean? Isnt each position incremented for each byte of data we have, and files start at position 0x0?
The file gets loaded at that address by the RP bootloader. We need to make sure the code we write is aware of that, otherwise offsets may be wrong in the code. Theoretically we could compile the code "position-independent" to get around this, but that's not always easy.
@@LowLevelTV ahhh its like an offset? so we have other data before that position (0x0 ..0x008000) and that file is loaded after all that content exactly at position 0x00..800
@@jordixboy at address 0x00000000 is the start of the bootloader (it's own vector table). and the 0x8000 offset is to be future proof (so the bootloader can grow/be replaced by another one without exceeding the reserved max size)
The 8000 is the address in memory that the code gets loaded at. It's not a file offset which is just the position of the bytes in the file.
Amazing content, thank you!
My pleasure!
Unironically an actually good rust tutorial in general lmao
Very nice and well explained. Every tNice tutorialng is crystal clear and easily understandable.
Calling it: NASA will soon use Rust exclusively.
You should honestly start a udemy or something alike. You're a natural teacher!
I'll give it a gold star for devising the most complicated way so far to flash and LED with a microcontroller. One wonders how many lines of code does it take to add two and two. More than the number of electricians to fit a lightbulb I'd say.
Great tuto! Thank you! You just earned a new satisfied subscriber ;)
That's what we did on the university, but I was never good enough to actually get a job in embedded, so I just write Python stuff...
Good luck to anyone pursuing this as a career choice. This is however a great hobby and great for home automation, maybe starting your startup...
I have no idea what I just watched but I enjoyed it
My wife has said that I'm mad, but I assure you that I am not! Great video, thank you!
I don't do rust, but still super useful information. I just got a pico W to do bare metal programming (and learning "properly" ARM assembly at the same time).
next step is using a hardware timer instead of a loop?
Hardware timer/interrupt would be a good alternative way to do this. Good luck with your Pico W! I'm still waiting on mine :(
Negative numbers are actually postitive, but with 1.
For instance, 8-bit signed integer 2 would be
00000010 in binary, and negative 2 would be bitwise_not(2) + 1 = 11111101 + 1 = 11111110.
When they are combined, it is equal to 100000000, and 1 gets truncated because its 8 bit. 2 - 2 = 0.
Niceee what's the software used for the illustration at 0:45, I'd love to try it out
It's fantastic to have so much knowledge packed into such a short video, BUT this knowledge should not even be necessary!
How one even gathers all this info on their own? That would probably take a few more hours to explain :)
I think this video clearly demonstrates how abnormal is the current state of software development:
* Half the story was about how to *disable* features.
* We needed a linker configuration, which was *not* in Rust, but some whatever file format, AND it was just as long as the final program.
* It also had to be copy-pasted, because it isn't intuitive enough to remember.
* Nothing in the 1st half was related to LED blinking.
* At the end of the 2nd half, we had to *download and trust* 3 binary files,
~3 *million* bytes in total, with "magic" file names,
to run this ~200 byte (NOT *kilobyte*, just *byte*) example program.
* Finally, we had to *disable* a feature, again, because we are not even utilizing the full 64bit capabilities of the hardware.
Good video thank you , updated visual studio and everything worked. I'm really glad I found a working crack
How do you learn this information starting at 2:14? This just feels like some sort of esoteric knowledge that one has to dig really deep to find. Not at all intuitive. But then again maybe I feel like this because of my limited knowledge of computer hardware.
Excellent tutorial and information. Thank you for sharing. Just gained a new subscriber! Thanks again!
Thanks for the sub!
@@LowLevelTV my pleasure!
This is insane. I can't believe it didn't take _that_ much work to make this work in Rust
The most work comes in figuring out what you need to do. Scouring documentation, and elsewhere for the key information is an absolute pain.
My question is: why are all these initial settings wrong? Like is there a case where you do baremetal coding on ARM and want to have all the extra data in the beginning of the code? I'm sure there's reasons why the things are done like this initially, but I don't know the whole picture.
It depends how the core starts up (is there a bootloader, which address does the CPU jump to on reset etc.) this depends on the manufacturer and/or whoever made the bootloader (if one is used).
Unless you use a compiler specifically made for a specific target processor, you will need a linker script even for other languages like C, C++ etc. because the compiler doesn't know how the processor works outside the instruction set.
this is very cool. embedded programming is very interesting but so far i didn't dare to try it yet
WOW!!!! This video is very helpful!!
screen in the top left, look at where it says program and click on where it says “aggressive te” and change it to “analog app 1 te”
Would love more videos on baremetal kernel programming in rust. Maybe stepping slightly into OS programming ?
Wait a minute, how did you figure out how many nop's you needed?
Really good work, totally earned my subscription!
It's just an arbitrary amount. NOP = no operation, which is used to make the program sleep. If it's blinking too fast, make it more. If it's too slow, reduce the number.
Did you hear about starfive riscv board? Its not out yet, but looks nice
I have not! I'll have to go check it out.
It looks really good.... I just wish you could get something with RISC-V that was as cheap as a Blue Pill .... RISC-V is better than ARM..... anything is better than ST Microelectronics..... but that Blue Pill is everso cheap!
.... oh, pardon me, I was thinking about the Lo-Five.... But, again, the price compared to a Raspberry Pi is kinda shocking.
Without them getting the price down, despite any superiority of design, I don't see how RISC-V will ever compete with ARM.
Love your stuff! Big help!
Amazing content dude!
Glad you liked it
Cool, I thought bare metal would be much more difficult.
Well it is not that bad if the program memory can be loaded from an external SD card. If not then you need some kind of gateway into the built in flash, usually board producer provides these.. custom boards it is on you.
Would be cool if you explained how you came up with the number 50000 (like a word about the built-in clock).
It's an incremental counter, imagine a for loop that does nothing but counts i from 0 to 50000 then exits, basically every timer is built like that, to count time you need a frequency clock to time ratio if you want to count seconds precisely.
Can someone explain the syntax he used for assigning the values to the memory addresses? Im just getting into this stuff and I am confused as to why bit shifting is necessary and what its actually doing there
It looks really hard to do low level programming. Huge respect for those who do.
I was surprised how understandable tNice tutorials tutorial is, thanks!
I was trying this on a raspi zero v1.3 (because that's one I have lying around)
But it's not booting properly (7 green flashes) I figured it probably wouldn't work but I'd just try.
Where would I even start to figure out the changes I should make?
1. Very humble request sir, Can you make videos on how to find and learn things, for example how to get the neccessary information required to do xyz task, like the kernel and program you wrote to blink an led using rust, suppose If someone just thought about it and just wants to do a basic thing , how can they achieve it
2. Grapichs and ML/DL processing chip, something like running a stereo vision camera on a edge device which is not a SoC like raspberry pi, performs good, can run basic depth perception, or use an FPGA , a custom ARM chip for product development 🙏🙏🙏🙏🙏🙏
Please
Not a rust guy here, just older guy who used to do Turbo Pascal with Inline Assembler 30 years ago.
Anyway, I wonder which constructs stops modern compiler, e.g. from optimizing away the nops?!
Is anything inside asm never optimized (would be reasonable), or anything inside unsafe, or is it that Raspberry PI CPU don't make such optimiziations, or is because we never called an optimiziation pendant like the -O3?
Maybe the question is dumb, but I'm so used to just add a
MOV AX, 50_000 // not sure what's the 32/64 bit accumulator register pendant for Raspberry PI
WAIT_LOOP:
NOP
DEC AX
JNZ WAIT_LOOP
so just doing the loop inside assembler on your own, where I might be concerned that a
for _ in range(50_000) { asm("nop") }
might be really optimized away by a compiler/LLVM?!
Also, I noticed the generated loop in the assembler is a bit longer than my intuitive expectation.
Is it because it doesn't use a register for the counter, or what did I miss here?
Is it again because optimizations are not active?!
I thought rust is good at detecting when to use registers is possible (it can't only be FORTRAN that gets it right, is it).
Of course, as we are waiting here anyway, it's purely academic, but just trying to understand modern embedded systems with old fashioned half knowledge :-)
A bit similar would be the question what stops the compiler from rearranging the lines.
It's clear, that the lines with the volatile addresses can't be rearranged, but not so clear why the for waiting loop might not be rearranged as they don't touch the volatiles and also semantically don't do anything.
Is it just me who don't understand optimizations or is it again because they are deactivated (with which instruction - there is no explicit release semantic visible like you would add in C)?!
Anyway, great video, makes appetite to try it out on my own - still have to buy a Raspberry :-)
Now explain how to write a driver for micro sd in Rust.
I was wondering what I was going to do with my three day weekend :)
Not a bad way to spend your time!
i wonder.. how would threading work using barmetal ..
Hey! I'm trying to call Rust Functions from C environment using the static library generation in Rust for the Cortex-M0+ target which is thumbv6m-none-eabi in Rust...The Linker in the C environment always throws some missing sections error like "section .ARM.exidx.text._start isn't included by the sections map". When i add this section..it throws more and more sections continuously. Appreciate any help
Since we're writing to mem addresses, doesn't some part of the code fundamentally have to be `unsafe`?
Thank you so much for this video - that’s really cool! I have done something similar in C++ but to see this in Rust is awesome!
A follow up question if that’s okay please: let’s say you wanted to write a Rust application to run on Linux on a RPi 3B, what would you prefer: using the /dev/gpio* interface, or actually tweaking memory mapped addresses? What does the Rust code look like there: obviously you don’t need to bother with no_main right?
Would love to see an example - if you or anyone has done it please.
Thank you for the well made video!
Which command can I use on windows to extract the binary from the elf file? I use the Visual Studio C++ Build Tools.
Does this not work on Raspberry Pi 3A? I didn't have any 3B+ laying around and so I did it on the 3A. LED came on but won't blink. Re-reviewed my work like 8 times hoping to find something I did wrong.
It might blink way too fast (or way too slow). Maybe try to fiddle with the amount of NOPs.
Forth is easier than Rust for low level stuff. I can literally flip bits on the microcontroller or control a register just by plugging in a USB cable.
I have grasped many info from explanation. Some of them were completely new to me.
I'll appreciate if you were able to zoom just to the area where lines of code are written, specially the IDE.
Thanks,,
Was it possible to achieve this result w/o using unsafe code?
Great video 10/10 clear and interesting