Author Topic: Comparing "Modern" embedded chip programming languages?  (Read 42508 times)

0 Members and 2 Guests are viewing this topic.

Offline dferyance

  • Regular Contributor
  • *
  • Posts: 225
Re: Comparing "Modern" embedded chip programming languages?
« Reply #25 on: July 08, 2016, 04:57:38 pm »
I don't see a practical point of a language beyond C++ or something designed quite similar (e.g. D) for embedded systems. I have played around with python and one of the crazier things I have done is compiled F# to JavaScript to run on the Espruino.

My main experience with a scripting language on embedded was the Bluegiga one. Kinda like BASIC but their own language. But it was horrible for debugging and ran really slow. The thing would freeze if I toggled a pin too fast. The nice thing is I didn't need to pay for expensive bluetooth stacks or compilers but that was the only good thing.

I think those languages are interesting both for getting people who aren't used to embedded started as well as a fun way of experimenting. It is sorta like the O.S. kernels written in C# or Java. They aren't practical, but just plain fun to mess around with.
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 2001
  • Country: 00
Re: Comparing "Modern" embedded chip programming languages?
« Reply #26 on: July 08, 2016, 05:28:44 pm »
I think one big issues with exotic languages is the huge amount of bootstrapping code we take for granted. The device declarations, startup code, RTOS, device drivers (CMSIS), protocol stacks, etc. This is kinda a chicken and egg story; as long as there are no applications written in said languages there is no demand for said software.

Although I'm comfortable writing C, I think some of it's language features are abused to the max by it's "optional type system":

https://twitter.com/mariofusco/status/696296466831298560

The way you can cast objects or pointers is absurd really, and there are plenty of type violations that just generate a little warning or info that can be ignored. I wouldn't shed a tear when the day comes that is behind us. I think Rust is a good candidate (although constrained by that it has decent optimizations for embedded and toolchains); because it can interface with legacy C code. This could solve the "legacy" problem, although initially it would still appear like a hackjob when combining both facets.

In my experience C is all you need for writing ARM applications, except when you're messing around with the CPU context in for example a RTOS or a bootloader. But still the amount of ASM lines is fairly limited; probably not more than 50 or 100 for a fully functional RTOS. The startup code can be written completely in C; it consists of a const array that can be placed at the vector position via sections, and the reset vector can be a naked C function that initializes the C runtime and calls to main.

Most scripting languages I have programmed with (python, PHP, some Lua) have arguably even worse type systems; but IMO these languages are designed for "quick and dirty" code that's productive to write. Javascript is a infectious disease and I always have a feeling I lose some braincells when I wrote some.
 

Offline C

  • Super Contributor
  • ***
  • Posts: 1346
  • Country: us
Re: Comparing "Modern" embedded chip programming languages?
« Reply #27 on: July 08, 2016, 06:34:28 pm »

What I see here is a lot of one sided comparisons.

Bytecode is bad, very bad!!!
No thought of the good side of bytecode to justify this one sided comparison.
A good bytecode program should have lower memory requirements as the program gets larger. A slower program that can do more then native code in same memory size.
Make a fair comparison of bytecode that has some error checking to a C program that has the same error checking.
Their are a lot of possible steps between a bytecode interpreter and native code changing the speed vs space requirements.
Adding a non verbose requirement to a language removes the choice of what step you want. With verbose you can have a mix of any in one program. 
 

I see Pascal is Bad because ................
Again how is comparing a poor Pascal compiler against a good C compiler a fair comparison of Pascal vs C?

So if I want to switch to a new MCU, I need to spend days describing bit fields? No, thanks.
So instead you spend days creating defines?

I see a lot more chances for errors in bad defines then a structure or record. How can a compiler catch a bad define?

Quote
All my interrupts are described in pure C and it is such a pleasure that I'm not going back to writing them in assembly no matter what other benefits are.

In 1982 I was programming in pascal using an operating system written in pascal and the interrupts were in pure pascal.

If you want to use a new language you need to use the new language properly to gain it's benefits.

 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12516
  • Country: us
    • Personal site
Re: Comparing "Modern" embedded chip programming languages?
« Reply #28 on: July 08, 2016, 06:37:10 pm »
So instead you spend days creating defines?
No, I take manufacturer-supplied ones.

You can preach using Pascal or any other language all you want, I personally won't even bother looking at then until there is significant part of the industry already doing so. Too much of a risk.
Alex
 

Offline vodka

  • Frequent Contributor
  • **
  • Posts: 518
  • Country: es
