Internals

Target APIs

This is the API description for the target tools (up- and download of data to MCU using different interfaces). See also the individual tools above and Commandline Tools.

The Target class defines an interface that is implemented by all the Target connections described here. This interface could be used for example in custom programming tools or testing equipment in manufacturing.

Target base class

msp430.target.identify_device(device_id, bsl_version)
Parameters:
  • device_id (int) – 16 bit number identifying the device
  • bsl_version (int) – 16 bit number identifying the ROM-BSL version
Returns:

F1x, F2x or F4x

Identification of F1x, F2x, F4x devices.

class msp430.target.Target(object)

This class implements a high level interface to targets. It also provides common code for command line tools so that e.g. the JTAG and BSL tools have a similar set of options.

memory_read(address, length)

Read from memory

memory_write(address, data)

Write to memory.

mass_erase()

Clear all Flash memory.

main_erase()

Clear main Flash memory (excl. infomem).

erase(address)

Erase Flash segment containing the given address.

execute(address)

Start executing code on the target.

version()

The 16 bytes of the ROM that contain chip and BSL info are returned.

reset()

Reset the device.

Additional methods that can be override in subclass.

open_connection()

Open the connection.

def close_connection()

Close the connection.

High level functions.

flash_segment_size(address)
Parameters:address – Address within MCU Flash memory
Returns:segment size in bytes

Determine the Flasg segment size for a given address.

get_mcu_family()
Returns:F1x, F2x or F4x

Get MCU family. It calls Version() to read from the device.

erase_infomem()

Erase all infomem segments of the device.

upload(start, end)
Parameters:
  • start – Start address of memory range (inclusive)
  • end – End address of memory range (inclusive)

Upload given memory range and store it in upload_data.

def upload_by_file()

Upload memory areas and store it in upload_data. The ranges uploaded are determined by download_data.

program_file(download_data=None)
Parameters:download_data – If not None, download this. Otherwise download_data is used.

Download data from download_data or the optional parameter.

verify_by_file()

Upload and compare to download_data.

Raises an exception when data differs.

erase_check_by_file()

Upload address ranges used in download_data and check if memory is erased (0xff). Raises an exception if not all memory is cleared.

erase_by_file()

Erase Flash segments that will be used by the data in self.download_data.

Command line interface helper functions.

create_option_parser()
Returns:an optparse.OptionParser instance.

Create an option parser, populated with a basic set of options for reading and writing files, upload, download and erase options.

parse_args()

Parse sys.argv now.

main()

Entry point for command line tools.

add_extra_options()

The user class can add items to parser.

parse_extra_options()

The user class can process options he added.

Actions list. This list is build and then processed in the command line tools.

add_action(function, *args, **kwargs)

Store a function to be called and parameters in the list of actions.

remove_action(function)

Remove a function from the list of actions.

do_the_work()

Process the list of actions

exception msp430.target.UnsupportedMCUFamily

Exception that may be raised by Target when the connected MCU is not compatible.

msp430.target.F1x
msp430.target.F2x
msp430.target.F4x

BSL Target

Interface to the BSL in F1x, F2x, F4x.

class msp430.bsl.bsl.BSL(object)

Implement low-level BSL commands as well as high level commands.

MAXSIZE

Maximum size of a block that can be read or written using low level commands.

checksum(data)
Parameters:data – A byte string with data
Returns:16 checksum (int)

Calculate the 16 XOR checksum used by the BSL over given data.

Low level functions.

BSL_TXBLK(address, data)
Parameters:
  • address – Start address of block
  • data – Contents (byte string)

Write given data to target. Size of data must be smaller than MAXSIZE

BSL_RXBLK(address, length)
Parameters:
  • address – Start address of block
  • length – Size of block to read
Returns:

uploaded data (byte string)

Read data from target. Size of data must be smaller than MAXSIZE

BSL_MERAS()

Execute the mass erase command.

