Shop OBEX P1 Docs P2 Docs Learn Events
Use of spin2cpp - Page 2 — Parallax Forums

Use of spin2cpp

2

Comments

  • Thank you Eric
    "C:/FlexGUI/bin/fastspin" -2 -l -O1 -I "C:/FlexGUI/include"  "C:/FlexGUI/kgsamples/blink1.c"
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
    Version 4.0.6 Compiled on: Dec 30 2019
    blink1.c
    blink1.p2asm
    Done.
    Program size is 1408 bytes
    Finished at Thu Jan  2 23:31:27 2020
    cmd.exe /c start "Propeller Output  " "C:/FlexGUI/bin/loadp2"  -b230400 "C:/FlexGUI/kgsamples/blink1.binary" "-9C:/FlexGUI/kgsamples" -q -k
    
  • Code from spin2cpp now in Code:Blocks (see attachment)
    <html>
    <head>
    <title>blink1 build log</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
    <body>
    <tt>
    Build started on: <u>03-01-2020 at 00:41.44</u><br />
    Build ended on: <u>03-01-2020 at 00:41.45</u><p />
    <b>-------------- Build: default in blink1 (compiler: Catalina C Compiler)---------------</b><br />
    catalina.exe -p2 -CP2_EVAL -CTTY -CNATIVE     -I"C:\Program Files (x86)\Catalina\include" -ID:\Catalina\blink1 -c main.c -o .objs\main.obj<br />
    Catalina Compiler 4.0<br />
    catalina.exe  -o blink1 .objs\main.obj -p2 -CP2_EVAL -lcx -lm -CTTY -CNATIVE<br />
    code = 284 bytes<br />
    Catalina Compiler 4.0<br />
    cnst = 0 bytes<br />
    init = 4 bytes<br />
    data = 4 bytes<br />
    file = 9984 bytes<br />
    <font color="#0000ff">Process terminated with status 0 (0 minute(s), 0 second(s))</font><br />
    <font color="#0000ff">0 error(s), 0 warning(s) (0 minute(s), 0 second(s))</font><br />
    </tt>
    </body>
    </html>
    
    687 x 935 - 85K
  • Now we are compiling much more:
    <html>
    <head>
    <title>blink1 build log</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
    <body>
    <tt>
    Build started on: <u>03-01-2020 at 01:39.04</u><br />
    Build ended on: <u>03-01-2020 at 01:39.06</u><p />
    <b>-------------- Build: default in blink1 (compiler: Catalina C Compiler)---------------</b><br />
    catalina.exe -g3 -CTTY -CNATIVE -Clibm -Clibcx -CP2_EVAL -p2     -I"C:\Program Files (x86)\Catalina\include" -ID:\Catalina\blink1 -c main.c -o .objs\main.obj<br />
    Catalina Compiler 4.0<br />
    catalina.exe  -o blink1 .objs\main.obj -g3 -CTTY -CNATIVE -lm -lcx -CP2_EVAL -p2<br />
    Catalina Compiler 4.0<br />
    code = 22896 bytes<br />
    cnst = 148 bytes<br />
    init = 216 bytes<br />
    data = 1348 bytes<br />
    file = 35264 bytes<br />
    <font color="#0000ff">Process terminated with status 0 (0 minute(s), 1 second(s))</font><br />
    <font color="#0000ff">0 error(s), 0 warning(s) (0 minute(s), 1 second(s))</font><br />
    </tt>
    </body>
    </html>
    
    687 x 935 - 85K
  • Any particular reason you're using Catalina rather than fastspin to compile these examples, @kg1? It'd be easier to just directly build everything in flexgui rather than having to convert with spin2cpp and then build in a different environment.
  • @ersmith Hi Eric I am a keen debugger. Perhaps some may say I should leave the "de" off debugger. Well I hope to get much code from SPIN and add it to C code I already have. I am also keen on multithreading and hope to put cogs to good use.
  • kg1kg1 Posts: 164
    edited 2020-01-04 02:46
    @RossH using Code:Blocks and selecting Tools->Download to Hub RAM and Debug with BlackCat
    Result:
    The Propeller is running!!! The debugger cannot control a running program.
    Also on the command line:
    C:\Program Files (x86)\Catalina\demos>catalina.exe -lci -p2 -C P2_EVAL -C NATIVE -D_getcnt=_cnt -g3 blink2.c
    Catalina Compiler 4.0
    
    code = 5852 bytes
    cnst = 107 bytes
    init = 208 bytes
    data = 772 bytes
    file = 16352 bytes
    
    
    C:\Program Files (x86)\Catalina\demos>payload blink2.bin
    Using Propeller (version 2) on port COM4 for download
    
    C:\Program Files (x86)\Catalina\demos>blackcat -P COM4 -B 115200 -D blink2
    
    Does BlackCat require a separate serial line?
    Thanks,
    Kevin.
    657 x 445 - 24K
  • Cluso99Cluso99 Posts: 18,066
    You will need RossH to answer this.
    He's been MIA for the past few weeks. It's a busy time for him as they cater for tourists, and also he's in the firezone south of Sydney. Hope all is well Ross!
  • Thank you for the info: @Cluso99 Your advice please: should I start a new discussion/ thread with heading: BlackCat
    There must be some members who have used BlackCat and know the start-up procedure. Adding the -g3 parameter and compiling seems to cause the program not to run when using payload.
    Kevin.
  • Cluso99Cluso99 Posts: 18,066
    I suggest you ask again on the Catalina thread as that is specific to Black Cat.
  • @Cluso99 I have found:
    BlackBox Reference:
    On Propeller 2 platforms, which generally use pins 62 & 63 for serial loading programs and for serial communications, Blackbox by default uses a second serial port provided by a PropPlug connected to pins 50 & 52.
    I am not technical but I do have a Sparkfun FTDI cable which I hope I can substitute for a PropPlug.
    On the Propeller 2 with regard to Pins 50 & 52 does it matter which one is TXD and/or RXD? I guess GND is also needed?
    Many thanks,
    Kevin.
  • Cluso99Cluso99 Posts: 18,066
    Yes, you will need gnd. Presuming P63 & P62 are equivalent to P52 & P50, then P52 will be an input ie TXD on the serial plug.
    The FTDI cable should be fine as you don’t need reset on this port.
    If you have 1K to 5K resistors, connect in series with the FTDI cable TXD and RXD for safety until you are sure of the correct connection.
  • Yes a prop plug would connect to GND - 48(Reset) - 50 (P2->PC) - 52 (PC->P2)

    As Cluso says you don't need to worry about reset, and the resistors are a good idea as long as comms aren't super fast
  • kg1kg1 Posts: 164
    edited 2020-01-06 02:26
    @RossH, @Cluso99 & @Tubular Thank you for your help. In the Device Manager I had two USB Serial Ports COM4 & COM6. I am still getting the original error dialogbox (see attachment). I guess I will need to wait for Ross.
    Kevin
  • kg1kg1 Posts: 164
    edited 2020-01-06 03:29
    using spin2cpp with --p2 it rejects any function name with a colon (:) in front of name (please see attached).
    Is this normal?
    Thank you,
    Kevin
    686 x 511 - 56K
  • The assembly language syntax has changed between Propeller 1 and Propeller 2 (in P1 a colon is used at the beginning of temporary labels, in P2 it's a period instead). That change is only the tip of the iceberg though -- the two processors have different registers and instruction sets. spin2cpp only converts the Spin code, not the assembly code in the DAT section, so you'll have to convert the PASM code manually.
  • Thanks Eric @ersmith
  • kg1kg1 Posts: 164
    edited 2020-01-07 06:43
    @ersmith Looking at output of spin2cpp from ILI9341-test.spin for Propeller 1:
    __asm__( " .global __clkfreqval\n" );
    __asm__( " __clkfreqval = 0x4c4b400\n" );
    __asm__( " .global __clkmodeval\n" );
    __asm__( " __clkmodeval = 0x6f\n" );
    This is preventing the build for Propeller 1 and does not fit the Catalina documents I am reading for PASM within C.
    Am I missing something?
    Kevin.
  • kg1 wrote: »
    @ersmith Looking at output of spin2cpp from ILI9341-test.spin for Propeller 1:
    __asm__( " .global __clkfreqval\n" );
    __asm__( " __clkfreqval = 0x4c4b400\n" );
    __asm__( " .global __clkmodeval\n" );
    __asm__( " __clkmodeval = 0x6f\n" );
    This is preventing the build for Propeller 1 and does not fit the Catalina documents I am reading for PASM within C.
    Am I missing something?
    Kevin.

    That syntax is used by PropGCC. I think that code is all wrapped in an #ifdef __propeller__. Does Catalina define the __propeller__ symbol? If it does then you'll have to manually edit it out. It sets the clock frequency and mode for PropGCC and is not applicable to Catalina (which probably has a different way to do that).
  • kg1kg1 Posts: 164
    edited 2020-01-07 21:33
    @ersmith Wow! I never would have resolved that! Is spin2cpp meant to also cover PropGCC? SimpleIDE uses PropGCC?
     */
    __asm__( "    .global __clkfreqval\n" );
    __asm__( "    __clkfreqval = 0x4c4b400\n" );
    __asm__( "    .global __clkmodeval\n" );
    __asm__( "    __clkmodeval = 0x6f\n" );
    
    Ili9341_test MainObj__;
    
    int main() {
      Ili9341_test_main(&MainObj__);
      return 0;
    }
    
    The above code is generated by spin2cpp for p1. No surrounding #ifdef __propeller__
    I also searched all files in the Catalina folder for __propeller__ no result
    I believe Catalina uses target files to set the clkfreq and clkmod values
    I found __asm__ used in two .c files in the catalina folder so it must be defined somewhere.
    I can't find clkfreqval or clkmodeval being used in code but _clkfreq is used.
    I will quote out clkfreqval or clkmodeval lines for now.

    Back to Propeller 2: In flexgui:
    I will try to manually convert spin files meant for P1 to be used as spin files for use on P2:
    Changing colon to period removes a lot of compile errors regarding temporary lables in asm.
    del_millis      mov     time, CNT
                    add     time, MSdelay
                    waitcnt time, #0
                    djnz    delaycount, #del_millis
    del_millis_ret  ret
    
    It seems that waitcnt is not available in PASM for P2? The error message is around the parameter time but is probably relates to number of parameters. Perhaps waitx could be used?
    Many thanks,
    Kevin.

  • Cluso99Cluso99 Posts: 18,066
    Check out the P2 Tricks and Traps thread. Timers are covered in there and other goodies.
  • Thanks @Cluso99 will do.
  • kg1 wrote: »
    @ersmith Wow! I never would have resolved that! Is spin2cpp meant to also cover PropGCC? SimpleIDE uses PropGCC?

    Yes to both. In fact spin2cpp was originally intended for PropGCC, and the Catalina support is an afterthought.
    The above code is generated by spin2cpp for p1. No surrounding #ifdef __propeller__

    Ah, there's a bug there then. I misread some of the code, and I think it was intended to have an #ifdef around it.
    It seems that waitcnt is not available in PASM for P2? The error message is around the parameter time but is probably relates to number of parameters. Perhaps waitx could be used?

    Neither waitcnt nor CNT is available in P2 assembly. waitx can be used to achieve something similar, as can getct/waitct. The thread Cluso pointed to is definitely a useful one.

  • kg1kg1 Posts: 164
    edited 2020-01-08 03:44
    Conversion of PASM from P1 to P2
    Please advise re the use of PAR in P1
    Photo attached explains
    Thanks Kevin
    @ersmith Thanks Eric. I really want to compile the SPIN code for P2, say goodbye for now to PASM, then study plugins for Catalina and "slot in" the SPIN code into a plugin. I hope it works on a P2!
    Cheers.
    941 x 591 - 35K
  • Cluso99Cluso99 Posts: 18,066
    For passing a value in PAR for the P2 requires a SETQ before the COGINIT instruction to set the value into PTRA or PTRB (cannot recall which one but it's in the P2 docs).
  • kg1kg1 Posts: 164
    edited 2020-01-10 01:29
    @Cluso99 Thank you for your reply. "docs" do you mean "Parallax Propeller 2 Documentation v33 - Rev B Silicon" or are there others? I have attached page 16 of Parallax Propeller 2 Documentation v33 - Rev B Silicon. Are there any examples for PASM for P2 which would be a good starting point?
    Also in the first file I have listed some reading material for PASM for P1 which I will work through.
    I do not wish to become an expert in PASM. I hope to convert P1 code to P2 code and create a Catalina Plugin.
    Regards,
    Kevin.
  • Do you have the full FlexGUI release? The examples in the samples/ directory would be a place to look for some simple PASM code for P2 (e.g. the led_server_pasm.c program and the multiply.spin program). You could also use "spin2cpp --asm --p2 foo.c" to translate simple code snippets in C (or BASIC or Spin), and/or look at the listing file that "fastspin -l" produces (there's a FlexGUI menu option for that, under Files).

    The Propeller2 is still in the Engineering Sample stage, so documentation is unfortunately sparse. Parallax has traditionally produced very good documentation for their products though, so we can expect that to improve as time goes on and the full release of the chip approaches.
  • For a more complicated example there's a VGA text driver at https://github.com/totalspectrum/p2_vga_text. The internals of it are written in P2 assembler but the wrapper is in Spin, which converts to C cleanly with spin2cpp (the C code compiles with fastspin, Catalina, and riscvp2). It might be an easier way to start plug-in development.
  • @ersmith Thank you Eric. That's really excellent.
  • @ersmith Hi Eric Is there an include file missing? Or .spinh
    C:\FlexGUI\samples>spin2cpp --ccode --main --files --p2 Smartpin.spin2
    C:/FlexGUI/include/spin/SmartSerial.spin:22: error: dirl_ is not a function
    C:/FlexGUI/include/spin/SmartSerial.spin:23: error: dirl_ is not a function
    C:/FlexGUI/include/spin/SmartSerial.spin:30: error: wrpin_ is not a function
    C:/FlexGUI/include/spin/SmartSerial.spin:31: error: wxpin_ is not a function
    C:/FlexGUI/include/spin/SmartSerial.spin:32: error: dirh_ is not a function
    C:/FlexGUI/include/spin/SmartSerial.spin:33: error: wrpin_ is not a function
    C:/FlexGUI/include/spin/SmartSerial.spin:34: error: wxpin_ is not a function
    C:/FlexGUI/include/spin/SmartSerial.spin:35: error: dirh_ is not a function
    C:/FlexGUI/include/spin/SmartSerial.spin:43: error: dirl_ is not a function
    C:/FlexGUI/include/spin/SmartSerial.spin:44: error: waitx_ is not a function
    C:/FlexGUI/include/spin/SmartSerial.spin:81: error: waitx_ is not a function
    C:/FlexGUI/include/spin/SmartSerial.spin:90: error: wypin_ is not a function
    C:/FlexGUI/include/spin/SmartSerial.spin:91: error: waitx_ is not a function
    
  • The Spin2 language is still in flux, so not all of the builtin functions used in .spin2 files are supported by spin2cpp. This is unfortunate, but it's probably going to be a while before everything settles down.

Sign In or Register to comment.