Re: Comparing "Modern" embedded chip programming languages?
« Reply #29 on: July 08, 2016, 06:47:09 pm »
But creating a new language and pushing it into industry is really hard and I doubt it will actually happen. Banking industry still uses COBOL.


Why ? Simply , my father ,a  neolithic programmer  :-DD :-DD told me, the problem that had had the colombian with the  recount system of votes .

The colombian had modernized the system ,changing the Cobol for other modern  language program. And when they used the new system , it didn't terminate to recount votes.
After 12 hours ,the new system hadn't yet counted . Then , they stopped the machine and returned to old system(Cobol) , it terminated to count on less of the 10 minuts . :-DD :-DD
 

Offline dferyance

  • Regular Contributor
  • *
  • Posts: 225
Re: Comparing "Modern" embedded chip programming languages?
« Reply #30 on: July 08, 2016, 06:49:17 pm »
A good bytecode program should have lower memory requirements as the program gets larger. A slower program that can do more then native code in same memory size.

What kind of bytecode system are you talking about? Is this applicable for a JIT? An interpreter? Or pre-compiling the bytecode to native?

A JIT is too big to run on a lot of systems. Interpreters can have their merits. As you mention it can reduce code size at the expense of speed. However a lot of embedded processors have so little RAM that the RAM is more precious than code-size. When doing JavaScript on embedded I found it was way too easy to run out of RAM without really being careless. In the case of limited RAM an interpreter makes things way worse. Pre-compiling to native is fine, that is no different than the internal architecture of a lot of compilers anyway.

I see Pascal is Bad because ................
Again how is comparing a poor Pascal compiler against a good C compiler a fair comparison of Pascal vs C?

I've done plenty of Pascal work but it was almost entirely in the Delphi / ObjectPascal style. It is pretty comparable to C regarding performance and being able to map closely to the machine architecture. There are things I both like and don't like about it. It is nice to be rid of the ugly #includes but is verbose and too picky about other things. However sometimes you just gotta use what is popular. C compilers are everywhere and Pascal is far less less common. There are good arguments that Pascal is better than C but the best of them doesn't make a huge amount of difference. They are close enough to each other; I have to default to C.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12516
  • Country: us
    • Personal site
Re: Comparing "Modern" embedded chip programming languages?
« Reply #31 on: July 08, 2016, 06:52:54 pm »
Why ?
It has noting to do with speed of execution. They just have a ton of code that no one wants to rewrite and debug again.

The same reason why lots of mathematical libraries (LApack and such) are written in Fortran. Those libraries are used in lots of mission-critical applications (aerospace, civil engineering) and no one wants to rock the boat.
Alex
 

Offline autobot

  • Regular Contributor
  • *
  • Posts: 66
Re: Comparing "Modern" embedded chip programming languages?
« Reply #32 on: July 08, 2016, 07:24:26 pm »
Rust has a ton of overhead in a standard library and some language features.

The potential of Rust(with the right framework[1], and maybe small improvement to the language) to offer higher quality, more reliable software is there. The question is can you turn that into money, either by faster development(maybe), or by convincing customers this has value.

Maybe we're not there yet, but a lot of the pieces are there.

[1]With the right platform you could make sure peripheral initialization is safe at compile time(Zinc), That no data races happen including in interrupts(RustyGecko talks about it), Almost no memory errors happen(Rust), That your communication protocols are protected from hackers(Nom[2]), And other libraries that are possible in C but might occur in rust first because poeple like it because a safety culture may be created around it.

[2]spw15.langsec.org/papers/couprie-nom.pdf
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 10095
  • Country: us
Re: Comparing "Modern" embedded chip programming languages?
« Reply #33 on: July 08, 2016, 07:46:12 pm »
I have spent the last day or so dealing with Ada and how it is used to describe hardware.  It's pretty verbose but packed, named bits seems pretty useful.  In the GNAT package, there are several board support packages from which is should be possible to create a description for just about any hardware.  It's just records and fields...
So if I want to switch to a new MCU, I need to spend days describing bit fields? No, thanks.
Unless somebody gives you the #defines, you have to do the work anyway.
Quote

But that's pretty typical for ARM code anyway.
No its is not. With ARM Cortex devices one of the design goals was to not have any assembly at all. All my interrupts are described in pure C and it is such a pleasure that I'm not going back to writing them in assembly no matter what other benefits are.
There are still vectors to populate (97 of them?).  The big difference is in eliminating the preamble and postamble.  The Cortex is a great improvement.  The Ada approach is to use assembly language to populate the vectors, set up the operating environment, start up the FPU and the I/D caches.  It may just be for convenience because underlying Ada is the same GCC compiler that works for C.

