5
\$\begingroup\$

Pardon my naïveté, but it seems like most programmable devices (FPGAs, PLCs, PICs, etc.) are programmable using the C or C++ languages, or a variant of one of these. Are there any devices out there that use something like D, Mozilla Rust, or Google Go? I realize that the latter two, especially, are immature languages; but surely someone, somewhere has released an experimental product.

Does anyone have any suggestions?

\$\endgroup\$
  • 1
    \$\begingroup\$ Do you like Forth? That's a popular language for embedded devices. There was a recent article here and discussion on Hacker News here, with very informative comments. Don't have time to bring any of that over here at the moment, though. If someone wants to craft that information into an answer, I'd be much obliged! \$\endgroup\$ – Kevin Vermeer May 23 '11 at 3:12
  • \$\begingroup\$ @reemrevnivek I actually saw that article earlier today, and I don't think Forth fits my personal taste, but definitely thanks for sharing that! \$\endgroup\$ – arussell84 May 23 '11 at 4:06
  • 2
    \$\begingroup\$ What would the modern languages bring to (really) embedded programming? PS. In this context by embedded programming I mean programming in which a Cortex-M3 is a screaming performance beast and you only ever use on-chip SRAM and Flash. \$\endgroup\$ – jpc May 24 '11 at 21:54
  • \$\begingroup\$ @arussell - Yeah, I wasn't sure it fit the mold of D, Rust, or Go. \$\endgroup\$ – Kevin Vermeer May 24 '11 at 22:14
  • \$\begingroup\$ related: What are good options for beginning hardware programming using high-level languages? \$\endgroup\$ – davidcary May 28 '11 at 3:48
14
\$\begingroup\$

You don't need different devices to use these languages, you just need the appropriate software system.

The main issues why this is not done more often are:

  • These languages typically need more resources (memory, runtime) for the same task. For large volumes the reduced effort in programming would be more than offset by higher hardware costs.

  • Most higher-level languages need dynamic memory allocation with garbage collection, which is hard to do in a real-time setting.

  • It is harder to get embedded developers for these languages.

That said, there are such things as Real-Time Java, which are used in real embedded systems.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ While not providing all the details I was looking for, your answer ultimately led me to my answer. Taking a PIC as an example, there are multiple steps in between the process of writing code on your computer and having that code running on the PIC. You have to compile it and upload it, and there are different ways to do even these. In order to, say, write with D for a PIC, someone would have to write an equivalent of SDCC for D. \$\endgroup\$ – arussell84 May 22 '11 at 22:36
  • \$\begingroup\$ Additional point: In Embedded systems, (especially small ones with no OS etc.) many of the features (and overheads / penalties) of higher level / more modern languages are at best irrelevant or actually undesirable. \$\endgroup\$ – John U Oct 6 '14 at 17:24
4
\$\begingroup\$

