Shop OBEX P1 Docs P2 Docs Learn Events
Newbie has great success right out of the gate, but I have a question — Parallax Forums

Newbie has great success right out of the gate, but I have a question

Tony B.Tony B. Posts: 356
edited 2012-02-07 21:23 in Propeller 1
I have been workingon learning C and remembered the GCC project for the propeller. I downloaded the alpha release this morningand before lunch had time to install it. I compiled the two samples in README_WINDOWS by using Notepad, propeller-elf-gccand then propeller-load. Everything workedjust fine. Had to change DIRA to matchthe Quick Start board and it sets and blinks all the LEDs beside me as I type. Although I have worked with PICs, BS2 andPropeller for some time I am a newbie when it comes to using C and the GCC toolchain (hope that’s the correct way to refer to it). I hope to be able to contribute to thisproject with suggestions and insight from said newbie.

Now for thequestion, I noticed in the example for blinking LEDs that keywords like DIRA,OUTA, waitcnt, and CLKFREQ function the same as in Spin accept they are used inC syntax. Is there a document or howwould I go about learning all the available keywords to use with the Propellerlibrary? Example, if I wanted to learnhow to use waitcnt in Spin, I would look in the Spin Language Reference. So my question in other words, how would I dothis for using propeller-gcc?

Thanks forthe help,
Tony

