Shop OBEX P1 Docs P2 Docs Learn Events
P2 Serial/Monitor/Debugger object: hubexec code callable from pasm and spin2, relocatable cog / hub — Parallax Forums

P2 Serial/Monitor/Debugger object: hubexec code callable from pasm and spin2, relocatable cog / hub

Cluso99Cluso99 Posts: 18,069
edited 2020-05-09 03:36 in Propeller 2
P2 Serial/Monitor/Debugger object

The Serial Monitor is usable as a FullDuplexSerial replacement with some added features such as dumping cog/lut/hub memory and calling the monitor to make memory changes.

Serial Monitor v1.53 2020-05-09
* Spin calls now simplify the calling methods from spin

Monitor v1.50
* Callable from pasm or spin2
* baud is set by software during the Serial Initialisation call
* hub buffer [80 bytes] location (default $fc000) can be set by software (used by Monitor and RxString)
* uses 16 cog registers (default $120-$12F) but can be compiled to any cog block
* code runs from hub in hubexec mode (~$570 bytes)
* code can be compiled to be located anywhere in hub (default $fcab8 which is the ROM Monitors location)
* simple 3 line relocation equates (_regs, _hub, buf)
* uses P2 standard serial pins P63 & P62 (reconfigurable only with recompile at this time)
* provides all ROM Monitor calls (ie replaces the ROM Monitor v1.3)

Demo code shows example calls from pasm and spin2.

Supported CALLS
''-------[ P2 ROM SERIAL MONITOR ROUTINES (HUBEXEC) ]--------------------------
  SerialInit    Serial Initialise     (x & bufad must be set first)
  Tx            Sends x               (can be up to 4 bytes) x unchanged
  TxCR          Sends <cr><lf>        (overwrites x)
  TxRev         Sends x with bytes reversed
  TxHex         Sends x as Hex char(s) as defined in f
  TxHex8        Sends x as Hex char(s) after setting f as 8 hex chars
  TxHexRev      Sends x with bytes reversed as Hex char(s) as defined in f
  TxStr         Sends $0 terminated string at p address
  TxStrVer      Sends $0 terminated string at p address after setting p=##_str_vers
  TxListA2      List/Dump line(s) from p address to p2 address after setting f=#_LIST+_ADDR2 
  TxList        List/Dump line(s) from p address to p2 address according to f
  Rx            Recv char into x
  RxStr         Recv string into p/bufad address according to params in f
  RxStrMon      Recv string into bufad address after setting prompt=x=#"*" & params=f=#_RXSTR+_ECHO_+_PROMPT
  Monitor       Calls the Monitor; uses bufad as the input buffer address
  ReadLong      read cog/lut/hub long from p address into x, then p++
' Download      only valid when in the monitor. Format...
                  [xx]xxx: xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx ['xxxxxxxxxxxxxxxx'] <cr>
  StrVer        locn of hub version string, $0 terminated

Monitor Commands
When in the Monitor, these commands are available
-----------------------------------------------------------------------------------------------
  MONITOR - SUPPORTED COMMANDS
-----------------------------------------------------------------------------------------------
  xxxxxx : xx xx xx xx ... <cr>  DOWNLOAD:  to cog/lut/hub {addr1} following {byte(s)}
  xxxxxx - [xxxxxx] [L] <cr>     LIST:      from cog/lut/hub {addr1} to < {addr2}, L=longs
  xxxxxx G <cr>                  GOTO:      to cog/lut/hub {addr1}
  Q <cr>                         QUIT:      Quit Rom Monitor and return to the User Program
-----------------------------------------------------------------------------------------------
  Note: No space permitted after first parameter/address

