PeekPoke: read and write hub memory remotely with Python

PeekPoke is a tool for reading and writing a Propeller's hub memory from a PC. It consists of two parts: a Python module for sending commands from the PC, and a Propeller program for responding to commands.

The Python module has methods to read and write hub memory as bytes, strings, integers, and lists of integers.

The Propeller program can be configured to restrict reads and writes to specific ranges, or to disable writes altogether.

PeekPoke has these additional features:
- the PAR register may be used to pass a value to the PC,
- the PC can set the baudrate remotely,
- the PC can reset the baudrate with a break condition,
- the Propeller can support baudrates as fast as 26 clocks per bit period,
- there is a four-byte identifier constant that can read by the PC,
- a four-byte token variable is 0 on launch and can be set by the PC,
- the PC can send PASM code to be executed (disabled by default),
- multiple instances of the Propeller program can run in separate cogs,
- the Propeller program is completely cog-contained after launch.

Spin Example
con
    _xinfreq = 5_000_000
    _clkmode = xtal1 + pll16x
    cBuffSize = 20   'must be divisible by 4

obj
    peekpoke : "PeekPoke.spin"

var
    long buffer[cBuffSize/4]    'buffer must be long-aligned since it is passed via PAR

pub main
    peekpoke.new(@buffer)

Python Example
from peekpoke import PeekPoke

# Assuming a PeekPoke instance is running on the serial port.
# ser_port is the name of the serial port (e.g. "COM1" or "/dev/cu.usbserial-XXXX")
p = PeekPoke(ser_port)
p.get_int(0, 4)                      # returns 80000000, if that is Spin's clkfreq
p.get_str(65297, 30)                 # returns 'Copyright 2005  Parallax, Inc.'
p.get_ints(0xe000, 2, 4)             # returns [0, 50, 101, 151], from sine table

# Assuming the address of a write-safe buffer of 20 bytes was passed as PAR.
addr = p.get_par()                   # returns the PAR register
p.fill_bytes(addr, 20, b'-')
p.set_bytes(addr, b'Cat')
p.get_bytes(addr, 20)                # returns bytearray(b'Cat-----------------')
p.set_str(addr, 20, 'Hello')
p.get_str(addr, 20)                  # returns 'Hello'
p.set_int(addr, 2, 2018)
p.get_int(addr, 2)                   # returns 2018
p.set_ints(addr, 4, [0, -1, 2000000000], signed=True)
p.get_ints(addr, 4, 3, signed=True)  # returns [0, -1, 2000000000]

# The following may be necessary when reloading the Propeller.
from crow.host import Host
Host.close(ser_port)                 # closes the serial port
Host.open(ser_port)                  # re-opens the serial port

Installation

PeekPoke requires Python 3. It can be installed with the command "pip install peekpoke". If that doesn't work, try using "pip3".

Alternatively, the package may be downloaded from https://pypi.org/project/peekpoke/. PeekPoke also requires the https://pypi.org/project/crow-serial/ and https://pypi.org/project/pyserial/ packages (pip automatically handles these dependencies).

To run PeekPoke on the Propeller include "PeekPoke.spin" in your project, and use the Spin methods to set up and launch a PeekPoke instance. The latest version of "PeekPoke.spin" can be found at https://github.com/chris-siedell/PeekPoke.

Links

Python Documentation: https://github.com/chris-siedell/PeekPoke/wiki/PeekPoke-Python-Documentation/
Spin Documentation: https://github.com/chris-siedell/PeekPoke/wiki/PeekPoke-Spin-Documentation/
On PyPI: https://pypi.org/project/peekpoke/
On Github (has spin file): https://github.com/chris-siedell/PeekPoke

Comments

  • 2 Comments sorted by Date Added Votes
  • ostrich,
    Thank you for a very well documented and complete application.
    It seems very interesting and I imagine it can be used for all sorts of interfacing projects between the Prop and computer systems.
    Do you have any examples of practical projects?
  • I've used it for controlling sensors and collecting data. At first when I created it I simply thought of it as a debugging tool. It took me a while to see the possibility of using it for PC to Propeller communications using data structures, just like with regular inter-cog communications.

    Although I didn't mention it in the original post, PeekPoke is built using a simple, general purpose command/response protocol. If someone is interested in controlling a Propeller from a PC this framework may be useful. The Python implementation is called crow-serial (https://pypi.org/project/crow-serial/), and the Propeller implementation is PropCR (https://github.com/chris-siedell/PropCR).


Sign In or Register to comment.