BSL_ERASE(address, option=0xa502)
Parameters:
  • address – Address within the segment to erase.
  • option – FCTL1 settings.

Execute a segment or main-erase command.

BSL_CHANGEBAUD(bcsctl, multiply)
Parameters:
  • bcsctl – BCSCTL1 settings for desired baud rate
  • multiply – Baud rate multiplier (compared to 9600)

Change the baud rate.

BSL_SETMEMOFFSET(address_hi_bits)
Parameters:address_hi_bits – Bits 16..19.

For devices with >64kB address space, set the high bits of all addresses for BSL_TXBLK, BSL_RXBLK and BSL_LOADPC.

BSL_LOADPC(address)
Parameters:address – The address to jump to.

Start executing code at given address. There is no feedback if the jump was successful.

BSL_TXPWORD(password)

Transmit password to get access to protected functions.

BSL_TXVERSION()

Read device and BSL info (byte string of length 16). Older ROM-BSL do not support this command.

High level functions.

check_extended()

Check if device has address space >64kB (BSL_SETMEMOFFSET needs to be used).

See also msp430.target.Target for high level functions

version()

Read version. It tries BSL_TXVERSION() and if that fails BSL_RXBLK() from address 0x0ff0. The later only word if the device has been unlocked (password transmitted).

reset()

Try to reset the device. This is done by a write to the WDT module, setting it for a reset within a few milliseconds.

exception msp430.bsl.bsl.BSLException(Exception)

Errors from the slave.

exception msp430.bsl.bsl.BSLTimeout(BSLException)

Got no answer from slave within time.

exception msp430.bsl.bsl.BSLError(BSLException)

Command execution failed.

msp430.bsl.target

This module can be executed as command line tool (python -m msp430.bsl.target). It implements the BSL target tool.

class msp430.bsl.target.SerialBSL(bsl.BSL)

Implement the serial port access.

open(port=0, baudrate=9600, ignore_answer=False)
Parameters:
  • port – Port name or number
  • ignore_answer – If set to true enables a mode where answers are not read.

Open given serial port (pySerial).

When ignore_answer is enabled, no answer will be read for any command. Instead a small delay will be made. This can be used for targets where only the TX line is connected. However no upload and or verification of downloaded data is possible.

close()

Close serial port

bsl(cmd, message='', expect=None)
Parameters:
  • cmd – Command number to send
  • message – Byte string with data to send.
  • expect – The number of bytes expected in a data reply or None to disable check.
Returns:

None on success with simple answers or a byte string for data answers.

Raises:

Implement the low level transmit-receive operation for BSL commands over the serial port. The cmd is filled in the data header, message appended and the checksum calculated for the sent packet.

Received answers are checked. If expect is set a data reply must be received and its length must match the given number, otherwise a bsl.BSLError is raised.

set_RST(level=True)
Parameters:level – Signal level

Set the RST pin to given level

set_TEST(level=True)
Parameters:level – Signal level

Set the TEST or TCK pin to given level

set_baudrate(baudrate)
Parameters:baudrate – New speed (e.g. 38400)

Send the change baud rate command and if successful change the baud rate of the serial port to the same value.

class msp430.bsl.target.SerialBSLTarget(SerialBSL, msp430.target.Target)

Combine the serial BSL backend and the common target code.

add_extra_options()

Adds extra options to configure the serial port and the usage of the control lines for RST and TEST/TCK.

parse_extra_options()

Used to output additional tool version info.

close_connection()

Close serial port.

open_connection()

Open serial port, using the options from the command line (in options). This will also execute the mass erase command and/or transmit the password so that executing other actions is possible.

This is also the place to download replacement BSL or the patch.

BSL_TXBLK()

Override the block write function to activate the patch if needed.

BSL_RXBLK()

Override the block read function to activate the patch if needed.

reset()

Override the reset methods to use the RST control line signal (instead of the WDT access)

BSL5 Target

Interface to the BSL in F5x and F6x devices. UART and USB-HID are supported.

