As a long time C programmer this is not very convincing. A C program to do the same requires far less voodoo. All you need to do is take the address of the GPIO register then toggle the bit. No name mangling. No error handlers to override. Don't get me wrong I know rust does have some compelling features. It does seem odd to me that so many of what would be compiler options in C are hard coded.
Raspberry Pi Bare Metal Programming with Rust
61–70 of 96 posts
Re: Raspberry Pi Bare Metal Programming with Rust
#62I have the perfect project for this! Generate a signal using the GPIO ports to drive a mirror and camera in a synchronized fashion. Does anyone know if the RPi GPIOs can be driven at around 80KHz? I've seen reports that this is possible, but that the USB or video driver tends to lock the CPU for long times, messing with timings - but hopefully running on bare metal would take care of that.
http://www.erlang-factory.com/static/upload/media/1394631509...
There is a video for the presentation as well.
https://www.youtube.com/watch?v=OBGqVmzuDQg&list=UUKrD_GYN3i...
The trick is Bealgebone black has 2 co-processors PRUs and they can be used for realtime work:
http://elinux.org/Ti_AM33XX_PRUSSv2
It is a programmable 200-MHz, 32-bit processor with single-cycle I/O so it can be used to toggling GPIO pins.
Re: Raspberry Pi Bare Metal Programming with Rust
#63Earlier quoted context omitted.
You could do this with much less than an RPi. I would recommend using an AVR or better yet a 555 timer if all you need is an 80KHz signal. Let me know if you want help with this I'm looking for projects like this or something much more complicated.
I wouldn't recommend an AVR. That is outdated technology. Even Atmel mostly makes ARM microcontrollers now (and they are much nicer than their AVR ones).
Re: Raspberry Pi Bare Metal Programming with Rust
#64Earlier quoted context omitted.
Could you list which packages you tried to use which were blocked on a nightly? In many cases a package can be moved off nightly with trivial changes, I can try to do it.
I tried digging around but couldn't find the package names -- I could've sworn ansi-term ( https://crates.io/crates/ansi_term/ ) and hyper ( https://crates.io/crates/hyper/ ) were two of them, but it looks like they both use stable. Thanks though!
So what happened was that many of these packages existed pre-1.0 when there was no stability system. Nobody knew which features would be stabilized (if you go further back, the fact that things would be stabilized in such a way wasn't clear either).
So we all just used whatever feature we liked. Many of these unstable APIs or features had stable counterparts, but the choice to use an API/feature was made pre-stability, so nobody had any way of knowing. Which meant that a lot of unnecessary unstable API usage persisted after 1.0. Some crates made a transition. some were slower (I think hyper was pretty quick to stabilize). Servo, for example, didn't have any issue with using nightlies for various reasons so we kept using unstable APIs (I later audited and removed low-hanging extraneous unstable API usage. Most of our out-of-tree crates are stable too).
There have been efforts both by maintainers and by individual community members to bring crates to stable, and I think at the moment most useful non-plugin crates work fine on stable. Let me know (@Manishearth on twitter) if you find a crate that you need that doesn't work on stable!
Re: Raspberry Pi Bare Metal Programming with Rust
#65As a long time C programmer this is not very convincing. A C program to do the same requires far less voodoo. All you need to do is take the address of the GPIO register then toggle the bit. No name mangling. No error handlers to override. Don't get me wrong I know rust does have some compelling features. It does seem odd to me that so many of what would be compiler options in C are hard coded.
Of course that same ability lets you clobber anything else in your address space and leads to those lovely debugging sessions playing "track down what corrupted my datastructure".
I don't do much C/++ these days, but when I do (and it's a large codebase which is hard to debug), `rr` is invaluable. It works with Rust too.
Re: Raspberry Pi Bare Metal Programming with Rust
#66As a C programmer who fiddles with low level stuff I wonder why people get exciting about such trivial thing. Don't get me wrong. Rust is an interesting language. The thing described in this post is well within its capability, i.e. IMO there isn't really anything that worths bragging about. Such trivial thing neither demonstrates the real potential of Rust, nor answers important questions from real world engineering…
I read it as a primer for writing simple Rust programs that can run baremetal on the Pi (I've cross compiled for a Pi-with-OS before but never tried this) and access GPIO.
If you're talking about the HN upvotes, HN just tends to upvote posts mentioning Rust a lot :)
Have you looked at https://zinc.rs/?
Re: Raspberry Pi Bare Metal Programming with Rust
#67As a long time C programmer this is not very convincing. A C program to do the same requires far less voodoo. All you need to do is take the address of the GPIO register then toggle the bit. No name mangling. No error handlers to override. Don't get me wrong I know rust does have some compelling features. It does seem odd to me that so many of what would be compiler options in C are hard coded.
My experience doing this sort of stuff in C is that this class of complexities is still present, but hidden outside the source in the crt0 and build scripts. Putting it in the actual program text seems like an improvement.
I can't imagine the full C example for this is any prettier or easier to follow?
[ed: As for "no name mangling" - having such an easy way to turn it off when needed, and yet avoid collisions when you do need it seems pretty good to me. Perhaps just having something that's "extern" be umangled by default would be better -- but it's not like one needs to bend over backwards to get a "mostly safe" bare metal program here.]
Re: Raspberry Pi Bare Metal Programming with Rust
#68Outside of C, are there any other languages or platforms that can do this? I'd like something modern, but I haven't liked what I've seen with Rust personally.
Still alive: Ada, SPARK, ATS, FreePascal, D Controversial: Go (if someone ports the runtime to bare metal), embedded JVMs, embedded, Swift (depending how Apple drives it), .NET Native (if C# gets missing features from System C#) Faded away: Algol, PL/I, CPL, Mesa, Modula-2, Modula-2+, Modula-3, Oberon, Oberon-2, Active Oberon, Component Pascal, Turbo Pascal, Forth, Sing#, System C#
It could probably be argued that Rust doesn't add much on top of D (as a "better" C++) -- but between the mind-share and the focus on "safe" (and boxing in unsafe) memory access, I think Rust is really interesting. Not sure how run-time free D is coming along - believe there were some issues with the standard lib?
Ada was troubled by a confusing split between FSF LGPL Gnat trailing Ada Core GPL/commercial compiler with a release -- leaving people a little confused if there was a good Free Ada compiler that could be used for commercial (or just non-GPL) development. (Yes, it was a real issue, just as one needs an LGPL libc for c development etc).
But as I understand it the GNAT compiler has matured to the point that one can now use modern Ada without having to worry about that. Unfortunately Ada probably lost a lot of potential developers due to the confusion/issue.
Re: Raspberry Pi Bare Metal Programming with Rust
#69Earlier quoted context omitted.
Yeah 80khz should be no problem. Even in Linux if you access the Pi's GPIO registers directly you can toggle pins in a tight loop at around 1-2mhz. As others mentioned though you might look at a small microcontroller though since the Pi is kind of overkill for generating a simple signal.
> Even in Linux if you access the Pi's GPIO registers directly you can toggle pins in a tight loop at around 1-2mhz. Careful, this is strongly dependent upon the hardware, not Linux. I seem to recall that people doing SWD programming can barely get the GPIO's to move faster than a couple of KHz. I can tell you that, at least on the BeagleBone Black, you have to do some Linux driver voodoo to get better than a couple…
Re: Raspberry Pi Bare Metal Programming with Rust
#70Earlier quoted context omitted.
> Even in Linux if you access the Pi's GPIO registers directly you can toggle pins in a tight loop at around 1-2mhz. Careful, this is strongly dependent upon the hardware, not Linux. I seem to recall that people doing SWD programming can barely get the GPIO's to move faster than a couple of KHz. I can tell you that, at least on the BeagleBone Black, you have to do some Linux driver voodoo to get better than a couple…
On the other hand, the BBB has two dedicated on-chip MCU's for driving the GPIO's.
The speed on the BBB for GPIO's is okay (I can get to about 12.5MHz with some care). It's more annoying that you actually have to be in supervisor mode to change the I/O direction of a GPIO pin.