News for hackers. Stuff that matters.
Re:Embedded in Rust: Brave new I/O by vvanders on Friday January 19, 2018 @03:39PM (#16189570)
This is amazing. Register and peripheral config is so easy to fuck up and waste a whole day chasing down because of limited debugging capabilities on these platforms. I've hit just about every one of those scenarios these compile-time guards now catch on one project or another.

Kudos, can't wait to see where to goes from here.

Re:Embedded in Rust: Brave new I/O by jfaucett on Friday January 19, 2018 @03:47PM (#16189646)
I know this has me really exited too. I think there is so much potential for rust in the embedded space. Personally, I'd be content if the core team just concentrated on making rust the best platform for doing embedded programming. IMHO that's where rust can really blow the competition away.
Re:Embedded in Rust: Brave new I/O by jvns on Friday January 19, 2018 @07:01PM (#16191076)
if you have ideas about what Rust should focus on in 2018, consider writing a blog post about your ideas! they have an open call for posts right now. https://blog.rust-lang.org/2018/01/03/new-years-rust-a-call-...
Re:Embedded in Rust: Brave new I/O by petra on Friday January 19, 2018 @04:14PM (#16189915)
The hard challenge in embedded is porting to every mcu. Can this be done without convincing mcu companies to do it themselves ?
Re:Embedded in Rust: Brave new I/O by henrikeh on Friday January 19, 2018 @04:37PM (#16190088)
Honestly it depends upon what people expect from "the port". A lot of people seem to be content with Arduino-like software compatibility: high-level constructs that offer basic functionality expected across a larger number of mcu's. Even something as "simple" as a timer peripheral will vary greatly across manufacturers and families of mcu's -- something you'd care about for real-time control, but not care about in other cases.

ARM controllers are (relatively) uniform and the svd files do a lot of the work by providing the mapping for the memory mapped peripherals.

Across other devices it becomes even more complicated. AVR devices, AFAIK, are not providing memory mapped flash. There are also differences in byte v page erasable flash and eeprom. How would something like this map to Rust? I don't know and I'm honestly skeptical of the practical use but there is a quite serious effort put into making the AVR backend for LLVM ready for use.

---

It really makes me wonder a lot about "embedded" programming and where it is heading. If I were to bet I'd say that there is a significant movement to employ more and more powerful "microcontrollers" in order to allow remove all the resource constraints typically associated with "embedded" programming.

Stuff like Esprino, MicroPython, huge layers of abstraction etc. are today kind of nice tools for learning and starting out -- but give it a few years and somebody will ship a successful product build around this. It doesn't matter that the BOM cost is higher, the current draw is larger and the complexity and security understanding decreased -- it enables a faster time to market and in the end that is what makes the business.

The same is happening in FPGA development.

The old-fashioned hardware folks say that "not how it's done" -- myself included. But you know what they say:

> When the wind of change blows, some build walls, while others build windmills.

Re:Embedded in Rust: Brave new I/O by nickpsecurity on Friday January 19, 2018 @09:01PM (#16191615)
No need to speculate: the market data has been showing a move toward 32-bit just as you thought would happen.

https://semiengineering.com/mcu-sales-up-in-2017-and-2018/

As vvanders says, the hard data shows plenty of the market is still maximizing profit by using 8-bitters (33%) and 16-bitters (26%). That's a combined 59% of microcontrollers a 32-/64-bit-only language would be leaving on the table in terms of deployment. Even ATS language, much more difficult than Rust, has already been deployed on 8-bitters.

http://metasepi.org/doc/metasepi-icfp2015-arduino-ats.pdf

Hopefully, Rust stays adding whatever features are necessary to support this stuff. If not, the Haskell crowd can always grab it up with DSL's like Ivory:

https://ivorylang.org/ivory-introduction.html

EDIT to add: A link about 4-bit MCU market that still exists for anyone wondering what that part of the pie chart was about.

http://www.ganssle.com/rants/is4bitsdead.htm

Re:Embedded in Rust: Brave new I/O by jabl on Saturday January 20, 2018 @08:57AM (#16193324)
Knowing very little about the low-end micro-controller manufacturing economics, isn't there some kind of lower bound limit where the marginal cost of the chip itself is utterly dwarfed by the cost of the pins and packaging?

Sure, a 32-bit chip is bound to be bigger than an equivalent 8 or 16-bit one, but e.g. the pulpino project has designed a 32-bit one using only 11.6 kGE. Not very much nowadays. For comparison, according to someone from Atmel, the AVR core is 12k gates, and megaAVR is 20k gates (https://www.embeddedrelated.com/showthread/comp.arch.embedde... ).

Re:Embedded in Rust: Brave new I/O by nickpsecurity on Saturday January 20, 2018 @11:03AM (#16193791)
I have no idea. They've probably optimized the hell out of it in ways we can't understand. I mean, I thought about getting academics to cover cost of putting Leon3 or RISC-V on a cutting-edge node where 32-bit would be so cheap FOSS could undercut them. They'd need to do peripherals, too, but EE students always need projects to learn with. :) The MOSIS runs I saw at the time had packaging alone at $10-20 a chip. I know it goes down for higher volume but how low can I get it on a new product doing maybe 10,000/units a year?

Well, let me show you how low they get it so you know what your reusable-for-better-products micro would compete with:

http://www.microchip.com/ParamChartSearch/chart.aspx?branchI...

The smallest one is designed, masked, printed on silicon, packaged and sold in 5k quantities at 24 cents a chip at a profit! That's nuts! I can only imagine what the 4-bitters cost. The cheapest 32-bitter I found were 32-bit NXP's at 10,000 units for about 50 cents. So, they're getting there. It's an understatement, though, to say the manufacturing costs are highly competitive in this sector. :)

Re:Embedded in Rust: Brave new I/O by Ericson2314 on Friday January 19, 2018 @10:22PM (#16191877)
Glad to hear it! Good languages as you agree have the potential to keep dev and material cost down, so there's no trade-off. But people seem to hate learning...anything, and was worried the market had already gone to too powerful devices out of laziness. Glad to hear the battle is not yet lost!
Re:Embedded in Rust: Brave new I/O by vvanders on Friday January 19, 2018 @04:46PM (#16190133)
> It doesn't matter that the BOM cost is higher, the current draw is larger and the complexity and security understanding decreased -- it enables a faster time to market and in the end that is what makes the business.

I think consumers are still going to be cost-sensitive in quite a few markets so BOM will still be critical. I'd argue you're already seeing this with more than a few companies using Android + mid-tier ARMs when market time matters more than final cost.

There's probably just going to be less people that know how to do it, much in the same way native programming is today.

Re:Embedded in Rust: Brave new I/O by fake-name on Friday January 19, 2018 @09:00PM (#16191613)
> ARM controllers are (relatively) uniform and the svd files do a lot of the work by providing the mapping for the memory mapped peripherals.

What?

Sure, the core is relatively uniform, but the peripherals are radically different between manufacturers.

Re:Embedded in Rust: Brave new I/O by FigBug on Friday January 19, 2018 @10:35PM (#16191915)
CMSIS provides an abstraction layer for peripherals, so at least the basics are the same between manufacturers. At least it's something, usually when switch MCUs you have to rewrite everything related to peripherals.

https://developer.arm.com/embedded/cmsis

Re:Embedded in Rust: Brave new I/O by dbcurtis on Saturday January 20, 2018 @01:10AM (#16192313)
True, but the main way an ARM licensee has to differentiate their product is adding unique peripherals. So the generic functionality is in CMSIS, but the reason you chose the processor may not be.

If you look at a die photo and see what area goes to what, pretty quickly you conclude all microcontroller makers are just selling value-added flash memory.

Re:Embedded in Rust: Brave new I/O by henrikeh on Saturday January 20, 2018 @01:17AM (#16192328)
Absolutely, device drivers must still be written. My observation is just that these device drivers are hidden deeper and deeper levels of abstraction, just like on a regular PC.
Re:Embedded in Rust: Brave new I/O by xfer on Friday January 19, 2018 @05:17PM (#16190381)
I have an xmos board(xcore architecture), although llvm has a backend for it, it is missing debugging support for timing analysis(XTA) and also outdated so potentially missing on various size optimizations.

Even ignoring that, because llvm instruction set mismatch between versions, i can't feed the rust generated IR to their firmware generating tool.

If you see their language xC(https://en.wikipedia.org/wiki/XC_(programming_language), it extends C with various pointer types(restricted, movable, alias) for memory safety. Rust definitely is a good fit for this kind of development with borrow checker, traits etc.

Re:Embedded in Rust: Brave new I/O by Eridrus on Friday January 19, 2018 @04:23PM (#16189997)
They could use Julia's "resurrected LLVM "C Backend"" and compile down to C, and then let developers use existing tools to get running on their MCU. Would probably mess with the debugging experience though.
Re:Embedded in Rust: Brave new I/O by steveklabnik on Friday January 19, 2018 @05:15PM (#16190363)
mrustc would be another path here.
Re:Embedded in Rust: Brave new I/O by nitrogen on Saturday January 20, 2018 @12:51AM (#16192271)
Would probably mess with the debugging experience though.

If the compiler in question supports the #line directive, it might not be too bad.

Re:Embedded in Rust: Brave new I/O by jfaucett on Friday January 19, 2018 @05:59PM (#16190737)
> The hard challenge in embedded is porting to every mcu. Can this be done without convincing mcu companies to do it themselves ?

Agreed, but I think long-term its certainly going to be easier doing that on the rust platform with a tool like cargo than the current state of affairs.

Maybe if rust just concentrated on the hobbyist/prototypers at first i.e. arduino / rasberry pi, to make that experience as great and pain free as possible and really showcase what can be done with rust and cargo. That would at least make it a viable tool for professors teaching the next gen of engineers and all the startups/prototypers/hobbiests.

Re:Embedded in Rust: Brave new I/O by steveklabnik on Friday January 19, 2018 @05:17PM (#16190388)
FWIW, I share your feelings regarding prioritizing this. In general, it's something we want, but we're still discussing what the overall goals for this year will be. We'll see!
Re:Embedded in Rust: Brave new I/O by robotjosh on Friday January 19, 2018 @07:20PM (#16191173)
What is limiting about being able to step thru each instruction?
Re:Embedded in Rust: Brave new I/O by vvanders on Friday January 19, 2018 @08:33PM (#16191507)
That's assuming that you have a functional ICE[1] and aren't dealing with a timing issue in another subsystem :).

ICE pins are usually configured with the exact registers this article talks about. It's common for UART/SPI serial port configuration to be a part of enabling ICE. Some chips also let you disable the ICE pins so that you can use them to pick the cheapest chip possible.

[1] https://en.wikipedia.org/wiki/In-circuit_emulation

Re:Embedded in Rust: Brave new I/O by alxlaz on Saturday January 20, 2018 @04:55AM (#16192803)
Why are you doing any kind of professional work, at such a low level, without an ICE?
Re:Embedded in Rust: Brave new I/O by __david__ on Saturday January 20, 2018 @05:52AM (#16192926)
Because ICEs are overrated. Many systems can't be debugged by single stepping (think servos or anything with physical hardware being controlled). ICEs rarely work well—every single one I've ever used was completely unreliable and required lots of fiddling to make it work. And then the next day you had to start the whole fiddling process over again. In the end they aren't very productive except for very specific types of bugs (they are invaluable in the very beginning of a project when you are bringing up a board). Once everything is generally up and running I find them to be pretty useless.
Re:Embedded in Rust: Brave new I/O by IshKebab on Saturday January 20, 2018 @03:50AM (#16192658)
Yeah if you can get that to work. It's usually a serious hassle.

Another issue is that with microcontrollers you are usually debugging really low level stuff like interrupts where you can't even do printf debugging. Or you are setting registers on some black box subsystem and it just won't work and the only way to fix it is just keep randomly changing registers until you find the one you got wrong, or if you're lucky find working example code and bisect from that.

Or you've got some timing sensitive code that you can't stop and the only debugging channel that is fast enough is toggling group connected to an oscilloscope.