Although I haven't tried it (obviously), there is some linkage between Ada and C or Fortran.  I kind of like Fortran so maybe I'll play with it one day.

Quote

it seems that I have some confusion in which library to use and where the USART registers are located.
Exactly. And try to work with something more complicated, like USB.

The library confusion is strictly on me.  That, and my board probably isn't the one the example code was targeted for.  More to follow when I get an older board some time next week.  I don't know much about USB but code is code.  Whatever the algorithm is that works in C it will also work in Fortran.  It might not be pretty but I'll bet it could be done.

I'm far from sold on Ada.  I don't really know why I am messing with it except that I am bored and looking for a project.  I have a STM32F746G-Disco board that might make a nice display for one of my FPGA projects.  I was thinking about writing the code in Ada just for the experience.  But first I have to get "Hello World" to work...
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12516
  • Country: us
    • Personal site
Re: Comparing "Modern" embedded chip programming languages?
« Reply #34 on: July 08, 2016, 08:02:08 pm »
Unless somebody gives you the #defines, you have to do the work anyway.
Most manufacturers give you header files. And all of them also give SVD files that can be used to generate your own headers. There is no real problem to create a converter from SVD to Ada-style definitions. But no one did it so far.

There are still vectors to populate (97 of them?).
Number of vectors depends on the specific MCU, but you can do that from pure C. Here is example of such pure C startup file https://github.com/ataradov/mcu-starter-projects/blob/master/samd21/startup_samd21.c
Alex
 

Offline vodka

  • Frequent Contributor
  • **
  • Posts: 518
  • Country: es
Re: Comparing "Modern" embedded chip programming languages?
« Reply #35 on: July 08, 2016, 08:09:54 pm »

They just have a ton of code that no one wants to rewrite and debug again.


And you have reason,but this code will have to upgrade according the new machines sooner or later somebody have to get source ,read,debug and modify
 .
The same reason why lots of mathematical libraries (LApack and such) are written in Fortran. Those libraries are used in lots of mission-critical applications (aerospace, civil engineering) and no one wants to rock the boat.

I believe that the prehistorics programmer haven't too faith and the youngs with his new programming methodology(POO). Furthermore, must have many valor for ordering to young that convert an old aplication.

As the colombian case ,a little ,fast  and working cobol application versus a big,slow and unworking modern aplication.

« Last Edit: July 08, 2016, 08:11:32 pm by vodka »
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6622
  • Country: 00
Re: Comparing "Modern" embedded chip programming languages?
« Reply #36 on: July 08, 2016, 08:15:19 pm »


From memory, PASCAL requires a semicolon as a statement terminator except for the last statement in a block, where it's not necessary since the block end forms the termination.  But you can add one if you want.


That's called 'statement separator', similar to enum separator in C.

 

Offline C

  • Super Contributor
  • ***
  • Posts: 1346
  • Country: us
Re: Comparing "Modern" embedded chip programming languages?
« Reply #37 on: July 08, 2016, 08:27:24 pm »
Unless somebody gives you the #defines, you have to do the work anyway.
Most manufacturers give you header files. And all of them also give SVD files that can be used to generate your own headers. There is no real problem to create a converter from SVD to Ada-style definitions. But no one did it so far.

There are still vectors to populate (97 of them?).
Number of vectors depends on the specific MCU, but you can do that from pure C. Here is example of such pure C startup file https://github.com/ataradov/mcu-starter-projects/blob/master/samd21/startup_samd21.c

SVD to ada done
https://www.eevblog.com/forum/microcontrollers/'make-with-ada'-competition/msg971184/#msg971184

edit to correct SCD to SVD above
« Last Edit: July 08, 2016, 08:30:18 pm by C »
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12516
  • Country: us
    • Personal site
Re: Comparing "Modern" embedded chip programming languages?
« Reply #38 on: July 08, 2016, 08:29:24 pm »
SCD to ada done
Well, that's awesome. I did not know about this.

Not that it will make me use Ada :)
Alex
 

Offline C

  • Super Contributor
  • ***
  • Posts: 1346
  • Country: us
Re: Comparing "Modern" embedded chip programming languages?
« Reply #39 on: July 08, 2016, 11:27:00 pm »
 dferyance
Think of what JIT is really for.
JIT lets a program run on many different processors and act the same on all. For a PC that is one program to i386 or x64 code for example.
Where is the need for JIT on a small embedded processor?
 
 

Offline timb

  • Super Contributor
  • ***
  • Posts: 2536
  • Country: us
  • Pretentiously Posting Polysyllabic Prose
    • timb.us
