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.
Parameters: |
|
---|---|
Returns: |
Identification of F1x, F2x, F4x devices.
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.
Read from memory
Write to memory.
Clear all Flash memory.
Clear main Flash memory (excl. infomem).
Erase Flash segment containing the given address.
Start executing code on the target.
The 16 bytes of the ROM that contain chip and BSL info are returned.
Reset the device.
Additional methods that can be override in subclass.
Open the connection.
Close the connection.
High level functions.
Parameters: |
|
---|---|
Returns: | segment size in bytes |
Determine the Flasg segment size for a given address.
Returns: | F1x, F2x or F4x |
---|
Get MCU family. It calls Version() to read from the device.
Erase all infomem segments of the device.
Parameters: |
|
---|
Upload given memory range and store it in upload_data.
Upload memory areas and store it in upload_data. The ranges uploaded are determined by download_data.
Parameters: |
|
---|
Download data from download_data or the optional parameter.
Upload and compare to download_data.
Raises an exception when data differs.
Upload address ranges used in download_data and check if memory is erased (0xff). Raises an exception if not all memory is cleared.
Erase Flash segments that will be used by the data in self.download_data.
Command line interface helper functions.
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 sys.argv now.
Entry point for command line tools.
The user class can add items to parser.
The user class can process options he added.
Actions list. This list is build and then processed in the command line tools.
Store a function to be called and parameters in the list of actions.
Remove a function from the list of actions.
Process the list of actions
Exception that may be raised by Target when the connected MCU is not compatible.
Interface to the BSL in F1x, F2x, F4x.
Implement low-level BSL commands as well as high level commands.
Maximum size of a block that can be read or written using low level commands.
Parameters: |
|
---|---|
Returns: | 16 checksum (int) |
Calculate the 16 XOR checksum used by the BSL over given data.
Low level functions.
Parameters: |
|
---|
Write given data to target. Size of data must be smaller than MAXSIZE
Parameters: |
|
---|---|
Returns: | uploaded data (byte string) |
Read data from target. Size of data must be smaller than MAXSIZE
Execute the mass erase command.
Parameters: |
|
---|
Execute a segment or main-erase command.
Parameters: |
|
---|
Change the baud rate.
Parameters: |
|
---|
For devices with >64kB address space, set the high bits of all addresses for BSL_TXBLK, BSL_RXBLK and BSL_LOADPC.
Parameters: |
|
---|
Start executing code at given address. There is no feedback if the jump was successful.
Transmit password to get access to protected functions.
Read device and BSL info (byte string of length 16). Older ROM-BSL do not support this command.
High level functions.
Check if device has address space >64kB (BSL_SETMEMOFFSET needs to be used).
See also msp430.target.Target for high level functions
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).
Try to reset the device. This is done by a write to the WDT module, setting it for a reset within a few milliseconds.
Errors from the slave.
Got no answer from slave within time.
Command execution failed.
This module can be executed as command line tool (python -m msp430.bsl.target). It implements the BSL target tool.
Implement the serial port access.
Parameters: |
|
---|
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 serial port
Parameters: |
|
---|---|
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.
Parameters: |
|
---|
Set the RST pin to given level
Parameters: |
|
---|
Set the TEST or TCK pin to given level
Parameters: |
|
---|
Send the change baud rate command and if successful change the baud rate of the serial port to the same value.
Combine the serial BSL backend and the common target code.
Adds extra options to configure the serial port and the usage of the control lines for RST and TEST/TCK.
Used to output additional tool version info.
Close serial port.
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.
Override the block write function to activate the patch if needed.
Override the block read function to activate the patch if needed.
Override the reset methods to use the RST control line signal (instead of the WDT access)
Interface to the BSL in F5x and F6x devices. UART and USB-HID are supported.
Parameters: |
|
---|---|
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).
Parameters: |
|
---|
Write given data to target memory.
Parameters: |
|
---|
Write given data to target memory. The target will not perform any checks and no respons is sent back.
Parameters: |
|
---|---|
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.
Parameters: |
|
---|
Start executing at given address. There is no check if the command is successful as the execution starts immediately.
Parameters: |
|
---|
Transmit the password in order to unlock protected function of the BSL.
Returns: | A tuple with 5 numbers. |
---|
The return value contains the following numbers:
Returns: | The maximal supported buffer size from the BSL. |
---|
Toggle lock flag of infomem segment A (the one with calibration data).
High level functions.
Auto detect buffer size. Saved the result in buffer_size. Silently ignores if the command is not successful and keeps the old value.
Parameters: |
|
---|---|
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.
Clear all Flash memory.
Parameters: |
|
---|
Erase Flash segment containing the given address
Parameters: |
|
---|
Start executing code on the target.
Parameters: |
|
---|
Transmit the BSL password.
Get the BSL version. The 16 bytes of the ROM that contain chip and BSL info are returned.
Reset target using the WDT module.
Common base class for errors from the slave
Got no answer from slave within time.
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).
Parameters: |
|
---|
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 |
+------+-----+-----------+
Parameters: |
|
---|
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 connection to target.
Parameters: |
|
---|
Write given data to the target device. The first bye of the data has to be the HID report number.
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.
Combine the HID BSL5 backend and the common target code.
Populate the option parser with options for the USB HID connection and password.
Close connection to target.
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.05.04.34.txt (loaded using pkgdata).
Try to reset the device. This is done by a write to the WDT module, setting it for a reset within a few milliseconds.
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).
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)
Extend timeout for responses by given number of seconds (int).
Invert signal on RST line (bool).
Invert signal on TEST/TCK line (bool).
Exchange the control lines on the serial port (RTS/DTR) which are used for RST and TEST/TCK.
Send BREAK condition on TX line (bool), additionally to use of TEST/TCK control line.
Do not receive and responses (bool).
Delay in seconds (float) that is waited after each change of RTS or TEST/TCK line change.
Initialize connection to a serial BSL.
Close serial port.
Parameters: |
|
---|
Low level command to change the BSL baud rate on the target.
Parameters: |
|
---|
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 |
+-----+----+----+-----------+----+----+
Parameters: |
|
---|
Controls RST/NMI pin (0: GND; 1: VCC; unless inverted flag is set)
Parameters: |
|
---|
Controls TEST pin (inverted on board: 0: VCC; 1: GND; unless inverted flag is set)
Change the BSL baud rate on the target and switch the serial port.
Start the ROM-BSL using the pulse pattern on TEST and RST.
Combine the serial BSL backend and the common target code.
Populate the option parser with options for the serial port and password.
Prints additional version info.
Close connection to target.
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.
Try to reset the device. This is done by a write to the WDT module, setting it for a reset within a few milliseconds.
interface to JTAG adapters (USB and parallel port).
Note
This module is currently only supported with parallel port JTAG adapters and MSP430mspgcc.dll/so
Returns: | frequency in Hz |
---|
Measure DCO frequency on a F1xx or F2xx device.
Returns: | (frequency, DCOCTL, BCSCTL1) |
---|
Software FLL for F1xx and F2xx devices.
Returns: | frequency in Hz. |
---|
Measure DCO frequency on a F4xx device
Returns: | (frequency, SCFI0, SCFI1, SCFQCTL, FLL_CTL0, FLL_CTL1) |
---|
Software FLL for F4xx devices.
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).
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.
Returns: | A dictionary with information about clock speeds (key depend on MCU type). |
---|
Measure fmin and fmax of RSEL ranges or hardware FLL.
Recalculate the clock calibration values and write them to the Flash.
Note
currently for F2xx only
JTAG programmer for the MSP430 embedded processor.
Requires Python 2+ 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:
Search for a .DLL or .so library on the given list of paths.
Parameters: |
|
---|
Initializes the global backend with a class that gives access to the JTAG library.
The backend implementation is selected automatically when force is None.
High level access to the target for upload, download and funclets. Uses the backend to communicate.
This module can be executed as command line tool (python -m msp430.jtag.target).
Read from memory.
Write to memory.
Clear all Flash memory.
Clear main Flash memory (excl. infomem).
Erase Flash segment containing the given address.
Start executing code on the target.
The 16 bytes of the ROM that contain chip and BSL info are returned.
Reset the device.
Close connection to target.
Combine the JTAG backend and the common target code.
Implement option --target-help.
Populate option parser with options for JTAG connection.
Apply extra options (such as forcing a backend implementation)
Close connection to target.
Connect to target.
Implements the command line frontend.
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
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:
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.
Generic protocol errors.
If target does not answer.
If target does not answer.
If target does not know this command.
Returns: | The error code that was received from the GDB server. |
---|
Make a connection through a TCP/IP socket. This version connects to a server (i.e. is a client).
The host/port tuple from the parameter is used to open a TCP/IP connection. It is passed to socket.connect().
Just send everything
All parameters are passed to ClientSocketConnector.__init__()
Parameters: |
|
---|
Process received data. It may be partial, i.e. no complete line etc.
Parameters: |
|
---|
Called by handle_partial_data() when a complete packet from the GDB server was decoded.
Callbacks (can be overridden in subclasses):
Called on o (output) packages. These are used by the GDB server to write messages for the user.
Commands:
Set extended mode. Expected answer empty string or or OK
Returns: | Stop Reply Packets |
---|
Get last signal.
Returns: | Stop Reply Packets |
---|
Continue execution on target.
Parameters: |
|
---|---|
Returns: | Stop Reply Packets |
Continue with signal.
Returns: | List of values of the regsiters (1 ... 16) |
---|
Read all registers.
Parameters: |
|
---|
Write all registers.
Parameters: |
|
---|
Cycle step (draft).
Parameters: |
|
---|---|
Returns: | Byte string with memory contents |
Read memory.
Parameters: |
|
---|
Read memory.
Parameters: |
|
---|---|
Returns: | integer (register contents) |
Read single register.
Parameters: |
|
---|
Write single register. expected answer ‘OK’ or ‘Enn’”“”
Parameters: |
|
---|
Send general query to GDB server.
Parameters: |
|
---|
Configure a setting.
Returns: | Stop Reply Packets |
---|
Single step on target.
Parameters: |
|
---|---|
Returns: | Stop Reply Packets |
Step with signal.
Write data to target, with binary transmission to GDB server. May not be supported by all servers.
Remove break or watchpoint (draft)
Insert break or watchpoint (draft).
Pass commands to a target specific interpreter in the GDB server. Servers for the MSP430 often implement commands such as erase.
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.
Remote GDB programmer for the MSP430 embedded processor.
This module can be executed as command line tool (python -m msp430.gdb.target).
Read from memory.
Write to memory.
Clear all Flash memory.
Clear main Flash memory (excl. infomem).
Erase Flash segment containing the given address.
Start executing code on the target.
The 16 bytes of the ROM that contain chip and BSL info are returned.
Reset the device.
Parameters: |
|
---|
Combine the GDB backend and the common target code.
Populate option parser with GDB client specific options.
Close connection to target.
Connect to target applying the command line options.
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).
Initialize the iterator. The data from the given memory instance is streamed.
Gets next tuple (address, byte) from the iterator.
Parameters: |
|
---|
Merge multiple streams of addressed bytes. If data is overlapping, take it from the later stream in the list.
Store a string or list with memory contents (bytes) along with its start address.
Parameters: |
|
---|
Initialize a new segment that starts at given address, containing the given data.
Parameters: |
|
---|---|
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.
Return the number of bytes in the segment.
Compare two segments. Implemented to support sorting a list of segments by address.
Represent memory contents.
Initialize an empty memory object.
Parameters: |
|
---|
Append a segment to the internal list. Note that there is no check for overlapping data.
Returns: | Segment instance |
---|---|
Raises IndexError: | |
index > number of segments |
Get a segment from the internal list.
Returns: | Number of segments in the internal list. |
---|
Parameters: |
|
---|---|
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).
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.
Parameters: |
|
---|---|
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.
Parameters: |
|
---|
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.
Parameters: |
|
---|---|
Returns: | Memory object. |
Return a Memory object with the contents of a file. File type is determined from extension and/or inspection of content.
Parameters: |
|
---|
Save given memory object to file like object.
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:
Each module provides such a function:
Parameters: |
|
---|---|
Returns: | A dictionary mapping labels (key) to addresses (values/int). |
The file format handler modules each provides a load and/or save function on module level.
Parameters: |
|
---|---|
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.
Parameters: |
|
---|
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.
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).