class msp430.bsl5.bsl5.BSL5
check_answer(data)
Parameters:data – the data received from the target
Returns:None
Raises:BSL5Error with the corresponding message if data contained an error code.

Note that the length for the following memory read/write functions is limited by the packet size of the interface (USB-HID, UART).

BSL_RX_DATA_BLOCK(address, data)
Parameters:
  • address – Location in target memory
  • data – Byte string with data to write

Write given data to target memory.

BSL_RX_DATA_BLOCK_FAST(address, data)
Parameters:
  • address – Location in target memory
  • data – Byte string with data to write

Write given data to target memory. The target will not perform any checks and no respons is sent back.

BSL_TX_DATA_BLOCK(address, length)
Parameters:
  • address – Location in target memory.
  • length – Number of bytes to read.
Returns:

Byte string with memory contents.

Read from target memory.

def BSL_MASS_ERASE()

Execute the mass erase command.

def BSL_ERASE_SEGMENT(address)

param address:An address within the segment to erase.

Erase a single Flash memory segment.

BSL_LOAD_PC(address)
Parameters:address – Location in target memory.

Start executing at given address. There is no check if the command is successful as the execution starts immediately.

BSL_RX_PASSWORD(password)
Parameters:password – Byte string with password (32 bytes)

Transmit the password in order to unlock protected function of the BSL.

BSL_VERSION()
Returns:A tuple with 5 numbers.

The return value contains the following numbers:

  • BSL vendor information
  • Command interpreter version
  • API version
  • Peripheral interface version
BSL_BUFFER_SIZE()
Returns:The maximal supported buffer size from the BSL.
BSL_LOCK_INFO()

Toggle lock flag of infomem segment A (the one with calibration data).

BSL_CRC_CHECK(XXX)

High level functions.

detect_buffer_size()

Auto detect buffer size. Saved the result in buffer_size. Silently ignores if the command is not successful and keeps the old value.

memory_read(address, length)
Parameters:
  • address – Location in target memory.
  • length – The number of bytes to read.
Returns:

A byte string with the memory contents.

Raises:

BSL5Error – when buffer_size is undefined

Read from memory. It creates multiple BSL_TX_DATA_BLOCK commands internally when the size is larger than the block size.

mass_erase()

Clear all Flash memory.

erase(address)
Parameters:address – Address within the segment to erase.

Erase Flash segment containing the given address

#~ def main_erase(self):
#~ Erase Flash segment containing the given address.
execute(address)
Parameters:address – Location in target memory.

Start executing code on the target.

password(password)
Parameters:password – Byte string with password (32 bytes)

Transmit the BSL password.

version()

Get the BSL version. The 16 bytes of the ROM that contain chip and BSL info are returned.

reset()

Reset target using the WDT module.

exception msp430.bsl5.bsl5.BSL5Exception(Exception)

Common base class for errors from the slave

exception msp430.bsl5.bsl5.BSL5Timeout(BSL5Exception)

Got no answer from slave within time.

exception msp430.bsl5.bsl5.BSL5Error(BSL5Exception)

msp430.bsl5.hid

This module can be executed as command line tool (python -m msp430.bsl5.hid). It implements the BSL protocol over USB-HID supported by F5xx devices with buil-in USB hardware.

Currently implementations for Windows (pywinusb) and GNU/Linux are provided (hidraw).

class msp430.bsl5.hid.HIDBSL5Base
bsl(cmd, message='', expect=None, receive_response=True)
Parameters:
  • cmd – BSL command number.
  • message – Byte string with data for command.
  • expect – Enable optional check of response length.
  • receive_response – When set to false, do not receive response.

Low level access to the HID communication.

This function sends a command and waits until it receives an answer (including timeouts). It will return a string with the data part of the answer. The first byte will be the response code from the BSL

If the parameter “expect” is not None, “expect” bytes are expected in the answer, an exception is raised if the answer length does not match. If “expect” is None, the answer is just returned.