There are open source projects working on such goals. There is a project for Ada on Atmel MCUs (though I couldn't get it to work). One of my coworkers is programming his 68HC11 MCU with a scaled down version of Ruby he has been working on himself. And there is a company, BlueSpec, that has a new HDL for FPGAs/ASICs that is based on Haskell. But it is not a tool that most would have access to.

Vendors tend to stick with C because there is a large audience for C and it is widely accepted. Likewise, for FPGAs/PLDs, VHDL/Verilog are widely accepted and proven. Instead of having to support many different languages, most prefer to focus on their chips, trying to improve the performance of their C compilers and offer better tools for configuring and managing resources on their chips. I kind of agree with this approach myself. I much prefer that Texas Instruments improves their tools for configuring advanced peripherals on their chips than implementing advanced template metaprogramming on their minimal C++ compiler.

| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

You are pardoned.

The reason that C, and less C++, (among other language as VHDL) is used for these kinds of devices is that it is easy to translate from the language constructs to the underlying hardware. C is considered lingua franca, understood by many and to port a new language to the device, especially if reading/writing to registers is awkward, is not worth the effort if the language isn't much better at expressing useful constructs.

The examples that you use as newer, shinier languages, D, for example, could be a candidate for a "low-level" language if more programmers use it. D is touted a the modern C++ without all the compromise with C and implemented right from the start. Unfortunately without all the C++ libraries. I think you can call C libs from D.

The question isn't if it is newer, the question is if they are better tools. As far as I can see, it isn't the case.
edit
When I have written embedded code (in C) I have wished for a better macros/templates than C can offer. As it is a compile time construct, it really has nothing to do with the underlying hardware. But much more complicated to implement in a compiler.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ You could use an external macro-processor, such as m4. It's very powerful. \$\endgroup\$ – Leon Heller May 21 '11 at 11:24
  • \$\begingroup\$ I've found myself wishing for the ability to overload inline functions based upon whether the compiler can evaluate a parameter as a constant. In a function like "raise x to the power y", it would be worthwhile for an inline version to special-case constant powers of 0 to 3, and call a library function for other powers. It would not be worthwhile to generate inline code to test for those constants, though. Unfortunately, I don't know nay compilers, for any language, that can distinguish overloads based upon constant values. \$\endgroup\$ – supercat May 21 '11 at 21:19
  • \$\begingroup\$ @supercat: You can do template specialization in C++ to address some of these issues, but when doing so your arguments have to be in the template instantiation "<>" instead of the function arguments "()", which is not ideal. Can't have your cake and eat it too. \$\endgroup\$ – TRISAbits Aug 27 '15 at 15:37
2
\$\begingroup\$

Devices have been designed to use other languages efficiently, such as LISP/Scheme, Forth and Java. I don't believe that any have been designed for those languages you mentioned, perhaps they are not suitable for embedded systems (apart from D which should run efficiently on anything designed for C/C++). They could, presumably, be implemented on any suitable MCU, if someone wished to do so.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Perhaps Go and Rust ultimately won't be suitable for embedded programming. They are a bit new, I guess, but they claim to be systems programming languages, which is why I listed them as examples. There's also been some news regarding these languages recently in programming circles, so I tried to pick languages that weren't too obscure. \$\endgroup\$ – arussell84 May 25 '11 at 7:38
2
\$\begingroup\$

There's always netduino, which lets you code in .NET.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I'm not a fan of .NET, but that is pretty much the type of thing I was looking for. =) \$\endgroup\$ – arussell84 May 24 '11 at 5:39
2
\$\begingroup\$

Take a look at Micro Python http://micropython.org/

Micro Python is a lean and fast implementation of the Python 3 programming language that is optimised to run on a microcontroller. The Micro Python board is a small electronic circuit board that runs the Micro Python language.

It was successfully funded as a kickstarter project in Dec 2013 and they have a reference board.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

You are looking for a microprocessor. Intel sells them, so do AMD and ARM. You can use any programming langue on these devices.

As for FPGA's: your choice of languages is limited. This is because you need a synthesis tool that will translate your code to a netlist. In addition to VHDL, Verilog and (restricted C), you can go with more modern languages like MyHDL (built on Python) or Bluespec (Haskell-like).

| improve this answer | |
\$\endgroup\$
  • 2
    \$\begingroup\$ Microcontrollers are merely low-power microprocessors with integrated peripherals. You can't run any old programming language on an FPGA (with soft core, I think we're assuming) or microcontroller because they're too slow, too small, and too low-level for other languages to work well (and, consequently, they don't have compilers written for those languages. Microprocessor vs. Microcontroller isn't the distinction we're interested in here. \$\endgroup\$ – Kevin Vermeer May 23 '11 at 3:17
  • \$\begingroup\$ I did not say microcontroller, I said microprocessor, which includes microcontrollers, but also your regular Intel Core i7 processor. As for FPGA's with soft cores or hard cores; they come in many different sizes and yes, the can run any language. They run an entire Linux operating system. \$\endgroup\$ – Philippe May 24 '11 at 8:23
  • \$\begingroup\$ Your citation of Intel reminds me of that old chip : 8052AH-BASIC. dusko-lolic.from.hr/i8052fract/sbc1.jpg. It had a BASIC interpreter in ROM ! \$\endgroup\$ – TEMLIB Oct 7 '14 at 0:52
1
\$\begingroup\$

Firstly your examples are small devices that has a limited set of resources, then the old languages that is close to hardware like c and vhdl does the job well.

The new "cool" languages need more resources to run well, so my guess is that what you are seeking will come quite soon since the MCU is getting more powerful over time.

My point is that right most MCU:s is still programmed in C, and the cool guy has just started to play with C++ on those devices.

But if you have a look at the 32-bit ARM based MCU that has a lot more resources than the old 8-bit onces you can find crazy project like eLua, that tries to run the script language lua on a Cortex-M3 based mcu...

So we will get there, but it is going to take a couple of more years. And I don't think that any of those crazy project is ready for production use (yet), but some of them will be since it is faster do develop in languages with s higher abstraction level.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

There is a proof-of-concept application running under Rust on STM32F4xx ARM microcontrollers. The surprisingly minor changes necessary to port Rust are available in this Rust fork.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.