Comments

  • denominatordenominator Posts: 242
    edited 2012-02-03 16:32
    Tony B. wrote: »
    Now for thequestion, I noticed in the example for blinking LEDs that keywords like DIRA,OUTA, waitcnt, and CLKFREQ function the same as in Spin accept they are used inC syntax. Is there a document or howwould I go about learning all the available keywords to use with the Propellerlibrary? Example, if I wanted to learnhow to use waitcnt in Spin, I would look in the Spin Language Reference. So my question in other words, how would I dothis for using propeller-gcc?

    Short answer: To find out what facilities PropGCC has to support the Propeller, look at the header files propeller-elf\include\propeller.h and propeller-elf\include\propeller.h in your propgcc directory. Also, and search for "propeller" in the gcc.pdf file that you can download from http://code.google.com/p/propgcc/downloads/list .

    To understand how to use the Propeller-specific functions you find, just cross-reference the names to those found in the standard Propeller Manual ( http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/Web-PropellerManual-v1.2.pdf ).

    To understand other details of the Propeller PropGCC environment, check out the documents at http://code.google.com/p/propgcc/w/list and http://propgcc.googlecode.com/hg/doc/ .

    Currently it's sometimes a bit like being on the frontier - you have to either know what you're doing or stumble around for a while until you find your bearings.

    Longer answer, from my perspective:

    I personally haven't seen anything like a complete, integrated "Using C (or C++) with Propeller" reference or tutorial. However, I'm not sure that typically exists for C/C++ on any platform or in any microcomputer environment. You typically find general documentation on the C/C++ language and then additional documentation on the special features of a particular environment (i.e. how to run the compiler/linker, any platform-specific libraries, headers, special built-in functions, etc.). Check out the documentation for a previous C compiler for the Propeller: https://www.imagecraft.com/help/iccprop/wwhelp/wwhimpl/js/html/wwhelp.htm ; it's more complete than currently exists for PropGCC, but nowhere near as complete and comprehensive as the Propeller Manual.

    The Propeller Manual really serves two purposes:

    (1) It documents the Propeller hardware architecture.

    (2) It also documents the Spin language (including on how to compile and load programs); it's really a very complete document.

    As for using the C or C++ languages: these are standard languages, and you typically don't see the same bundle of "here's how to use the language", and "here's how to use the environment". To learn the languages, if you're running Linux, the compilers are almost assuredly already on your machine. If you use Windows/Mac, you can find free compilers. If you don't know the languages, then pick up a book or use an online tutorial to learn them and play around on your desktop system until you're comfortable (use your desktop because the debugging environment will be so much easier and complete).

    Personally, I've known C since the old days so that wasn't an issue for me. But the first programs I ever wrote for the Propeller were all in C (ICC V7 C at the time). Every program I've ever written for the Propeller has been in either C or PASM. So it is possible to jump directly in with PropGCC without starting at Spin.

    However, I figured out at the time that the way one uses the Propeller's unique facilities (e.g. cogs, registers (including I/O, clocks, the counters, etc.), wait instructions, etc.) is the same no matter which language you use (Spin, Propeller Assembler, Basic, C, C++, etc.).

    So the way I personally grokked this information was to read the Propeller Manual and I also looked at the Spin demo programs. When I picked up PropGCC specifically, I looked at the demo programs ( download from http://code.google.com/p/propgcc/downloads/list ). And I also looked at the above-mentioned header files and documentation.
  • ReinhardReinhard Posts: 489
    edited 2012-02-04 02:59
    Hi Tony,
    at time I can approve different ways :

    1. Have a look into propgcc\propeller-elf\include\ propeller.h
    This is the propeller specific header file.

    2. Have a look to the wiki: http://code.google.com/p/propgcc/w/list

    3. See the demos.

    Hope this is useful for you.

    best regards
    Reinhard

    edit: I forget, of course use this forum for further questions :smile:
  • Tony B.Tony B. Posts: 356
    edited 2012-02-04 06:34
    Thank you Reinhard for the response. I will study the resources mentioned.

    Tony
  • jazzedjazzed Posts: 11,803
    edited 2012-02-04 12:25
    Hi Tony B.

    Welcome to the test forum. Indeed your questions will benefit us all.

    There are also other resources for understanding programming with GCC.

    A very good on-line book is: http://publications.gbdirect.co.uk/c_book/

    A simple reference for the standard library is:
    http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html

    Many library reference manual pages are available on the net.
    If you are unsure of a library function usage, you can google it.

    For example enter: man 3 printf

    From the results you will see urls like this:
    man page printf section 3 and
    printf(3): formatted output conversion - Linux man page

    "man" is the unix/linux manual command and section 3 is for the library.

    It may not be immediately clear why these links will help, but as you go through
    the tutorials that have been mentioned elsewhere you'll understand.

    Additionally we are working on some propeller libraries that will make things easier for everyone.

    Hope this helps you and others.

    Thanks,
    --Steve
  • Tony B.Tony B. Posts: 356
    edited 2012-02-05 20:22
    Thank you Steve for all the helpful links and info.

    I started reading through the Toggle Tutorials and it stated "The default memory model is LMM" so, this is true if no other model is chosen and you didn't use assembler(-mcog), correct?

    Thanks,
    Tony
  • jazzedjazzed Posts: 11,803
    edited 2012-02-05 21:02
    Tony B. wrote: »
    I started reading through the Toggle Tutorials and it stated "The default memory model is LMM" so, this is true if no other model is chosen and you didn't use assembler(-mcog), correct?
    Yes, it is true. If you say propeller-elf-gcc hello.c you will get an LMM program that uses HUB memory for program storage and 1 COG to run the program.

    As you noted, the only way to get a COG program is to say propeller-elf-gcc -mcog hello.c. Flags -mxmm and -mxmmc are used to build programs that run from external memory; for example, propeller-elf-gcc -mxmmc hello.c will make a program that can be run from EEPROM, Flash, or SDcard.
  • Tony B.Tony B. Posts: 356
    edited 2012-02-06 14:53
    Thanks Steve, I'm glad to know I'm understanding what I am reading and studying. I will continue to work with propeller-gcc and post my questions and work.

    Tony
  • Tony B.Tony B. Posts: 356
    edited 2012-02-07 16:25
    I have been testing propgcc on different Propeller board with great success. I have begun testing with a SpinStamp on a BOE and have been able to write a simple blink program, compile, load and run it . The issue I am having is that the LEDs are blinking at about 4 times a second (best guess) and the code I've written (so I think) should blink on for a second and off for a second. Am I missing something in my code? Have I done the CMD line command incorrectly? Or may this be an issue with propgcc.

    Below is the SpinStamp Spin Code I would use if in Spin, the command line I used and the code.

    Thanks,
    Tony

    _clkmode = xtal1 + pll8x ' Enabled External Crystal and PLL X8
    _xinfreq = 10_000_000 ' External Crystal Frequency

    propeller-load -p com4 blinkss.elf -r -Dclkfreq=10000000 -Dclkmode=XTAL1+PLL8X
    #include <propeller.h>
    int main()
    {
     DIRA = 0x6;
     while(1)
     {
      OUTA ^= DIRA;
      waitcnt(CLKFREQ+CNT);
     }
     return 0;
    }
    
  • jazzedjazzed Posts: 11,803
    edited 2012-02-07 17:39
    Tony B. wrote: »
    I have been testing propgcc on different Propeller board with great success. I have begun testing with a SpinStamp on a BOE and have been able to write a simple blink program, compile, load and run it . The issue I am having is that the LEDs are blinking at about 4 times a second (best guess) and the code I've written (so I think) should blink on for a second and off for a second. Am I missing something in my code? Have I done the CMD line command incorrectly? Or may this be an issue with propgcc.

    Below is the SpinStamp Spin Code I would use if in Spin, the command line I used and the code.

    Thanks,
    Tony

    _clkmode = xtal1 + pll8x ' Enabled External Crystal and PLL X8
    _xinfreq = 10_000_000 ' External Crystal Frequency

    propeller-load -p com4 blinkss.elf -r -Dclkfreq=10000000 -Dclkmode=XTAL1+PLL8X

    Tony, the -Dclkfreq is the Propeller clock frequency and not the crystal frequency.
    Your example should work with this (same as -Dclkfreq=80000000):

    propeller-load -p com4 blinkss.elf -r -Dclkmode=XTAL1+PLL8X

    We are adding -b spinstamp by request, so in the future you can say:

    propeller-load -p com4 blinkss.elf -r -b spinstamp

    Hope this helps,
    --Steve
  • Tony B.Tony B. Posts: 356
    edited 2012-02-07 19:52
    Thanks Steve. Guess I should have thought it through a little bit more. It works just fine now. I have other testing/project plans for this set up. I will post this simple project along with others in a new post as I complete them to hopefully inspire others to work with propeller-gcc and give me a great opportunity to learn.

    Tony
  • jazzedjazzed Posts: 11,803
    edited 2012-02-07 21:23
    Tony B. wrote: »
    Thanks Steve. Guess I should have thought it through a little bit more. It works just fine now. I have other testing/project plans for this set up. I will post this simple project along with others in a new post as I complete them to hopefully inspire others to work with propeller-gcc and give me a great opportunity to learn.

    Tony

    I look forward to answering questions. Some are easier than others. I would rather have a bunch of both types of questions now than later.

    You're doing fine. Thanks.
    --Steve
Sign In or Register to comment.