Comparing "Modern" embedded chip programming languages?
« Reply #40 on: July 09, 2016, 02:58:19 am »
dferyance
Think of what JIT is really for.
JIT lets a program run on many different processors and act the same on all. For a PC that is one program to i386 or x64 code for example.
Where is the need for JIT on a small embedded processor?

That's only one of the small advantages of JIT. There are many more advantages, speed being one of them.

Edit: For embedded systems, there's also the case of being able to write once and deploy on several different targets just like you mentioned. Like ARMv7 vs ARMv6. The JIT VM would take care of optimizing statics at run time, for example. I would say that's a bigger advantage on embedded devices due to the plethora of different architectures!

Remember back in the day you had MIPS, SH3, PPC, ARM, Xscale, etc. Now it's mainly come down to different flavors of ARM cores, though various routers still use MIPS and friends.

On the PC side, it's all basically x64 now. Aside from legacy applications, x86 is dead. (Embedded x86 use notwithstanding.)
« Last Edit: July 09, 2016, 03:11:44 am by timb »
Any sufficiently advanced technology is indistinguishable from magic; e.g., Cheez Whiz, Hot Dogs and RF.
 

Offline C

  • Super Contributor
  • ***
  • Posts: 1346
  • Country: us
Re: Comparing "Modern" embedded chip programming languages?
« Reply #41 on: July 09, 2016, 04:45:26 am »
Edit: For embedded systems, there's also the case of being able to write once and deploy on several different targets just like you mentioned. Like ARMv7 vs ARMv6. The JIT VM would take care of optimizing statics at run time, for example. I would say that's a bigger advantage on embedded devices due to the plethora of different architectures!

Remember back in the day you had MIPS, SH3, PPC, ARM, Xscale, etc. Now it's mainly come down to different flavors of ARM cores, though various routers still use MIPS and friends.

Think of the steps
1. Run a Program.
2. Use JIT to change JIT source to a program in RAM.
3. Run the Ram program.
4. Delete the Ram program.

Need to ask how much computing power do you want to waste?
How much longer startup time?
Is the program going to change each time it's run?

Go back a little more, 8080, 8085,Z80,6502,6800,6809,8051.
A JIT on these would probably cripple them.
 
If you change #2 from RAM to storage, Flash or something like this, then you have a compiler not JIT.
 

Offline vodka

  • Frequent Contributor
  • **
  • Posts: 518
  • Country: es
Re: Comparing "Modern" embedded chip programming languages?
« Reply #42 on: July 09, 2016, 06:00:56 am »
Edit: For embedded systems, there's also the case of being able to write once and deploy on several different targets just like you mentioned. Like ARMv7 vs ARMv6. The JIT VM would take care of optimizing statics at run time, for example. I would say that's a bigger advantage on embedded devices due to the plethora of different architectures!

Remember back in the day you had MIPS, SH3, PPC, ARM, Xscale, etc. Now it's mainly come down to different flavors of ARM cores, though various routers still use MIPS and friends.

Think of the steps
1. Run a Program.
2. Use JIT to change JIT source to a program in RAM.
3. Run the Ram program.
4. Delete the Ram program.

Need to ask how much computing power do you want to waste?
How much longer startup time?
Is the program going to change each time it's run?

Go back a little more, 8080, 8085,Z80,6502,6800,6809,8051.
A JIT on these would probably cripple them.
 
If you change #2 from RAM to storage, Flash or something like this, then you have a compiler not JIT.
[/quote]

I amn't only ,there is an other heretic on  the forum :-DD :-DD

Carefull ,i commented a thing seem  to yours an other post, almost somebody sent me to bonfire :-DD :-DD
 

Offline george.b

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: br
Re: Comparing "Modern" embedded chip programming languages?
« Reply #43 on: July 09, 2016, 06:21:42 am »
Maybe I'm just a bit dense, but... it's embedded electronics, what do you need more than ASM and C/C++ for? :-//
 

Offline ebclr

  • Super Contributor
  • ***
  • Posts: 2332
  • Country: 00
Re: Comparing "Modern" embedded chip programming languages?
« Reply #44 on: July 09, 2016, 06:36:33 am »
For me Pascal is the most readable language, and forces clean coding, But I'm forced to use this shit C, because is the industry standard, But anywhere a Pascal compiler is available is my 1st choice
 

Offline chris_leyson

  • Super Contributor
  • ***
  • Posts: 1556
  • Country: wales