Frame format:

+------+-----+-----------+
| 0x3f | len | D1 ... DN |
+------+-----+-----------+
class msp430.bsl5.hid.HIDBSL5
open(device=None)
Parameters:device – Name of device to use or None for auto detection.

Connect to target device.

Auto detection searches for a device with USB VID:PID: 2047:0200. It may pick a random one if multiple devices with that ID are connected.

Examples for the device parameter under GNU/Linux: /dev/hidraw4. Windows currently does not support passing an explicit device (only auto detection).

close()

Close connection to target.

write_report(data)
Parameters:data – Byte string with report for target. 1st byte is the report number.

Write given data to the target device. The first bye of the data has to be the HID report number.

read_report()
Returns:Byte string with report from target. 1st byte is the report number.

Read a HID report from the target. May block if no data is sent by the device.

class msp430.bsl5.hid.HIDBSL5Target(HIDBSL5, msp430.target.Target)

Combine the HID BSL5 backend and the common target code.

add_extra_options()

Populate the option parser with options for the USB HID connection and password.

close_connection()

Close connection to target.

open_connection()

connect to USB HID device using the options from the command line (in options). This will also execute the mass erase command and/or transmit the password so that executing other actions is possible.

As USB devices only have a stub BSL, this also downloads a full BSL to the device RAM. The BSL is kept in the package as RAM_BSL.00.06.05.34.txt (loaded using pkgdata).

reset()

Try to reset the device. This is done by a write to the WDT module, setting it for a reset within a few milliseconds.

msp430.bsl5.uart

This module can be executed as command line tool (python -m msp430.bsl5.uart). It implements the BSL target tool for F5xx/F6xx devices w/o USB hardware (it uses the UART).

msp430.bsl5.uart.crc_update(crc, byte)

Calculate the 16 bit CRC that is used by the BSL. Input is byte-wise. The function can be used with reduce:

crc = reduce(crc_update, b"data", 0)
class msp430.bsl5.uart.SerialBSL5(bsl5.BSL5)
extra_timeout

Extend timeout for responses by given number of seconds (int).

invertRST

Invert signal on RST line (bool).

invertTEST

Invert signal on TEST/TCK line (bool).

swapResetTest

Exchange the control lines on the serial port (RTS/DTR) which are used for RST and TEST/TCK.

testOnTX

Send BREAK condition on TX line (bool), additionally to use of TEST/TCK control line.

blindWrite

Do not receive and responses (bool).

control_delay

Delay in seconds (float) that is waited after each change of RTS or TEST/TCK line change.

open(port=0, baudrate=9600, ignore_answer=False)

Initialize connection to a serial BSL.

close()

Close serial port.

BSL_CHANGE_BAUD_RATE(multiply)
Parameters:multiply – Multiplier of baud rate compared to 9600.

Low level command to change the BSL baud rate on the target.

bsl(cmd, message='', expect=None)
Parameters:
  • cmd – BSL command number.
  • message – Byte string with data for command.
  • expect – Enable optional check of response length.
  • receive_response – When set to false, do not receive response.

Low level access to the serial communication.

This function sends a command and waits until it receives an answer (including timeouts). It will return a string with the data part of the answer. In case of a failure read timeout or rejected commands by the slave, it will raise an exception.

If the parameter “expect” is not None, “expect” bytes are expected in the answer, an exception is raised if the answer length does not match. If “expect” is None, the answer is just returned.

Frame format:

+-----+----+----+-----------+----+----+
| HDR | LL | LH | D1 ... DN | CL | CH |
+-----+----+----+-----------+----+----+
set_RST(level=True)
Parameters:level – Signal level.

Controls RST/NMI pin (0: GND; 1: VCC; unless inverted flag is set)

set_TEST(level=True)
Parameters:level – Signal level.

Controls TEST pin (inverted on board: 0: VCC; 1: GND; unless inverted flag is set)

