P2 Serial/Monitor/Debugger object: hubexec code callable from pasm and spin2, relocatable cog / hub
Cluso99
Posts: 18,069
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
Monitor Commands
When in the Monitor, these commands are available
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
Demo spin code...
Adds set.TxHexOpt (not shown in output)
gives the following output...
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... 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)...
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"
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
Just before I go out, here it is
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'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.
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.