Re: Comparing "Modern" embedded chip programming languages?
« Reply #45 on: July 09, 2016, 07:34:45 am »
I'm a hardware guy not a programmer, but why the hell do companies like Microchip have to abstract everything into some half baked C++ sort of language with missing library support, I gave up trying to use their latest C compiler and went back a few versions and used the old PLIB libraries. Spent a few days trying to figure out how to turn global interrupts on and off, tried at least two function calls only to find that the compiler hadn't generated any code whatsoever, not even a warning message for the unsupported and badly documented function call. I'm thinking what the hell they can't even get plain vanilla C compilers right, next time I need a small embedded microcontroller it won't be from Microchip. 20 or 30 years ago companies like Intel, Microsoft and Motorola would properly document their C library functions. Next time I need to use an embedded microcontroller the choice will probably come down to the compiler and not the hardware. Peripheral library support is crucial in any embedded application and if you can't even get C right.. :palm:
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5534
  • Country: gb
Re: Comparing "Modern" embedded chip programming languages?
« Reply #46 on: July 09, 2016, 08:13:05 am »
<rant> The last thing we need is yet another f***ing language! </rant>

In the past few years it seems like world+dog has to come out with yet another language, and when they're not doing that, they apply an existing language inappropriately to a platform it was never designed for.

The lifetime of the vast majority of these next-big-thing languages is a few years at most. Flash. Ruby. Perl. Those are the well known ones, most don't even get as far as they did, but you get the idea.

Furthermore, if you want to produce medium to long term maintainable code, then it makes little sense to adopt some new random language fresh off the boat, you choose one appropriate to the task at hand, and that enjoys a reasonable pool of skilled individuals available to write and support it.

Only rarely does a "new" language bear longevity. C# and Java are examples, although even Java has a somewhat rocky road, with recent questions over Oracle's commitment to some facets such as Java EE.

Although it's certainly worth being aware of various programming languages, it's far, far better to be a master of two or three established ones than it is to try to be a jack of all trades. Particularly as a young player, the temptation is to fanny about with the next big thing, which changes on almost a monthly basis. While expanding one's knowledge and exposure is to be applauded, indeed by doing so you will realise this next big thing is rarely that big at all, it's a super risky strategy to commit your career to, say, node.js without also being reasonably competent in the far more established languages and frameworks.

Apologies for the rant-like comments here, I've just seem so much of this nonsense over the years that I've become rather cynical about it!
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4720
  • Country: au
  • Question Everything... Except This Statement
Re: Comparing "Modern" embedded chip programming languages?
« Reply #47 on: July 09, 2016, 08:33:10 am »
So as another young member, for embedded on things like a small ARM (96K ram), without digging into assembly are there any reference guides or similar to compiling and running these tiny native snippets most seem to be describing, or a preferred way to running scripts or similar, my current thoughts have been using an interpreter with a limited version of C, but was wondering if there are any better ways?
 

Offline Boomerang

  • Regular Contributor
  • *
  • Posts: 53
Re: Comparing "Modern" embedded chip programming languages?
« Reply #48 on: July 09, 2016, 08:35:21 am »
Any language can work for microcontrollers if it is able to:

1. read from specific locations
2. write to specific locations
3. get addresses of functions/procedures

 :)
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2178
  • Country: fi
  • Embedded SW/HW.
Re: Comparing "Modern" embedded chip programming languages?
« Reply #49 on: July 09, 2016, 10:36:34 am »
For those who are interested in software robustness, correctness and safety, and still want to use C as the implementation language of their choice might find the Frama-C and the ANSI/ISO C Specification Language (ACSL) quite interesting in addition to the MISRA C guidelines:

https://en.wikipedia.org/wiki/Frama-C
https://en.wikipedia.org/wiki/ANSI/ISO_C_Specification_Language
https://en.wikipedia.org/wiki/MISRA_C

Here is an interesting paper "Program Verification in SPARK and ACSL: A Comparative Case Study":
http://haslab.uminho.pt/jsp/files/2010_rstae_10.pdf
Quote
Curiously,  our  industrial  research  partners  who  work  in  the  safety-critical context (more specifically, in the development of real-time, embedded applications) are mainly interested in two programming languages: SPARK and C. This may sound surprising, as one can hardly think of two imperative languages that
stand  farther  away  from  each  other  in  terms  of  safety  restrictions,  but  it  is  a reality.**

Note: "In SPARK83/95/2005, the contracts are encoded in Ada comments (and so are ignored by any standard Ada compiler), but are processed by the SPARK "Examiner" and its associated tools. SPARK 2014, in contrast, uses Ada 2012's built-in "aspect" syntax to express contracts, bringing them into the core of the language."
https://en.wikipedia.org/wiki/SPARK_(programming_language)

** It is fully possible to link SPARK (ie. subset of the Ada) and C code in the same application thus be able to call the C functions from the Ada and the Ada functions from the C.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->