set_baudrate(baudrate)

Change the BSL baud rate on the target and switch the serial port.

start_bsl()

Start the ROM-BSL using the pulse pattern on TEST and RST.

class msp430.bsl5.uart.SerialBSL5Target(SerialBSL5, msp430.target.Target)

Combine the serial BSL backend and the common target code.

add_extra_options()

Populate the option parser with options for the serial port and password.

parse_extra_options()

Prints additional version info.

close_connection()

Close connection to target.

open_connection()

Open serial port, using the options from the command line (in options). This will also execute the mass erase command and/or transmit the password so that executing other actions is possible.

reset()

Try to reset the device. This is done by a write to the WDT module, setting it for a reset within a few milliseconds.

JTAG Target

interface to JTAG adapters (USB and parallel port).

msp430.jtag.clock

Note

This module is currently only supported with parallel port JTAG adapters and MSP430mspgcc.dll/so

msp430.jtag.clock.getDCOFreq(dcoctl, bcsctl1, bcsctl2=0)
Returns:frequency in Hz

Measure DCO frequency on a F1xx or F2xx device.

msp430.jtag.clock.setDCO(fmin, fmax, maxrsel=7, dcor=False)
Returns:(frequency, DCOCTL, BCSCTL1)

Software FLL for F1xx and F2xx devices.

msp430.jtag.clock.getDCOPlusFreq(scfi0, scfi1, scfqctl, fll_ctl0, fll_ctl1)
Returns:frequency in Hz.

Measure DCO frequency on a F4xx device

msp430.jtag.clock.setDCOPlus(fmin, fmax)
Returns:(frequency, SCFI0, SCFI1, SCFQCTL, FLL_CTL0, FLL_CTL1)

Software FLL for F4xx devices.

msp430.jtag.dco

Note

This module is currently only supported with parallel port JTAG adapters and MSP430mspgcc.dll/so

MSP430 clock calibration utility.

This tool can measure the internal oscillator of F1xx, F2xx and F4xx devices that are connected to the JTAG. It can display the supported frequencies, or run a software FLL to find the settings for a specified frequency.

This module can be executed as command line tool (python -m msp430.jtag.dco).

msp430.jtag.dco.adjust_clock(out, frequency, tolerance=0.02, dcor=False, define=False)

Detect MSP430 type and try to set the clock to the given frequency. When successful, print the clock control register settings.

This function assumes that the JTAG connection to the device has already been initialized and that the device is under JTAG control and stopped.

msp430.jtag.dco.measure_clock()
Returns:A dictionary with information about clock speeds (key depend on MCU type).

Measure fmin and fmax of RSEL ranges or hardware FLL.

msp430.jtag.dco.calibrate_clock(out, tolerance=0.002, dcor=False)

Recalculate the clock calibration values and write them to the Flash.

Note

currently for F2xx only

msp430.jtag.jtag

JTAG programmer for the MSP430 embedded processor.

Requires Python 2.7+ and the binary extension _parjtag or ctypes and MSP430mspgcc.dll/libMSP430mspgcc.so or MSP430.dll/libMSP430.so and HIL.dll/libHIL.so

Constants used to identify backend implementations:

msp430.jtag.jtag.PARJTAG
msp430.jtag.jtag.CTYPES_MSPGCC
msp430.jtag.jtag.CTYPES_TI
msp430.jtag.jtag.locate_library(libname, paths=sys.path, loader=None)

Search for a .DLL or .so library on the given list of paths.

msp430.jtag.jtag.init_backend(force=None)
Parameters:force – One of PARJTAG, CTYPES_MSPGCC, CTYPES_TI or None.

Initializes the global backend with a class that gives access to the JTAG library.

The backend implementation is selected automatically when force is None.

class msp430.jtag.jtag.JTAG

High level access to the target for upload, download and funclets. Uses the backend to communicate.

exception msp430.jtag.jtag.JTAGException(Exception)

