Is the Propeller the right tool to Learn C
JCee
Posts: 36
I have become familiar with the Propeller+Spin, and a little Assembly over the past 2 years. ·Prior to the Propeller, I experimented with the Basic stamp, flashing LEDs.· As my exposure to microcontrollers and other embedded projects grows I find that C is the dominant language.·
·
I have read other posts asking “Is Spin hard to learn”,· my take is that once you know how to “program” learning different a syntax is not hard it just takes time.· I found the shift from Spin to ASM much harder than from Basic to Spin. ·I had to learn how to “program” all over again with Assembly.·
·
Getting on to the question; I need to learn C and I am wondering if the propeller is the right platform.· I know Catalina and ICC are available to compile C to run on the propeller but this is not the *native* language.
·
Should I try to learn C on the Propeller or (dare I say) Arduino.·
·
Don’t take this post the wrong way, I am not trying to promote another microcontroller just trying to get more tools in my toolbox.
·
I have read other posts asking “Is Spin hard to learn”,· my take is that once you know how to “program” learning different a syntax is not hard it just takes time.· I found the shift from Spin to ASM much harder than from Basic to Spin. ·I had to learn how to “program” all over again with Assembly.·
·
Getting on to the question; I need to learn C and I am wondering if the propeller is the right platform.· I know Catalina and ICC are available to compile C to run on the propeller but this is not the *native* language.
·
Should I try to learn C on the Propeller or (dare I say) Arduino.·
·
Don’t take this post the wrong way, I am not trying to promote another microcontroller just trying to get more tools in my toolbox.
Comments
But to *really* learn C you want to be coding a whole GUI or something substantial with large quantities of dynamic objects.
Ok, I'm biased - but I think the Prop is a fantastic platform for C.
C is at least as "native" to the Prop as SPIN. SPIN is an interpreted byte-coded language executed by a SPIN interpreter. C compiles to PASM instructions executed via an LMM Kernel. The only thing that makes SPIN appear more "native" is that the SPIN interpreter is built into every Prop while the LMM Kernel has to be explicitly loaded on boot. But such details are all hidden from you in either language.
C for LMM programs is faster than SPIN, and for XMM programs C allows much larger programs to be run, and is still competitive with SPIN.
Ross.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Catalina - a FREE C compiler for the Propeller - see Catalina
Editing to elaborate...
C is widely regarded as "portable assembly language" (an assessment I disagree with) but it gives you maximum speed with some high level conveniences and some very low level dangers.· There are very low level C environments that don't use stack frames and other features common to high-level C environments, but if you "learn C" in such an environment you really don't "know C" compared to someone who learned C on an X86 processor or heck even an Arduino.
The Prop C environments must make a variety of compromises to work at all, since the Prop has no native stack and everyone agrees trying to compile C to Pasm is a waste of time with 512 instructions per cog.· So it's either compiled to Spin bytecode, in which case Spin really works better and is more convenient, or to LMM in which case it's faster than Spin but also takes three or four times the Hub RAM to do the same thing.· (I am developing industrial controls, and have come to the conclusion that Hub RAM is the limiting factor, possibly by design on Chip Gracey's part.· Makes you learn some optimization strategy to get anything done.)· Or you can go to one of the external memory schemes which are slower than Hub RAM access but offer virtually unlimited memory, even with the efficiency hit, compared to the 32K boundary of Spin.· The problem there is that you're suddenly in seriously nonstandard territory -- you can't just buy a Demoboard and try out some code, or share what you write here with the hope that many of us can help you make it work.· Whereas with other processors for which C is native, you can do that.
So what I'm getting at is, the Prop isn't a very good tool to learn C.· It's a much better tool for learning to program, if you start with its native languages Spin and Pasm, and if you get very far at all with that you'll be able to get into C very easily because many of the concepts are the same.··But for learning to program C is a horrible language full of bear traps and kludges.· If you want to learn to program, please pick another language.· If you need to learn C in particular, you will probably have more success with a platform which supports ICE debugging, which you will need to navigate past all the bear traps and kludges.
Post Edited (localroger) : 12/17/2009 1:06:39 AM GMT
It is the compiler's job to take care of that level of detail.
You need to know that kind of stuff to WRITE a C compiler - not to USE one.
Writing C programs for the Prop is often easier than writing the equivalent program in SPIN.
Ross.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Catalina - a FREE C compiler for the Propeller - see Catalina
Do you have some examples to highlight where it is easier?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
I realize you have done an amazing job with Catalina, and for already written C code you have performed a miracle. But the poster was asking about learning C, and I really don't see how that's easier here than on one of the many platforms that have fully integrated debugging and tracing as well as native stack support and all the other stuff that makes C work better.
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
C on Propeller is fine, but you should first get comfortable with C language in a friendly environment which means use a world class compiler and a debugger that lets you see the effect of your program, then move to C on Propeller or other micro. Many C programming tutorial pages are on the net ... one of the first returned by Google search is www.cprogramming.com/tutorial/c/lesson1.html ... browse that or some other tutorial. When you're ready to get serious, install a world class compiler/tool chain like GNU or MSVC++, and have at it. Learn C first and not C++. C++ is important at some point, but has weird things that will confuse you as a beginner. When you're learning C forget about using C99 inline functions and dynamic sized arrays, because neither will be available on the C89 LCC based Propeller C variations. Books are nice if you like things to hold in your hand, but the help for library functions and other resources are available everywhere.
Best of luck. C-ya!
--Steve
I genuinely believe the Prop is a fantastic way for people who already know the hardware (and SPIN and PASM) to learn C (which was JCee's original question). JCee is quite correct that C is by far the dominant language for embedded work - so why not learn it on an embedded platform? The Prop is such a rewarding and interactive platform - one Prop chip and a couple bits of "glue" and you have a fully functional computer - but one that can also drive all sorts of real equipment. It really does bring the fun back into programming. Learning a new language is much more fun when you can actually see your program do real stuff - control motors, light LEDs - who cares what it actually does, as long as it does stuff? I'm not riding any Catalina hobbyhorse here - I'm sure much the same would be true of ICC.
As for C being easier than SPIN - maybe that's just what I'm used to. But I can (and just have) coded this in about 30 seconds in C ...
... and I'm fairly confident I can compile and run it on any Propeller platform regardless of the actual hardware devices that are connected. But it would probably take me half an hour to code the equivalent in SPIN - and even then it would probably only run on one particular Prop, and if I wanted to run it on another Prop I'd need to know what devices were connected and then change the software to suit.
Ross.
EDIT: Just read jazzed's reply and also localrogers edited reply - ok, I agree that C is a language that can get you into trouble faster than almost any other - but so what? That's the nature of C, and pretending otherwise is not teaching you about C. You may as well go say "go learn Java first, because its safer". Ys it is - but doing so won't teach you C. By the way, PASM is even worse than C in this respect - so would you also suggest to a Propeller-head who already knew the Propeller (and also knew SPIN) to go learn assembly on some other "safer" platform first and then come back and tackle PASM on the Prop? I think instead (and I've seen it happen in these forums several times) that you'd simply tell them about the Prop's specific pitfalls, point them in the direction of any documents that might help them, and then encourage them to experiment!
On the other hand, the lack of a source level debugger is a problem on the Prop for newbies - one that I hope to rectify in Catalina at some point. But if ICC has one (I don't actually know) then I'd happily recommend a C newbie to use ICC instead of Catalina. They can come back to Catalina when they get serious about C (<- that's me keeping an eye out behind in case Richard sneaks up and belts me!)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Catalina - a FREE C compiler for the Propeller - see Catalina
Post Edited (RossH) : 12/17/2009 4:17:38 AM GMT
With Propeller or any other micro, you have to worry about things like having to download hardware, having to remember to disconnect your terminal program before testing code (not an issue with jtag enabled devices), or dealing with memory constraints (when you know better, you can deal with that).
RossH with Catalina and Richard@ImageCraft have given a great deal of effort to making what you ask possible. In Richard's case, he spent a money and time on the project that will never pay him any return. RossH obviously has lots of personal pride in his product as evidenced by the platforms he is supporting. I appreciate the efforts of both.
If you like Propeller enough to try it, then great ... knowing RossH and Richard, they will bend over backwards for you to help you succeed. It is exceedingly unlikely that anyone supporting GNU or at MS will help more than by delivering high quality industry standard products.
For someone just starting out though, it's probably better to learn on a great and flexible IDE.
There is nothing to get in the way of learning C on Windows/Linux/OSX PC. The finest possible world class PC/Linux/OSX tools exist to help you on your way. Things such as a good IDE, helpful compiler/linker, and vivid/simple debug tools exist there and work perfectly for understanding clearly what is happening. You don't have to wonder about whether or not the hardware is working. You don't have to have any hardware at all other than your PC to learn.
I first learned C on Unix cc and TurboC. It took me years to realize there were bugs in the TurboC compiler ... all I knew for sure at the time was that the Unix cc seemed to work much better than TurboC on the PC. The PC "platform" was very immature compared to Unix. I'm not saying anything is wrong with Catalina or ICC. I'm just saying that learning on a very well known and unquestionably solid platform with no strings (or USB cables attached) is more productive than having to decide whether or not I have issues with my platform.
Cheers.
--Steve
Tonto: What do you mean "we", kemosabee?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Catalina - a FREE C compiler for the Propeller - see Catalina
A. He found out what "kimosabe" really meant.
What ever you do take the advice here and whilst learning C do your exercises on a PC. Not sure what is the best compiler for a beginner to start with but that interpreting environment suggestion sounds great. The old Borland Turbo tools were great for this kind of thing. Something whwere you can quickly edit and compile and step through the code in a debugger.
Never mind that stuff about dynamic structures and GUI's you want to learn C with a aim of using it on micro-controller I believe. In that world you are lucky to have any dynamic structures and GUIs are a large and complicated other world away.
No, exercise those parts of C you want in an MCU, integer arithmetic, bit twiddling/shifting, the normal conditional, loops, functions, parameters etc etc. It's quite possible to use C in a very Spin like way.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
We spec'ed a debugger for Propeller C, but with us moving to CodeBlocks as our V8 IDE, we will probably just go ahead and generate ELF/DWARF and use GDB instead. As we have a foot in the door, when the market is ready, we will be there. Right now, I am up to my eyeballs optimizing for the PSoC and making progress with CodeBlocks and the Dinkumware full standard compliant library. Never a dull moment.
The Prop isn't a bad platform for C. The missing stack-ops have absolutely nothing to do with that. SPIN also needs a stack. So this argument was worthless.
The suggestions to start C on a different platform that does have a debugger are valid to some extend. But then, SPIN also doesn't have a debugger and you mastered (at least to some extend) that too.
So, yes, learning C on the Prop is OK as long as you already learned some debugging techniques (in SPIN, PASM, whatever). C on a µC is different. Not from the language POV, but from the techniques. And *ANY* µC is quite the same to that respect. It's more bare-bones-programming than on a PC-platform.
So take the plunge, do it on the Prop! You already have a Prop, no gain in investing into a different platform.
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
DJGPP! OMG! The worst Smile I have ever used!
Download the Open-Watcom compiler. The IDE is quite ... um ... antique, but the libs and the C-implementation is rock-solid and effective.
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
Now, the watcom compiler has been opensourced some years ago.. so maybe it is now an better alternative.
But if you like gcc, then djgpp is the way to go.
C compilers for the PC exist for DOS and for winblows. You can use Netbeans and the C compiler provided by cygwin for instance, but alternatives exist aplenty. (Or Moco$oft's Visual C(rap) I mean Studio, supposedly the "best" IDE ever blah blah ).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
What's wrong with it? It's gcc, which is a pretty good compiler.
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
So, as a total newbie, let's see if this new-fangled 'C' language can run on a propeller.
RossH has issued a challenge which I reproduce below
As for C being easier than SPIN - maybe that's just what I'm used to. But I can (and just have) coded this in about 30 seconds in C ...
#include <stdio.h>
main() {
char name[noparse][[/noparse]11];
printf("Enter your name: ");
scanf("%10s", name);
printf(" Hello %s", name);
}
... and I'm fairly confident I can compile and run it on any Propeller platform regardless of the actual hardware devices that are connected. But it would probably take me half an hour to code the equivalent in SPIN - and even then it would probably only run on one particular Prop, and if I wanted to run it on another Prop I'd need to know what devices were connected and then change the software to suit.
Now remember, I don't understand C. Actually, I don't really understand Spin either, though I'm getting better with PASM. But I'm going to take RossH's program and I'm going to run it on a propeller.
Actually, I'm going to do more than that. I'm going to compile it on a propeller too. And even more than that, I'm going to write it on a propeller as well.
And I'll go even further. Even though I know RossH wrote is challenge for his own compiler, I'm going to use a different C compiler. Just to really test the intercompatability of this *tiny voice* language I'm quite coming to like...
Hardware is a DracBlade, which is essentially a Prop plus a ram chip plus a vga screen, keyboard and an sd card for storage. So it is self contained and can run without a PC once all the software has been copied over.
First, write the program. I'm using Wordstar. Next, save it as a .C file called ROSSH.C and TYPE it out to check it looks like RossH's original:
Drive B contains the disk image of the BDS C compiler which I obtained from the SIMH archive and dropped onto the sd card as a disk image. The instruction manual is available here www.bdsoft.com/resources/bdsc.html in the primary downloads section.
To compile a program (I've not done this before on a propeller but I'm just following the instruction manual here), I understand I type something like "cc rossh"
so, here is a trace of what it does:
Hmm - that seemed to work ok. So, the next instruction is something called a Linker (you could write a batch file to do this if you like, but this is fun and it doesn't seem to have gone wrong so far)
"clink rossh"
and here is the trace:
Hey, that seemed to work. And I just noticed something nifty. I've got 43k left and I'm using a propeller with only 32k of ram. Groovy..
Oh well, can't put it off any longer. Time to run this program and see if it crashes and burns...
Well, there you go. It worked. Grr. Just wait till I tell my BASIC programmer friends...
Not only did it work, but RossH seems to have his own compiler which does the above even more easily.
So - is the prop a good platform for learning C? Well, I don't know any C and I just wrote a program and got it to work first time, so I reckon the answer is a resounding YES!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
Post Edited (Dr_Acula) : 12/17/2009 1:29:02 PM GMT
C has some tricky features to master but first you have to figure out how on earth to get your compiler to do anything!
Then you get sucked into the wonderful world of Make files and such....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
caveats:
1) Setting yourself up with a Prop + RAM that runs CP/M may not be an option.
2) The dialect of C that BDS implements is rather ancient now.
When you are done with C you can move on to explore FORTRAN, ALGOL, PASCAL, PL/M, ADA and more. All with nothing much more than Prop + RAM + SD card + keyboard + VGA [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
Provided you know that when you compile hello.c with GCC the resulting executable is called "a.out" rather than anything sensible like "hello". Or provided you know how to tell GCC what to call the output. For a total newbie getting started with all this nonsense can be a trial. As you say "not always clear".
Might I suggest, for first steps in C use the most wonderful "Tiny C Compiler" from here bellard.org/tcc/
This thing is amazing. For example:
1) Edit your first hello world program in file hello.c
2) Compile and run it with one simple command: "tcc -run hello.c"
Bingo! it compiles the thing and runs it before you can bat an eye.
Also available for Windows.
Edit: Blimey TCC can compile 10 times faster than GCC. And it can build a Linux kernel in 10 seconds!
If this tiny thing can do that Linux on the prop cannot be far away[noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Post Edited (heater) : 12/17/2009 2:18:09 PM GMT
DJGPP used (last time I tried it was about 3 years ago) an outdated gcc. There was something with the memory-model (no choice or something like that). Compiler accepted bad constructs without warning or error, very little checking etc. don't remember that well. Only thing was that I was willing to $$$-buy one (for DOS) just to get rid of it. Code-size 20% more than Open-Watcom.
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
> Then you get sucked into the wonderful world of Make files and such....
Try ImageCraft's ICCProp! I never had to make a make-file. And for the compiler to do something ... well ... click on an icon!
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
Just use switches like -Wall to get better source code checking. Checking can be about as strict as Lint with the correct switches.
Code size and speed can be optimised, as with most compilers.
Running gcc under Cygwin is another option - most of the GNU utilities are available.
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Post Edited (Leon) : 12/17/2009 5:09:09 PM GMT