Comments

  • Cluso99Cluso99 Posts: 18,069
    <reserved>
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-05-09 03:38
    Update v1.52 v1.53 (see top post for code)

    Demo spin code...
    Adds set.TxHexOpt (not shown in output)
        ser.startSerial(mon.BUF, _bitper)                   ' copy serial to hub then setup buf and baud
        ser.TxStrVer()                                      ' print Monitor Version string
    
        ser.DumpMem($100, $110)                             ' dump memory cog $100-$110     (f=List+Addr2)
        ser.DumpMem($01000, $01100)                         ' dump memory hub $01000-$01100 (f=List+Addr2)
    
        ser.Tx("S"+"p"<<8+"i"<<16+"n"<<24)                  ' print "Spin" (prints lowest byte first)
        ser.TxCR()
    
        ser.TxHex8($41424344)                               ' print hex 8 digits
        ser.TxCR()
    
        ser.TxHexOpt(mon._REV+mon._SP+6, $12345678)         ' reverses, then prints 6 hex nibbles in pairs
        ser.TxCR()
    
        ser.TxStr(@testString)                              ' print testString
    
        ser.Monitor()                                       ' call Monitor (Q<cr> returns)
    

    gives the following output...
    P2-Monitor V1.52
      100: DE 0A 00 00  DF 02 00 00  E4 1A 00 00  E4 BA 3F 00   '..............?.'
      104: E4 7A 00 00  E4 FA 3E 00  E4 FA 01 00  E4 BA 03 00   '.z....>.........'
      108: E4 BA 37 00  E4 BA 0F 00  E4 BA 1F 00  F3 1A 00 00   '..7.............'
      10C: F3 02 00 00  FD FA DE 36  FD FA DD 36  FD FA DB 36   '.......6...6...6'
    01000: C4 00 00 00  0C 00 00 00  68 00 00 80  C2 00 00 00   '........h.......'
    01010: 3A 3A 3A 3A  3A 3A 3A 3A  3A 3A 3A 3A  3A 3A 3A 3A   '::::::::::::::::'
    01020: 3A 3A 3A 3A  3A 3A 3A 3A  3A 3A 3A 3A  3A 3A 3A 3A   '::::::::::::::::'
    01030: 3A 3A 3A 3A  3A 3A 3A 3A  3A 3A 3A 3A  3A 3A 3A 3A   '::::::::::::::::'
    01040: 3A 3A 3A 3A  3A 3A 3A 3A  3A 3A 3A 3A  3A 3A 3A 3A   '::::::::::::::::'
    01050: 41 20 74 65  73 74 20 73  74 72 69 6E  67 0A 0D 00   'A test string...'
    01060: 00 47 88 13  22 78 00 49  00 C0 0F 00  49 07 00 12   '.G.."x.I....I...'
    01070: 0A 08 01 02  00 08 01 08  00 4A 08 47  10 01 08 01   '.........J.G....'
    01080: 09 00 4A 0C  47 00 11 08  01 09 00 49  53 70 69 6E   '..J.G......ISpin'
    01090: 08 01 03 00  08 01 06 00  49 44 43 42  41 08 01 07   '........IDCBA...'
    010A0: 00 08 01 06  00 50 58 7F  08 01 05 00  08 01 0A 45   '.....PX........E'
    010B0: 38 39 47 F4  01 22 78 11  77 04 00 00  38 06 00 00   '89G.."x.w...8...'
    010C0: 08 00 00 00  A0 05 00 82  CF 05 00 81  DD 05 00 81   '................'
    010D0: EB 05 00 81  F9 05 00 80  02 06 00 81  10 06 00 80   '................'
    010E0: 19 06 00 82  2C 06 00 80  35 06 00 00  00 00 80 FF   '....,...5.......'
    010F0: 3E F8 0C FC  3E 40 16 FC  41 7C 64 FD  00 00 80 FF   '>...>@..A|d.....'
    Spin
    41424344
    A test string
    *
    
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-05-09 03:06
    The DumpMem call

    The DumpMem call (also known as the LIST call) is an extremely powerful COG/LUT/HUB memory dump routine.
    DumpMem(addr1,addr2) will list memory in the byte format...
    01050: 41 20 74 65  73 74 20 73  74 72 69 6E  67 0A 0D 00   'A test string...'
    01060: 00 47 88 13  22 78 00 49  00 C0 0F 00  49 07 00 12   '.G.."x.I....I...'
    
    addr1 and addr2 are the first and last addresses in cog, lut, or hub.
    A full 4 longs will be listed on each line, together with their ASCII representation.
    Addresses < $200 will be interpreted as COG
    Addresses >=$200 and < $400 will be interpreted as LUT
    Addresses >= $400 will be interpreted as HUB.
    To list hub addresses <$400, just add $1_00000 to each addr1 and addr2. (eg $100100,$100200 will list hub $100-$200)

    DumpMemL(addr1,addr2) will list memory in the long format (note the reversal of bytes in the long)...
    01050: 65742041 73207473 6E697274 000D0A67  'et As tsnirt...g'
    01060: 13884700 49007822 000FC000 12000749  '..G.I.x".......I'
    
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-05-09 03:32
    The TxHex call

    The base TxHex call is extremely powerful. There are options that control how the TxHex command works. The main calls are supported by simplified calls...

    TxHex8(long) will transmit the hex value to the serial port as 8 hex digits in byte pairs.

    TxHexRev(long) will first reverse the bytes and then transmit the hex value to the serial port as 8 hex digits in byte pairs.

    Additional options are available by first setting a bit-mask to control the TxHex routine.
    TxHexOpt(options, long) where the options are
    _REV - will reverse the byte order
    _SP - will print digit (nibble) pairs instead of the long format (_SP=spaces)
    _DIGITS - 0-7 where 0=8 digits (nibbles)

    Example use of the options...
    ser.TxHexOpt(mon._REV+mon._SP+6, $12345678) ' reverses, then prints 6 hex nibbles in pairs "56 34 12"
  • Mike GreenMike Green Posts: 23,101
    edited 2020-05-09 04:20
    Thanks for doing this. I'm already using the SD card driver objects. The one thing missing in this set of objects is rxcheck. I suppose I could just write a short stub that does it, something like:
    _HubRxChk
                      neg     mon.x,           #1           '  <--- receive char --->
                      testp   #rx_pin          wc           ' default -1, is char ready?
             if_c    rdpin   mon.x,          #rx_pin   ' recv byte (bits31:24) from rx pin
             if_c    shr     mon.x,           #24         ' shift rx bits
                      RET                           wcz         '  <--- return to calling routine --->
    
  • Cluso99Cluso99 Posts: 18,069
    Mike,
    The one caveat is that I don't use interrupts (at least for now anyway) so Rx and RxString are always half duplex.

    I've added it. Will post with other updates shortly :)

  • Cluso99Cluso99 Posts: 18,069
    @Mike,
    Just before I go out, here it is
  • I still can't get your serial routines to work. It must be something simple I just haven't been able to see. Here's a stripped down version. Look at the beginning of the main method for the call to startSerial. The program just mounts an SD card, lists the files in the root directory, then accepts filenames and opens each for reading, and closes each.
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-05-15 06:30
    Quick question Mike...
    Are you using pnut34r or s, or fastspin?

    Eric said a few days ago that cog registers are not available for use!!!
    While my code works for me, I think that may be a fluke :(

    I re-targetted the registers to work around pnut a few weeks ago, and finally got both the serial and sd working. The P2-EVAL requires P59^ switch on else pnut will not download the code with an SD Card present.

    Mike,
    I looked at the code and decided to compile with pnut34r. After numerous errors and not knowing what some things did I gave up.
    Unfortunately fastspin isn't going to be compatible with pnut, nor the reverse either. :(:(:(
    My code requires spare cog longs to work, so I don't expect my code will likely run with fastspin :(

    There seems no point in trying to make general use objects anymore. It's all just been a huge waste of time!
  • I'm using fastspin since it runs on my Mac. I've also tried to use PNut since I can run Windows 10 under Parallels and, as you've noticed, they're not compatible with each other. Fastspin is still buggy ... FemtoBasic is around 2000 lines of code and, although I've found my share of bugs in my code, there are too many situations where it seems to work and I make a small change ... often to remove some debugging code or to add a small feature, and another part of the program breaks ... distant and unrelated and had been working for several days.

    I've mostly gotten the flash version of FemtoBasic working, but it's all my code including the Winbond flash driver ... and all in Spin. I think I'll wait for SD card support to settle down and for PNut and fastspin to mature a bit more.

    Thanks again for your time.
  • Cluso99Cluso99 Posts: 18,069
    No problem Mike.
    Yes I've had my fair share of untrackable bugs. That's why I needed the serial monitor working. I made great progress for a short time with both pnut and fastspin working. Then I discovered that fastspin didn't actually let me use cog even tho it was working, so as soon as I push it, I know it will eventually fail randomly.
Sign In or Register to comment.