msp430.jtag.target

This module can be executed as command line tool (python -m msp430.jtag.target).

class msp430.jtag.target.JTAGTarget(object)
def memory_read(address, length)

Read from memory.

memory_write(address, data)

Write to memory.

def mass_erase()

Clear all Flash memory.

main_erase()

Clear main Flash memory (excl. infomem).

erase(address)

Erase Flash segment containing the given address.

execute(address)

Start executing code on the target.

version()

The 16 bytes of the ROM that contain chip and BSL info are returned.

reset()

Reset the device.

close()

Close connection to target.

class msp430.jtag.target.JTAG(JTAGTarget, msp430.target.Target)

Combine the JTAG backend and the common target code.

help_on_backends()

Implement option --target-help.

add_extra_options()

Populate option parser with options for JTAG connection.

parse_extra_options()

Apply extra options (such as forcing a backend implementation)

close_connection()

Close connection to target.

open_connection()

Connect to target.

msp430.jtag.target.main()

Implements the command line frontend.

msp430.jtag.profile

Statistical profiler for the MSP430.

It works by sampling the address bus and counting addresses seen. The problem there is, that it is not sure that we’re reading a valid address every time. An other issue is the relatively slow sampling rate compared to the execution speed of the MCU, which means that several runs are need to get meaningful numbers.

This module can be executed as command line tool (python -m msp430.jtag.profile).

Note

This module is currently only supported with parallel port JTAG adapters and MSP430mspgcc.dll/so

msp430.jtag.profile.main()

Command line frontend. It connects to a target using JTAG. It then samples the address bus as fast as possible (which is still much slower that the typical CPU speed). When the tool is aborted with CTRL+C, it outputs a list of addresses and the number of samples that were hit.

The idea is that the data can be used to create a statistical analysis of code coverage and usage.

There are a number of problems, so this tool has to be considered as experimental:

  • Sampling is relatively slow.
  • There is no guarantee that the value read from the address bus is correct. Samples may occur when the CPU is altering the value.
  • There is no difference between instruction fetch and data access.

GDB Target

Interface to GDB servers (msp430-gdbproxy, mspdebug). This can be used to up- and download data via the GDB servers. No debugging support is provided.

msp430.gdb.gdb

exception msp430.gdb.gdb.GDBException(Exception)

Generic protocol errors.

exception msp430.gdb.gdb.GDBRemoteTimeout(GDBException)

If target does not answer.

exception msp430.gdb.gdb.GDBRemoteTooManyFailures(GDBException)

If target does not answer.

exception msp430.gdb.gdb.GDBUnknownCommandError(GDBException)

If target does not know this command.

exception msp430.gdb.gdb.GDBRemoteError(GDBException)
getErrorCode()
Returns:The error code that was received from the GDB server.
class msp430.gdb.gdb.ClientSocketConnector(threading.Thread)

Make a connection through a TCP/IP socket. This version connects to a server (i.e. is a client).

__init__(host_port)

The host/port tuple from the parameter is used to open a TCP/IP connection. It is passed to socket.connect().

write(text)

Just send everything

class msp430.gdb.gdb.GDBClient(ClientSocketConnector)
__init__(*args, **kwargs)

All parameters are passed to ClientSocketConnector.__init__()

handle_partial_data(data)
Parameters:data – Byte string with received data from the GDB server.

Process received data. It may be partial, i.e. no complete line etc.

handle_packet(packet)
Parameters:packet – A packet received from the GDB server.

Called by handle_partial_data() when a complete packet from the GDB server was decoded.

Callbacks (can be overridden in subclasses):

output(message)

Called on o (output) packages. These are used by the GDB server to write messages for the user.

Commands:

set_extended()

Set extended mode. Expected answer empty string or or OK

last_signal()
Returns:Stop Reply Packets

Get last signal.

cont(startaddress=None, nowait=False)
Returns:Stop Reply Packets

Continue execution on target.

