Getting started with P2 Eval Rev B
n_ermosh
Posts: 294
in Propeller 2
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.
Compile and load with the following (some things are redundant from using a scrappy Makefile).
Result of load command:
I've also tried running the blink.c example that comes with p2gcc using the examples from the p2gcc readme, and get the following:
I'm running on macOS 10.13.6, with propgcc built from the master branch.
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
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.
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
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:
You'd compile it with one of: and run via: 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.
Why "for (;;)" instead of while (1)? Any restriction?
Kind regards, Samuel Lourenço
You can use either one, whatever you'd like. I think the compilers will all produce the same code either way.
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.
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.
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.
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).