Shop OBEX P1 Docs P2 Docs Learn Events
flexspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler - Page 8 — Parallax Forums

flexspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler

15681011120

Comments

  • Press and release the PROPELLER RESET button, and then click the [Compile & RUN] button a second later.

    Do you know what com# is assigned to the USB to SERIAL device when you plug in your P2-EVAL?

    I think loadp2.exe only looks for up to com19
  • I've updated spin2gui to fix the problem with spaces in folder names, to make P2 the default again, and to add a "Port" menu that will let you specify COM1 to COM9 if you want to override the default behavior of having the program search for the port. I've also included a simple C demo and fixed a few bugs in fastspin, although I haven't crafted a new fastspin release yet.

    As always, spin2gui is available for download at:

    https://github.com/totalspectrum/spin2gui/releases

    Grab the most recent release there (1.3.1 at the time of this writing).

  • jmgjmg Posts: 15,162
    ersmith wrote: »
    ... and to add a "Port" menu that will let you specify COM1 to COM9 if you want to override the default behavior of having the program search for the port. ...

    Can that (easily?) support above COM9 ? eg mine added as COM19

  • jmg wrote: »
    ersmith wrote: »
    ... and to add a "Port" menu that will let you specify COM1 to COM9 if you want to override the default behavior of having the program search for the port. ...

    Can that (easily?) support above COM9 ? eg mine added as COM19

    The menu doesn't, but the command used to run programs on the P2 is completely configurable (via the Command > Configure Commands... menu). So all you have to do to use COM19 is to replace the "%P" string in that command with "-p COM19". ("%P" stands for "the com port selected by the menu")
  • It should be possible to enumerate all COM ports that actually exist. That way you could include every port in the menu even though some might have very high numbers. It is very likely that the actual list of ports is a very sparse list.
  • David Betz wrote: »
    It should be possible to enumerate all COM ports that actually exist. That way you could include every port in the menu even though some might have very high numbers. It is very likely that the actual list of ports is a very sparse list.

    I was dreading trying to do that, but I found some tcl code that is supposed to do the enumeration. It works on my Win10 machine and on Linux. @jmg, do you want to try the new spin2gui release (v1.3.2) and see if that finds your device on com19?
  • Got it working with the help of dgatley. I have to press reset so as to load a different program. Now going to attempt to write a counting program. Any one have a quick example of printing to the serial terminal?
    Thanks
  • pilot0315 wrote: »
    Got it working with the help of dgatley. I have to press reset so as to load a different program. Now going to attempt to write a counting program. Any one have a quick example of printing to the serial terminal?
    Thanks

    There is a samples/ folder that comes with spin2gui that has a few sample programs. The simplest hello world program for P2 would look like:
    ' hellop2.bas
    ' P2 hello world program in BASIC
    
    const _clkmode = 0x010c3f04
    const _clkfreq = 160_000_000
    
    clkset(_clkmode, _clkfreq)
    _setbaud(2000000)
    
    do
      print "hello from P2!"
    loop
    
  • In P2asm??
  • pilot0315 wrote: »
    In P2asm??

    Why not use a high level language if you have one available? Or, if you really want to see P2ASM, you could look at the hellop2.p2asm file that fastspin will produce from the above example, although that's got a lot of library code in it that may not be of interest.

    I think Cluso99 posted an assembly language serial demo in one of the P2 Newbies or P2 Eval board samples threads.
  • I found Cluso99 demo and sent him a message about a simpler version.
    Is C or C++ available?
    It is my understanding that fastspin is part of the Spin2gui??
    Would you please send me a couple of links of now to access the hellop2.p2asm file that is in fast spin. I tried to launch fastspin
    autonomously and it just flashed and goes away.
    Appreciate the help.
    Martin
    I would like to use a high level language like C or C++ or maybe SPIN if it is available. In p2asm I would just like to start with simple math and move
    up.
  • ersmithersmith Posts: 6,030
    edited 2019-01-02 20:13
    pilot0315 wrote: »
    Is C or C++ available?

    Only partially. C support in fastspin is still very incomplete, but you can write simple programs in it. If you prefer C to BASIC, then you can use that, and there's even a serial demo in the samples folder. Here's how to access it:

    1. Open spin2gui.exe (version 1.3.0 or later)
    2. Go to the File > Open file... menu item
    3. Navigate to spin2gui\samples and select cdemo.c.
    4. The P2 blinking lights and serial demo C program will open in the spin2gui window.
    5. Now push the "Compile & Run" button.
    6. A "Propeller Output" window will open that will show "fastspin C demo" and then a lot of lines that say "toggle 0", "toggle 1", etc. You'll also see the P2 LED connected to pin 58 start blinking.

    You can use the C program as a start if you want to, although honestly I would recommend using Spin or BASIC. All 3 languages are supported by the fastspin built in to spin2gui, but C is still under development and pretty buggy.

    For example, you could repeat the steps above except that in step 3 select "multest2.spin" instead of "cdemo.c" to try out a simple Spin program that uses the SimpleSerial object (in the spin2gui\lib folder) and the multiply object (in the samples\ folder).

    To see the P2 assembly language generated by building a program, select the Commands > "Open Listing File..." menu item. This will open up a window showing the assembly language that fastspin generated from your Spin, BASIC, or C program. But really there's no need to look at the P2ASM -- it's totally optional, and just informational.

  • Thank you for your help. I can do spin and prop c. (old days fortran, basic and some cobol I am dating my self old ibm 1130, 360/370 and hp 2000c), I will follow your directions and let you know what happens. Just checked those examples are not in the samples. 1.3.0. I will look for a later version.
    Martin
  • Cluso99Cluso99 Posts: 18,069
    The FORTRAN WATFOR was pretty common to learn first ;)
  • pilot0315 wrote: »
    Thank you for your help. I can do spin and prop c. (old days fortran, basic and some cobol I am dating my self old ibm 1130, 360/370 and hp 2000c), I will follow your directions and let you know what happens. Just checked those examples are not in the samples. 1.3.0. I will look for a later version.
    Martin

    Sorry, I misremembered when the cdemo.c sample was added. It's certainly there in spin2gui 1.3.2, and it's probably worth upgrading to that version (for one thing it should fix the problem you ran into with spaces in folder names).

    The fastspin BASIC that's used in spin2gui is pretty similar to old style BASICs, except it doesn't have line numbers and it (optionally) allows you to specify types for variables and functions. So it sounds like you're set for working with all of the languages that spin2gui supports :).

    Eric
  • pilot0315 wrote: »
    Thank you for your help. I can do spin and prop c. (old days fortran, basic and some cobol I am dating my self old ibm 1130, 360/370 and hp 2000c), I will follow your directions and let you know what happens. Just checked those examples are not in the samples. 1.3.0. I will look for a later version.
    Martin
    Dont worry about dating yourself.

    My first programming was on a FACOM 230/45 (Japanese copy of IBM 360) mainframe,
    and the program was read in from punched paper tape. I kept that roll of paper tape
    for years until i finally lost it, and yes my first programming language was COBOL.

    There is another C compiler that works.
    (See thread - Can't Wait for PropGCC on the P2?)
  • RaymanRayman Posts: 14,364
    I've updated SpinEdit for P2 Eval and also made many improvements.
    I should have posted it here, but it's in "Microcontrollers" because it can complile for P1 and P2.
    Fastspin is working very well for P2ASM and Basic.

    https://forums.parallax.com/discussion/169259/
  • Announcement:

    The punch card chat has been moved to it's own thread here:

    http://forums.parallax.com/discussion/169527/punch-card-nostalgia


  • RaymanRayman Posts: 14,364
    I think there's an issue with clkset…
    Was just trying SimpleSerial and sometimes it works, sometimes it doesn't. Baud looks wrong...

    I think you're supposed to set the clock in a two step process with a delay like this:
    CON  'RJA:  new for real P2 - you can use different xdiv and xmul to set clock frequency:  /10*125 -> 250 MHz
      _XTALFREQ     = 20_000_000                                    ' crystal frequency
      _XDIV         = 10                                            ' crystal divider to give 1MHz
      _XMUL         = 125                                          ' crystal / div * mul
      _XDIVP        = 1                                             ' crystal / div * mul /divp to give _CLKFREQ (1,2,4..30)
      _XOSC         = %10                                  'OSC    ' %00=OFF, %01=OSC, %10=15pF, %11=30pF
      _XSEL         = %11                                   'XI+PLL ' %00=rcfast(20+MHz), %01=rcslow(~20KHz), %10=XI(5ms), %11=XI+PLL(10ms)
      _XPPPP        = ((_XDIVP>>1) + 15) & $F                       ' 1->15, 2->0, 4->1, 6->2...30->14
      _CLOCKFREQ    = _XTALFREQ / _XDIV * _XMUL / _XDIVP            ' internal clock frequency                
      _SETFREQ      = 1<<24 + (_XDIV-1)<<18 + (_XMUL-1)<<8 + _XPPPP<<4 + _XOSC<<2  ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_00  ' setup  oscillator
      _ENAFREQ      = _SETFREQ + _XSEL                                             ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_ss  ' enable oscillator
      
    CON
    
      intensity = 80    '0..128
    
      fclk      = _CLOCKFREQ 'RJA:  Adjusted for real P2 '80_000_000.0
      fpix      = 25_000_000.0
      fset      = (fpix / fclk * 2.0) * float($4000_0000)
    
      vsync     =   4   'vsync pin 'RJA:  changed for real P2
    
    DAT     org
    '
    '
    ' Setup 
    '
    '+-------[ Set Xtal ]----------------------------------------------------------+ 
    ' RJA:  New for real P2
                    hubset  #0                              ' set 20MHz+ mode
                    hubset  ##_SETFREQ                      ' setup oscillator
                    waitx   ##20_000_000/100                ' ~10ms
                    hubset  ##_ENAFREQ                      ' enable oscillator
    '+-----------------------------------------------------------------------------+
    
  • ersmithersmith Posts: 6,030
    edited 2019-01-05 20:02
    The fastspin library code for clkset looks very much like what you posted:
    pri clkset(mode, freq)
      CLKFREQ := freq
      CLKMODE := mode
      asm
        hubset #0
        hubset mode
        waitx ##20_000_000/100
        add  mode, #3
        hubset mode
      endasm
    
    The only difference is that _XSEL is hard-coded to 3 (%11), but that's fixed in the version of fastspin in github, where it's another parameter to clkset (which defaults to 3).

    Could you post the code you're having trouble with?

    EDIT: Just realized what you might be having trouble with: the parameter to clkset() needs to be the _SETFREQ number, not _ENAFREQ.
  • Hmmm, now I'm seeing some serial character corruption that looks like baud problems. But in my case I think it's due to SimpleSerial not being able to bit-bang fast enough for the P2's default 2000000 baud rate. I think it's kind of on the edge, and depending on code alignment and other timing it sometimes fails.

    Slowing it down to 115200 baud fixed it. But an even better fix is to use smartpins for the I/O, for example with the attached SmartSerial.spin2 object.

  • There are new releases of spin2gui and fastspin, available at:

    https://github.com/totalspectrum/spin2gui/releases
    https://github.com/totalspectrum/spin2cpp/releases

    (Note that if you download spin2gui you do not have to get fastspin separately, as it's already included; the separate fastspin release is for people who just want the command line version, e.g. to use with Spin Edit.)

    This has a number of bug fixes, some new demos (e.g. a SmartSerial object that uses the smartpin for serial I/O on P2), and improvements to all 3 languages:

    - Spin has a few of the proposed P2 methods (like dirh_, drvh_, and the like)
    - BASIC now supports multiple statements per line and changing the default type for variables
    - C has an updated <propeller.h> that is more like the PropGCC one
  • David Betz wrote: »
    I naively cloned spin2gui and just tried running the following command on the Mac:
    wish spin2gui.tcl
    
    This brings up the GUI but none of the button labels appear. Is there some other step required to run spin2gui on the Mac?
    I finally figured out why the buttons do not appear, a work-around and a solution for macOS users...

    This is a Tcl-Tk issue with macOS Mojave, fixed with the latest Wish or Tcl-Tk versions (8.6.8)...

    A work-around for those not wanting to update Tcl-Tk or Wish is to resize the window (works for the text editing window as well as the configuration window). The button labels will appear on forcing a window resize.

    BTW: It is difficult to actually update the wish version that resides in /usr/bin/ on macOS Mojave (permissions issue and you can't just 'sudo rm' the older version)... You'll need to get Wish or TclTk and exec them from their newly installed location (kind of a pain). I'm able to run spin2gui.tcl like this:
    /Applications/Utilities/Wish.app/Contents/MacOS/Wish Spin2gui.tcl
    

    dgately
  • Does fastspin support local labels? Some of my code will not compile that has local labels.
  • ke4pjw wrote: »
    Does fastspin support local labels? Some of my code will not compile that has local labels.

    Local label syntax is different in PASM2 and PASM. In PASM2 local labels start with "." rather than ":".
  • There are new versions of fastspin (3.9.15) and spin2gui (1.3.4) at the usual places:

    https://github.com/totalspectrum/spin2cpp/releases
    https://github.com/totalspectrum/spin2gui/releases

    The fastspin changes are:

    - Fixed abort/catch in P2
    - Fixed a problem with quotes in strings
    - Fixed potential name conflict with labels, and improved optimization of branches as a side benefit
    - Added -H and -E flags to fastspin to allow changing HUB start address. For example, `fastspin -2 -H 0x10000 -E foo.bas` compiles a program to load and execute at address 65536. If the `-E` is left off then it still loads at 0, but is padded to start executing at 0x10000.
    - Added some more C library functions

    @msrobots : I think you'll find -H and -E useful for your experiments with TAQOZ. For example, you can compile a program with
    fastspin -2 -H 0x10000 myprog.spin
    
    to move its HUB base address to start at 64K. Note that this is basically equivalent to your earlier trick of manually editing the .p2asm file to change the ORGH. There will still be 64K of padding inserted. To get rid of that padding add the -E flag:
    fastspin -2 -H 0x10000 -E myprog.spin
    
    That creates a program that must be loaded at 64K in order to work properly. loadp2 has a -s flag that can do that.

    @Cluso99 : I think you could use -H plus -E to create binaries to run in a Spin OS. You'd compile the OS code to run at 0 (as usual) and the disk based programs to run at some offset (like 64K). Dave Hein did something like this for p2gcc as well.

  • What is the status of fastspin/C? It seems it works pretty well. I wrote and compiled a simple "Hello, world" program but it didn't run when I loaded it with loadp2. I suspect it has to do with the baud rate that is being used by printf. I told loadp2 to use 115200. Is there something I need to do to get the fastspin/C runtime library to use that baud rate? It seems that the Mac doesn't support 2000000.
  • David BetzDavid Betz Posts: 14,516
    edited 2019-01-22 02:39
    Another question: How do I compile a program that has more than one source file? Do I just include all of the source file names on the same command line?
  • David Betz wrote: »
    Another question: How do I compile a program that has more than one source file? Do I just include all of the source file names on the same command line?
    Okay, I answered my own question. Yes, it is possible to specify more than one file name on the command line. At least it seems to work with two. Is it reasonable to expect it to work with dozens as well?

  • David BetzDavid Betz Posts: 14,516
    edited 2019-01-22 03:07
    I entered the following trivial program:
    #include <stdio.h>
    
    int main(void)
    {
        printf("Hello, world!\n");
        return 0;
    }
    
    I compiled it with this command line:
    fastspin -2 -I include -b hello.c
    
    And tried to load it onto my P2-Eval board with this command line:
    loadp2 -p /dev/tty.usbserial-P2EEQXU hello.binary -b 115200 -t
    
    It seemed to load but I got nothing on the terminal. Can someone provide a simple example of a program that writes to the serial port? This same program works fine when built for the P1 and loaded with proploader.
Sign In or Register to comment.