cont_with_signal(signal, startaddress=None)
Parameters:signal – Signal number that is sent to the target.
Returns:Stop Reply Packets

Continue with signal.

read_registers()
Returns:List of values of the regsiters (1 … 16)

Read all registers.

write_registers(registers)
Parameters:registers – List with values for all registers (list of 16 ints).

Write all registers.

cycle_step(cycles, startaddress=None)
Parameters:cycles – Run the given number of cycles on the target.

Cycle step (draft).

read_memory(startaddress, size)
Parameters:
  • startaddress – Address on target.
  • size – Number of bytes to read.
Returns:

Byte string with memory contents

Read memory.

write_memory(startaddress, data)
Parameters:
  • startaddress – Address on target.
  • data – Byte string with memory contents

Read memory.

read_register(regnum)
Parameters:regnum – Register number.
Returns:integer (register contents)

Read single register.

write_register(regnum, value)
Parameters:
  • regnum – Register number.
  • value – integer (register contents)

Write single register. expected answer ‘OK’ or ‘Enn’”””

query(query, nowait=False)
Parameters:query – String with query for the GDB server.

Send general query to GDB server.

set(name, value)
Parameters:
  • name – Name of the setting.
  • value – New value for the setting.

Configure a setting.

step(startaddress = None):
Returns:Stop Reply Packets

Single step on target.

step_with_signal(signal, startaddress=None)
Parameters:signal – Signal number that is sent to the target.
Returns:Stop Reply Packets

Step with signal.

write_memory_binary(startaddress, data)

Write data to target, with binary transmission to GDB server. May not be supported by all servers.

remove_breakpoint(type, address, length)

Remove break or watchpoint (draft)

set_breakpoint(type, address, length)

Insert break or watchpoint (draft).

monitor(command, nowait=False)

Pass commands to a target specific interpreter in the GDB server. Servers for the MSP430 often implement commands such as erase.

interrupt()

Send Control+C. May be used to stop the target if it is running (e.g. after a continue command). No effect on a stopped target.

msp430.gdb.target

Remote GDB programmer for the MSP430 embedded processor.

This module can be executed as command line tool (python -m msp430.gdb.target).

class msp430.gdb.target.GDBTarget(object)
memory_read(address, length)

Read from memory.

memory_write(address, data)

Write to memory.

mass_erase()

Clear all Flash memory.

main_erase()

Clear main Flash memory (excl. infomem).

erase(address)

Erase Flash segment containing the given address.

execute(address)

Start executing code on the target.

version()

The 16 bytes of the ROM that contain chip and BSL info are returned.

reset()

Reset the device.

open(host_port)
Parameters:host_port – A tuple (str, port) with target host address and port number.
close()
class msp430.gdb.target.GDB(GDBTarget, msp430.target.Target)

Combine the GDB backend and the common target code.

add_extra_options()

Populate option parser with GDB client specific options.

close_connection()

Close connection to target.

open_connection()

Connect to target applying the command line options.

Utility APIs

msp430.memory

class msp430.memory.DataStream(object)

An iterator for addressed bytes. It yields all the bytes of a Memory instance in ascending order. It allows peeking at the current position by reading the address attribute. None signals that there are no more bytes (and next() would raise StopIteration).

__init__(self, memory)

Initialize the iterator. The data from the given memory instance is streamed.

next()

Gets next tuple (address, byte) from the iterator.

address

The address of the byte that will be returned by next().

msp430.memory.stream_merge(*streams)
Parameters:streams – Any number of DataStream instances.

Merge multiple streams of addressed bytes. If data is overlapping, take it from the later stream in the list.

class msp430.memory.Segment(object)

Store a string or list with memory contents (bytes) along with its start address.

__init__(startaddress = 0, data=None)
Parameters:
  • startaddress – Address of 1st byte in data.
  • data – Byte string.

Initialize a new segment that starts at given address, containing the given data.

