News for hackers. Stuff that matters.
Re:Programming ARM Cortex-M Microcontrollers with Rust by turbinerneiter on Sunday April 09, 2017 @06:27AM (#14071521)
I recently finished my Master's Thesis on using anything other than C/C++ on microcontrollers.

It's a mess. A couple of languages like Rust, D, etc. can be hacked on micros due to their compiler suite, but it is always messy. Above guide uses inline assembly to blink a GPIO. Hardware access is on register level. None of this makes your live easier.

In order to be viable for microcontrollers you need two things: * a compiler or interpreter for your target * a Hardware API

There are some projects, like MicroPython and Espruino who realized the importance of the Hardware API. They basically transcend micro-interpreters and RTOS (especially given the languages asyncio features).

Microcontroller vendors ship C/C++ libraries for their hardware. You either have to wrap that, like the micro-interpreters do, or your language has to be able to use them natively.

What Rust on microcontrollers need is a Kickstarter campaign with a nice dev-board as perk to finance a project that implements a nice API for that specific micro.

Re:Programming ARM Cortex-M Microcontrollers with Rust by kam on Sunday April 09, 2017 @10:01AM (#14072316)
> Above guide uses inline assembly to blink a GPIO.

No, the only inline ASM in this guide is to cause a debugger breakpoint. You also need inline ASM to enable/disable interrupts, and that's about it.

The code in this guide looks ugly because it's written to show how to use the hardware without any abstraction. Higher level APIs like f3 (https://docs.rs/f3/0.3.1/f3/) exist, though not nearly for every chip or peripheral. Even in C, for anything outside the popular Arduino/mbed/etc boards, your choice is usually between buggy vendor bloatware and using the registers directly after carefully reading the datasheet.

Re:Programming ARM Cortex-M Microcontrollers with Rust by snovv_crash on Sunday April 09, 2017 @05:24PM (#14074443)
From what I've seen, using registers is often simpler and easier than using the vendor GPIO libraries.
Re:Programming ARM Cortex-M Microcontrollers with Rust by turbinerneiter on Sunday April 09, 2017 @10:31AM (#14072472)
True, I was a bit hyperbolic.
Re:Programming ARM Cortex-M Microcontrollers with Rust by robotjosh on Sunday April 09, 2017 @09:14AM (#14072120)
The vendor SDKs are the weak link, not the compiler or language. Development could go 4x smoother if the vendor code were solid. Every single project I bump into sdk bugs that make it clear they have shipped code that was not tested. Its like they expect us to debug their code that they had developed on the cheap. Lately my philosophy is to just take the vendor header file and write my own low level drivers because it takes a more predictable amount of time. Our industry could use 3rd party SDKs.
Re:Programming ARM Cortex-M Microcontrollers with Rust by petra on Sunday April 09, 2017 @10:54AM (#14072561)
There's a big conflict in mcu development:On the one hand, you have developers who want reliable and comfortable libraries so they can develop well and fast. Higher-level is a word to describe that(it's only partially accurate).

On the other hand, mcu companies make a significant amount of their profit based on lock-in(since mcu's are mostly commodities). And the higher level the API's and the rapid development is, the less lock-in companies get.

That together with the fact it costs a lot to develop quality libraries are the main reason to the state we're in today.

As for solutions:

1. ARM did face that problem once, with cores, and played it hand well , they came to mcu vendors and told them - the carrot: using our core will save you money on development(core/compilers/etc). The stick: a startup called luminary-micro , who could do cheap mcu's since all that was free.

- So can this move be played again, today, with peripherals ? maybe build a nice peripheral set, with libraries, well tested, etc - and offer it cheaply to the risc-v guys , and other mcu vendors, including Chinese mcu vendors ?

- Maybe the place to look for quality libraries is at mcu startups ? the last one was the acquired energy-micro , are their libraries better ?

2. The IOT is a big shift. Shifts create different leverage points sometime. Is there something that open-source community can do together to push the vendors towards great libraries in that niche , even if vendors don't like it much?

For example, what if the open-source community focused on one of the hardest building block of the IOT - security ? what if we created a highly proven security IP, proven by the community to a great extent, but used it licensing to push mcu vendors ?

Are there any other ideas how to solve this conflict ?

Re:Programming ARM Cortex-M Microcontrollers with Rust by user5994461 on Sunday April 09, 2017 @02:16PM (#14073579)
I don't think they need software lock-in. They already have hardware lock-in, which is easily 10 times stronger.

Rewiring and redesigning all electronics around a new MCU is just an insane undertaking. Irrelevant of API change in the software.

Re:Programming ARM Cortex-M Microcontrollers with Rust by petra on Sunday April 09, 2017 @03:02PM (#14073789)
In the EBM embedded survey 2013, regarding microcontorllers[1], they asked the question "why did you use the same processor", pg 56:

https://www.slideshare.net/MTKDMI/2013-embedded-market-study...

Many of the reasons we're regarding software, indicating that software lock-in is a significant factor.

[1]they called it microprocessors , but pages 54, 60 hint we're talking about mcu's.

Re:Programming ARM Cortex-M Microcontrollers with Rust by user5994461 on Sunday April 09, 2017 @03:10PM (#14073831)
Assuming there was a bit of standardisation around the basic API. There is still significant lock-in by other factors.

It could be that the software is the thing they think first, if you ask the people writing it.

Re:Programming ARM Cortex-M Microcontrollers with Rust by petra on Sunday April 09, 2017 @03:37PM (#14073981)
Maybe. But you have to consider that such surveys(and similar tools) could make semi company managers believe that software lock-in is important, and that's all it takes.
Re:Programming ARM Cortex-M Microcontrollers with Rust by robotjosh on Sunday April 09, 2017 @11:56AM (#14072869)
freertos or projects like that could help. They need different drivers anyway so good rtos support would mean you can ignore the official sdk.
Re:Programming ARM Cortex-M Microcontrollers with Rust by user5994461 on Sunday April 09, 2017 @02:17PM (#14073587)
Agree. Hardware SDK and tools are utterly terrible.

That's the major reason I stay away from embedded development.

Re:Programming ARM Cortex-M Microcontrollers with Rust by pjmlp on Sunday April 09, 2017 @10:29AM (#14072458)
> Microcontroller vendors ship C/C++ libraries for their hardware

They also ship Basic, Pascal, Ada, Oberon and Java, here's a small selection for those curious about the offerings.

https://www.mikroe.com/

http://www.astrobe.com/default.htm

http://www.microej.com/

http://www.adacore.com/press/8-bit-avr-microcontroller/

https://www.parallax.com/microcontrollers/propeller

https://www.parallax.com/microcontrollers/basic-stamp

Re:Programming ARM Cortex-M Microcontrollers with Rust by petra on Sunday April 09, 2017 @10:10AM (#14072359)
Is creating a Hardware API that complex that it would require a kickstarter ? because this link talk about using rustbindgen to automatically generate embedded bindings to a vendor library:

https://spin.atomicobject.com/2015/05/21/generate-embedded-r...

Re:Programming ARM Cortex-M Microcontrollers with Rust by turbinerneiter on Sunday April 09, 2017 @10:34AM (#14072483)
Creating a _nice_ and _reliable_ API with _good_ documentation that is _native_ to the language - I do think so, yes. Also keep in mind that there would be a specific devboard to build a community around.
Re:Programming ARM Cortex-M Microcontrollers with Rust by dbcurtis on Sunday April 09, 2017 @11:32AM (#14072745)
Total agreement.

And even before the coding starts, defining good abstractions for complex peripherals is very difficult. Counter/timer modules are the poster child for that. Heck, if you look at the Micropyothon issues on github you will find pages of vigorous debate about GPIO pullup configuration, much less anything complex.

Re:Programming ARM Cortex-M Microcontrollers with Rust by valarauca1 on Sunday April 09, 2017 @06:46AM (#14071596)
C/C++ library?!?

In my experience most bundle their own compiler suite. Nothing like learning what parts of C++03 are/aren't implemented.

Especially in the RTOS space where most the time your program is just an object file being injected into the OS.

Re:Programming ARM Cortex-M Microcontrollers with Rust by turbinerneiter on Sunday April 09, 2017 @06:49AM (#14071606)
True, the libraries are C. Compilers are often gcc. Like AVR has a gcc compiler and as you said some parts of C++ are implemented. For ARM there is also a gcc.

I only have experience with AVR and ARM (STM) to be honest.

Re:Programming ARM Cortex-M Microcontrollers with Rust by uxp on Sunday April 09, 2017 @09:30AM (#14072175)
I came across this [0] yesterday while looking for STM32 stuff for those cheap ass $2 STM32F103 boards. To your point, however, it's still just writing values directly out to register pointers. That entire repo can be boiled down to one little C program like this [1].

0. https://github.com/jamesmunns/bluepill

1. https://gist.github.com/uxp/35c9d5d51b2229f5c4c2e5b11c3341e5

Re:Programming ARM Cortex-M Microcontrollers with Rust by AlphaSite on Sunday April 09, 2017 @08:54AM (#14072035)
The MBed suite is rather nice to use.
Re:Programming ARM Cortex-M Microcontrollers with Rust by ksrm on Sunday April 09, 2017 @05:13PM (#14074399)
Perhaps a viable way to break the monopoly that C/C++ has in embedded software is to create a language that compiles to C. That way people can use their existing compilers (which may be the only choice for a particular target), drivers, middleware, etc. but benefit from a modern, safe(r) language.
Re:Programming ARM Cortex-M Microcontrollers with Rust by desiderantes on Sunday April 09, 2017 @05:45PM (#14074523)
Re:Programming ARM Cortex-M Microcontrollers with Rust by fest on Sunday April 09, 2017 @09:03AM (#14072080)
Another interesting language for embedded targets is Ada: http://blog.adacore.com/tag/STM32
Re:Programming ARM Cortex-M Microcontrollers with Rust by geon on Sunday April 09, 2017 @10:56AM (#14072570)
Did you look at Céu? A really cute language, I think.

http://ceu-lang.org/

Re:Programming ARM Cortex-M Microcontrollers with Rust by pcarolan on Sunday April 09, 2017 @01:40PM (#14073392)
Can you go into your experience evaluating MicroPython a little deeper? What were the pros and cons you discovered?
Re:Programming ARM Cortex-M Microcontrollers with Rust by turbinerneiter on Sunday April 09, 2017 @04:41PM (#14074258)
Look out for ISBN 978-3-8007-4395-7 "Evaluation of MicroPython as Application Layer Programming Language on CubeSats" in the "ARCS 2017 Conference Proceedings" - paper should come out soon enough.

I have a presentation under http://plamauer.space/presentation.html - hard to follow without moderation, but pros and cons are at the end.

Re:Programming ARM Cortex-M Microcontrollers with Rust by mafribe on Sunday April 09, 2017 @08:13AM (#14071892)
Is your Masters dissertation online? I'd be interested in reading it.
Re:Programming ARM Cortex-M Microcontrollers with Rust by turbinerneiter on Sunday April 09, 2017 @10:30AM (#14072465)
I do plan to make it a website, like a gitbook or something, but right now, I'm hammocking.

Also don't expect much. I'm a Mechanical Engineer and it was a bit out of my league, so it didn't go very deep.

The paper will hopefully soon be published: ISBN 978-3-8007-4395-7 "Evaluation of MicroPython as Application Layer Programming Language on CubeSats" in the "ARCS 2017 Conference Proceedings"