Shop OBEX P1 Docs P2 Docs Learn Events
Getting started with P2 Eval Rev B — Parallax Forums

Getting started with P2 Eval Rev B

I just got the new P2 Eval board and am trying to get an LED blinking. While I haven't followed P2 development very closely, I've been reading through various posts and updates to try to catch up. I haven't used Spin in years (upwards of 7 I think) and have been using propgcc exclusively in many projects, so I'm hoping to use the P2 without having to re-learn Spin. Immediate questions that have come up:

1. What's the latest or "most official" C library (with propeller.h defining OUTA/OUTB, etc). The propeller2.h header in propgcc doesn't define OUTx, but instead a new PINx register (though the latest instruction info seems to show that OUTA/OUTB still exist)
2. What's the state of affairs in terms of a C compiler and loader? It looks p2load in propgcc hasn't been updated since 2013, so I'm guessing it's not relevant. Does propgcc actually support P2 or is it different enough that the code generated won't even run on P2?
3. is there any sort of "getting started" doc out there for the eval boards at a level higher than assembly? I don't expect it given how new the chip is, but worth asking.

Below is my attempts at trying to run a program to toggle pins. I'm guessing I'm doing something that's very obviously wrong, just don't know what it is. I was getting "hardware lost" errors when trying to use the p2load in propgcc, so I switched to loadp2 from p2gcc.

The program I'm trying to run.
#include <propeller.h>

int main() {

    DIRB |= 0xffffffff; // LED on pin 56 should be covered by this. 

    while(1) {
        OUTB ^= 0xffffffff;
        waitcnt(CLKFREQ + CNT);
    }
}

Compile and load with the following (some things are redundant from using a scrappy Makefile).
/opt/parallax/bin/propeller-elf-gcc -c  -o build/p2_scratchpad/p2_scratchpad.o -mlmm -Os -mno-fcache  main.cpp
/opt/parallax/bin/propeller-elf-gcc   -o build/p2_scratchpad/p2_scratchpad.elf -mlmm -Os -mno-fcache build/p2_scratchpad/p2_scratchpad.o
/opt/p2gcc/bin/loadp2 -v -CHIP -l 230400 -p /dev/cu.usbserial-* build/p2_scratchpad/p2_scratchpad.elf

Result of load command:
Setting clock_mode to 12427f8
Loading build/p2_scratchpad/p2_scratchpad.elf - 8177 bytes
build/p2_scratchpad/p2_scratchpad.elf loaded

I've also tried running the blink.c example that comes with p2gcc using the examples from the p2gcc readme, and get the following:
a.out failed to load
Error response was ""

I'm running on macOS 10.13.6, with propgcc built from the master branch.

Comments

  • please excuse the brevity of my post, but to answer

    2) propgcc isn't the proper compiler to be using. Try Catalina C compiler. https://sourceforge.net/projects/catalina-c/

    3) there are some great examples and readme files in the flexgui package for the basic and spin languages.
  • evanhevanh Posts: 15,187
    That'll be an outdated loadp2. That error message is typical of baud not set correctly. Forcing down to 115200 will make it work without updating but best to get the latest edition. It'll come with FlexGUI - https://forums.parallax.com/discussion/170730/flexgui-4-0-3-a-complete-programming-system-for-p2-and-p1/p1
    and also has its own forum pages - https://forums.parallax.com/discussion/170754/proposed-loadp2-changes/p1 and https://forums.parallax.com/discussion/170652/loadp2-loader-for-p2/p1
  • propgcc does not support P2.

    The C compilers available for P2 right now are:

    (1) Catalina C: fairly complete C package, easy to use. Downsides: C89 only, generated code not particularly fast (although I suspect Ross is working on that).

    (2) FlexGUI (fastspin): C compiler integrated with Spin & BASIC too. Some C99 and C++ extensions. Downsides: incomplete library, no stand-alone linker

    (3) riscvp2: Full GCC support, small code size thanks to compressed instructions. Downsides: poor documentation, and uses a JIT compiler behind the scenes, which seems to be anathema to forum users

    (4) p2gcc: Probably most compatible with PropGCC. Downsides: has a non-standard propeller2.h, uses an older GCC. Not sure if this is still supported.

    The standard header file for P2 programming is propeller2.h, as discussed at http://forums.parallax.com/discussion/170253/propeller2-h-for-c-compilers. Catalina, FlexGUI, and riscvp2 all support this. A portable LED blink program would look like:
    #include <propeller2.h>
    #define PIN 56
    
    void main()
    {
        for(;;) {
            _pinnot(PIN);
            _waitx(_clockfreq());
        }
    }
    

    You'd compile it with one of:
    catalina -p2 -C NATIVE -lci foo.c
    fastspin -2 foo.c
    riscv-none-embed-gcc -Triscvp2.ld -Os -o foo.elf foo.c
    
    and run via:
    loadp2 -b230400 -PATCH <filename> -t
    
    where <filename> is "foo.bin" for Catalina, "foo.binary" for fastspin/FlexGUI, and "foo.elf" for riscvp2. Catalina also comes with a different loader ("payload") but I tend to stick with loadp2, since it's what I know.

  • samuellsamuell Posts: 554
    edited 2019-11-20 18:04
    Hi Eric ( @ersmith ),

    Why "for (;;)" instead of while (1)? Any restriction?

    Kind regards, Samuel Lourenço
  • samuell wrote: »
    Why "for (;;)" instead of while (1)? Any restriction?

    You can use either one, whatever you'd like. I think the compilers will all produce the same code either way.
  • ersmith wrote: »
    propgcc does not support P2.

    Is there a plan for it to support P2 or will it continue to be for P1 only? Will there be an "official" C/C++ system for P2? I understand that all this is still very early and there's still lots of development to do, but before I go start porting some of my code for P2 to one of these systems, I'm curious which of these (if any) will be the most supported compiler/loader.

    I got an LED blinking with the instructions you gave, now the real fun an begin.

  • Native C++ for P2 is quite the undertaking, and i don't think there will ever be an official C++ compiler. That all could change in a hurry though if you're thinking like buying hundreds of thousands of P2 chips per year.

    If you absolutely must have C++ and GCC, Riscvp2 is what's available. Please help make it better with feedback and suggestions and progress posts.
  • David BetzDavid Betz Posts: 14,511
    edited 2019-11-20 21:22
    whicker wrote: »
    Native C++ for P2 is quite the undertaking, and i don't think there will ever be an official C++ compiler. That all could change in a hurry though if you're thinking like buying hundreds of thousands of P2 chips per year.

    If you absolutely must have C++ and GCC, Riscvp2 is what's available. Please help make it better with feedback and suggestions and progress posts.
    Forum user @ntosme2 is working on a port of the current version of GCC. I'm not sure if Parallax has been in touch with him but his work could be the basis of an official Parallax GCC for the P2.

  • n_ermosh wrote: »
    ersmith wrote: »
    propgcc does not support P2.

    Is there a plan for it to support P2 or will it continue to be for P1 only? Will there be an "official" C/C++ system for P2?

    You'd have to ask Parallax that. As far as I know the only tool they've committed to support is Chip's Spin2 interpreter.
    I understand that all this is still very early and there's still lots of development to do, but before I go start porting some of my code for P2 to one of these systems, I'm curious which of these (if any) will be the most supported compiler/loader.

    At this point that probably depends on what the users in the forums choose to support. @RossH has been supporting Catalina for a long time, so I don't think it's going away. Similarly fastspin/FlexGUI has been around for a while (fastspin grew out of spin2cpp, which was first released at the end of 2011).

Sign In or Register to comment.