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

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

1457910123

Comments

  • ersmith wrote: »
    David Betz wrote: »
    ersmith wrote: »
    dgately wrote: »
    One of the Spin objects that is used in almost all of my Spin projects is FullDuplexSerial (and its cousin FullDuplexserialPlus)... Of course that object has a dependency on its PASM code that includes several jmpret instructions. Building P2 projects with fastspin is chocking on those instructions...

    Is there a quick solution or should I just remove my Spin code projects dependencies on FDS? Seems that I'll need to replace FDS with a P2 equivalent, eventually, right?

    You'll certainly have to replace FDS (as you've noticed, it won't work on P2 anyway because of the PASM code not being compatible). I usually use some variant of SimpleSerial.spin, which is a dead simple half-duplex driver that'll work on P1, P2, and PC. I think it's in the fastspin Libs/ directory, but I've attached a copy here just in case.
    Nice and simple as advertised but I don't see how rx will work on a PC.

    You're right, rx was a late addition and I forgot to put in an #ifdef PC to make it use getchar(). So at the moment SimpleSerial won't work on PC. It'd be easy enough to fix (just follow the template for tx).

    Actually it looks like rx is broken on P2 as well :(. I'll have to take a look at that.
    I don't really have a need to run it on the PC but getting it working on the P2 would be nice. :smile:
  • I've fixed the missing rx for PC and P2 and updated my comment above. The rx code on P2 seems a bit fragile; it could be that it's triggering a P2 only optimizer bug (P1 seems OK) or else there's a subtle timing problem that I'm missing. I had to compile hello.spin for my P2 FPGA with -O0 to get it to work correctly.
  • I should warn everyone that the P2 code generation has received a lot less testing than P1 code generation. Now that we're really getting P2's out "in the wild" I suspect we're going to find lots of P2 bugs in fastspin. Please bear with me while we shake those out :)
  • 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?
  • 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?

    As far as I know the wish command should be all that's required. I don't know why button labels wouldn't show up! Do other TCL programs work OK on that system?
  • ersmith wrote: »
    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?

    As far as I know the wish command should be all that's required. I don't know why button labels wouldn't show up! Do other TCL programs work OK on that system?
    I have no idea if other TCL programs run. spin2gui is the only one I've ever tried. :smile:

  • 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?

    Same here on macOS... But, those buttons have corresponding menus in the menu bar. You can open files, compile and load from there.
  • twm47099twm47099 Posts: 867
    edited 2018-12-27 04:53
    Note that to get Basic and C programs to load & run it was necessary to do a couple of things:
    1. Replace loadp2 that is in the spin2gui bin folder with version 0.005 from
    forums.parallax.com/discussion/download/122835/p2gcc004.zip

    2. Change the run command to
    cmd.exe /c start %D/bin/loadp2 -pCOM9 %B -t
    
    Be sure to use your serial port ID where I have COM9.

    3. Compile the program

    4. After compiling rename the "xxx.p2asm" file to "xxx.spin2"

    5. Open the xxx.spin2 file and change near the top of the file:
    hubset #255
    
    to
    hubset #0
    

    6. Then compile & run

    If you want to set the P2ES clock to 180KHz do the following as part of step 5 above.
    1. open xxx.spin2 and change/add lines with ****
    CON		          ' **** add
     _SETFREQ = $010C4708   ' **** add,  value from Dave Hein
     _ENAFREQ = $010C470B	' **** add, value from Dave Hein
    
    dat
    	org	0
    entry
    	cmp	ptra, #0 wz
     if_ne	jmp	#spininit
    	mov	ptra, ptr_stackspace_
    	hubset	#0			' **** changed
                                            ' **** add, the next 3 lines set for 180MHz
            hubset  ##_SETFREQ           ' **** add, setup oscillator
            waitx   ##20_000_000/100     ' **** add, ~10ms dely
            hubset  ##_ENAFREQ           ' **** add, enable oscillator
    			' **** note with 180 MHz clock use 250,000 baud
    'program continues
    

    2. If printing set the terminal baud to 250000.

    Hope this helps.
    Tom
    constants edited
  • twm47099twm47099 Posts: 867
    edited 2018-12-27 04:55
    I wrote a short Basic program to demonstrate doing things in different cogs. I list the BASIC program and the beginning of P2asm file (to be saved with extension ".spin2") modified as described in the above post. The P2asm file was too long to list here and the beginning is where the edits are needed.
    ' testcpubas.bas
    ' Use 3 cogs. Open a new cog and blink an LED (pin 1) at a given frequency, 
    ' open a second cog and blink LED at pin 2 twice as fast,
    ' print a series of numbers from cog 0.
    
    ' rename p2asm file to testcpubas.spin2 and change/add lines with ****
    ' clock will be set to 180MHz
    ' set terminal baud to 250000
    
    sub blink(pin, freq)          ' this subroutine is used in both cogs 1 and 2 
     direction(pin) = output
     do
       output(pin) = not output(pin)
       waitcnt(getcnt() + freq) 
    loop
    end sub
    
    dim stack(8)
    dim stack1(8)
    ' blink in cog 1
    var a = cpu(blink(1, 180_000_000), @stack(1))
    ' blink 2x as fast in cog 2
    var b = cpu(blink(2, 90_000_000), @stack1(1))
    
    ' print a number every half second independent of what is happening in cogs 1 and 2
    ' I used PST as the terminal and set the baud to 250000
    dim i
    i=0
    do
      i=i+1
      print i,
      pausems 500
    loop
    
    

    ' testcpubas.spin2
    
    CON			' **** add
     _SETFREQ = $010C4708    ' **** add
     _ENAFREQ = $010C470B 	' **** add
    
    dat
    	org	0
    entry
    	cmp	ptra, #0 wz
     if_ne	jmp	#spininit
    	mov	ptra, ptr_stackspace_
    	hubset	#0			' **** changed
                                         ' **** add set for 180MHz
            hubset  ##_SETFREQ           ' **** add setup oscillator
            waitx   ##20_000_000/100     ' **** add ~10ms
            hubset  ##_ENAFREQ           ' **** add enable oscillator
    			' **** note with 180 MHz clock use 250,000 baud
    
    	calla	#@_program
    
    constants edited.
  • jmgjmg Posts: 15,175
    twm47099 wrote: »
    The P2asm file was too long to list here and the beginning is where the edits are needed.
    CON			' **** add
     _SETFREQ = $010C4704   ' **** add
     _ENAFREQ = $010C4707	' **** add
    

    See garryj's post that corrects the lower nibble for cap selection.
    CC: %10 input 600-ohm drive 1M-ohm 15pF per pin ( I get -6.700 ppm on this setting)
  • twm47099twm47099 Posts: 867
    edited 2018-12-27 04:59
    jmg wrote: »
    twm47099 wrote: »
    The P2asm file was too long to list here and the beginning is where the edits are needed.
    CON			' **** add
     _SETFREQ = $010C4704   ' **** add
     _ENAFREQ = $010C4707	' **** add
    

    See garryj's post that corrects the lower nibble for cap selection.
    CC: %10 input 600-ohm drive 1M-ohm 15pF per pin ( I get -6.700 ppm on this setting)

    Thanks, I changed the constants.
    Also note that if you want to use the on-board LEDs just change the pin numbers
    ' blink in cog 1
    var a = cpu(blink(56, 180_000_000), @stack(1))
    ' blink 2x as fast in cog 2
    var b = cpu(blink(57, 90_000_000), @stack1(1))
    
  • rosco_pcrosco_pc Posts: 465
    edited 2018-12-27 07:55
    twm47099 wrote: »
    Note that to get Basic and C programs to load & run it was necessary to do a couple of things:
    5. Open the xxx.spin2 file and change near the top of the file:
    hubset #255
    
    to
    hubset #0
    
    This is a simple patch in in the spincc code file backends/asm/outasm.c
    change line 5046
    EmitOp1(irl, OPC_HUBSET, NewImmediate(255));
    
    to
    EmitOp1(irl, OPC_HUBSET, NewImmediate(0));
    

    Have not tested as I don't have my P2-eval board yet.

    The changes proposed in step 6 are a bit more elaborate, will have a look if Eric does not beat me to it :)

    edit: attached patch file now
  • I have tried spin 2 gui and get an error. See attached.
    I have also tried fastspin but it launches a window and disappears. ?????
    Help please.
    694 x 683 - 75K
  • cheezuscheezus Posts: 298
    edited 2018-12-28 18:37
    I think fastspin needs 8.3 filenames for spin2 objects. Pretty sure I ran into the same issue.

    *edit

    To be clear, it looks like the path "propeller 2 docs" is only being seen as propeller. Could be wrong but it's worth a try
  • What steps to you suggest. I am unfamiliar with manipulating those types of paths. How do I change it?
    Thanks
  • OK, sorry I haven't been quicker to respond to the various issues people have found on P2 Eval boards but the holidays have been crazy busy for me. I have managed to try out fastspin and spin2gui on a P2 Eval board. As you've noticed, some fixes were required to get the generated code to work on real hardware. I've made those fixes now. It's entirely possible that P2 FPGA doesn't work any more -- I'll have to look at that later, but I suspect most FPGA users have Eval boards now, so hopefully that won't be a big blocker.

    The new spin2gui (version 1.3.0) is in the usual place:

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

    The biggest changes are (1) using an updated loadp2 from Dave Hein which supports the P2 Eval, and (2) not implicitly setting the clock mode at startup on P2. I recommend putting in an explicit "clkset(mode, freq)" in P2 programs (BASIC or Spin). In BASIC you should follow this by "_setbaud(2000000)" if you want to use the serial port. The clkset() takes as a mode argument the hubset mode for setting up the oscillator. It implicitly enables the oscillator with an XSEL of %11. That's something we can change later, but I wanted to get some code out quickly.

    I hope this works for everyone -- as always, let me know of any issues you find.

    Happy New Year all!
    Eric
  • pilot0315 wrote: »
    I have tried spin 2 gui and get an error. See attached.
    I have also tried fastspin but it launches a window and disappears. ?????
    Help please.

    Folder names with spaces in them seem to be a problem for spin2gui. Just rename them (in Windows right-click and select Rename) to something without a space, for example by replacing all spaces with underscores.

  • ersmith,
    Thanks for the update! I'd like to use this for doing C/C++. I know it's "not ready for prime time" or whatever, with a lot missing, but you've mentioned having some simple stuff working.
    I don't see any C samples in the samples folder, do you have some stuff that works for P2 Eval board available someplace?

    I did see the c.md doc file which explains a bunch, but do you have any "builtin" things or does that sort of stuff all need to be done with inline asm? I'm thinking things like a clkset equivalent, or other basic stuff.
  • You might try the sample programs in p2gcc to see if they work with fastspin. There are some simple programs like hello.c and prime.c, and more complicated ones like chess.c and bas.c.
  • I still get this error is there a fix?
    727 x 671 - 76K
  • pilot0315 wrote: »
    I still get this error is there a fix?
    As Eric suggested above, get rid of the spaces in your directory names and this problem will likely go away.

  • Roy Eltham wrote: »
    ersmith,
    Thanks for the update! I'd like to use this for doing C/C++. I know it's "not ready for prime time" or whatever, with a lot missing, but you've mentioned having some simple stuff working.
    I don't see any C samples in the samples folder, do you have some stuff that works for P2 Eval board available someplace?
    [/code]
    The C compiler is very much not ready for prime time, and has a ton of bugs (and missing features). If you want to try it out feel free, but you'll probably be disappointed in its current state.

    Here's a simple C program to toggle an LED and print a message on the serial port. It works with my board on spin2gui v1.3.0.
    // P2 blinking lights and serial demo
    // this requires a P2-EVAL board
    
    #include <stdio.h>
    #include <propeller.h>
    
    #define CLKFREQ 160000000
    #define CLKMODE 0x10c3f04
    #define BAUD 2000000
    
    #define PIN 58
    
    void main()
    {
        unsigned int pinmask = 1<<(PIN-32);
        unsigned i = 0;
    
        clkset(CLKMODE, CLKFREQ);
        _setbaud(BAUD);
        printf("fastspin C demo\n");
        DIRB |= pinmask; // set pins as output
        for(;;) {
            OUTB ^= pinmask;
            waitcnt(getcnt() + CLKFREQ/4);
            printf("toggle %u\n", i++);
        }
    }
    
  • Dave Hein wrote: »
    You might try the sample programs in p2gcc to see if they work with fastspin. There are some simple programs like hello.c and prime.c, and more complicated ones like chess.c and bas.c.

    I think hello.c works, but the others manage to turn up bugs in the fastspin C compiler -- prime.c, for example, has a large local array that fastspin tries to cram into COG RAM. The p2gcc demo programs are great tests though, and I hope to get them running soon.
  • pilot0315 wrote: »
    I still get this error is there a fix?

    As David Betz mentioned, you'll need to rename your "NEW SPIN2GUI UPDATE 1.3.0" folder to something like "NEW_SPIN2GUI_UPDATE_1.3.0" that has no spaces in it.
  • I've tried spin2gui vers1.3.0 together with Eric's recommendations for the timing defines and additions to main(). It works. I've also used the CLKMODE for 180MHz and that works. 2000000 baud is the fastest I've been able to use with the builtin terminal, PST can use 3000000.

    I wrote a program (below) to reverse the bits in an integer (for a MSBFIRST data transfer). It is listed below and it works to change the initial value of 26 (0b11010) to 11 (0b01011). Because of problems I had with the earlier version of spin2gui, I did the printout in an infinite loop so I would be able to start the PST.
    /*
     reversebits.c
      reverses bits in an integer to make a MSBFIRST bit stream
    */
    #include <stdio.h>
    #include <propeller.h>
    
    #define CLKFREQ 180000000
    #define CLKMODE 0x10C4708
    #define BAUD 2000000	// this is max baud for built in terminal
    
    int reversed;
    
    int revbits(int n)    // Reverses bits, n is current number
    {
      int pos = 31;
      int reverse = 0;
      while(pos >= 0 && n)
      {
        if(n & 1) reverse = reverse | (1 << pos);
        n >>= 1;
        pos--;
      }   
      return reverse;
    }
    
    int makemsbfirst(int n, int nbits)   // shift n by nbits to MSB, then call revbits
    {
     n <<= (32 - nbits);
     //printf("n = %d ",n);
     n = revbits(n);
     return n;
    }
       
    int main()   // 
    { 
     clkset(CLKMODE, CLKFREQ);
     _setbaud(BAUD);
     
    while(1)
    {
      int initial = 26;   // 0b11010 reversed should be 0b01011 (dec 11)
      int bitsx = 5;    // number of bits to reverse
      printf("\n initial = %d  ", initial);
      reversed = makemsbfirst(initial, bitsx);
      printf("MSBFIRST = %d \n", reversed);
    }
    }
    
    
  • Btw getting rid of the spaces in the directory names did not fix the problem.
  • pilot0315 wrote: »
    Btw getting rid of the spaces in the directory names did not fix the problem.

    The error you received is precisely about spaces in the directory named "NEW SPIN2GUI UPDATE 1.3.0"...
    SpaceError.png

    There may be other issues past that problem, but that directory name was causing the issue you displayed in the image you attached. Attach any new error images and maybe we'll be able to help you further.

    dgately
  • I will try again. I see now what you have said. I corrected it and now get this:
    I had clicked on p2 in the commands.
    1290 x 761 - 161K
  • Pnut can see the p2
  • pilot0315 wrote: »
    Pnut can see the p2

    Is Pnut still running? Or a terminal program? If any other program is using the P2 then loadp2 will not be able to find it.

    If that's not the problem you could try unplugging and re-plugging the P2 eval board. If it's still not found, take a look at what PNut is reporting as the serial port for the P2. If, for example, it's COM9, try adding "-p COM9" to the loadp2 command line in spin2gui. To do this, go to Commands > Configure Commands..., and in the "Run Command" (the one that starts with "cmd.exe /c start ..." add -p COM9 at the very end of the line.
Sign In or Register to comment.