__getitem__(index)
Parameters:index – Index of byte to get.
Returns:A byte string with one byte.
Raises:IndexError – offset > length of data

Read a byte from the segment. The offset is 0 for the 1st byte in the block.

__len__()

Return the number of bytes in the segment.

__cmp__(other)

Compare two segments. Implemented to support sorting a list of segments by address.

class msp430.memory.Memory(object)

Represent memory contents.

__init__()

Initialize an empty memory object.

append(segment)
Parameters:segment – A Segment instance.

Append a segment to the internal list. Note that there is no check for overlapping data.

__getitem__(index)
Returns:Segment instance
Raises:IndexError – index > number of segments

Get a segment from the internal list.

__len__()
Returns:Number of segments in the internal list.
get_range(fromadr, toadr, fill='xff')
Parameters:
  • fromadr – Start address (including).
  • toadr – End address (including).
  • fill – Fill value (a byte).
Returns:

A byte string covering the given memory range.

Get a range of bytes from the memory. Unavailable values are filled with fill (default 0xff).

get(address, size)
param address:Start address of block to read.
param size:Size of the of block to read.
return:A byte string covering the given memory range.
exception ValueError:
 unavailable addresses are tried to read.

Get a range of bytes from the memory.

set(address, contents)
Parameters:
  • address – Start address of block to read.
  • contents – Bytes to write to the memory.
Raises:

ValueError – Writing to an undefined memory location.

Write a range of bytes to the memory. A segment covering the address range to be written has to be existent. A ValueError is raised if not all data could be written (attention: a part of the data may have been written!). The contents may span multiple (existing) segments.

merge(other)
Parameters:other – A Memory instance, its contents is copied to this instance.

Merge an other memory object into this one. The data is merged: in case of overlapping, the data from other is used. The segments are recreated so that consecutive blocks of bytes are each in one segment.

msp430.memory.load(filename, fileobj=None, format=None)
Parameters:
  • filename – Name of the file to open
  • fileobj – None to let this function open the file or an open, seekable file object (typically opened in binary mode).
  • format – File format name, None for auto detection.
Returns:

Memory object.

Return a Memory object with the contents of a file. File type is determined from extension and/or inspection of content.

msp430.memory.save(memory, fileobj, format='titext')
Parameters:
  • fileobj – A writeable file like object (typically opened in binary mode).
  • format – File format name.

Save given memory object to file like object.

msp430.listing

This module provides parser for listing/map files of the IAR and mspgcc C compilers. This can be used in tools that need to know the addresses of variables or functions. E.g. to create a checksum patch application.

Sub-modules:

  • msp430.listing.iar
  • msp430.listing.mspgcc

Each module provides such a function:

msp430.listing.label_address_map(filename)
Parameters:filename – Name of a listing or map file.
Returns:A dictionary mapping labels (key) to addresses (values/int).

File format handlers

Overview

The file format handler modules each provides a load and/or save function on module level.

msp430.listing.load(filelike)
Parameters:filelike – A file like object that is used to write the data.
Returns:msp430.memory.Memory instance with the contents loaded from the fike like object.

Read from a file like object and fill in the contents to a memory object. The file like should typically be a file opened for reading in binary mode.

msp430.listing.save(memory, filelike)
Parameters:
  • memorymsp430.memory.Memory instance with the contents loaded from the fike like object.
  • filelike – A file like object that is used to write the data.

Write the contents of the memory object to the given file like object. This should typically be a file opened for writing in binary mode.

Handlers

msp430.memory.bin

Load and save binary data. Note that this is not practical for MSP430 binaries as they usually are not one block and do not start at address null. The binary format can not keep track of addresses.

msp430.memory.elf

ELF object file reader (typical file extension .elf). There is currently no support for writing this type.

msp430.memory.hexdump

Read and write hex dumps.

msp430.memory.titext

Read and write TI-text format files (often named .txt).

msp430.memory.intelhex

Read and write Intel-HEX format files (often named .a43).