├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── MANIFEST.in ├── README.rst ├── doc ├── Makefile ├── README-msp430-bsl.txt ├── README-msp430-bsl5.txt ├── README-msp430-dco.txt ├── README-msp430-downloader.txt ├── README-msp430-jtag.txt ├── asm │ ├── api.rst │ ├── commandline.rst │ ├── forth.rst │ ├── forth_wordlist.py │ ├── rpn_wordlist.py │ └── tutorial.rst ├── assembler.rst ├── commandline_tools.rst ├── conf.py ├── index.rst ├── internals.rst ├── license.rst ├── overview.rst ├── shell.rst ├── target.rst └── utilities.rst ├── examples ├── asm │ ├── calibrate │ │ ├── calibrate.S │ │ └── makefile │ ├── forth_to_asm │ │ ├── led.forth │ │ └── makefile │ ├── forth_to_asm_advanced │ │ ├── README.txt │ │ ├── demo.forth │ │ ├── demo_adc.py │ │ ├── hardware.h │ │ ├── makefile │ │ └── xprotocol.py │ ├── launchpad_led │ │ ├── README.txt │ │ ├── led.S │ │ └── makefile │ ├── led │ │ ├── README.txt │ │ ├── led.S │ │ └── makefile │ └── led5x │ │ ├── README.txt │ │ ├── led.S │ │ └── makefile ├── mmc.py └── nsis-demos │ ├── README.txt │ ├── bsl-updater.ini │ ├── bsl-updater.nsi │ ├── downloader-demo.m43 │ └── jtag-updater.nsi ├── makefile ├── msp430 ├── __init__.py ├── asm │ ├── README.txt │ ├── __init__.py │ ├── as.py │ ├── cpp.py │ ├── definitions │ │ ├── ADC10.peripheral │ │ ├── ADC12.peripheral │ │ ├── BCS.peripheral │ │ ├── BCSplus.peripheral │ │ ├── ComparatorA.peripheral │ │ ├── DAC12.peripheral │ │ ├── DMA.peripheral │ │ ├── FLASH.peripheral │ │ ├── MPY32.peripheral │ │ ├── MSP430.peripheral │ │ ├── MSP430G2231.peripheral │ │ ├── P1.peripheral │ │ ├── P1R.peripheral │ │ ├── P2.peripheral │ │ ├── P2R.peripheral │ │ ├── P3.peripheral │ │ ├── P4.peripheral │ │ ├── P5.peripheral │ │ ├── P6.peripheral │ │ ├── SVS.peripheral │ │ ├── TLV.peripheral │ │ ├── TLV_G2.peripheral │ │ ├── Timer0_A2.peripheral │ │ ├── Timer0_A3.peripheral │ │ ├── Timer0_B7.peripheral │ │ ├── USART0.peripheral │ │ ├── USART1.peripheral │ │ ├── USI.peripheral │ │ ├── WDT.peripheral │ │ ├── _parse_devices.py │ │ ├── bit_names.peripheral │ │ └── msp430-mcu-list.txt │ ├── disassemble.py │ ├── forth.py │ ├── forth │ │ ├── __init__.forth │ │ ├── _asm_snippets.forth │ │ ├── _builtins.forth │ │ ├── _helpers.forth │ │ ├── _interrupts.forth │ │ ├── _memory.forth │ │ ├── _msp430_lowlevel.forth │ │ └── core.forth │ ├── h2forth.py │ ├── include │ │ ├── README.txt │ │ ├── fetchfiles.py │ │ ├── in430.h │ │ └── iomacros.h │ ├── infix2postfix.py │ ├── ld.py │ ├── lib.py │ ├── librarian │ │ └── asm │ │ │ ├── adc10.S │ │ │ ├── intvec16.S │ │ │ ├── intvec32.S │ │ │ ├── startup.S │ │ │ ├── timer_a_uart │ │ │ ├── putchar.S │ │ │ ├── putchar_outmod.S │ │ │ └── receive_interrupt.S │ │ │ └── write.S │ ├── mcu_definition_parser.py │ ├── peripherals.py │ └── rpn.py ├── bsl │ ├── BL_150S_14x.txt │ ├── BL_150S_44x.txt │ ├── BS_150S_14x.txt │ ├── __init__.py │ ├── __main__.py │ ├── bsl.py │ ├── patch.txt │ └── target │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── fcdprog.py │ │ └── telosb.py ├── bsl5 │ ├── RAM_BSL.00.06.05.34.txt │ ├── __init__.py │ ├── bsl5.py │ ├── hid.py │ └── uart.py ├── commandline_helper.py ├── downloader.py ├── gdb │ ├── __init__.py │ ├── __main__.py │ ├── gdb.py │ └── target.py ├── jtag │ ├── HIL.py │ ├── __init__.py │ ├── __main__.py │ ├── clock.py │ ├── dco.py │ ├── hilspi.py │ ├── jtag.py │ ├── profile.py │ └── target.py ├── legacy │ ├── __init__.py │ ├── bsl.py │ ├── bsl_main.py │ └── jtag.py ├── listing │ ├── __init__.py │ ├── iar.py │ └── mspgcc.py ├── memory │ ├── __init__.py │ ├── bin.py │ ├── compare.py │ ├── convert.py │ ├── elf.py │ ├── error.py │ ├── generate.py │ ├── hexdump.py │ ├── intelhex.py │ └── titext.py ├── ram_usage.py ├── shell │ ├── __init__.py │ ├── command.py │ └── watch.py ├── target.py └── tool.py ├── pylintrc ├── requirements.txt ├── setup.cfg ├── setup.py └── win32 ├── downloader.ico ├── downloader.xcf └── setup-combined-tools-py2exe.py /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | dist 3 | doc/asm/*_words.rst 4 | doc/_build/* 5 | doc/_static/* 6 | doc/_templates/* 7 | msp430/asm/include/upstream 8 | msp430/asm/include/upstream.tar.gz 9 | msp430/asm/include/upstream.tar.bz2 10 | MANIFEST 11 | *.o4 12 | *.titext 13 | examples/asm/*/led.titxt 14 | examples/asm/forth_to_asm/msp430.forth 15 | examples/asm/forth_to_asm/*.S 16 | examples/asm/forth_to_asm/*.s-cpp 17 | examples/asm/forth_to_asm_advanced/msp430.forth 18 | examples/asm/forth_to_asm_advanced/*.S 19 | examples/asm/forth_to_asm_advanced/*.s-cpp 20 | examples/asm/forth_to_asm_advanced/*.map 21 | *.pyc 22 | xxx.txt 23 | __pycache__ 24 | python_msp430_tools.egg-info 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright Chris Liechti 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | language: python 5 | 6 | python: 7 | - 2.7 8 | - 3.6 9 | - pypy 10 | - pypy3 11 | 12 | script: 13 | - python setup.py install 14 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001-2017 Chris Liechti 2 | All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | --------------------------------------------------------------------------- 33 | Note: 34 | Individual files contain the following tag instead of the full license text. 35 | 36 | SPDX-License-Identifier: BSD-3-Clause 37 | 38 | This enables machine processing of license information based on the SPDX 39 | License Identifiers that are here available: http://spdx.org/licenses/ 40 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | include LICENSE.txt 3 | include MANIFEST.in 4 | include setup.py 5 | recursive-include examples *.py *.txt *.S *akefile *.ini *.nsi *.m43 *.forth 6 | 7 | include msp430/asm/forth/*.forth 8 | 9 | include msp430/asm/librarian/asm/startup.S 10 | include msp430/asm/librarian/asm/intvec16.S 11 | include msp430/asm/librarian/asm/intvec32.S 12 | include msp430/asm/librarian/asm/adc10.S 13 | include msp430/asm/librarian/asm/write.S 14 | include msp430/asm/librarian/asm/timer_a_uart/putchar.S 15 | include msp430/asm/librarian/asm/timer_a_uart/putchar_outmod.S 16 | include msp430/asm/librarian/asm/timer_a_uart/receive_interrupt.S 17 | 18 | include doc/*.rst 19 | include doc/*.txt 20 | include doc/asm/*.rst 21 | include doc/asm/forth_wordlist.py 22 | include doc/asm/rpn_wordlist.py 23 | include doc/conf.py 24 | include doc/Makefile 25 | 26 | include win32/downloader.ico 27 | include win32/downloader.xcf 28 | include win32/setup-combined-tools-py2exe.py 29 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ==================================== 2 | MSP430 Tools |build-status| |docs| 3 | ==================================== 4 | 5 | The python-msp430-tools are a collection of tools related to the MSP430 6 | embedded processor. 7 | 8 | Python_ 2.6 or newer (2.x series) is required for most modules. The python 9 | package "msp430" can be installed with "python setup.py install". These modules 10 | can be used as standalone applications or as library for other programs. 11 | 12 | Documentation 13 | ============= 14 | For API documentation, usage and examples_ see files in the "doc" 15 | directory. The ".rst" files can be read in any text editor or being converted 16 | to HTML or PDF using Sphinx_. A HTML version is online at 17 | https://python-msp430-tools.readthedocs.io 18 | 19 | 20 | Download tools 21 | ============== 22 | Command line tools, e.g. ``python -m msp430.gdb.target``. They can up and 23 | download memory of MSP430 targets. 24 | 25 | - ``msp430.jtag.target`` JTAG interface 26 | - ``msp430.bsl.target`` F1x, F2x, F4x BSL 27 | - ``msp430.bsl5.uart`` F5x, F6x BSL (non-USB devices) 28 | - ``msp430.bsl5.hid`` F5x, F6x BSL (USB devices) 29 | - ``msp430.gdb.target`` Using a GDB proxy (TCP/IP connection). 30 | 31 | 32 | Other tools 33 | =========== 34 | - ``msp430.memory.convert`` Convert between hex file formats 35 | 36 | - ``msp430.memory.dco`` Measure or calibrate the DCO clock 37 | 38 | - ``msp430.memory.compare`` Compare two hex files 39 | 40 | - ``msp430.memory.hexdump`` Show contents of hex files 41 | 42 | - ``msp430.memory.generate`` Create hex files with a defined pattern. Can be 43 | used for testing or to create underlays for other binaries (e.g. to fill 44 | unused memory with "NOPs" or "JMP $") 45 | 46 | - ``msp430.memory.downloader`` Small program, suitable for file associations, 47 | so that double clicking an ELF or a43 file can be used to download via 48 | JTAG. 49 | 50 | - ``msp430.asm.as``, ``msp430.asm.ld``, ``msp430.asm.cpp``: An assembler, 51 | linker and preprocessor for MSP430(X) 52 | 53 | - ``msp430.asm.disassemble`` 54 | 55 | 56 | Description of Python library 57 | ============================= 58 | ``msp430`` 59 | Root package for the Python modules related to the MSP430. 60 | 61 | ``msp430.asm`` 62 | A simple assembler and linker, also a disassembler, supporting MSP430(X). 63 | 64 | ``msp430.bsl`` 65 | Support for the boot strap loader. ``msp430.bsl.target`` is the main 66 | package for the downloader and contains subclassed modules for target 67 | specific BSL hardware. 68 | 69 | ``msp430.bsl5`` 70 | Support for the boot strap loader of F5xx/F6xx devices. ``msp430.bsl5.hid`` 71 | is the main module for the downloader for F5xx USB devices and 72 | ``msp430.bsl5.uart`` for all others. 73 | 74 | ``msp430.jtag`` 75 | JTAG tools using the MSP430[mspgcc] library. ``msp430.jtag.target`` is the 76 | main module for the downloader. 77 | 78 | ``msp430.gdb`` 79 | Communicate with a GDB server/proxy. ``msp430.gdb.target`` is the 80 | main module for the downloader. 81 | 82 | ``msp430.memory`` 83 | Memory implementation, used to store an memory image used to download to 84 | the MSP430. File format handlers are here too. 85 | Interesting submodules are: 86 | - convert 87 | - compare 88 | - hexdump 89 | - generate 90 | 91 | ``msp430.shell.commands`` 92 | Shell commands, useful for makefiles etc. 93 | 94 | ``msp430.shell.watch`` 95 | Watch a file for changes and execute a command in that case. 96 | 97 | ``msp430.listing`` 98 | Parser for listing files. 99 | 100 | ``msp430.legacy`` 101 | Support code for older tools. 102 | 103 | 104 | 105 | .. _examples: https://github.com/zsquareplusc/python-msp430-tools/tree/master/examples 106 | .. _Python: http://python.org/ 107 | .. _Sphinx: http://sphinx-doc.org/ 108 | .. |build-status| image:: https://travis-ci.org/zsquareplusc/python-msp430-tools.svg?branch=master 109 | :target: https://travis-ci.org/zsquareplusc/python-msp430-tools 110 | :alt: Build status 111 | .. |docs| image:: https://readthedocs.org/projects/python-msp430-tools/badge/?version=latest 112 | :target: http://python-msp430-tools.readthedocs.io/ 113 | :alt: Documentation 114 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | 9 | # Internal variables. 10 | PAPEROPT_a4 = -D latex_paper_size=a4 11 | PAPEROPT_letter = -D latex_paper_size=letter 12 | ALLSPHINXOPTS = -d _build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 13 | 14 | .PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest 15 | 16 | help: 17 | @echo "Please use \`make ' where is one of" 18 | @echo " html to make standalone HTML files" 19 | @echo " dirhtml to make HTML files named index.html in directories" 20 | @echo " pickle to make pickle files" 21 | @echo " json to make JSON files" 22 | @echo " htmlhelp to make HTML files and a HTML help project" 23 | @echo " qthelp to make HTML files and a qthelp project" 24 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 25 | @echo " changes to make an overview of all changed/added/deprecated items" 26 | @echo " linkcheck to check all external links for integrity" 27 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 28 | @echo " zip to create archive of HTML docs for upload to packages.python.org" 29 | 30 | clean: 31 | -rm -rf _build/* 32 | 33 | forthwords: 34 | cd asm; python forth_wordlist.py 35 | cd asm; python rpn_wordlist.py --title "Linker Word List" -o linker_words.rst msp430.asm.ld Linker 36 | cd asm; python rpn_wordlist.py --title "MCU Definition Word List" -o mcdudef_words.rst msp430.asm.mcu_definition_parser MCUDefintitions 37 | 38 | html: forthwords 39 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) _build/html 40 | @echo 41 | @echo "Build finished. The HTML pages are in _build/html." 42 | 43 | dirhtml: 44 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) _build/dirhtml 45 | @echo 46 | @echo "Build finished. The HTML pages are in _build/dirhtml." 47 | 48 | pickle: 49 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) _build/pickle 50 | @echo 51 | @echo "Build finished; now you can process the pickle files." 52 | 53 | json: 54 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) _build/json 55 | @echo 56 | @echo "Build finished; now you can process the JSON files." 57 | 58 | htmlhelp: 59 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) _build/htmlhelp 60 | @echo 61 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 62 | ".hhp project file in _build/htmlhelp." 63 | 64 | qthelp: 65 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) _build/qthelp 66 | @echo 67 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 68 | ".qhcp project file in _build/qthelp, like this:" 69 | @echo "# qcollectiongenerator _build/qthelp/python-msp430-tools.qhcp" 70 | @echo "To view the help file:" 71 | @echo "# assistant -collectionFile _build/qthelp/python-msp430-tools.qhc" 72 | 73 | latex: 74 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) _build/latex 75 | @echo 76 | @echo "Build finished; the LaTeX files are in _build/latex." 77 | @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \ 78 | "run these through (pdf)latex." 79 | 80 | changes: 81 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) _build/changes 82 | @echo 83 | @echo "The overview file is in _build/changes." 84 | 85 | linkcheck: 86 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) _build/linkcheck 87 | @echo 88 | @echo "Link check complete; look for any errors in the above output " \ 89 | "or in _build/linkcheck/output.txt." 90 | 91 | doctest: 92 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) _build/doctest 93 | @echo "Testing of doctests in the sources finished, look at the " \ 94 | "results in _build/doctest/output.txt." 95 | 96 | zip: 97 | cd _build/html; zip ../../onlinedocs.zip -r * 98 | -------------------------------------------------------------------------------- /doc/README-msp430-downloader.txt: -------------------------------------------------------------------------------- 1 | msp430-downloader 2 | ================= 3 | 4 | Software to talk to the parallel port and USB JTAG adapters as seen with the 5 | FET kits. 6 | 7 | 8 | Features 9 | -------- 10 | 11 | - understands ELF, TI-Text and Intel-hex object files 12 | - download to Flash and/or RAM, erase flash, verify 13 | - reset device 14 | - upload a memory block MSP->PC (output as binary data or hex dump, ihex) 15 | - written in Python, runs on Win32, Linux, BSD, ... 16 | - use on command line, or in a Python script 17 | - reset and wait for keypress (to run a device directly from the port 18 | power) 19 | - TI/3rd party library support for USB JTAG adaptors (Windows only) 20 | 21 | 22 | Short introduction 23 | ------------------ 24 | The tool is intended to be assigned to .a43 and .elf files. 25 | 26 | Without configuration file a dialog box is shown, first to ask for the 27 | programmer type, USB or parallel, and then the erase mode. These settings 28 | and some additional options can be preconfigured in a configuration file. 29 | 30 | The configuration file together with the binary can be bundled into a single ZIP 31 | archive (extension must be renamed to .z43). The name of the configuration file 32 | is irrelevant as the first one with the ending ``.m43`` is loaded. The binary 33 | is referenced in the configuration file, its name must match. 34 | 35 | Example configuration file ``downloader-demo.m43``:: 36 | 37 | ########################################################################## 38 | # This is a configuration file for msp430-download 39 | # It shows and describes all available options. 40 | # 41 | # When used as separate file: 42 | # - copy a binary to the destination folder 43 | # - copy this file to the destination folder 44 | # - edit configuration for your needs 45 | # 46 | # When used with a ZIP file: 47 | # - as above copy binary and configuration file, edit config 48 | # - add all files to a zip file and rename it with to a .z43 ending 49 | # 50 | ########################################################################## 51 | 52 | [modes] 53 | ########################################################################## 54 | ## Erase modes: 55 | ## "all" or "mass" erase all memory 56 | ## "main" leave information memory 57 | ## "ask" ask the user 58 | erase_mode = mass 59 | 60 | ########################################################################## 61 | ## Interface selection: 62 | ## "ask" ask the user 63 | ## "1" or "parallel" parallel port. hint: numbers: LPT1, LPT2 etc 64 | ## "TIUSB" or "COMn" USB interface 65 | interface = parallel 66 | 67 | ########################################################################## 68 | ## Program in a loop, so that several targets can easily be programmed 69 | ## Single run and exit if not set. 70 | #loop = Yes 71 | 72 | ########################################################################## 73 | ## Ask again before programming. 74 | ## Recommended if no ther questions before programming are enabled, so 75 | ## that the user has a chance to abort. It is forced on if "loop" 76 | ## programming is on. 77 | #ask_start = Yes 78 | 79 | ########################################################################## 80 | ## Fake the progress bar and increment depending on state, not depending 81 | ## on data. Automatically set if the USB JTAG is used. 82 | fake_progess = No 83 | 84 | ########################################################################## 85 | ## For developers only. Remove key or set it to "no" for releases. 86 | ## When enabled, some diagnostic messages are printed to stdout. 87 | #debug = Yes 88 | 89 | ########################################################################## 90 | ## Backend selection: 91 | ## "mspgcc" use MSP430mspgcc.dll 92 | ## "parjtag" use _parjtag + MSP430mspgcc.dll (not recommended) 93 | ## "ti" use MSP430.dll from TI ord 3rd party 94 | ## Autodetect if key is not given. 95 | #backend = mspgcc 96 | 97 | [data] 98 | ########################################################################## 99 | ## A filename can be predefined. 100 | ## File open dialog will not be shown in this case. 101 | filename = leds.a43 102 | 103 | ########################################################################## 104 | ## If defined, a question is displayed, asking the user if he wants to 105 | ## see the readme. 106 | #readme = readme.txt 107 | 108 | ########################################################################## 109 | ## Select the viewer for the readme. Possible values are: 110 | ## "browser" the default web browser or text editor, depending 111 | ## on file ending 112 | ## "internal" use a message box (only for very short texts) 113 | viewer = browser 114 | 115 | -------------------------------------------------------------------------------- /doc/asm/forth_wordlist.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | """\ 3 | Create documentation of Forth system by extracting a word list 4 | from '.forth' files and writing a '.rst' file 5 | """ 6 | 7 | import sys 8 | import re 9 | import glob 10 | import inspect 11 | 12 | re_word = re.compile(r'^(?PCODE|:)\s+(?P\S+)\s+(?P\(.*?--.*?\))?') 13 | re_doc_comment = re.compile(r'^\( > ?(.*?)\)?$') 14 | 15 | wordlist = {} 16 | 17 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 18 | # scan the forth source files. this will yield words for host and target 19 | for filename in glob.glob('../../msp430/asm/forth/*.forth'): 20 | print("scanning", filename) 21 | last_comment = [] 22 | for n, line in enumerate(open(filename)): 23 | m = re_doc_comment.match(line) 24 | if m: 25 | last_comment.append(m.group(1)) 26 | 27 | m = re_word.match(line) 28 | if m: 29 | #~ print m.groups() 30 | info = wordlist.setdefault(m.group('name').upper(), {'doc':'', 'deftype':set()}) 31 | info['deftype'].add(m.group('type')) 32 | if m.group('balance'): 33 | info['stack'] = m.group('balance') 34 | info.setdefault('locations', []).append(u'%s:%s' % (filename[23:], n+1)) 35 | if last_comment and info['doc']: 36 | print("WARNING: multiple definitions of %r, skipping docs in %s" % (m.group('name'), filename)) 37 | else: 38 | info['doc'] = u'\n'.join(last_comment) 39 | last_comment = [] 40 | 41 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 42 | # also include all builtin words on the host. 43 | sys.path.append('../..') 44 | import msp430.asm.forth 45 | f = msp430.asm.forth.Forth() 46 | for word, func in f.builtins.items(): 47 | info = wordlist.setdefault(word.upper(), {'doc':'', 'deftype':set()}) 48 | info['deftype'].add('python') 49 | #~ info['stack'] = m.group('balance') or 'n/a' 50 | info.setdefault('locations', []).append(u'forth.py') 51 | if func.__doc__ is not None: 52 | if info['doc']: 53 | print("WARNING: multiple definitions of %r, skipping docs in forth.py" % (word,)) 54 | else: 55 | info['doc'] = u'%s\n' % inspect.getdoc(func) 56 | # XXX cut prefixing whitespace 57 | 58 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 59 | # write output in reST format 60 | output = open('forth_words.rst', 'w') 61 | output.write("""\ 62 | ================= 63 | Forth Word List 64 | ================= 65 | .. .. contents:: 66 | """) 67 | for word, info in sorted(wordlist.items()): 68 | output.write('\n``%s``\n' % word) 69 | output.write('%s\n' % ('-'*(4+len(word)))) 70 | output.write('%s\n' % info['doc']) 71 | if 'stack' in info: output.write('\nStack: ``%s``\n' % info['stack']) 72 | available = [] 73 | if set([':', 'CODE']) & info['deftype']: # runs_on_target 74 | available.append('target') 75 | if set([':', 'python']) & info['deftype']: # runs_on_host 76 | available.append('host') 77 | output.write('\nAvailability: %s\n' % ' and '.join(available)) 78 | output.write('\nDefined in file(s): %s\n' % ' and '.join('``%s``' % f for f in info['locations'])) 79 | print("%d words" % len(wordlist)) 80 | -------------------------------------------------------------------------------- /doc/asm/rpn_wordlist.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | """\ 3 | Create documentation of msp430.asm.rpn based classes. 4 | """ 5 | 6 | import sys 7 | import inspect 8 | import codecs 9 | 10 | def create_wordlist(obj, output, title): 11 | wordlist = {} 12 | 13 | for word, func in obj.builtins.items(): 14 | info = wordlist.setdefault(word.upper(), {'doc':'', 'deftype':set()}) 15 | info['deftype'].add('python') 16 | #~ info['stack'] = m.group('balance') or 'n/a' 17 | #~ info.setdefault('locations', []).append(obj.__class__.__name__) 18 | if func.__doc__ is not None: 19 | if info['doc']: 20 | print("WARNING: multiple definitions of %r, skipping docs in forth.py" % (word,)) 21 | else: 22 | info['doc'] = u'%s\n' % inspect.getdoc(func) 23 | # XXX cut prefixing whitespace 24 | 25 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 26 | # write output in reST format 27 | if title: 28 | output.write('%s\n' % ('=' * (2+len(title)))) 29 | output.write('%s\n' % title) 30 | output.write('%s\n' % ('=' * (2+len(title)))) 31 | 32 | for word, info in sorted(wordlist.items()): 33 | output.write('\n``%s``\n' % word) 34 | output.write('%s\n' % ('-'*(4+len(word)))) 35 | output.write('%s\n' % info['doc']) 36 | if 'stack' in info: output.write('\nStack: ``%s``\n' % info['stack']) 37 | #~ available = [] 38 | #~ if set([':', 'CODE']) & info['deftype']: # runs_on_target 39 | #~ available.append('target') 40 | #~ if set([':', 'python']) & info['deftype']: # runs_on_host 41 | #~ available.append('host') 42 | #~ output.write('\nAvailability: %s\n' % ' and '.join(available)) 43 | if 'locations' in info: 44 | output.write('\nDefined in file(s): %s\n' % ' and '.join('``%s``' % f for f in info['locations'])) 45 | print("%d words" % len(wordlist)) 46 | 47 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 48 | 49 | def main(): 50 | import sys 51 | import os 52 | from optparse import OptionParser 53 | 54 | parser = OptionParser() 55 | parser.add_option("-t", "--title", 56 | dest = "title", 57 | help = "document title") 58 | parser.add_option("-o", "--outfile", 59 | dest = "outfile", 60 | help = "name of the object file", 61 | metavar = "FILE") 62 | parser.add_option("-v", "--verbose", 63 | action = "store_true", 64 | dest = "verbose", 65 | default = False) 66 | 67 | (options, args) = parser.parse_args() 68 | 69 | #~ if len(args) > 1: 70 | #~ sys.stderr.write("Only one module name at a time.\n") 71 | #~ sys.exit(1) 72 | 73 | if options.outfile: 74 | outfile = codecs.open(options.outfile, 'w', 'utf-8') 75 | else: 76 | outfile = codecs.getwriter("utf-8")(sys.stdout) 77 | 78 | sys.path.append('../..') 79 | mod = __import__(args[0]) 80 | cls = getattr(sys.modules[args[0]], args[1]) 81 | obj = cls() 82 | create_wordlist(obj, outfile, options.title) 83 | 84 | if __name__ == '__main__': 85 | main() 86 | 87 | -------------------------------------------------------------------------------- /doc/assembler.rst: -------------------------------------------------------------------------------- 1 | =========== 2 | Assembler 3 | =========== 4 | 5 | The module ``msp430.asm`` provides an assembler for MSP430 and MSP430X CPUs. 6 | There is also a disassembler. 7 | 8 | Additionally a (almost C compatible) preprocessor is provided. 9 | 10 | The tutorial and command line sections cover the command line tools and how to 11 | use them. The API section is about the internals of the tools and may be 12 | interesting to developers that extended the tools or use them as a library. 13 | 14 | Also available is a Forth cross compiler that can translate Forth programs to 15 | MSP430 assembler. 16 | 17 | .. toctree:: 18 | :maxdepth: 3 19 | 20 | asm/tutorial 21 | asm/commandline 22 | asm/forth 23 | asm/api 24 | -------------------------------------------------------------------------------- /doc/commandline_tools.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _command_line_tools: 3 | 4 | =================== 5 | Commandline Tools 6 | =================== 7 | 8 | The following sections show the README files of the different command line tools. 9 | 10 | Programming tools: 11 | 12 | - msp430-bsl: F1x, F2x, F4x BSL 13 | - msp430-bsl5: F5x, F6x BSL 14 | - msp430-jtag: JTAG interface 15 | 16 | Other Utilities: 17 | 18 | - msp430-dco: clock calibration tool 19 | - msp430-downloader: JTAG download wrapper (GUI) 20 | 21 | 22 | .. include:: README-msp430-bsl.txt 23 | .. include:: README-msp430-bsl5.txt 24 | .. include:: README-msp430-jtag.txt 25 | .. include:: README-msp430-dco.txt 26 | .. include:: README-msp430-downloader.txt 27 | -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | .. python-msp430-tools documentation master file, created by 2 | sphinx-quickstart on Thu Jan 6 03:42:07 2011. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | python-msp430-tools documentation 7 | ================================= 8 | 9 | This page's online home is at: http://python-msp430-tools.readthedocs.io 10 | 11 | Package home (PyPI): http://pypi.python.org/pypi/python-msp430-tools 12 | 13 | Developement / Project page: https://github.com/zsquareplusc/python-msp430-tools 14 | 15 | Contents: 16 | 17 | .. toctree:: 18 | :maxdepth: 2 19 | 20 | overview 21 | commandline_tools 22 | target 23 | utilities 24 | shell 25 | assembler 26 | internals 27 | license 28 | 29 | Indices and tables 30 | ================== 31 | 32 | * :ref:`genindex` 33 | * :ref:`modindex` 34 | * :ref:`search` 35 | 36 | -------------------------------------------------------------------------------- /doc/license.rst: -------------------------------------------------------------------------------- 1 | ========= 2 | License 3 | ========= 4 | 5 | This is the simplified BSD license. 6 | 7 | .. literalinclude:: ../LICENSE.txt 8 | -------------------------------------------------------------------------------- /doc/overview.rst: -------------------------------------------------------------------------------- 1 | ========== 2 | Overview 3 | ========== 4 | This is about the python-msp430-tools, that provide a number of tools related 5 | to the MSP430 microcontroller. 6 | 7 | Python 2.6 or newer should be used. The Python package "msp430" can be 8 | installed with ``python setup.py install``. These modules can be used as 9 | standalone applications or as library for other programs. 10 | 11 | 12 | NEWS 13 | ==== 14 | Compared to the python-mspgcc-tools: 15 | 16 | - new "target" base implementation that all upload/download tools share 17 | 18 | - >64k address space support for most tools 19 | 20 | - new download tool: ``msp430.gdb.target``. It communicates with a GDB server 21 | for the MSP430 such as ``msp430-gdbproxy`` or ``mspdebug``. 22 | 23 | - new BSL implementation (F1x, F2x, F4x): ``msp430.bsl.target`` 24 | 25 | - new BSL implementation (F5x, F6x): ``msp430.bsl5.hid`` and 26 | ``msp430.bsl5.uart`` 27 | 28 | - JTAG tool renamed to: ``msp430.jtag.target`` 29 | 30 | - renamed command line options ``-l/--lpt`` to ``-p/--port`` 31 | - new command line option ``-l/--library-path`` 32 | 33 | - all target tools: 34 | 35 | - renamed command line options ``-P``, ``-V`` to upper case 36 | - new command line option ``-U/--upload-by-file`` 37 | - new command line option ``-b/--erase-by-file`` 38 | - multiple files on the command line are merged before downloading 39 | (supporting overlapping areas - last one counts). Useful e.g. if a 40 | boot loader part should be merged with an application part. 41 | - specifying input format is now one option: ``-i/--input-format`` 42 | - specifying output format is now one option: ``-f/--output-format`` 43 | - new file formats: ``hex``, ``bin`` 44 | 45 | - new modules: 46 | 47 | - ``msp430.listing`` (read IAR and mspgcc listing files) 48 | - ``msp430.gdb`` (GDB client code for use with GDB servers) 49 | - ``msp430.shell.command`` (busybox alike shell commands: ``mv``, ``cp``, ``rm`` and more) 50 | - ``msp430.bsl5`` (F5xx/F6xx BSL support) 51 | 52 | - ``msp430.bsl5.hid`` (USB HID frontend) 53 | - ``msp430.bsl5.uart`` (serial frontend) 54 | 55 | - new tools: 56 | 57 | - ``msp430.memory.convert`` (convert hex file formats) 58 | - ``msp430.memory.generate`` (create hex files with fill pattern) 59 | - ``msp430.memory.compare`` (compare hex files) 60 | - ``msp430.memory.hexdump`` (show contents of hex files) 61 | 62 | - new license: Simplified BSD License instead of Python License. 63 | 64 | 65 | There is no longer a separate line frontend for each tool. However tools can be 66 | used as follows:: 67 | 68 | python -m [options] [arguments] 69 | 70 | e.g.:: 71 | 72 | python -m msp430.bsl.target -p /dev/ttyUSB0 -e somefile.elf 73 | 74 | -------------------------------------------------------------------------------- /doc/shell.rst: -------------------------------------------------------------------------------- 1 | ================= 2 | Shell utilities 3 | ================= 4 | 5 | The module :mod:`msp430.shell` provides some useful scripts for the shell. 6 | 7 | ``msp430.shell.command`` 8 | ======================== 9 | 10 | This tool emulates a number of shell utilities. The idea is that makefiles or 11 | similar build tools can use these commands to be OS independent (so that the 12 | same set of commands works on Windows, MacOS, GNU/Linux, etc.). 13 | 14 | Command collection: 15 | 16 | - ``cat`` Show file contents. 17 | - ``cp`` Copy files. 18 | - ``expand`` Expand shell patterns ("\*.c", "?" etc.). 19 | - ``false`` Simply return exit code 1 20 | - ``list`` This text. 21 | - ``mkdir`` Create directories. 22 | - ``mv`` Move/rename files. 23 | - ``rm`` Delete files/directories. 24 | - ``touch`` Update file date, create file. 25 | - ``true`` Simply return exit code 0 26 | 27 | More help with "command.py COMMAND --help" 28 | 29 | Example:: 30 | 31 | python -m msp430.shell.command rm -f no_longer_needed.txt 32 | python -m msp430.shell.command cp src.txt dst.txt 33 | 34 | 35 | ``msp430.shell.watch`` 36 | ====================== 37 | 38 | This tool watches one or multiple files for changes. When a change on one file 39 | is detected it runs a given command. This could be used e.g. to automatically 40 | trigger a download when a hex file has changed or trigger compilation when one 41 | of the source files has changed. 42 | 43 | Usage: watch.py FILENAME \[FILENAME...\] --execute "some/program/ --" 44 | 45 | Options: 46 | -h, --help show this help message and exit 47 | -x COMMAND, --execute=COMMAND 48 | run this command when watched file(s) changed, -- is 49 | replaced by FILENAME(s) 50 | 51 | -------------------------------------------------------------------------------- /doc/utilities.rst: -------------------------------------------------------------------------------- 1 | =========== 2 | Utilities 3 | =========== 4 | 5 | ``msp430.memory.convert`` 6 | ========================= 7 | 8 | This is a command line tool that can load multiple hex files, combine them and 9 | output a hex file of the same or different file type. 10 | (run as ``python -m msp430.memory.convert``):: 11 | 12 | Usage: convert.py [options] [INPUT...] 13 | 14 | Simple hex file conversion tool. 15 | 16 | It is also possible to specify multiple input files and create a single, 17 | merged output. 18 | 19 | Options: 20 | -h, --help show this help message and exit 21 | -o DESTINATION, --output=DESTINATION 22 | write result to given file 23 | -i TYPE, --input-format=TYPE 24 | input format name (titext, ihex, bin, hex, elf) 25 | -f TYPE, --output-format=TYPE 26 | output format name (titext, ihex, bin, hex) 27 | -d, --debug print debug messages 28 | 29 | 30 | ``msp430.memory.compare`` 31 | ========================= 32 | Compare two hex files. The files are loaded and a hex dump is compared. The 33 | diff between the hex dumps is output (unless the ``--html`` option is used). 34 | The tool also sets the shell exit code so that it could be used in shell/bat 35 | scripts. 36 | 37 | (run as ``python -m msp430.memory.compare``):: 38 | 39 | Usage: compare.py [options] FILE1 FILE2 40 | 41 | Compare tool. 42 | 43 | This tool reads binary, ELF or hex input files, creates a hex dump and shows 44 | the differences between the files. 45 | 46 | 47 | Options: 48 | -h, --help show this help message and exit 49 | -o DESTINATION, --output=DESTINATION 50 | write result to given file 51 | -d, --debug print debug messages 52 | -v, --verbose print more details 53 | -i TYPE, --input-format=TYPE 54 | input format name (titext, ihex, bin, hex, elf) 55 | --html create HTML output 56 | 57 | ``msp430.memory.generate`` 58 | ========================== 59 | Generate hex files filled with some pattern. The pattern can be a counter or 60 | a useful MSP430 instruction such as ``JMP $`` (0x3fff). 61 | 62 | (run as ``python -m msp430.memory.generate``):: 63 | 64 | Usage: generate.py [options] 65 | 66 | Test File generator. 67 | 68 | This tool generates a hex file, of given size, ending on address 69 | 0xffff if no start address is given. 70 | 71 | Options: 72 | -h, --help show this help message and exit 73 | -o DESTINATION, --output=DESTINATION 74 | write result to given file 75 | -f TYPE, --output-format=TYPE 76 | output format name (titext, ihex, bin, hex) 77 | -l SIZE, --length=SIZE 78 | number of bytes to generate 79 | -s START_ADDRESS, --start-address=START_ADDRESS 80 | start address of data generated 81 | -c, --count use address as data 82 | --const=CONST use given 16 bit number as data (default=0x3fff) 83 | --random fill with random numbers 84 | 85 | 86 | ``msp430.memory.hexdump`` 87 | ========================= 88 | Show hex dump of files. Note that the same can be achieved with 89 | ``msp430.memory.convert -f hex``. 90 | 91 | (run as ``python -m msp430.memory.hexdump``):: 92 | 93 | Usage: hexdump.py [options] [SOURCE...] 94 | 95 | Hexdump tool. 96 | 97 | This tool generates hex dumps from binary, ELF or hex input files. 98 | 99 | What is dumped? 100 | - Intel hex and TI-Text: only data 101 | - ELF: only segments that are programmed 102 | - binary: complete file, address column is byte offset in file 103 | 104 | Options: 105 | -h, --help show this help message and exit 106 | -o DESTINATION, --output=DESTINATION 107 | write result to given file 108 | --debug print debug messages 109 | -v, --verbose print more details 110 | -i TYPE, --input-format=TYPE 111 | input format name (titext, ihex, bin, hex, elf) 112 | 113 | -------------------------------------------------------------------------------- /examples/asm/calibrate/makefile: -------------------------------------------------------------------------------- 1 | # example make file for the calibrate demo 2 | 3 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4 | # setting up the environment 5 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 6 | 7 | # set Python path in case we're running from the original 8 | # source repository 9 | PYTHONPATH = ../../.. 10 | export PYTHONPATH 11 | 12 | # options 13 | ASFLAGS = 14 | LDFLAGS = -v --mcu MSP430G2231 15 | #~ LDFLAGS = -v --mcu MSP430G2231 --symbols MSP430G2231 16 | CPPFLAGS = -D_GNU_ASSEMBLER_ -D__ASSEMBLER__ -D__MSP430G2132__ 17 | 18 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 19 | # commands 20 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 21 | PY = python 22 | CPP = $(PY) -m msp430.asm.cpp 23 | AS = $(PY) -m msp430.asm.as 24 | LD = $(PY) -m msp430.asm.ld 25 | RM = $(PY) -m msp430.shell.command rm -f 26 | CAT = $(PY) -m msp430.shell.command cat 27 | DIS = $(PY) -m msp430.asm.disassemble 28 | 29 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 30 | # the rules used to build 31 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 32 | .PHONY: clean all 33 | 34 | all: clean calibrate.titext 35 | $(CAT) calibrate.titext 36 | 37 | clean: 38 | $(RM) calibrate.titext calibrate.o4 calibrate.s-cpp 39 | 40 | 41 | calibrate.o4: calibrate.S 42 | calibrate.titext: calibrate.o4 43 | $(LD) $(LDFLAGS) -o $@ $^ 44 | 45 | # pattern rules for the assembler 46 | %o4: %s-cpp 47 | $(AS) $(ASFLAGS) -o $@ $< 48 | 49 | %s-cpp: %S 50 | ${CPP} ${CPPFLAGS} -o $@ $< 51 | 52 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 53 | # additional download rules 54 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 55 | .PHONY: download-jtag download-bsl download-gdb 56 | 57 | download-jtag: calibrate.titext 58 | $(PY) -m msp430.jtag.target -p TIUSB -e $^ --spy-bi-wire 59 | 60 | download-bsl: calibrate.titext 61 | $(PY) -m msp430.bsl.target -e $^ 62 | 63 | download-gdb: calibrate.titext 64 | $(PY) -m msp430.gdb.target -e $^ 65 | 66 | download-mspdebug: calibrate.titext 67 | mspdebug rf2500 "prog $^" exit 68 | 69 | download: download-jtag 70 | -------------------------------------------------------------------------------- /examples/asm/forth_to_asm/led.forth: -------------------------------------------------------------------------------- 1 | ( LED flashing example 2 | Hardware: Launchpad 3 | 4 | vi:ft=forth 5 | ) 6 | 7 | ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ) 8 | INCLUDE core.forth 9 | INCLUDE msp430.forth 10 | 11 | ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ) 12 | ( Control the LEDs on the Launchpad ) 13 | : RED_ON BIT0 P1OUT CSET ; 14 | : RED_OFF BIT0 P1OUT CRESET ; 15 | : GREEN_ON BIT6 P1OUT CSET ; 16 | : GREEN_OFF BIT6 P1OUT CRESET ; 17 | 18 | ( Read in the button on the Launchpad ) 19 | : S2 BIT3 P1IN CTESTBIT NOT ; 20 | 21 | ( Delay functions ) 22 | : SHORT-DELAY 0x4fff DELAY ; 23 | : LONG-DELAY 0xffff DELAY ; 24 | : VERY-LONG-DELAY LONG-DELAY LONG-DELAY ; 25 | 26 | ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ) 27 | ( Initializations run after reset ) 28 | : INIT ( - ) 29 | ( Initialize pins ) 30 | 0 P1OUT C! 31 | [ BIT0 BIT6 + ] LITERAL P1DIR C! 32 | ( Stop Watchdog module ) 33 | [ WDTPW WDTHOLD + ] LITERAL WDTCTL ! 34 | 35 | ( Initialize clock from calibration values ) 36 | CALDCO_1MHZ DCOCTL C@! 37 | CALBC1_1MHZ BCSCTL1 C@! 38 | 39 | ( Indicate startup with LED ) 40 | GREEN_ON 41 | VERY-LONG-DELAY 42 | GREEN_OFF 43 | VERY-LONG-DELAY 44 | VERY-LONG-DELAY 45 | ; 46 | 47 | ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ) 48 | ( Main application, run after INIT ) 49 | : MAIN ( - ) 50 | BEGIN 51 | S2 IF 52 | ( Green flashing if button is pressed ) 53 | GREEN_ON 54 | SHORT-DELAY 55 | GREEN_OFF 56 | SHORT-DELAY 57 | ELSE 58 | ( Red flashing ) 59 | RED_ON 60 | LONG-DELAY 61 | RED_OFF 62 | LONG-DELAY 63 | ENDIF 64 | AGAIN 65 | ; 66 | 67 | ( ========================================================================= ) 68 | ( Generate the assembler file now ) 69 | " LED example " HEADER 70 | 71 | ( output important runtime core parts ) 72 | " Core " HEADER 73 | CROSS-COMPILE-CORE 74 | 75 | ( cross compile application ) 76 | " Application " HEADER 77 | CROSS-COMPILE-VARIABLES 78 | CROSS-COMPILE INIT 79 | CROSS-COMPILE MAIN 80 | CROSS-COMPILE-MISSING ( This compiles all words that were used indirectly ) 81 | -------------------------------------------------------------------------------- /examples/asm/forth_to_asm/makefile: -------------------------------------------------------------------------------- 1 | # example make file for the led demo 2 | 3 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4 | # setting up the environment 5 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 6 | 7 | # set Python path in case we're running from the original 8 | # source repository 9 | PYTHONPATH = ../../.. 10 | export PYTHONPATH 11 | 12 | # options 13 | MCU = msp430g2231 14 | ASFLAGS = 15 | LDFLAGS = -v --mcu $(MCU) 16 | CPPFLAGS = -I /usr/msp430/include/ 17 | FORTHFLAGS = -DMCU=$(MCU) 18 | H2FORTHFLAGS = $(CPPFLAGS) 19 | 20 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 21 | # commands 22 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 23 | PY = python 24 | CPP = $(PY) -m msp430.asm.cpp 25 | AS = $(PY) -m msp430.asm.as 26 | LD = $(PY) -m msp430.asm.ld 27 | FORTH = $(PY) -m msp430.asm.forth 28 | H2FORTH = $(PY) -m msp430.asm.h2forth 29 | LIB = $(PY) -m msp430.asm.lib 30 | 31 | RM = $(PY) -m msp430.shell.command rm -f 32 | CAT = $(PY) -m msp430.shell.command cat 33 | DIS = $(PY) -m msp430.asm.disassemble 34 | 35 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 36 | # the rules used to build 37 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 38 | .PHONY: clean all 39 | 40 | all: clean led.titext led.S 41 | # $(CAT) led.titext 42 | 43 | clean: 44 | $(RM) led.titext led.o4 led.s-cpp led.S \ 45 | startup.o4 startup.s-cpp \ 46 | intvec16.S intvec16.o4 intvec.s-cpp msp430.forth 47 | 48 | # dependencies 49 | led.forth: msp430.forth 50 | 51 | # linking final program 52 | led.titext: startup.o4 led.o4 intvec16.o4 53 | $(LD) $(LDFLAGS) -o $@ $^ 54 | 55 | # files generated from templates / other files 56 | startup.s-cpp: 57 | $(LIB) -o $@ asm/startup.S 58 | intvec16.S: 59 | $(LIB) -o $@ asm/intvec16.S 60 | 61 | msp430.forth: 62 | $(H2FORTH) $(H2FORTHFLAGS) -o $@ $(MCU).h 63 | 64 | # pattern rules for the assembler 65 | %o4: %s-cpp 66 | $(AS) $(ASFLAGS) -o $@ $< 67 | 68 | %s-cpp: %S 69 | ${CPP} ${CPPFLAGS} -o $@ $< 70 | 71 | %S: %forth 72 | ${FORTH} ${FORTHFLAGS} -o $@ $< 73 | # $(CAT) $@ 74 | 75 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 76 | # additional download rules 77 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 78 | .PHONY: download-jtag download-bsl download-gdb 79 | 80 | download-jtag: led.titext 81 | $(PY) -m msp430.jtag.target -e -l /opt/mspgcc/lib $^ --no-close -r 82 | 83 | download-bsl: led.titext 84 | $(PY) -m msp430.bsl.target -e $^ 85 | 86 | download-gdb: led.titext 87 | $(PY) -m msp430.gdb.target -e $^ 88 | 89 | download-mspdebug: led.titext 90 | mspdebug rf2500 "prog $^" exit 91 | -------------------------------------------------------------------------------- /examples/asm/forth_to_asm_advanced/demo_adc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2011 Chris Liechti 5 | # All Rights Reserved. 6 | # Simplified BSD License (see LICENSE.txt for full text) 7 | 8 | import xprotocol 9 | from matplotlib.pylab import * 10 | 11 | box = xprotocol.XProtocol('/dev/ttyACM0', 2400) 12 | box.open() 13 | #~ for i in range(16): 14 | #~ print x.decode(x.command('a%02x' % i)) 15 | 16 | CHANNELS = [0, 4, 5, 7, 8, 9, 10, 11] 17 | rows = [[] for x in CHANNELS] 18 | for n in range(10): 19 | for n, i in enumerate(CHANNELS): 20 | rows[n].append(box.decode(box.command('a%02x' % i))[0]) 21 | 22 | fig = figure() 23 | ax = fig.add_subplot(111) 24 | for y in rows: 25 | if y: 26 | x = arange(len(y)) 27 | ax.plot(x,y) 28 | show() 29 | #~ plot(samples) 30 | -------------------------------------------------------------------------------- /examples/asm/forth_to_asm_advanced/hardware.h: -------------------------------------------------------------------------------- 1 | #ifndef HARDWARE_H 2 | #define HARDWARE_H 3 | 4 | #include 5 | 6 | // Timer A UART configuration 7 | #define TAUART_RX_INTERRUPT __vector_100 8 | #define TAUART_VECTOR TIMERA1_VECTOR 9 | //~ #define TAUART_TX_DINT 10 | 11 | #define TAUART_BIT_TICKS 416 // ~2400 @ 1e6 12 | //~ #define TAUART_BIT_TICKS 208 // ~480 @ 1e6 13 | //~ #define TAUART_BIT_TICKS 104 // ~9600 @ 1e6 14 | 15 | #endif // HARDWARE_H 16 | -------------------------------------------------------------------------------- /examples/asm/forth_to_asm_advanced/makefile: -------------------------------------------------------------------------------- 1 | # example make file 2 | 3 | NAME = demo 4 | 5 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 6 | # setting up the environment 7 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 8 | 9 | # set Python path in case we're running from the original 10 | # source repository 11 | PYTHONPATH = ../../.. 12 | export PYTHONPATH 13 | 14 | # options 15 | MCU = msp430g2231 16 | ASFLAGS = 17 | LDFLAGS = -v --mcu $(MCU) --map $(NAME).map 18 | CPPFLAGS = 19 | FORTHFLAGS = -DMCU=$(MCU) 20 | H2FORTHFLAGS = $(CPPFLAGS) 21 | 22 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 23 | # commands 24 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 25 | PY = python 26 | CPP = $(PY) -m msp430.asm.cpp 27 | AS = $(PY) -m msp430.asm.as 28 | LD = $(PY) -m msp430.asm.ld 29 | FORTH = $(PY) -m msp430.asm.forth 30 | H2FORTH = $(PY) -m msp430.asm.h2forth 31 | LIB = $(PY) -m msp430.asm.lib 32 | RM = $(PY) -m msp430.shell.command rm -f 33 | CAT = $(PY) -m msp430.shell.command cat 34 | DIS = $(PY) -m msp430.asm.disassemble 35 | 36 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 37 | # the rules used to build 38 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 39 | .PHONY: clean all 40 | 41 | all: clean $(NAME).titext demo.S 42 | # $(CAT) demo.titext 43 | 44 | clean: 45 | $(RM) $(NAME).titext *.o4 $(NAME).s-cpp $(NAME).S $(NAME).map \ 46 | startup.s-cpp \ 47 | intvec16.S intvec16.s-cpp msp430.forth \ 48 | write.s-cpp putchar.S timer_a_uart_rx.S adc10.S adc10.s-cpp 49 | 50 | # dependencies 51 | $(NAME).forth: msp430.forth 52 | 53 | # linking final program 54 | $(NAME).titext: startup.o4 $(NAME).o4 intvec16.o4 write.o4 putchar.o4 timer_a_uart_rx.o4 adc10.o4 55 | $(LD) $(LDFLAGS) -o $@ $^ 56 | 57 | 58 | # files generated from templates / other files 59 | startup.s-cpp: 60 | $(LIB) -o $@ asm/startup.S 61 | write.s-cpp: 62 | $(LIB) -o $@ asm/write.S 63 | putchar.S: 64 | $(LIB) -o $@ asm/timer_a_uart/putchar_outmod.S 65 | timer_a_uart_rx.S: 66 | $(LIB) -o $@ asm/timer_a_uart/receive_interrupt.S 67 | adc10.S: 68 | $(LIB) -o $@ asm/adc10.S 69 | intvec16.S: 70 | $(LIB) -o $@ asm/intvec16.S 71 | 72 | 73 | msp430.forth: 74 | $(H2FORTH) $(H2FORTHFLAGS) -o $@ $(MCU).h 75 | 76 | # pattern rules for the assembler 77 | %o4: %s-cpp 78 | $(AS) $(ASFLAGS) -o $@ $< 79 | 80 | %s-cpp: %S 81 | ${CPP} ${CPPFLAGS} -o $@ $< 82 | 83 | %S: %forth 84 | ${FORTH} ${FORTHFLAGS} -o $@ $< 85 | # $(CAT) $@ 86 | 87 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 88 | # additional download rules 89 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 90 | .PHONY: download-jtag download-bsl download-gdb 91 | 92 | download-jtag: $(NAME).titext 93 | $(PY) -m msp430.jtag.target -e -l /opt/mspgcc/lib $^ --no-close -r 94 | 95 | download-bsl: $(NAME).titext 96 | $(PY) -m msp430.bsl.target -e $^ 97 | 98 | download-gdb: $(NAME).titext 99 | $(PY) -m msp430.gdb.target -e $^ 100 | 101 | download-mspdebug: $(NAME).titext 102 | mspdebug rf2500 "prog $^" exit 103 | 104 | -------------------------------------------------------------------------------- /examples/asm/launchpad_led/README.txt: -------------------------------------------------------------------------------- 1 | LED 2 | === 3 | 4 | Example program for MSP430G2 Launchpad kit. 5 | 6 | 7 | Function 8 | -------- 9 | This one toggles the pin P1.0. 10 | 11 | 12 | Building 13 | -------- 14 | Assembling and linking:: 15 | 16 | python -m msp430.asm.as -o led.o4 led.S 17 | python -m msp430.asm.ld --mcu MSP430G2231 --symbols MSP430G2231 -o led.titxt led.o4 18 | 19 | 20 | Usage 21 | ----- 22 | This is like the LED flashing example that comes preprogrammed on some of the 23 | eval boards from TI. The eval boards from TI typically have a LED connected to 24 | the pin P1.0. 25 | 26 | Download:: 27 | 28 | mspdebug rf2500 "prog led.titxt" exit 29 | 30 | or with a recent MSP430.dll:: 31 | 32 | python -m msp430.jtag.target -p TIUSB --spy-bi-wire -e led.titext 33 | -------------------------------------------------------------------------------- /examples/asm/launchpad_led/led.S: -------------------------------------------------------------------------------- 1 | ; Example for MSP430G2 Launchpad kit 2 | ; 3 | ; This one toggles the pin P1.0. 4 | ; Clock is initialized from calibration values 5 | 6 | .text 7 | ; entry point after device reset 8 | RESET: mov #WDTPW|WDTHOLD, &WDTCTL ; disable WDT 9 | ; init clock to 1MHz from calibration values 10 | mov.b CALDCO_1MHZ, &DCOCTL 11 | mov.b CALBC1_1MHZ, &BCSCTL1 12 | ; init ports 13 | bis.b #BIT0, &P1DIR ; set pin to output 14 | 15 | ; loop toggling the pin and then doing a delay 16 | .L1: xor.b #BIT0, &P1OUT ; toggle pin 17 | mov #0xc350, R15 ; init delay loop 18 | .L2: dec R15 ; count down 19 | jnz .L2 ; jump while counter is not zero 20 | jmp .L1 ; loop the toggling part 21 | 22 | 23 | ; set the reset vector (and all the others) to the program start 24 | .section .vectors 25 | .word RESET 26 | .word RESET 27 | .word RESET 28 | .word RESET 29 | .word RESET 30 | .word RESET 31 | .word RESET 32 | .word RESET 33 | .word RESET 34 | .word RESET 35 | .word RESET 36 | .word RESET 37 | .word RESET 38 | .word RESET 39 | .word RESET 40 | .word RESET ; reset vector 41 | 42 | ; vim: set ft=msp430: 43 | -------------------------------------------------------------------------------- /examples/asm/launchpad_led/makefile: -------------------------------------------------------------------------------- 1 | # example make file for the led demo 2 | 3 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4 | # setting up the environment 5 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 6 | 7 | # set Python path in case we're running from the original 8 | # source repository 9 | PYTHONPATH = ../../.. 10 | export PYTHONPATH 11 | 12 | # options 13 | ASFLAGS = -v 14 | LDFLAGS = -v --mcu MSP430G2231 --symbols MSP430G2231 15 | 16 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 17 | # commands 18 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 19 | PY = python 20 | AS = $(PY) -m msp430.asm.as 21 | LD = $(PY) -m msp430.asm.ld 22 | RM = $(PY) -m msp430.shell.command rm -f 23 | CAT = $(PY) -m msp430.shell.command cat 24 | 25 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 26 | # the rules used to build 27 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 28 | .PHONY: clean all 29 | 30 | all: clean led.titext 31 | $(CAT) led.titext 32 | 33 | clean: 34 | $(RM) led.titext led.o4 35 | 36 | 37 | led.o4: led.S 38 | led.titext: led.o4 39 | $(LD) $(LDFLAGS) -o $@ $^ 40 | 41 | # pattern rule for the assembler 42 | %o4: %S 43 | $(AS) $(ASFLAGS) -o $@ $< 44 | 45 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 46 | # additional download rules 47 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 48 | .PHONY: download-jtag download-bsl download-gdb 49 | 50 | download-jtag: led.titext 51 | $(PY) -m msp430.jtag.target -e -l /opt/mspgcc/lib $^ --no-close -r 52 | 53 | download-bsl: led.titext 54 | $(PY) -m msp430.bsl.target -e $^ 55 | 56 | download-gdb: led.titext 57 | $(PY) -m msp430.gdb.target -e $^ 58 | 59 | download-mspdebug: led.titext 60 | mspdebug rf2500 "prog $^" exit 61 | -------------------------------------------------------------------------------- /examples/asm/led/README.txt: -------------------------------------------------------------------------------- 1 | LED 2 | === 3 | 4 | Minimalistic assembler program that can be used to test the assembler and 5 | download tools. 6 | 7 | This version uses the peripherals (WDT, PORT1) of a 1xx, 2xx, 4xx or 8 | ValueLine device (not compatiple with 5xx/6xx). 9 | 10 | 11 | Function 12 | -------- 13 | This one toggles the pin P1.0. 14 | 15 | 16 | Building 17 | -------- 18 | Assembling and linking:: 19 | 20 | python -m msp430.asm.as -o led.o4 led.S 21 | python -m msp430.asm.ld --mcu MSP430G2121 -o led.titxt led.o4 22 | 23 | 24 | Usage 25 | ----- 26 | This is like the LED flashing example that comes preprogrammed on some of the 27 | eval boards from TI. The eval boards from TI typically have a LED connected to 28 | the pin P1.0. 29 | 30 | Download:: 31 | 32 | python -m msp430.bsl.target -e led.txt 33 | 34 | The download could also be made with msp430.jtag.target or msp430.gdb.target 35 | 36 | -------------------------------------------------------------------------------- /examples/asm/led/led.S: -------------------------------------------------------------------------------- 1 | ; Test program for msp430.asm.as and msp430.asm.ld 2 | ; 3 | ; This one toggles the pin P1.1. This is like the LED flashing example that 4 | ; comes preprogrammed on some of the eval boards from TI. 5 | 6 | 7 | .text 8 | ; entry point after device reset 9 | RESET: mov #0x5a80, &0x120 ; disable WDT 10 | bis.b #1, &0x22 ; set pin to output 11 | 12 | ; loop toggling the pin and then doing a delay 13 | .L1: xor.b #1, &0x21 ; toggle pin 14 | mov #0xc350, R15 ; init delay loop 15 | .L2: dec R15 ; count down 16 | jnz .L2 ; jump while counter is not zero 17 | jmp .L1 ; loop the toggling part 18 | 19 | 20 | ; set the reset vector (and all the others) to the program start 21 | .section .vectors 22 | .word RESET 23 | .word RESET 24 | .word RESET 25 | .word RESET 26 | .word RESET 27 | .word RESET 28 | .word RESET 29 | .word RESET 30 | .word RESET 31 | .word RESET 32 | .word RESET 33 | .word RESET 34 | .word RESET 35 | .word RESET 36 | .word RESET 37 | .word RESET ; reset vector 38 | 39 | -------------------------------------------------------------------------------- /examples/asm/led/makefile: -------------------------------------------------------------------------------- 1 | # example make file for the led demo 2 | 3 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4 | # setting up the environment 5 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 6 | 7 | # set python path in case we're running from the original 8 | # source repository 9 | PYTHONPATH = ../../.. 10 | export PYTHONPATH 11 | 12 | # set the assembler 13 | AS = python -m msp430.asm.as 14 | ASFLAGS = -v 15 | 16 | # set up the linker 17 | LD = python -m msp430.asm.ld 18 | LDFLAGS = -v --mcu MSP430G2121 19 | 20 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 21 | # commands 22 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 23 | PY = python 24 | AS = $(PY) -m msp430.asm.as 25 | LD = $(PY) -m msp430.asm.ld 26 | RM = $(PY) -m msp430.shell.command rm -f 27 | CAT = $(PY) -m msp430.shell.command cat 28 | 29 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 30 | # the rules used to build 31 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 32 | .PHONY: clean all 33 | 34 | all: clean led.titext 35 | $(CAT) led.titext 36 | 37 | 38 | led.o4: led.S 39 | led.titext: led.o4 40 | $(LD) $(LDFLAGS) -o $@ $^ 41 | 42 | clean: 43 | $(RM) led.titext led.o4 44 | 45 | # pattern rule for the assembler 46 | %o4: %S 47 | $(AS) $(ASFLAGS) -o $@ $< 48 | 49 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 50 | # additional download rules 51 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 52 | .PHONY: download-jtag download-bsl download-gdb 53 | download-jtag: led.titext 54 | $(PY) -m msp430.jtag.target -e -l /opt/mspgcc/lib $^ --no-close -r 55 | download-bsl: led.titext 56 | $(PY) -m msp430.bsl.target -e $^ 57 | download-gdb: led.titext 58 | $(PY) -m msp430.gdb.target -e $^ 59 | -------------------------------------------------------------------------------- /examples/asm/led5x/README.txt: -------------------------------------------------------------------------------- 1 | LED 2 | === 3 | 4 | Minimalistic assembler program that can be used to test the assembler and 5 | download tools. 6 | 7 | This version uses the peripherals on a 5xx/6xx device (WDT, PORT1), MSP430X 8 | instructions and the upper Flash memory (starting at 0x10000). 9 | 10 | 11 | Function 12 | -------- 13 | This one toggles the pin P1.1. 14 | 15 | 16 | Building 17 | -------- 18 | Assembling and linking:: 19 | 20 | python -m msp430.asm.as -x -o led.o4 led.S 21 | python -m msp430.asm.ld --mcu MSP430F5529 -o led.txt led.o4 22 | 23 | 24 | Usage 25 | ----- 26 | This is like the LED flashing example that comes preprogrammed on some of the 27 | eval boards from TI. The eval boards from TI typically have a LED connected to 28 | the pin P1.1. 29 | 30 | Download:: 31 | 32 | python -m msp430.bsl5.hid -e led.txt 33 | 34 | The download could also be made with msp430.jtag.target or msp430.gdb.target 35 | 36 | -------------------------------------------------------------------------------- /examples/asm/led5x/led.S: -------------------------------------------------------------------------------- 1 | ; Test program for msp430.asm.cpp, msp430.asm.as and msp430.asm.ld 2 | ; 3 | ; This one toggles the pin P1.0. This is like the LED flashing example that 4 | ; comes preprogrammed on some of the eval boards from TI. 5 | 6 | 7 | .text 8 | ; entry point after device reset 9 | RESET: mov #0x5a80, &0x015c ; disable WDT 10 | bis.b #1, &0x0204 ; set pin to output 11 | bra #.L1 ; go to the main loop 12 | 13 | ; just for fun, place the main loop in the upper flash memory 14 | .section FLASH2 15 | ; loop toggling the pin and then doing a delay 16 | .L1: xor.b #1, &0x0202 ; toggle pin 17 | mov #0xc350, R15 ; init delay loop 18 | .L2: dec R15 ; count down 19 | jnz .L2 ; jump while counter is not zero 20 | jmp .L1 ; loop the toggling part 21 | 22 | 23 | ; set the reset vector to the program start 24 | .section .vectors 25 | .skip 126 ; skip other vectors 26 | .word RESET ; reset vector 27 | 28 | -------------------------------------------------------------------------------- /examples/asm/led5x/makefile: -------------------------------------------------------------------------------- 1 | # example make file for the led demo 2 | 3 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4 | # setting up the environment 5 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 6 | 7 | # set python path in case we're running from the original 8 | # source repository 9 | PYTHONPATH = ../../.. 10 | export PYTHONPATH 11 | 12 | PY = python 13 | 14 | # set the assembler 15 | AS = $(PY) -m msp430.asm.as 16 | ASFLAGS = -x -v 17 | 18 | # set up the linker 19 | LD = $(PY) -m msp430.asm.ld 20 | LDFLAGS = -v --mcu MSP430F5529 21 | 22 | RM = $(PY) -m msp430.shell.command rm -f 23 | 24 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 25 | # the rules used to build 26 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 27 | .PHONY: clean all 28 | 29 | all: clean led.txt 30 | cat led.txt 31 | 32 | 33 | led.o4: led.S 34 | led.txt: led.o4 35 | ${LD} ${LDFLAGS} -o $@ $^ 36 | 37 | clean: 38 | ${RM} led.txt led.o4 39 | 40 | # pattern rule for the assembler 41 | %o4: %S 42 | ${AS} ${ASFLAGS} -o $@ $< 43 | 44 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 45 | # additional download rules 46 | #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 47 | .PHONY: download-jtag download-bsl download-gdb 48 | download-jtag: led.txt 49 | $(PY) -m msp430.jtag.target -e -l /opt/mspgcc/lib $^ --no-close -r 50 | download-bsl: led.txt 51 | $(PY) -m msp430.bsl5.uart -e $^ 52 | download-usb: led.txt 53 | $(PY) -m msp430.bsl5.hid -e $^ 54 | download-gdb: led.txt 55 | $(PY) -m msp430.gdb.target -e $^ 56 | -------------------------------------------------------------------------------- /examples/nsis-demos/README.txt: -------------------------------------------------------------------------------- 1 | +--------------------------------------------------------+ 2 | ! This file is displayed on startup of the installer. ! 3 | ! And is used here as a short description. ! 4 | +--------------------------------------------------------+ 5 | whats this 6 | ---------- 7 | 8 | two NSIS scripts, used to build executables that provide a 9 | simple GUI for msp430-jtag or msp430-bsl programmers 10 | not installers in the common sense are created, but 11 | executales that extract the required files, program, and 12 | clean up afterwards. 13 | 14 | these exectables can be useful for field updates of msp430 15 | based products. 16 | 17 | short instructions 18 | ------------------ 19 | (there are no long instructions ;-) 20 | 21 | - install NSIS (Nullsoft installer creator): 22 | http://prdownloads.sourceforge.net/nsis/nsis20.exe?download 23 | it will associate the .nsi ending to its tool. you can then 24 | rightclick nsi files to run "makensis", which interprets 25 | these files and build the installer exe. 26 | 27 | - install mspgcc, the installer contains the complete 28 | toolchain but also msp430-jtag and the giveio driver which 29 | you want: 30 | http://prdownloads.sourceforge.net/mspgcc/mspgcc-20040602.exe?download 31 | 32 | - get the installer project files from here (where this file 33 | comes from): 34 | http://cvs.sourceforge.net/viewcvs.py/mspgcc/python/demos/ 35 | 36 | - copy a .a43 file (intel hex format) to the project directory, 37 | edit the defines in jtag-updater.nsi, so that it references 38 | your .a43 and your file descriptions. you must also provide 39 | a readme.txt in the same directory. 40 | 41 | - run makensis on jtag-updater.nsi (right click file in the 42 | windows explorer, the popup menu should have entries for that) 43 | 44 | the resulting executable detects the presence of the giveio 45 | driver (used for parallel port access) and loads (and removes) 46 | it if needed, that way you shouldn't have problems using the 47 | tool on NT/Xp/2k, but the user that runs the exe needs Admin 48 | privileges to install that driver and access the parallel port. 49 | 50 | the bsl-* files can be used to build a similar executable for 51 | the serial bootstraploader. the BSL has the advantage that it 52 | works with a simple serial port (incl. USB<->serial converters) 53 | and no special drivers. 54 | the parallel port on some laptops are not compatible with the 55 | JTAG interface and you dont need extra hardware (but serial port 56 | interfacing on in your product) 57 | 58 | files 59 | ----- 60 | 61 | bsl-updater.ini dialog for the serial port selection, 62 | used by bsl-updater.nsi 63 | 64 | bsl-updater.nsi NSIS script to build the msp430-bsl 65 | based executable 66 | 67 | jtag-updater.nsi NSIS script to build the msp430-jtag 68 | based executable 69 | 70 | readme.txt this help text and also the readme used 71 | in the executables built with the scripts 72 | from above 73 | -------------------------------------------------------------------------------- /examples/nsis-demos/bsl-updater.ini: -------------------------------------------------------------------------------- 1 | [Settings] 2 | NumFields=2 3 | NextButtonText="Next >" 4 | 5 | [Field 1] 6 | Type=Label 7 | Left=10 8 | Right=-10 9 | Top=17 10 | Bottom=25 11 | Text=Select Serial Port 12 | 13 | [Field 2] 14 | Type=DropList 15 | Left=10 16 | Right=-10 17 | Top=30 18 | Bottom=-10 19 | State=COM1 20 | ListItems=COM1|COM2|COM3|COM4|COM5|COM6|COM7|COM8 21 | -------------------------------------------------------------------------------- /examples/nsis-demos/bsl-updater.nsi: -------------------------------------------------------------------------------- 1 | ;This NSIS installer script creates an application rather than an installer 2 | ;It extracts msp430-bsl to a temp location and runs it with a supplied 3 | ;binary (intel hex recomended, elf should work too) and flashes a MSP430 4 | ;processor connected at the parallel port JTAG adapter 5 | ; 6 | ;Requirements: 7 | ;NSIS and pybsl needs to be installed. 8 | ;tested with NSIS 2.0b3 and install-pybsl-20040102.exe 9 | ; 10 | ;The COM port selection is configured in the ini file. 11 | ; 12 | ;(C)2004 Chris Liechti 13 | ; 14 | ;Python style license. In short, you can use this product in commercial 15 | ;and non-commercial applications, modify it, redistribute it. 16 | 17 | 18 | ;User options, project specific 19 | !define IMAGE_DIR "..\..\examples\leds" ;location of the image file 20 | !define IMAGE "leds.a43" ;name of the image file 21 | !define BSLOPTIONS "-e" ;options to msp430-bsl 22 | !define MSPGCCBIN "C:\mspgcc\bin" ;location of msp430-bsl 23 | OutFile "updater.exe" ;The file to write the installer to 24 | Name "Firmware updater" ;The name of the installer 25 | LicenseData "readme.txt" ;readme file 26 | !define COPYRIGHT "BSL Firmware Updater (C)2004 Chris Liechti " 27 | !define BSLHINTS "Make sure that the 'BSL update' jumper is set.$\n" 28 | ;Icon "icon.ico" ;custom installer icon 29 | 30 | ;Other Definitions, usualy not needed to change 31 | !include "Sections.nsh" ;section flags definitions 32 | ShowInstDetails show ;display log texts 33 | InstType /COMPONENTSONLYONCUSTOM ;no install type selection 34 | InstallDir "$TEMP\bsl_updater" ;The default installation directory 35 | LicenseText "Readme" "Next >" ;Texts on the dialogs 36 | SubCaption 0 ": Readme" ;License Agreement page title 37 | SubCaption 3 ": Download" ;Installing Files page title 38 | ReserveFile "${NSISDIR}\Plugins\InstallOptions.dll" 39 | ReserveFile "bsl-updater.ini" 40 | 41 | !define PORT $7 42 | 43 | ;Order of pages, other pages are not shown 44 | Page license ;used as readme page 45 | Page custom SetCustom ;Custom page. InstallOptions gets called in SetCustom. 46 | Page instfiles ;where the work is done 47 | 48 | Section "Download Firmware" mand_sec_exp 49 | SectionIn 1 50 | DetailPrint "${COPYRIGHT}" 51 | 52 | ;Get Install Options dialog user input 53 | ReadINIStr ${PORT} "$PLUGINSDIR\bsl-updater.ini" "Field 2" "State" 54 | 55 | ; wait until the user says we're ready 56 | MessageBox MB_YESNO|MB_ICONEXCLAMATION \ 57 | "Connect target the serial port ${PORT}.$\n${BSLHINTS}$\n\ 58 | Press Yes to update the product or No to abort."\ 59 | IDYES do_download 60 | DetailPrint "User aborted." 61 | Abort 62 | do_download: 63 | DetailPrint "Download on ${PORT}..." 64 | ClearErrors 65 | nsExec::ExecToLog '"$INSTDIR\msp430-bsl" ${BSLOPTIONS} -c ${PORT} "$INSTDIR\${IMAGE}"' 66 | Pop $0 67 | IntCmp $0 0 ext_ok 68 | ;ext_err: 69 | DetailPrint "An error occoured, could not write target." 70 | MessageBox MB_OK|MB_ICONSTOP "An error occoured, could not write target.$\nAborted." 71 | DetailPrint "Aborted" 72 | Abort 73 | ext_ok: 74 | SectionEnd 75 | 76 | 77 | Function .onInit 78 | ;set up working directory 79 | ;$PLUGINSDIR will automatically be removed when the installer closes 80 | InitPluginsDir 81 | File /oname=$PLUGINSDIR\bsl-updater.ini "bsl-updater.ini" 82 | 83 | SetOutPath "$INSTDIR" 84 | File "${IMAGE_DIR}\${IMAGE}" 85 | File "${MSPGCCBIN}\msp430-bsl.exe" 86 | File "${MSPGCCBIN}\python23.dll" 87 | SetOutPath "$INSTDIR\lib" 88 | File "${MSPGCCBIN}\lib\_sre.pyd" 89 | File "${MSPGCCBIN}\lib\PyWinTypes23.dll" 90 | File "${MSPGCCBIN}\lib\shared-bsl.zip" 91 | File "${MSPGCCBIN}\lib\select.pyd" 92 | File "${MSPGCCBIN}\lib\win32event.pyd" 93 | File "${MSPGCCBIN}\lib\win32file.pyd" 94 | SetOutPath "$INSTDIR" 95 | FunctionEnd 96 | 97 | Function .onInstFailed 98 | Call Cleanup 99 | FunctionEnd 100 | 101 | Function .onInstSuccess 102 | Call Cleanup 103 | FunctionEnd 104 | 105 | Function .onUserAbort 106 | Call Cleanup 107 | FunctionEnd 108 | 109 | Function Cleanup 110 | ;Clean up working directory 111 | RMDir /r "$INSTDIR" 112 | FunctionEnd 113 | 114 | ;helpers 115 | Function SetCustom 116 | ;Display the InstallOptions dialog 117 | Push $R0 118 | InstallOptions::dialog "$PLUGINSDIR\bsl-updater.ini" 119 | Pop $R0 120 | Pop $R0 121 | FunctionEnd 122 | -------------------------------------------------------------------------------- /examples/nsis-demos/downloader-demo.m43: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # This is a configuration file for msp430-download 3 | # It shows and describes all available options. 4 | # 5 | # When used as separate file: 6 | # - copy a binary to the destination folder 7 | # - copy this file to the destination folder 8 | # - edit configuration for your needs 9 | # 10 | # When used with a ZIP file: 11 | # - as above copy binary and configuration file, edit config 12 | # - add all files to a zip file and rename it with to a .z43 ending 13 | # 14 | ############################################################################## 15 | 16 | [modes] 17 | ############################################################################## 18 | ## Erase modes: 19 | ## "all" or "mass" erase all memory 20 | ## "main" leave information memory 21 | ## "ask" ask the user 22 | erase_mode = mass 23 | 24 | ############################################################################## 25 | ## Interface selection: 26 | ## "ask" ask the user 27 | ## "1" or "parallel" parallel port. hint: numbers: LPT1, LPT2 etc 28 | ## "TIUSB" or "COMn" USB interface 29 | interface = parallel 30 | 31 | ############################################################################## 32 | ## Program in a loop, so that several targets can easily be programmed 33 | ## Single run and exit if not set. 34 | #loop = Yes 35 | 36 | ############################################################################## 37 | ## Ask again before programming. 38 | ## Recomended if no ther questions before programming are enabled, so that the 39 | ## user has a chance to abort. It is forced on if "loop" programming is on. 40 | #ask_start = Yes 41 | 42 | ############################################################################## 43 | ## Fake the progress bar and increment depending on state, not depending on 44 | ## data. Automaticaly set if the USB JTAG is used. 45 | fake_progess = No 46 | 47 | ############################################################################## 48 | ## For developers only. Remove key or set it to "no" for releases. 49 | ## When enabled, some diagnostic messages are printed to stdout. 50 | #debug = Yes 51 | 52 | ############################################################################## 53 | ## Backend selection: 54 | ## "mspgcc" use MSP430mspgcc.dll 55 | ## "parjtag" use _parjtag and MSP430mspgcc.dll (not recomended) 56 | ## "ti" use MSP430.dll from TI ord 3rd party 57 | ## Autodetect if key is not given. 58 | #backend = mspgcc 59 | 60 | [data] 61 | ############################################################################## 62 | ## A filename can be predefined. 63 | ## File open dialog will not be shown in this case. 64 | filename = leds.a43 65 | 66 | ############################################################################## 67 | ## If defined, a question is displayed, asking the user if he wants to see the 68 | ## readme. 69 | #readme = readme.txt 70 | 71 | ############################################################################## 72 | ## Select the viewer for the readme. Possible values are: 73 | ## "browser" the default webbrowser or text editor, depending on 74 | ## file ending 75 | ## "internal" use a message box (only for very short texts) 76 | viewer = browser 77 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | @echo "Nothing to do." 4 | @echo "Use setup.py to build and or install the python module." 5 | @echo "Make targets: doc-html doc-pdf doc-clean" 6 | 7 | install: 8 | python setup.py install 9 | 10 | 11 | # Sphinx docs 12 | doc-html: 13 | cd doc; $(MAKE) html 14 | 15 | doc-pdf: 16 | cd doc; $(MAKE) latex 17 | cd doc/_build/latex; $(MAKE) 18 | 19 | doc-clean: 20 | cd doc; $(MAKE) clean 21 | 22 | # This watches the file for changes and triggers rebuilds automatically on edits. 23 | doc-auto: 24 | python -m msp430.shell.watch doc/*.rst -x "make doc-html" 25 | 26 | .PHONY: FORCE 27 | -------------------------------------------------------------------------------- /msp430/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsquareplusc/python-msp430-tools/d6400069a9cb91568294eead89191682856a3910/msp430/__init__.py -------------------------------------------------------------------------------- /msp430/asm/README.txt: -------------------------------------------------------------------------------- 1 | ===================== 2 | MSP430[X] Assembler 3 | ===================== 4 | 5 | (C) 2001-2006, 2010-2011 Chris Liechti 6 | 7 | Released under the Simplified BSD license. 8 | 9 | 10 | Overview 11 | -------- 12 | 13 | This is an experimental assembler and linker for the TI MSP430 processor. 14 | It is implemented in Python (get it from www.python.org). 15 | 16 | The assembler (``as.py``) produces a file in a proprietary object format which 17 | can be read by the linker (``ld.py``). The linker writes TI-Text format files 18 | which can be downloaded to the processor or run in the simulator. 19 | 20 | A disassembler (``disassemble.py``) is also provided. 21 | 22 | 23 | Features 24 | -------- 25 | - Complete MSP430 assembler instruction set, including MSP430X instructions 26 | 27 | - Constant registers are used. 28 | 29 | - Assembler directives are implemented as pseudo instructions. 30 | 31 | - Number formats: 32 | 33 | - "0x1af" for hexadecimal 34 | - "0b101" binary 35 | - "123" for decimal 36 | 37 | - Memory layout (segments) is loaded from file optionally use a user supplied 38 | definition file and can be specified 39 | 40 | - Expressions are evaluated by a built in calculator. 41 | (some operators: +, -, *, /, %, <<, >>, |, &, ^, and, or, not) 42 | 43 | 44 | Example 45 | ------- 46 | (for use in a un*x like shell, windows users can replace "./" by "python " 47 | or the full path to the interpreter or use cygwin/bash) 48 | 49 | ./as.py led.S 50 | ./as.py intvec.S 51 | ./ld.py intvec.o4 led.o4 52 | 53 | 54 | Sections 55 | -------- 56 | These are the sections as they are meant to be used by the provided MCU 57 | definition file. The user can supply a different file with completely 58 | different sections, when desired. 59 | 60 | .data 61 | This section is in the RAM. It is meant for initialized variables, see also 62 | .data_init. 63 | 64 | .bss 65 | This section is in the RAM and meant for uninitialized variables. The 66 | startup code should zero out this section. 67 | 68 | .noinit 69 | An other section in the RAM. It is not altered by the startup code. 70 | 71 | .const 72 | This is like .text in the Flash. It is meant for non-code items. 73 | 74 | .text 75 | Code and other things in the Flash. 76 | 77 | .data_init 78 | Automatically created copy of .data but placed in Flash. 79 | The startup code would then copy the contents of this 80 | segment to the .data section in RAM. 81 | 82 | Symbols: 83 | _stack 84 | The last address in RAM, used to initialized the stack pointer. 85 | 86 | .. note:: 87 | 88 | using ``_stack``, copying ``.data_init``, zeroing ``.bss`` needs to 89 | be implemented in startup code which is not provided. 90 | 91 | -------------------------------------------------------------------------------- /msp430/asm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsquareplusc/python-msp430-tools/d6400069a9cb91568294eead89191682856a3910/msp430/asm/__init__.py -------------------------------------------------------------------------------- /msp430/asm/definitions/ADC10.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL ADC10 2 | REGISTER 0x004A NAMED ADC10AE BYTE-ACCESS END-REGISTER 3 | 4 | REGISTER 0x01B0 NAMED ADC10CTL0 WORD-ACCESS 5 | 15 BIT SREF2 6 | 14 BIT SREF1 7 | 13 BIT SREF0 8 | 12 BIT ADC10SHT1 9 | 11 BIT ADC10SHT0 10 | 10 BIT ADC10SR 11 | 9 BIT REFOUT 12 | 8 BIT REFBURST 13 | 7 BIT MSC 14 | 6 BIT REF2_5V 15 | 5 BIT REFON 16 | 4 BIT ADC10ON 17 | 3 BIT ADC10IE 18 | 2 BIT ADC10IFG 19 | 1 BIT ENC 20 | 0 BIT ADC10SC 21 | END-REGISTER 22 | 23 | REGISTER 0x01B2 NAMED ADC10CTL1 WORD-ACCESS 24 | 15 BIT INCH3 25 | 14 BIT INCH2 26 | 13 BIT INCH1 27 | 12 BIT INCH0 28 | 11 BIT SHS1 29 | 10 BIT SHS0 30 | 9 BIT ADC10DF 31 | 8 BIT ISSH 32 | 7 BIT ADC10DIV2 33 | 6 BIT ADC10DIV1 34 | 5 BIT ADC10DIV0 35 | 4 BIT ADC10SSEL1 36 | 3 BIT ADC10SSEL0 37 | 2 BIT CONSEQ1 38 | 1 BIT CONSEQ0 39 | 0 BIT ADC10BUSY 40 | END-REGISTER 41 | 42 | REGISTER 0x01B4 NAMED ADC10MEM WORD-ACCESS END-REGISTER 43 | 44 | REGISTER 0x0048 NAMED ADC10DTC0 BYTE-ACCESS 45 | 3 BIT ADC10TB 46 | 2 BIT ADC10CT 47 | 1 BIT ADC10B1 48 | 0 BIT ADC10FETCH 49 | END-REGISTER 50 | 51 | REGISTER 0x0049 NAMED ADC10DTC1 BYTE-ACCESS END-REGISTER 52 | 53 | REGISTER 0x01BC NAMED ADC10SA WORD-ACCESS END-REGISTER 54 | END-PERIPHERAL 55 | -------------------------------------------------------------------------------- /msp430/asm/definitions/ADC12.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL ADC12 2 | REGISTER 0x01A0 NAMED ADC12CTL0 WORD-ACCESS 3 | 15 BIT SHT13 4 | 14 BIT SHT12 5 | 13 BIT SHT11 6 | 12 BIT SHT10 7 | 11 BIT SHT03 8 | 10 BIT SHT02 9 | 9 BIT SHT01 10 | 8 BIT SHT00 11 | 7 BIT MSC 12 | 6 BIT REF2_5V 13 | 5 BIT REFON 14 | 4 BIT ADC12ON 15 | 3 BIT ADC12OVIE 16 | 2 BIT ADC12_TOVIE 17 | 1 BIT ENC 18 | 0 BIT ADC12SC 19 | END-REGISTER 20 | 21 | REGISTER 0x01A2 NAMED ADC12CTL1 WORD-ACCESS 22 | 15 BIT CSTARTADD3 23 | 14 BIT CSTARTADD2 24 | 13 BIT CSTARTADD1 25 | 12 BIT CSTARTADD0 26 | 11 BIT SHS1 27 | 10 BIT SHS0 28 | 9 BIT SHP 29 | 8 BIT ISSH 30 | 7 BIT ADC12DIV2 31 | 6 BIT ADC12DIV1 32 | 5 BIT ADC12DIV0 33 | 4 BIT ADC12SSEL1 34 | 3 BIT ADC12SSEL0 35 | 2 BIT CONSEQ1 36 | 1 BIT CONSEQ0 37 | 0 BIT ADC12BUSY 38 | END-REGISTER 39 | 40 | REGISTER 0x01A4 NAMED ADC12IFG WORD-ACCESS END-REGISTER 41 | REGISTER 0x01A6 NAMED ADC12IE WORD-ACCESS END-REGISTER 42 | REGISTER 0x01A8 NAMED ADC12IV WORD-ACCESS END-REGISTER 43 | 44 | REGISTER 45 | WORD-ACCESS 46 | 0x0140 NAMED ADC12MEM0 47 | 0x0142 NAMED ADC12MEM1 48 | 0x0144 NAMED ADC12MEM2 49 | 0x0146 NAMED ADC12MEM3 50 | 0x0148 NAMED ADC12MEM4 51 | 0x014A NAMED ADC12MEM5 52 | 0x014C NAMED ADC12MEM6 53 | 0x014E NAMED ADC12MEM7 54 | 0x0150 NAMED ADC12MEM8 55 | 0x0152 NAMED ADC12MEM9 56 | 0x0154 NAMED ADC12MEM10 57 | 0x0156 NAMED ADC12MEM11 58 | 0x0158 NAMED ADC12MEM12 59 | 0x015A NAMED ADC12MEM13 60 | 0x015C NAMED ADC12MEM14 61 | 0x015E NAMED ADC12MEM15 62 | END-REGISTER 63 | 64 | REGISTER 65 | BYTE-ACCESS 66 | 7 BIT EOS 67 | 6 BIT SREF2 68 | 5 BIT SREF1 69 | 4 BIT SREF0 70 | 3 BIT INCH3 71 | 2 BIT INCH2 72 | 1 BIT INCH1 73 | 0 BIT INCH0 74 | 75 | 0x0080 NAMED ADC12MCTL0 76 | 0x0081 NAMED ADC12MCTL1 77 | 0x0082 NAMED ADC12MCTL2 78 | 0x0083 NAMED ADC12MCTL3 79 | 0x0084 NAMED ADC12MCTL4 80 | 0x0085 NAMED ADC12MCTL5 81 | 0x0086 NAMED ADC12MCTL6 82 | 0x0087 NAMED ADC12MCTL7 83 | 0x0088 NAMED ADC12MCTL8 84 | 0x0089 NAMED ADC12MCTL9 85 | 0x008A NAMED ADC12MCTL10 86 | 0x008B NAMED ADC12MCTL11 87 | 0x008C NAMED ADC12MCTL12 88 | 0x008D NAMED ADC12MCTL13 89 | 0x008E NAMED ADC12MCTL14 90 | 0x008F NAMED ADC12MCTL15 91 | END-REGISTER 92 | END-PERIPHERAL 93 | 94 | -------------------------------------------------------------------------------- /msp430/asm/definitions/BCS.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL BCS 2 | REGISTER 0x0056 NAMED DCOCTL BYTE-ACCESS 3 | 7 BIT DCO2 4 | 6 BIT DCO1 5 | 5 BIT DCO0 6 | 4 BIT MOD4 7 | 3 BIT MOD3 8 | 2 BIT MOD2 9 | 1 BIT MOD1 10 | 0 BIT MOD0 11 | END-REGISTER 12 | 13 | REGISTER 0x0057 NAMED BCSCTL1 BYTE-ACCESS 14 | 7 BIT XT2OFF 15 | 6 BIT XTS 16 | 5 BIT DIVA1 17 | 4 BIT DIVA0 18 | # 3 BIT RSEL3 19 | 2 BIT RSEL2 20 | 1 BIT RSEL1 21 | 0 BIT RSEL0 22 | END-REGISTER 23 | 24 | REGISTER 0x0058 NAMED BCSCTL2 BYTE-ACCESS 25 | 7 BIT SELM1 26 | 6 BIT SELM0 27 | 5 BIT DIVM1 28 | 4 BIT DIVM0 29 | 3 BIT SELS 30 | 2 BIT DIVS1 31 | 1 BIT DIVS0 32 | 0 BIT DCOR 33 | END-REGISTER 34 | END-PERIPHERAL 35 | 36 | -------------------------------------------------------------------------------- /msp430/asm/definitions/BCSplus.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL BCSplus 2 | REGISTER 0x0056 NAMED DCOCTL BYTE-ACCESS 3 | 7 BIT DCO2 4 | 6 BIT DCO1 5 | 5 BIT DCO0 6 | 4 BIT MOD4 7 | 3 BIT MOD3 8 | 2 BIT MOD2 9 | 1 BIT MOD1 10 | 0 BIT MOD0 11 | END-REGISTER 12 | 13 | REGISTER 0x0057 NAMED BCSCTL1 BYTE-ACCESS 14 | 7 BIT XT2OFF 15 | 6 BIT XTS 16 | 5 BIT DIVA1 17 | 4 BIT DIVA0 18 | 3 BIT RSEL3 19 | 2 BIT RSEL2 20 | 1 BIT RSEL1 21 | 0 BIT RSEL0 22 | END-REGISTER 23 | 24 | REGISTER 0x0058 NAMED BCSCTL2 BYTE-ACCESS 25 | 7 BIT SELM1 26 | 6 BIT SELM0 27 | 5 BIT DIVM1 28 | 4 BIT DIVM0 29 | 3 BIT SELS 30 | 2 BIT DIVS1 31 | 1 BIT DIVS0 32 | 0 BIT DCOR 33 | END-REGISTER 34 | END-PERIPHERAL 35 | -------------------------------------------------------------------------------- /msp430/asm/definitions/ComparatorA.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL ComparatorA 2 | REGISTER 0x0059 NAMED CACTL1 BYTE-ACCESS 3 | 7 BIT CAEX 4 | 6 BIT CARSEL 5 | 5 BIT CAREF1 6 | 4 BIT CAREF0 7 | 3 BIT CAON 8 | 2 BIT CAIES 9 | 1 BIT CAIE 10 | 0 BIT CAIFG 11 | END-REGISTER 12 | 13 | REGISTER 0x005a NAMED CACTL2 BYTE-ACCESS 14 | 3 BIT P2CA1 15 | 2 BIT P2CA0 16 | 1 BIT CAF 17 | 0 BIT CAOUT 18 | END-REGISTER 19 | 20 | REGISTER 0x005b NAMED CAPD BYTE-ACCESS 21 | 7 BIT CAPD7 22 | 6 BIT CAPD6 23 | 5 BIT CAPD5 24 | 4 BIT CAPD4 25 | 3 BIT CAPD3 26 | 2 BIT CAPD2 27 | 1 BIT CAPD1 28 | 0 BIT CAPD0 29 | END-REGISTER 30 | END-PERIPHERAL 31 | 32 | -------------------------------------------------------------------------------- /msp430/asm/definitions/DAC12.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL DAC12 2 | REGISTER 3 | WORD-ACCESS 4 | 14 BIT DAC12SREF1 5 | 13 BIT DAC12SREF0 6 | 12 BIT DAC12RES 7 | 11 BIT DAC12LSEL1 8 | 10 BIT DAC12LSEL0 9 | 9 BIT DAC12CALON 10 | 8 BIT DAC12IR 11 | 7 BIT DAC12AMP2 12 | 6 BIT DAC12AMP1 13 | 5 BIT DAC12AMP0 14 | 4 BIT DAC12DF 15 | 3 BIT DAC12IE 16 | 2 BIT DAC12IFG 17 | 1 BIT DAC12ENC 18 | 0 BIT DAC12GRP 19 | 20 | 0x01C0 NAMED DAC12_0CTL 21 | 0x01C2 NAMED DAC12_1CTL 22 | END-REGISTER 23 | 24 | REGISTER 0x01C8 NAMED DAC12_0DAT WORD-ACCESS END-REGISTER 25 | REGISTER 0x01CA NAMED DAC12_1DAT WORD-ACCESS END-REGISTER 26 | END-PERIPHERAL 27 | 28 | -------------------------------------------------------------------------------- /msp430/asm/definitions/DMA.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL DMA 2 | REGISTER 0x0122 NAMED DMACTL0 WORD-ACCESS 3 | 11 BIT DMA2TSEL11 4 | 10 BIT DMA2TSEL10 5 | 9 BIT DMA2TSEL9 6 | 8 BIT DMA2TSEL8 7 | 7 BIT DMA1TSEL7 8 | 6 BIT DMA1TSEL6 9 | 5 BIT DMA1TSEL5 10 | 4 BIT DMA1TSEL4 11 | 3 BIT DMA0TSEL3 12 | 2 BIT DMA0TSEL2 13 | 1 BIT DMA0TSEL1 14 | 0 BIT DMA0TSEL0 15 | END-REGISTER 16 | 17 | REGISTER 0x0124 NAMED DMACTL1 WORD-ACCESS 18 | 2 BIT DMA_ONFETCH 19 | 1 BIT ROUND_ROBIN 20 | 0 BIT ENNMI 21 | END-REGISTER 22 | 23 | REGISTER 24 | WORD-ACCESS 25 | 14 BIT DMADT2 26 | 13 BIT DMADT1 27 | 12 BIT DMADT0 28 | 11 BIT DMADSTINCR1 29 | 10 BIT DMADSTINCR0 30 | 9 BIT DMASRCINCR1 31 | 8 BIT DMASRCINCR0 32 | 7 BIT DMA_DSTBYTE 33 | 6 BIT DMA_SRCBYTE 34 | 5 BIT DMALEVEL 35 | 4 BIT DMAEN 36 | 3 BIT DMAIFG 37 | 2 BIT DMAIE 38 | 1 BIT DMA_ABORT 39 | 0 BIT DMAREQ 40 | 41 | 0x01E0 NAMED DMA0CTL WORD-ACCESS 42 | 0x01E8 NAMED DMA1CTL WORD-ACCESS 43 | 0x01F0 NAMED DMA2CTL WORD-ACCESS 44 | END-REGISTER 45 | 46 | REGISTER 0x01E2 NAMED DMA0SA WORD-ACCESS END-REGISTER 47 | REGISTER 0x01E4 NAMED DMA0DA WORD-ACCESS END-REGISTER 48 | REGISTER 0x01E6 NAMED DMA0SZ WORD-ACCESS END-REGISTER 49 | 50 | REGISTER 0x01EA NAMED DMA1SA WORD-ACCESS END-REGISTER 51 | REGISTER 0x01EC NAMED DMA1DA WORD-ACCESS END-REGISTER 52 | REGISTER 0x01EE NAMED DMA1SZ WORD-ACCESS END-REGISTER 53 | 54 | REGISTER 0x01F2 NAMED DMA2SA WORD-ACCESS END-REGISTER 55 | REGISTER 0x01F4 NAMED DMA2DA WORD-ACCESS END-REGISTER 56 | REGISTER 0x01F6 NAMED DMA2SZ WORD-ACCESS END-REGISTER 57 | END-PERIPHERAL 58 | 59 | -------------------------------------------------------------------------------- /msp430/asm/definitions/FLASH.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL FLASH 2 | REGISTER 0x0128 NAMED FCTL1 WORD-ACCESS 3 | 0xa500 VALUE FWKEY 4 | 7 BIT BLKWRT 5 | 6 BIT WRT 6 | 2 BIT MERASE 7 | 1 BIT ERASE 8 | END-REGISTER 9 | 10 | REGISTER 0x012A NAMED FCTL2 WORD-ACCESS 11 | 0xa500 VALUE FWKEY 12 | 7 BIT FSSEL1 13 | 6 BIT FSSEL0 14 | 5 BIT FN5 15 | 4 BIT FN4 16 | 3 BIT FN3 17 | 2 BIT FN2 18 | 1 BIT FN1 19 | 0 BIT FN0 20 | END-REGISTER 21 | 22 | REGISTER 0x012C NAMED FCTL3 WORD-ACCESS 23 | 0xa500 VALUE FWKEY 24 | 5 BIT EMEX 25 | 4 BIT LOCK 26 | 3 BIT WAIT 27 | 2 BIT ACCVIFG 28 | 1 BIT KEYV 29 | 0 BIT BUSY 30 | END-REGISTER 31 | END-PERIPHERAL 32 | -------------------------------------------------------------------------------- /msp430/asm/definitions/MPY32.peripheral: -------------------------------------------------------------------------------- 1 | 2 | PERIPHERAL SFR 3 | REGISTER 0x0000 NAMED IE1 BYTE-ACCESS 4 | 7 BIT UTXIE0 5 | 6 BIT URXIE0 6 | 5 BIT ACCVIE 7 | 4 BIT NMIIE 8 | 1 BIT OFIE 9 | 0 BIT WDTIE 10 | END-REGISTER 11 | 12 | REGISTER 0x0001 NAMED IE2 BYTE-ACCESS 13 | 5 BIT UTXIE1 14 | 4 BIT URXIE1 15 | END-REGISTER 16 | 17 | REGISTER 0x0002 NAMED IFG1 BYTE-ACCESS 18 | 7 BIT UTXIFG0 19 | 6 BIT URXIFG0 20 | 4 BIT NMIIFG 21 | 1 BIT OFIFG 22 | 0 BIT WDTIFG 23 | END-REGISTER 24 | 25 | REGISTER 0x0003 NAMED IFG2 BYTE-ACCESS 26 | 5 BIT UTXIFG1 27 | 4 BIT URXIFG1 28 | END-REGISTER 29 | 30 | REGISTER 0x0004 NAMED ME1 BYTE-ACCESS 31 | 6 BIT USPIE0 32 | END-REGISTER 33 | 34 | REGISTER 0x0005 NAMED ME2 BYTE-ACCESS 35 | 4 BIT USPIE1 36 | END-REGISTER 37 | END-PERIPHERAL 38 | 39 | PERIPHERAL MPY32 40 | REGISTER 0x0130 NAMED MPY WORD-ACCESS END-REGISTER 41 | REGISTER 0x0132 NAMED MPYS WORD-ACCESS END-REGISTER 42 | REGISTER 0x0134 NAMED MAC WORD-ACCESS END-REGISTER 43 | REGISTER 0x0136 NAMED MACS WORD-ACCESS END-REGISTER 44 | REGISTER 0x0138 NAMED OP2 WORD-ACCESS END-REGISTER 45 | REGISTER 0x013a NAMED RESLO WORD-ACCESS END-REGISTER 46 | REGISTER 0x013c NAMED RESHI WORD-ACCESS END-REGISTER 47 | REGISTER 0x013e NAMED SUMEXT WORD-ACCESS END-REGISTER 48 | END-PERIPHERAL 49 | 50 | 51 | -------------------------------------------------------------------------------- /msp430/asm/definitions/MSP430.peripheral: -------------------------------------------------------------------------------- 1 | INCLUDE bit_names 2 | 3 | # status register 4 | PERIPHERAL MSP430_CORE 5 | REGISTER VIRTUAL SR 6 | 8 BIT V 7 | 7 BIT SCG1 8 | 6 BIT SCG0 9 | 5 BIT OSCOFF 10 | 4 BIT CPUOFF 11 | 3 BIT GIE 12 | 2 BIT N 13 | 1 BIT Z 14 | 0 BIT C 15 | 16 | CPUOFF VALUE LPM0 17 | SCG0 CPUOFF + VALUE LPM1 18 | SCG1 CPUOFF + VALUE LPM2 19 | SCG1 SCG0 CPUOFF + + VALUE LPM3 20 | SCG1 SCG0 OSCOFF CPUOFF + + + VALUE LPM4 21 | END-REGISTER 22 | END-PERIPHERAL 23 | -------------------------------------------------------------------------------- /msp430/asm/definitions/MSP430G2231.peripheral: -------------------------------------------------------------------------------- 1 | INCLUDE MSP430 2 | INCLUDE FLASH 3 | INCLUDE USI 4 | INCLUDE P1R 5 | INCLUDE P2R 6 | INCLUDE ADC10 7 | INCLUDE WDT 8 | INCLUDE BCSplus 9 | INCLUDE Timer0_A2 10 | INCLUDE TLV_G2 11 | 12 | PERIPHERAL SFR 13 | REGISTER 0x0000 NAMED IE1 BYTE-ACCESS 14 | 5 BIT ACCVIE 15 | 4 BIT NMIIE 16 | 1 BIT OFIE 17 | 0 BIT WDTIE 18 | END-REGISTER 19 | 20 | REGISTER 0x0001 NAMED IE2 BYTE-ACCESS 21 | END-REGISTER 22 | 23 | REGISTER 0x0002 NAMED IFG1 BYTE-ACCESS 24 | 4 BIT NMIIFG 25 | 1 BIT OFIFG 26 | 0 BIT WDTIFG 27 | END-REGISTER 28 | 29 | REGISTER 0x0003 NAMED IFG2 BYTE-ACCESS 30 | END-REGISTER 31 | END-PERIPHERAL 32 | 33 | PERIPHERAL vectors 34 | 4 VALUE PORT1_VECTOR # 0xFFE4 Port 1 35 | 6 VALUE PORT2_VECTOR # 0xFFE6 Port 2 36 | 8 VALUE USI_VECTOR # 0xFFE8 USI 37 | 10 VALUE ADC10_VECTOR # 0xFFEA ADC10 38 | 16 VALUE TIMERA1_VECTOR # 0xFFF0 Timer A CC1-2, TA 39 | 18 VALUE TIMERA0_VECTOR # 0xFFF2 Timer A CC0 40 | 20 VALUE WDT_VECTOR # 0xFFF4 Watchdog Timer 41 | 28 VALUE NMI_VECTOR # 0xFFFC Non-maskable 42 | END-PERIPHERAL 43 | -------------------------------------------------------------------------------- /msp430/asm/definitions/P1.peripheral: -------------------------------------------------------------------------------- 1 | INCLUDE bit_names 2 | 3 | PERIPHERAL P1 4 | REGISTER 0x0020 NAMED P1IN BYTE-ACCESS 8bits END-REGISTER 5 | REGISTER 0x0021 NAMED P1OUT BYTE-ACCESS 8bits END-REGISTER 6 | REGISTER 0x0022 NAMED P1DIR BYTE-ACCESS 8bits END-REGISTER 7 | REGISTER 0x0023 NAMED P1IFG BYTE-ACCESS 8bits END-REGISTER 8 | REGISTER 0x0024 NAMED P1IES BYTE-ACCESS 8bits END-REGISTER 9 | REGISTER 0x0025 NAMED P1IE BYTE-ACCESS 8bits END-REGISTER 10 | REGISTER 0x0026 NAMED P1SEL BYTE-ACCESS 8bits END-REGISTER 11 | END-PERIPHERAL 12 | -------------------------------------------------------------------------------- /msp430/asm/definitions/P1R.peripheral: -------------------------------------------------------------------------------- 1 | INCLUDE bit_names 2 | 3 | PERIPHERAL P1R 4 | REGISTER 0x0020 NAMED P1IN BYTE-ACCESS 8bits END-REGISTER 5 | REGISTER 0x0021 NAMED P1OUT BYTE-ACCESS 8bits END-REGISTER 6 | REGISTER 0x0022 NAMED P1DIR BYTE-ACCESS 8bits END-REGISTER 7 | REGISTER 0x0023 NAMED P1IFG BYTE-ACCESS 8bits END-REGISTER 8 | REGISTER 0x0024 NAMED P1IES BYTE-ACCESS 8bits END-REGISTER 9 | REGISTER 0x0025 NAMED P1IE BYTE-ACCESS 8bits END-REGISTER 10 | REGISTER 0x0026 NAMED P1SEL BYTE-ACCESS 8bits END-REGISTER 11 | REGISTER 0x0027 NAMED P1REN BYTE-ACCESS 8bits END-REGISTER 12 | REGISTER 0x0041 NAMED P1SEL2 BYTE-ACCESS 8bits END-REGISTER 13 | END-PERIPHERAL 14 | -------------------------------------------------------------------------------- /msp430/asm/definitions/P2.peripheral: -------------------------------------------------------------------------------- 1 | INCLUDE bit_names 2 | 3 | PERIPHERAL P2 4 | REGISTER 0x0028 NAMED P2IN BYTE-ACCESS 8bits END-REGISTER 5 | REGISTER 0x0029 NAMED P2OUT BYTE-ACCESS 8bits END-REGISTER 6 | REGISTER 0x002a NAMED P2DIR BYTE-ACCESS 8bits END-REGISTER 7 | REGISTER 0x002b NAMED P2IFG BYTE-ACCESS 8bits END-REGISTER 8 | REGISTER 0x002c NAMED P2IES BYTE-ACCESS 8bits END-REGISTER 9 | REGISTER 0x002d NAMED P2IE BYTE-ACCESS 8bits END-REGISTER 10 | REGISTER 0x002e NAMED P2SEL BYTE-ACCESS 8bits END-REGISTER 11 | END-PERIPHERAL 12 | -------------------------------------------------------------------------------- /msp430/asm/definitions/P2R.peripheral: -------------------------------------------------------------------------------- 1 | INCLUDE bit_names 2 | 3 | PERIPHERAL P2R 4 | REGISTER 0x0028 NAMED P2IN BYTE-ACCESS 8bits END-REGISTER 5 | REGISTER 0x0029 NAMED P2OUT BYTE-ACCESS 8bits END-REGISTER 6 | REGISTER 0x002a NAMED P2DIR BYTE-ACCESS 8bits END-REGISTER 7 | REGISTER 0x002b NAMED P2IFG BYTE-ACCESS 8bits END-REGISTER 8 | REGISTER 0x002c NAMED P2IES BYTE-ACCESS 8bits END-REGISTER 9 | REGISTER 0x002d NAMED P2IE BYTE-ACCESS 8bits END-REGISTER 10 | REGISTER 0x002e NAMED P2SEL BYTE-ACCESS 8bits END-REGISTER 11 | REGISTER 0x002f NAMED P2REN BYTE-ACCESS 8bits END-REGISTER 12 | REGISTER 0x0042 NAMED P2SEL2 BYTE-ACCESS 8bits END-REGISTER 13 | END-PERIPHERAL 14 | -------------------------------------------------------------------------------- /msp430/asm/definitions/P3.peripheral: -------------------------------------------------------------------------------- 1 | INCLUDE bit_names 2 | 3 | PERIPHERAL P3 4 | REGISTER 0x0018 NAMED P3IN BYTE-ACCESS 8bits END-REGISTER 5 | REGISTER 0x0019 NAMED P3OUT BYTE-ACCESS 8bits END-REGISTER 6 | REGISTER 0x001a NAMED P3DIR BYTE-ACCESS 8bits END-REGISTER 7 | REGISTER 0x001b NAMED P3SEL BYTE-ACCESS 8bits END-REGISTER 8 | END-PERIPHERAL 9 | 10 | -------------------------------------------------------------------------------- /msp430/asm/definitions/P4.peripheral: -------------------------------------------------------------------------------- 1 | INCLUDE bit_names 2 | 3 | PERIPHERAL P4 4 | REGISTER 0x001c NAMED P4IN BYTE-ACCESS 8bits END-REGISTER 5 | REGISTER 0x001d NAMED P4OUT BYTE-ACCESS 8bits END-REGISTER 6 | REGISTER 0x001e NAMED P4DIR BYTE-ACCESS 8bits END-REGISTER 7 | REGISTER 0x001f NAMED P4SEL BYTE-ACCESS 8bits END-REGISTER 8 | END-PERIPHERAL 9 | 10 | -------------------------------------------------------------------------------- /msp430/asm/definitions/P5.peripheral: -------------------------------------------------------------------------------- 1 | INCLUDE bit_names 2 | 3 | PERIPHERAL P5 4 | REGISTER 0x0030 NAMED P5IN BYTE-ACCESS 8bits END-REGISTER 5 | REGISTER 0x0031 NAMED P5OUT BYTE-ACCESS 8bits END-REGISTER 6 | REGISTER 0x0032 NAMED P5DIR BYTE-ACCESS 8bits END-REGISTER 7 | REGISTER 0x0033 NAMED P5SEL BYTE-ACCESS 8bits END-REGISTER 8 | END-PERIPHERAL 9 | 10 | -------------------------------------------------------------------------------- /msp430/asm/definitions/P6.peripheral: -------------------------------------------------------------------------------- 1 | INCLUDE bit_names 2 | 3 | PERIPHERAL P6 4 | REGISTER 0x0034 NAMED P6IN BYTE-ACCESS 8bits END-REGISTER 5 | REGISTER 0x0035 NAMED P6OUT BYTE-ACCESS 8bits END-REGISTER 6 | REGISTER 0x0036 NAMED P6DIR BYTE-ACCESS 8bits END-REGISTER 7 | REGISTER 0x0037 NAMED P6SEL BYTE-ACCESS 8bits END-REGISTER 8 | END-PERIPHERAL 9 | 10 | -------------------------------------------------------------------------------- /msp430/asm/definitions/SVS.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL SVS 2 | REGISTER 0x0055 NAMED SVSCTL BYTE-ACCESS 3 | 7 BIT VLD2 4 | 6 BIT VLD2 5 | 5 BIT VLD1 6 | 4 BIT VLD0 7 | 3 BIT PORON 8 | 2 BIT SVSON 9 | 1 BIT SYSOP 10 | 0 BIT SVSFG 11 | END-REGISTER 12 | END-PERIPHERAL 13 | 14 | -------------------------------------------------------------------------------- /msp430/asm/definitions/TLV.peripheral: -------------------------------------------------------------------------------- 1 | # TLV Calibration Data Structure 2 | PERIPHERAL TLV 3 | 0x01 VALUE TAG_DCO_30 # Tag for DCO30 Calibration Data 4 | 0x10 VALUE TAG_ADC12_1 # Tag for ADC12_1 Calibration Data 5 | 0xFE VALUE TAG_EMPTY # Tag for Empty Data Field in Calibration Data 6 | 7 | REGISTER 0x10C0 NAMED TLV_CHECKSUM WORD-ACCESS END-REGISTER 8 | REGISTER 0x10F6 NAMED TLV_DCO_30_TAG BYTE-ACCESS END-REGISTER 9 | REGISTER 0x10F7 NAMED TLV_DCO_30_LEN BYTE-ACCESS END-REGISTER 10 | REGISTER 0x10DA NAMED TLV_ADC12_1_TAG BYTE-ACCESS END-REGISTER 11 | REGISTER 0x10DB NAMED TLV_ADC12_1_LEN BYTE-ACCESS END-REGISTER 12 | 13 | REGISTER 0x10F8 NAMED CALDCO_16MHZ BYTE-ACCESS END-REGISTER 14 | REGISTER 0x10F9 NAMED CALBC1_16MHZ BYTE-ACCESS END-REGISTER 15 | REGISTER 0x10FA NAMED CALDCO_12MHZ BYTE-ACCESS END-REGISTER 16 | REGISTER 0x10FB NAMED CALBC1_12MHZ BYTE-ACCESS END-REGISTER 17 | REGISTER 0x10FC NAMED CALDCO_8MHZ BYTE-ACCESS END-REGISTER 18 | REGISTER 0x10FD NAMED CALBC1_8MHZ BYTE-ACCESS END-REGISTER 19 | REGISTER 0x10FE NAMED CALDCO_1MHZ BYTE-ACCESS END-REGISTER 20 | REGISTER 0x10FF NAMED CALBC1_1MHZ BYTE-ACCESS END-REGISTER 21 | 22 | 0x0007 VALUE CAL_ADC_25T85 # Index for 2.5V/85Deg Cal. Value 23 | 0x0006 VALUE CAL_ADC_25T30 # Index for 2.5V/30Deg Cal. Value 24 | 0x0005 VALUE CAL_ADC_25VREF_FACTOR # Index for 2.5V Ref. Factor 25 | 0x0004 VALUE CAL_ADC_15T85 # Index for 1.5V/85Deg Cal. Value 26 | 0x0003 VALUE CAL_ADC_15T30 # Index for 1.5V/30Deg Cal. Value 27 | 0x0002 VALUE CAL_ADC_15VREF_FACTOR # Index for ADC 1.5V Ref. Factor 28 | 0x0001 VALUE CAL_ADC_OFFSET # Index for ADC Offset 29 | 0x0000 VALUE CAL_ADC_GAIN_FACTOR # Index for ADC Gain Factor 30 | 31 | 0x0000 VALUE CAL_DCO_16MHZ # Index for DCOCTL Calibration Data for 16MHz 32 | 0x0001 VALUE CAL_BC1_16MHZ # Index for BCSCTL1 Calibration Data for 16MHz 33 | 0x0002 VALUE CAL_DCO_12MHZ # Index for DCOCTL Calibration Data for 12MHz 34 | 0x0003 VALUE CAL_BC1_12MHZ # Index for BCSCTL1 Calibration Data for 12MHz 35 | 0x0004 VALUE CAL_DCO_8MHZ # Index for DCOCTL Calibration Data for 8MHz 36 | 0x0005 VALUE CAL_BC1_8MHZ # Index for BCSCTL1 Calibration Data for 8MHz 37 | 0x0006 VALUE CAL_DCO_1MHZ # Index for DCOCTL Calibration Data for 1MHz 38 | 0x0007 VALUE CAL_BC1_1MHZ # Index for BCSCTL1 Calibration Data for 1MHz 39 | END-PERIPHERAL 40 | -------------------------------------------------------------------------------- /msp430/asm/definitions/TLV_G2.peripheral: -------------------------------------------------------------------------------- 1 | # TLV Calibration Data Structure 2 | PERIPHERAL TLV_G2 3 | REGISTER 0x10FE NAMED CALDCO_1MHZ BYTE-ACCESS END-REGISTER 4 | REGISTER 0x10FF NAMED CALBC1_1MHZ BYTE-ACCESS END-REGISTER 5 | END-PERIPHERAL 6 | -------------------------------------------------------------------------------- /msp430/asm/definitions/Timer0_A2.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL Timer0_A2 2 | REGISTER 0x0160 NAMED TACTL WORD-ACCESS 3 | 9 BIT TASSEL1 4 | 8 BIT TASSEL0 5 | 7 BIT ID1 6 | 6 BIT ID0 7 | 5 BIT MC1 8 | 4 BIT MC0 9 | #~ 3 BIT 10 | 2 BIT TACLR 11 | 1 BIT TAIE 12 | 0 BIT TAIFG 13 | END-REGISTER 14 | 15 | REGISTER 0x0170 NAMED TAR WORD-ACCESS END-REGISTER 16 | 17 | REGISTER 18 | WORD-ACCESS 19 | 15 BIT CM1 20 | 14 BIT CM0 21 | 13 BIT CCIS1 22 | 12 BIT CCIS0 23 | 11 BIT SCS 24 | 10 BIT SCCI 25 | #~ 9 BIT 26 | 8 BIT CAP 27 | 7 BIT OUTMOD2 28 | 6 BIT OUTMOD1 29 | 5 BIT OUTMOD0 30 | 4 BIT CCIE 31 | 3 BIT CCI 32 | 2 BIT OUT 33 | 1 BIT COV 34 | 0 BIT CCIFG 35 | 36 | 0x0162 NAMED TACCTL0 37 | 0x0164 NAMED TACCTL1 38 | END-REGISTER 39 | 40 | REGISTER 0x0172 NAMED TACCR0 WORD-ACCESS END-REGISTER 41 | REGISTER 0x0174 NAMED TACCR1 WORD-ACCESS END-REGISTER 42 | REGISTER 0x012E NAMED TAIV WORD-ACCESS END-REGISTER 43 | END-PERIPHERAL 44 | -------------------------------------------------------------------------------- /msp430/asm/definitions/Timer0_A3.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL Timer0_A3 2 | REGISTER 0x0160 NAMED TACTL WORD-ACCESS 3 | 9 BIT TASSEL1 4 | 8 BIT TASSEL0 5 | 7 BIT ID1 6 | 6 BIT ID0 7 | 5 BIT MC1 8 | 4 BIT MC0 9 | #~ 3 BIT 10 | 2 BIT TACLR 11 | 1 BIT TAIE 12 | 0 BIT TAIFG 13 | END-REGISTER 14 | 15 | REGISTER 0x0170 NAMED TAR WORD-ACCESS END-REGISTER 16 | 17 | REGISTER 18 | WORD-ACCESS 19 | 15 BIT CM1 20 | 14 BIT CM0 21 | 13 BIT CCIS1 22 | 12 BIT CCIS0 23 | 11 BIT SCS 24 | 10 BIT SCCI 25 | #~ 9 BIT 26 | 8 BIT CAP 27 | 7 BIT OUTMOD2 28 | 6 BIT OUTMOD1 29 | 5 BIT OUTMOD0 30 | 4 BIT CCIE 31 | 3 BIT CCI 32 | 2 BIT OUT 33 | 1 BIT COV 34 | 0 BIT CCIFG 35 | 36 | 0x0162 NAMED TACCTL0 37 | 0x0164 NAMED TACCTL1 38 | 0x0166 NAMED TACCTL2 39 | END-REGISTER 40 | 41 | REGISTER 0x0172 NAMED TACCR0 WORD-ACCESS END-REGISTER 42 | REGISTER 0x0174 NAMED TACCR1 WORD-ACCESS END-REGISTER 43 | REGISTER 0x0176 NAMED TACCR2 WORD-ACCESS END-REGISTER 44 | REGISTER 0x012E NAMED TAIV WORD-ACCESS END-REGISTER 45 | END-PERIPHERAL 46 | -------------------------------------------------------------------------------- /msp430/asm/definitions/Timer0_B7.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL Timer0_B7 2 | REGISTER 0x0180 NAMED TBCTL WORD-ACCESS 3 | 14 BIT TBCLGRP1 4 | 13 BIT TBCLGRP0 5 | 12 BIT CNTL1 6 | 11 BIT CNTL0 7 | #~ 10 BIT 8 | 9 BIT TBSSEL1 9 | 8 BIT TBSSEL0 10 | 7 BIT ID1 11 | 6 BIT ID0 12 | 5 BIT MC1 13 | 4 BIT MC0 14 | #~ 3 BIT 15 | 2 BIT TBCLR 16 | 1 BIT TBIE 17 | 0 BIT TBIFG 18 | END-REGISTER 19 | 20 | REGISTER 0x0190 NAMED TBR WORD-ACCESS END-REGISTER 21 | 22 | REGISTER 23 | WORD-ACCESS 24 | 15 BIT CM1 25 | 14 BIT CM0 26 | 13 BIT CCIS1 27 | 12 BIT CCIS0 28 | 11 BIT SCS 29 | 10 BIT CLLD1 30 | 9 BIT CLLD0 31 | 8 BIT CAP 32 | 7 BIT OUTMOD2 33 | 6 BIT OUTMOD1 34 | 5 BIT OUTMOD0 35 | 4 BIT CCIE 36 | 3 BIT CCI 37 | 2 BIT OUT 38 | 1 BIT COV 39 | 0 BIT CCIFG 40 | 41 | 0x0182 NAMED TBCCTL0 42 | 0x0184 NAMED TBCCTL1 43 | 0x0186 NAMED TBCCTL2 44 | 0x0188 NAMED TBCCTL3 45 | 0x018a NAMED TBCCTL4 46 | 0x018c NAMED TBCCTL5 47 | 0x018e NAMED TBCCTL6 48 | END-REGISTER 49 | 50 | REGISTER 0x0192 NAMED TBCCR0 WORD-ACCESS END-REGISTER 51 | REGISTER 0x0194 NAMED TBCCR1 WORD-ACCESS END-REGISTER 52 | REGISTER 0x0196 NAMED TBCCR2 WORD-ACCESS END-REGISTER 53 | REGISTER 0x0198 NAMED TBCCR3 WORD-ACCESS END-REGISTER 54 | REGISTER 0x019a NAMED TBCCR4 WORD-ACCESS END-REGISTER 55 | REGISTER 0x019c NAMED TBCCR5 WORD-ACCESS END-REGISTER 56 | REGISTER 0x019e NAMED TBCCR6 WORD-ACCESS END-REGISTER 57 | REGISTER 0x011E NAMED TBIV WORD-ACCESS END-REGISTER 58 | END-PERIPHERAL 59 | 60 | 61 | -------------------------------------------------------------------------------- /msp430/asm/definitions/USART0.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL USART0 2 | REGISTER 0x0070 NAMED U0CTL BYTE-ACCESS 3 | 7 BIT PENA 4 | 6 BIT PEV 5 | 5 BIT SPB 6 | 4 BIT CHAR 7 | 3 BIT LISTEN 8 | 2 BIT SYNC 9 | 1 BIT MM 10 | 0 BIT SWRST 11 | END-REGISTER 12 | 13 | REGISTER 0x0071 NAMED U0TCTL BYTE-ACCESS 14 | # 7 BIT 15 | 6 BIT CKPL 16 | 5 BIT SSEL1 17 | 4 BIT SSEL0 18 | 3 BIT URXSE 19 | 2 BIT TXWAKE 20 | # 1 BIT 21 | 0 BIT TXEPT 22 | END-REGISTER 23 | 24 | REGISTER 0x0072 NAMED U0RCTL BYTE-ACCESS 25 | 7 BIT FE 26 | 6 BIT PE 27 | 5 BIT OE 28 | 4 BIT BRK 29 | 3 BIT URXEIE 30 | 2 BIT URXWIE 31 | 1 BIT RXWAKE 32 | 0 BIT RXERR 33 | END-REGISTER 34 | 35 | REGISTER 0x0073 NAMED U0MCTL BYTE-ACCESS END-REGISTER 36 | REGISTER 0x0074 NAMED U0BR0 BYTE-ACCESS END-REGISTER 37 | REGISTER 0x0075 NAMED U0BR1 BYTE-ACCESS END-REGISTER 38 | REGISTER 0x0076 NAMED U0RXBUF BYTE-ACCESS END-REGISTER 39 | REGISTER 0x0077 NAMED U0TXBUF BYTE-ACCESS END-REGISTER 40 | END-PERIPHERAL 41 | 42 | # XXX I2C mode 43 | -------------------------------------------------------------------------------- /msp430/asm/definitions/USART1.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL USART1 2 | REGISTER 0x0078 NAMED U0CTL BYTE-ACCESS 3 | 7 BIT PENA # RXDMAEN 4 | 6 BIT PEV # TXDMAEN 5 | 5 BIT SPB # I2C 6 | 4 BIT CHAR # XA 7 | 3 BIT LISTEN 8 | 2 BIT SYNC 9 | 1 BIT MM # MST 10 | 0 BIT SWRST 11 | END-REGISTER 12 | 13 | REGISTER 0x0079 NAMED U0TCTL BYTE-ACCESS 14 | 7 BIT CKPH 15 | 6 BIT CKPL 16 | 5 BIT SSEL1 17 | 4 BIT SSEL0 18 | 3 BIT URXSE 19 | 2 BIT TXWAKE 20 | 1 BIT STC 21 | 0 BIT TXEPT 22 | END-REGISTER 23 | 24 | REGISTER 0x007a NAMED U0RCTL BYTE-ACCESS 25 | 7 BIT FE 26 | 6 BIT PE 27 | 5 BIT OE 28 | 4 BIT BRK 29 | 3 BIT URXEIE 30 | 2 BIT URXWIE 31 | 1 BIT RXWAKE 32 | 0 BIT RXERR 33 | END-REGISTER 34 | 35 | REGISTER 0x007b NAMED U0MCTL BYTE-ACCESS END-REGISTER 36 | REGISTER 0x007c NAMED U0BR0 BYTE-ACCESS END-REGISTER 37 | REGISTER 0x007d NAMED U0BR1 BYTE-ACCESS END-REGISTER 38 | REGISTER 0x007e NAMED U0RXBUF BYTE-ACCESS END-REGISTER 39 | REGISTER 0x007f NAMED U0TXBUF BYTE-ACCESS END-REGISTER 40 | END-PERIPHERAL 41 | 42 | -------------------------------------------------------------------------------- /msp430/asm/definitions/USI.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL USI 2 | REGISTER 0x0078 NAMED USICTL0 BYTE-ACCESS 3 | 7 BIT USIPE7 4 | 6 BIT USIPE6 5 | 5 BIT USIPE5 6 | 4 BIT USILSB 7 | 3 BIT USIMST 8 | 2 BIT USIGE 9 | 1 BIT USIOE 10 | 0 BIT USISWRST 11 | END-REGISTER 12 | 13 | REGISTER 0x0079 NAMED USICTL1 BYTE-ACCESS 14 | 7 BIT USICKPH 15 | 6 BIT USII2C 16 | 5 BIT USISTTIE 17 | 4 BIT USIIE 18 | 3 BIT USIAL 19 | 2 BIT USISTP 20 | 1 BIT USISTTIFG 21 | 0 BIT USIIFG 22 | END-REGISTER 23 | 24 | REGISTER 0x007a NAMED USICKCTL BYTE-ACCESS 25 | 7 BIT USIDIV2 26 | 6 BIT USIDIV1 27 | 5 BIT USIDIV0 28 | 4 BIT USISSEL2 29 | 3 BIT USISSEL1 30 | 2 BIT USISSEL0 31 | 1 BIT USICKPL 32 | 0 BIT USISWCLK 33 | END-REGISTER 34 | 35 | REGISTER 0x007b NAMED USICNT BYTE-ACCESS 36 | 7 BIT USISCLREL 37 | 6 BIT USI16B 38 | 5 BIT USIIFGCC 39 | 4 BIT USICNT4 40 | 3 BIT USICNT3 41 | 2 BIT USICNT2 42 | 1 BIT USICNT1 43 | 0 BIT USICNT0 44 | END-REGISTER 45 | 46 | REGISTER 0x007c NAMED USISRL BYTE-ACCESS END-REGISTER 47 | REGISTER 0x007d NAMED USISRH BYTE-ACCESS END-REGISTER 48 | 49 | # 16 bit registers 50 | REGISTER 0x0078 NAMED USICTL WORD-ACCESS END-REGISTER 51 | REGISTER 0x007a NAMED USICCTL WORD-ACCESS END-REGISTER 52 | REGISTER 0x007c NAMED USISR WORD-ACCESS END-REGISTER 53 | END-PERIPHERAL 54 | -------------------------------------------------------------------------------- /msp430/asm/definitions/WDT.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL WDT 2 | REGISTER 0x0120 NAMED WDTCTL WORD-ACCESS 3 | 0x5a00 VALUE WDTPW 4 | 7 BIT WDTHOLD 5 | 6 BIT WDTNMIES 6 | 5 BIT WDTNMI 7 | 4 BIT WDTTMSEL 8 | 3 BIT WDTCNTCL 9 | 2 BIT WDTSSEL 10 | 1 BIT WDTIS1 11 | 0 BIT WDTIS0 12 | END-REGISTER 13 | 14 | # Aliases 15 | 0x0000 VALUE WDTIS_0 16 | 0x0001 VALUE WDTIS_1 17 | 0x0002 VALUE WDTIS_2 18 | 0x0003 VALUE WDTIS_3 19 | 20 | # WDT is clocked by fMCLK (assumed 1MHz) 21 | WDTPW WDTTMSEL WDTCNTCL | | VALUE WDT_MDLY_32 # 32ms interval (default) 22 | WDTPW WDTTMSEL WDTCNTCL WDTIS0 | | | VALUE WDT_MDLY_8 # 8ms 23 | WDTPW WDTTMSEL WDTCNTCL WDTIS1 | | | VALUE WDT_MDLY_0_5 # 0.5ms 24 | WDTPW WDTTMSEL WDTCNTCL WDTIS1 WDTIS0 | | | | VALUE WDT_MDLY_0_064 # 0.064ms 25 | 26 | # WDT is clocked by fACLK (assumed 32kHz) 27 | WDTPW WDTTMSEL WDTCNTCL WDTSSEL | | | VALUE WDT_ADLY_1000 # 1000ms 28 | WDTPW WDTTMSEL WDTCNTCL WDTSSEL WDTIS0 | | | | VALUE WDT_ADLY_250 # 250ms 29 | WDTPW WDTTMSEL WDTCNTCL WDTSSEL WDTIS1 | | | | VALUE WDT_ADLY_16 # 16ms 30 | WDTPW WDTTMSEL WDTCNTCL WDTSSEL WDTIS1 WDTIS0 | | | | | VALUE WDT_ADLY_1_9 # 1.9ms 31 | 32 | # Watchdog mode -> reset after expired time 33 | # WDT is clocked by fMCLK (assumed 1MHz) 34 | WDTPW WDTCNTCL | VALUE WDT_MRST_32 # 32ms interval (default) 35 | WDTPW WDTCNTCL WDTIS0 | | VALUE WDT_MRST_8 # 8ms 36 | WDTPW WDTCNTCL WDTIS1 | | VALUE WDT_MRST_0_5 # 0.5ms 37 | WDTPW WDTCNTCL WDTIS1 WDTIS0 | | | VALUE WDT_MRST_0_064 # 0.064ms 38 | 39 | # WDT is clocked by fACLK (assumed 32kHz) 40 | WDTPW WDTCNTCL WDTSSEL | | VALUE WDT_ARST_1000 # 1000ms 41 | WDTPW WDTCNTCL WDTSSEL WDTIS0 | | | VALUE WDT_ARST_250 # 250ms 42 | WDTPW WDTCNTCL WDTSSEL WDTIS1 | | | VALUE WDT_ARST_16 # 16ms 43 | WDTPW WDTCNTCL WDTSSEL WDTIS1 WDTIS0 | | | | VALUE WDT_ARST_1_9 # 1.9ms 44 | 45 | END-PERIPHERAL 46 | -------------------------------------------------------------------------------- /msp430/asm/definitions/_parse_devices.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2013 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Parse TI's device.csv and output lines for msp430-mcu-list.txt. The output is 10 | not final, it has to manually pasted into the correct template sections in the 11 | file (based on family and interrupt table size). 12 | """ 13 | import csv 14 | import collections 15 | 16 | # column names in the device.csv 17 | msp430_device_info = collections.namedtuple( 18 | 'msp430_device_info', ( 19 | 'name', 'CPU_TYPE', 'CPU_Bugs', 'MPY_TYPE', 20 | 'SBW', 'EEM', 'BREAKPOINTS', 'CLOCKCONTROL', 'CYCLECOUNTER', 'STACKSIZE', 21 | 'RAMStart', 'RAMEnd', 'RAMStart2', 'RAMEnd2', 'USBRAMStart', 22 | 'USBRAMEnd', 'MirrowedRAMSource', 'MirrowedRAMStart', 'MirrowRAMEnd', 23 | 'BSLStart', 'BSLSize', 'BSLEnd', 'INFOStart', 'INFOSize', 'INFOEnd', 24 | 'INFOA', 'INFOB', 'INFOC', 'INFOD', 'FStart', 'FEnd', 'FStart2', 25 | 'FEnd2', 'Signature_Start', 'Signature_Size', 'INTStart', 'INTEnd')) 26 | 27 | # create a mapping with all devices 28 | devmap = {} 29 | 30 | 31 | def numberify(x): 32 | """convert hex numbers, return original string on failure""" 33 | try: 34 | return int(x, 16) 35 | except ValueError: 36 | return x 37 | 38 | # read the devices file 39 | devices = csv.reader(open('../include/upstream/devices.csv', 'rb')) 40 | for row in devices: 41 | #~ print row 42 | if not row or row[0][0] == '#': 43 | continue 44 | device = msp430_device_info(*([row[0].upper()] + [numberify(x) for x in row[1:]])) 45 | 46 | devmap[device.name] = (1 + device.INTEnd - device.INTStart), device, (device.FStart2 != 0) 47 | 48 | 49 | # output devices in groups of the same vector table size, alphabetically sorted within each group. 50 | last_vecsize = None 51 | for vecsize, device, has_highmem in sorted(devmap.values()): 52 | # print group name if vector size changes (list is sorted by this) 53 | if last_vecsize != vecsize: 54 | last_vecsize = vecsize 55 | print("Vectors: %d" % vecsize) 56 | # alter output depending on memory present above 64kB 57 | if has_highmem: 58 | print(" %-20s 0x%04x-0x%04x 0x%04x-0x%04x 0x%08x-0x%08x # %dkB %dkB + %dkB = %dkB" % ( 59 | device.name, 60 | device.RAMStart, device.RAMEnd, 61 | device.FStart, device.FEnd, 62 | device.FStart2, device.FEnd2, 63 | 64 | (1 + device.RAMEnd - device.RAMStart) / 1024, 65 | ((1 + device.FEnd - device.FStart) + (1 + device.INTEnd - device.INTStart)) / 1024, 66 | (1 + device.FEnd2 - device.FStart2) / 1024, 67 | ((1 + device.FEnd - device.FStart) + (1 + device.FEnd2 - device.FStart2) + (1 + device.INTEnd - device.INTStart)) / 1024, 68 | )) 69 | 70 | else: 71 | print(" %-20s 0x%04x-0x%04x 0x%04x-0x%04x # %dB %dkB" % ( 72 | device.name, 73 | device.RAMStart, device.RAMEnd, 74 | device.FStart, device.FEnd, 75 | 76 | (1 + device.RAMEnd - device.RAMStart), 77 | ((1 + device.FEnd - device.FStart) + (1 + device.INTEnd - device.INTStart)) / 1024, 78 | )) 79 | -------------------------------------------------------------------------------- /msp430/asm/definitions/bit_names.peripheral: -------------------------------------------------------------------------------- 1 | PERIPHERAL dummy_for_constants 2 | REGISTER SHORTCUT 8bits 3 | 7 BIT BIT7 4 | 6 BIT BIT6 5 | 5 BIT BIT5 6 | 4 BIT BIT4 7 | 3 BIT BIT3 8 | 2 BIT BIT2 9 | 1 BIT BIT1 10 | 0 BIT BIT0 11 | END-REGISTER 12 | 13 | REGISTER SHORTCUT 16bits 14 | 15 BIT BITF 15 | 14 BIT BITE 16 | 13 BIT BITD 17 | 12 BIT BITC 18 | 11 BIT BITB 19 | 10 BIT BITA 20 | 9 BIT BIT9 21 | 8 BIT BIT8 22 | 8bits 23 | END-REGISTER 24 | END-PERIPHERAL 25 | -------------------------------------------------------------------------------- /msp430/asm/forth/_asm_snippets.forth: -------------------------------------------------------------------------------- 1 | ( vi:ft=forth 2 | 3 | Some assembler snippets that are commonly used. 4 | 5 | Copyright [C] 2011 Chris Liechti 6 | All Rights Reserved. 7 | Simplified BSD License [see LICENSE.txt for full text] 8 | ) 9 | 10 | ( > Emit the backspace character. ) 11 | : BS 8 EMIT ; 12 | 13 | ( > Emit the line feed character. ) 14 | : LF 10 EMIT ; 15 | 16 | ( > Emit the hash character. ) 17 | : HASH 35 EMIT ; 18 | 19 | ( > Emit the text for a define. ) 20 | : DEFINE HASH ." define " SPACE ; 21 | 22 | ( > Emit assembler for NEXT. ) 23 | : ASM-NEXT ." \t br @IP+ \t; NEXT \n " ; 24 | 25 | ( > Emit assembler for DROP. ) 26 | ( > Example:: 27 | ( > 28 | ( > CODE DROP-DEMO ( n -- ) 29 | ( > ASM-DROP 30 | ( > ASM-NEXT 31 | ( > END-CODE ) 32 | : ASM-DROP ." \t incd SP \t; DROP \n " ; 33 | 34 | ( > Emit assembler to pop top of stack to register R15. ) 35 | : ASM-TOS->R15 ." \t pop R15 \n " ; 36 | 37 | ( > Emit assembler to pop top of stack to register R14. ) 38 | : ASM-TOS->R14 ." \t pop R14 \n " ; 39 | 40 | ( > Emit assembler to push R15 on stack. ) 41 | : ASM-R15->TOS ." \t push R15 \n " ; 42 | 43 | ( > Emit assembler to pop top of stack to register W. ) 44 | : ASM-TOS->W ." \t pop W \n " ; 45 | 46 | ( > Emit assembler to push register W on stack. ) 47 | : ASM-W->TOS ." \t push W \n " ; 48 | 49 | ( > Helper to write a call in assembler. ) 50 | ( > Example:: 51 | ( > 52 | ( > CODE PUTCHAR ( u -- ) 53 | ( > ASM-TOS->R15 54 | ( > ASM-CALL putchar 55 | ( > ASM-NEXT 56 | ( > END-CODE ) 57 | ( The function inserts commands in the currently compiling frame so that the 58 | corresponding assembler snippet is output when that functionis called. ASM-CALL 59 | itself is immediate [executed during compilation].) 60 | : ASM-CALL 61 | ' LIT , " \t call \x23" , ' . , ( output string ) 62 | ' LIT , WORD , ' . , ( output saved word ) 63 | ' LF , ( output newline ) 64 | IMMEDIATE ; 65 | -------------------------------------------------------------------------------- /msp430/asm/forth/_helpers.forth: -------------------------------------------------------------------------------- 1 | ( vi:ft=forth 2 | 3 | Helper function to generate text for the assembler. 4 | 5 | Copyright [C] 2011 Chris Liechti 6 | All Rights Reserved. 7 | Simplified BSD License [see LICENSE.txt for full text] 8 | ) 9 | 10 | ( > Generate a simple line for headers ) 11 | : LINE ( -- ) 12 | ." ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n " 13 | ; 14 | 15 | ( > Generate a header in the assembler file ) 16 | : HEADER ( str -- ) 17 | ." ;============================================================================\n " 18 | ." ; " SPACE . LF ( print value from stack ) 19 | ." ;============================================================================\n " 20 | ; 21 | 22 | -------------------------------------------------------------------------------- /msp430/asm/forth/_interrupts.forth: -------------------------------------------------------------------------------- 1 | ( vi:ft=forth 2 | 3 | Words to work with interrupts. 4 | 5 | Copyright [C] 2011 Chris Liechti 6 | All Rights Reserved. 7 | Simplified BSD License [see LICENSE.txt for full text] 8 | ) 9 | 10 | ( Example: 11 | PORT1_VECTOR INTERRUPT handler_name 12 | WAKEUP 13 | 0 P1IFG C! 14 | END-INTERRUPT 15 | 16 | - Words defined with INTERRUPT must not be called from user code. 17 | ) 18 | 19 | ( Interrupts save the MSP430 context [registers] on the data stack. This is no 20 | problem as an interrupt handler can work with values that have been on the 21 | stack and it must be stack balanced itself. 22 | ) 23 | 24 | ( The word INTERRUPT generates an entry code block specific for each interrupt. 25 | SP and IP are remebered on the return stack. However, the user should not 26 | work with them directly so we call it 'int-sys' in the docs below. 27 | 28 | sub \x23 4, RTOS ; prepare to push 2 values on return stack 29 | mov IP, 2[RTOS] ; save IP on return stack 30 | mov SP, 0[RTOS] ; save SP pointer on return stack it points to SR on stack 31 | mov #XXX, IP ; Move address of thread of interrupt handler in IP 32 | br @IP+ ; NEXT 33 | ) 34 | 35 | ( > Entering an interrupt handler. For internal use only. ) 36 | CODE DO-INTERRUPT ( R: - int-sys ) 37 | ." \t ; save registers\n " 38 | ." \t push R6\n " 39 | ." \t push R7\n " 40 | ." \t push R8\n " 41 | ." \t push R9\n " 42 | ." \t push R10\n " 43 | ." \t push R11\n " 44 | ." \t push R12\n " 45 | ." \t push R13\n " 46 | ." \t push R14\n " 47 | ." \t push R15\n " 48 | ASM-NEXT 49 | END-CODE 50 | 51 | ( > Restore state at exit of interrupt handler. For internal use only. ) 52 | CODE EXIT-INTERRUPT ( R: int-sys -- ) 53 | ." \t ; restore registers\n " 54 | ." \t pop R15\n " 55 | ." \t pop R14\n " 56 | ." \t pop R13\n " 57 | ." \t pop R12\n " 58 | ." \t pop R11\n " 59 | ." \t pop R10\n " 60 | ." \t pop R9\n " 61 | ." \t pop R8\n " 62 | ." \t pop R7\n " 63 | ." \t pop R6\n " 64 | ." \t incd RTOS ; forget about pointer to SR on stack \n " 65 | ." \t mov @RTOS+, IP \t; get last position from return stack \n " 66 | ." \t reti\n " 67 | END-CODE 68 | 69 | ( > Patch the saved status register so that LPM modes are exit after the 70 | ( > interrupt handler is finished. 71 | ( > 72 | ( > Only allowed directly in INTERRUPT_ definition. Not in called functions. 73 | ( > 74 | ( > May be called multiple times. ) 75 | CODE WAKEUP ( R: int-sys -- int-sys ) 76 | ." \t mov @RTOS, W \t; get pointer to SR into W\n " 77 | ." \t bic \x23 LPM4, 0(W) \t; patch SR on [HW] stack\n " 78 | ASM-NEXT 79 | END-CODE 80 | 81 | -------------------------------------------------------------------------------- /msp430/asm/forth/_memory.forth: -------------------------------------------------------------------------------- 1 | ( vi:ft=forth 2 | 3 | Forth functions to read and write memory. 4 | 5 | Copyright [C] 2011 Chris Liechti 6 | All Rights Reserved. 7 | Simplified BSD License [see LICENSE.txt for full text] 8 | ) 9 | 10 | ( > Fetch byte value. ) 11 | CODE C@ ( adr -- n ) 12 | ." \t mov @SP, W \n " ( copy address ) 13 | ." \t mov.b @W, W \n " ( execute read ) 14 | ." \t mov W, 0(SP) \n " ( replace TOS with value ) 15 | ASM-NEXT 16 | END-CODE 17 | 18 | ( > Store byte value. ) 19 | CODE C! ( n adr -- ) 20 | ASM-TOS->R15 ( pop address ) 21 | ASM-TOS->R14 ( pop value ) 22 | ." \t mov.b R14, 0(R15) \n " ( write to address - separate instruction b/c byte mode ) 23 | ASM-NEXT 24 | END-CODE 25 | 26 | ( > Fetch word value. ) 27 | CODE @ ( adr -- n ) 28 | ." \t mov @SP, W \n " ( copy address ) 29 | ." \t mov @W, 0(SP) \n " ( replace TOS with value ) 30 | ASM-NEXT 31 | END-CODE 32 | 33 | ( > Store word value. ) 34 | CODE ! ( n adr -- ) 35 | ASM-TOS->W ( pop address ) 36 | ." \t mov @SP+, 0(W) \n " ( pop value and write to address ) 37 | ASM-NEXT 38 | END-CODE 39 | 40 | -------------------------------------------------------------------------------- /msp430/asm/forth/core.forth: -------------------------------------------------------------------------------- 1 | ( vi:ft=forth 2 | 3 | Core definitions for the cross compiler 4 | for Forth -> MSP430 assembler. 5 | 6 | Copyright [C] 2011 Chris Liechti 7 | All Rights Reserved. 8 | Simplified BSD License [see LICENSE.txt for full text] 9 | ) 10 | 11 | INCLUDE _asm_snippets.forth 12 | 13 | ( > Terminate program and restart from the beginning. 14 | ( > The implementation is is also providing the 'main' entry point. ) 15 | CODE ABORT 16 | ." main: \t; also the main entry point.\n " 17 | ." \t mov \x23 _stack, SP \n " 18 | ." \t mov \x23 .return_stack_end, RTOS \n " 19 | ." \t mov \x23 thread, IP \n " 20 | ASM-NEXT 21 | END-CODE 22 | 23 | ( > Internal helper to execute a thread of forth instructions. ) 24 | CODE DOCOL 25 | ." \t decd RTOS \t; prepare to push on return stack \n " 26 | ." \t mov IP, 0(RTOS) \t; save IP on return stack \n " 27 | ." \t mov -2(IP), IP \t; get where we are now \n " 28 | ( ." \t incd IP \t; jump over 'jmp DOCOL' \n " ) 29 | ." \t add \x23 4, IP \t; jump over 'br HASH DOCOL' \n " 30 | ASM-NEXT 31 | END-CODE 32 | 33 | ( > a.k.a return from subroutine. ) 34 | CODE EXIT 35 | ." \t mov @RTOS+, IP \t; get last position from return stack \n " 36 | ASM-NEXT 37 | END-CODE 38 | 39 | ( Get additional library functions. ) 40 | INCLUDE _builtins.forth 41 | INCLUDE _memory.forth 42 | INCLUDE _helpers.forth 43 | INCLUDE _msp430_lowlevel.forth 44 | 45 | 46 | ( > Generate init code for forth runtime and core words. ) 47 | : CROSS-COMPILE-CORE ( - ) 48 | LINE 49 | HASH ." include < " MCU . ." .h> " LF 50 | LF 51 | LINE 52 | ." ; Assign registers. \n " 53 | DEFINE ." RTOS R4 \n " 54 | DEFINE ." IP R5 \n " 55 | DEFINE ." W R6 \n " 56 | LF 57 | LINE 58 | ." ; Memory for the return stack. \n " 59 | ." .bss \n " 60 | ." return_stack: .skip 2*16 \n " 61 | ." .return_stack_end: \n " 62 | LF 63 | LINE 64 | ." .text\n " 65 | ." ; Initial thread that is run. Hardcoded init-main-loop. \n " 66 | ." thread: \n " 67 | ." \t .word _INIT \n " 68 | ." \t .word _MAIN \n " 69 | ." \t .word _ABORT \n " 70 | LF 71 | 72 | ( output important runtime core parts ) 73 | CROSS-COMPILE ABORT 74 | CROSS-COMPILE DOCOL 75 | CROSS-COMPILE EXIT 76 | ; 77 | 78 | -------------------------------------------------------------------------------- /msp430/asm/h2forth.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2011 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Conversion of C header files (specially for the MSP430) to Forth. 10 | 11 | It's main purpose is to extract the #defines from the CPU specific 12 | header files for the TI MSP430. 13 | """ 14 | 15 | import logging 16 | import codecs 17 | import msp430.asm.cpp 18 | 19 | 20 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 21 | def main(): 22 | import sys 23 | import os 24 | import argparse 25 | logging.basicConfig() 26 | 27 | parser = argparse.ArgumentParser() 28 | parser.add_argument( 29 | 'HEADERFILE', 30 | nargs='?', 31 | default='-', 32 | help='name of the input file (default: %(default)s)') 33 | 34 | group = parser.add_argument_group('Input') 35 | 36 | group.add_argument( 37 | '-I', '--include-path', 38 | action='append', 39 | metavar="PATH", 40 | default=[], 41 | help='Add directory to the search path list for includes') 42 | 43 | group.add_argument( 44 | '-D', '--define', 45 | action='append', 46 | dest='defines', 47 | metavar='SYM[=VALUE]', 48 | default=[], 49 | help='define symbol') 50 | 51 | group = parser.add_argument_group('Output') 52 | 53 | group.add_argument( 54 | '-o', '--outfile', 55 | type=argparse.FileType('w'), 56 | default='-', 57 | help='name of the output file (default: %(default)s)', 58 | metavar="FILE") 59 | 60 | parser.add_argument( 61 | '-v', '--verbose', 62 | action='store_true', 63 | default=False, 64 | help='print status messages') 65 | 66 | parser.add_argument( 67 | '--develop', 68 | action='store_true', 69 | default=False, 70 | help='print debug messages') 71 | 72 | args = parser.parse_args() 73 | 74 | if args.develop: 75 | logging.getLogger('cpp').setLevel(logging.DEBUG) 76 | elif args.verbose: 77 | logging.getLogger('cpp').setLevel(logging.INFO) 78 | else: 79 | logging.getLogger('cpp').setLevel(logging.WARN) 80 | 81 | cpp = msp430.asm.cpp.Preprocessor() 82 | # extend include search path 83 | # built in places for msp430.asm 84 | d = os.path.join(os.path.dirname(sys.modules['msp430.asm'].__file__), 'include') 85 | cpp.include_path.append(d) 86 | cpp.include_path.append(os.path.join(d, 'upstream')) 87 | # user provided directories (-I) 88 | cpp.include_path.extend(args.include_path) 89 | # insert predefined symbols (XXX function like macros not yet supported) 90 | for definition in args.defines: 91 | if '=' in definition: 92 | symbol, value = definition.split('=', 1) 93 | else: 94 | symbol, value = definition, '1' 95 | cpp.namespace.defines[symbol] = value 96 | 97 | if not args.HEADERFILE or args.HEADERFILE == '-': 98 | infilename = '' 99 | infile = argparse.FileType('r')('-') 100 | else: 101 | # search include path for files 102 | for path in cpp.include_path: 103 | infilename = os.path.join(path, args.HEADERFILE) 104 | if os.path.exists(infilename): 105 | infile = codecs.open(infilename, 'r', 'utf-8') 106 | break 107 | else: 108 | sys.stderr.write('h2forth: {}: File not found\n'.format(infilename)) 109 | sys.exit(1) 110 | 111 | try: 112 | error_found = cpp.preprocess(infile, msp430.asm.cpp.Discard(), infilename) 113 | if error_found: 114 | sys.exit(1) 115 | except msp430.asm.cpp.PreprocessorError as e: 116 | sys.stderr.write('{e.filename}:{e.line}: {e}\n'.format(e=e)) 117 | if args.develop: 118 | if hasattr(e, 'text'): 119 | sys.stderr.write('{e.filename}:{e.line}: input line: {e.text!r}\n'.format(e=e)) 120 | sys.exit(1) 121 | 122 | args.outfile.write(': 0 ;\n') 123 | #~ for definition in cpp.macros: 124 | #~ print definition 125 | for name, definition in sorted(cpp.namespace.defines.items()): 126 | #~ print name, definition 127 | # MSP430 specific hack to get peripherals: 128 | if name.endswith('_') and not name.startswith('_'): 129 | name = name[:-1] 130 | if definition: 131 | try: 132 | value = cpp.namespace.eval(definition) 133 | except msp430.asm.cpp.PreprocessorError as e: 134 | sys.stderr.write('cannot convert expression: {}\n'.format(e)) 135 | except msp430.asm.rpn.RPNError as e: 136 | sys.stderr.write('cannot convert expression: {}\n'.format(e)) 137 | else: 138 | args.outfile.write('{!r} CONSTANT {}\n'.format(value, name)) 139 | else: 140 | args.outfile.write('1 CONSTANT {}\n'.format(name)) 141 | 142 | 143 | if __name__ == '__main__': 144 | main() 145 | -------------------------------------------------------------------------------- /msp430/asm/include/README.txt: -------------------------------------------------------------------------------- 1 | MSP430 Header Files 2 | =================== 3 | 4 | The files are not included. 5 | 6 | However, they can be downloaded manually. The ``fetchfiles.py`` script is there 7 | to assist. It will download a snapshot of the header files from the 8 | mspgcc.sf.net project and extract the files from there. 9 | 10 | .. note:: 11 | 12 | The script currently has a hard coded URL so not the latest file might be 13 | downloaded. 14 | 15 | 16 | Installation 17 | ------------ 18 | Just open a shell in the include directory and execute the script:: 19 | 20 | cd python-msp430-tools/msp430/asm/include 21 | python fetchfiles.py 22 | -------------------------------------------------------------------------------- /msp430/asm/include/fetchfiles.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2011 Chris Liechti 5 | # All Rights Reserved. 6 | # Simplified BSD License (see LICENSE.txt for full text) 7 | 8 | import urllib2 9 | import tarfile 10 | import os 11 | import sys 12 | import shutil 13 | 14 | # XXX method to get latest? currently a version is hardcoded. 15 | URL = 'http://sourceforge.net/projects/mspgcc/files/msp430mcu/msp430mcu-20130321.tar.bz2/download' 16 | ARCHIVE_NAME = 'upstream.tar.bz2' 17 | 18 | # set up environment 19 | if os.path.exists('upstream'): 20 | sys.stderr.write("ERROR upstream directory already exists. Manually remove to proceed\n") 21 | sys.exit(1) 22 | 23 | os.mkdir('upstream') 24 | 25 | if os.path.exists(ARCHIVE_NAME): 26 | sys.stderr.write("%s found on disk using it. To download latest data, rename or delete the file.\n" % (ARCHIVE_NAME)) 27 | else: 28 | # download archive from MSPGCC (git web interface) 29 | sys.stderr.write("Downloading archive from sf.net (~15MB). This may take a few minutes...\n") 30 | archive = urllib2.urlopen(URL) 31 | archfile = open(ARCHIVE_NAME, 'wb') 32 | archfile.write(archive.read()) 33 | archfile.close() 34 | sys.stderr.write("Download complete.\n") 35 | 36 | 37 | sys.stderr.writet("Extracting the archive contents...\n") 38 | tar = tarfile.open(ARCHIVE_NAME, 'r') 39 | for tarinfo in tar: 40 | #~ print tarinfo.name, "is", tarinfo.size, "bytes in size and is", 41 | if tarinfo.isreg() and 'upstream' in tarinfo.name: 42 | filename = os.path.basename(tarinfo.name) 43 | target_name = os.path.join('upstream', filename) 44 | shutil.copyfileobj( 45 | tar.extractfile(tarinfo), 46 | open(target_name, 'wb')) 47 | tar.close() 48 | sys.stderr.write("Completed\n") 49 | -------------------------------------------------------------------------------- /msp430/asm/include/in430.h: -------------------------------------------------------------------------------- 1 | // no contents for assembler only 2 | -------------------------------------------------------------------------------- /msp430/asm/include/iomacros.h: -------------------------------------------------------------------------------- 1 | // map macros from TI header files to commands for assembler 2 | #define sfrb(x,x_) x=x_ 3 | #define sfrw(x,x_) x=x_ 4 | #define sfra(x,x_) x=x_ 5 | 6 | #define const_sfrb(x,x_) sfrb(x,x_) 7 | #define const_sfrw(x,x_) sfrw(x,x_) 8 | #define const_sfra(x,x_) sfra(x,x_) 9 | 10 | -------------------------------------------------------------------------------- /msp430/asm/lib.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2011 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Librarian - Access source code library based on templates. 10 | 11 | It more or less just a copy program, that copies files from a library of 12 | snippets to the given output. It can textually replace words, so that 13 | the output can be adjusted, e.g. when a template contains variables. 14 | """ 15 | 16 | import logging 17 | import codecs 18 | import pkgutil 19 | 20 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 21 | 22 | 23 | def main(): 24 | import sys 25 | import os 26 | import argparse 27 | logging.basicConfig() 28 | 29 | parser = argparse.ArgumentParser() 30 | 31 | group = parser.add_mutually_exclusive_group(required=True) 32 | group.add_argument('TEMLATE_NAME', nargs='?') 33 | group.add_argument( 34 | '-l', '--list', 35 | action='store_true', 36 | default=False, 37 | help='List available snippets') 38 | 39 | parser.add_argument( 40 | '-o', '--outfile', 41 | type=argparse.FileType('w'), 42 | default='-', 43 | help='name of the object file (default: %(default)s)', 44 | metavar="FILE") 45 | parser.add_argument( 46 | '-D', '--define', 47 | action='append', 48 | dest='defines', 49 | metavar='SYM[=VALUE]', 50 | default=[], 51 | help='define symbol') 52 | parser.add_argument( 53 | '--develop', 54 | action='store_true', 55 | default=False, 56 | help='print debug messages to stdout') 57 | 58 | args = parser.parse_args() 59 | 60 | if args.list: 61 | args.outfile.write('List of available snippets:\n') 62 | # XXX this method won't work when package is zipped (e.g. py2exe) 63 | d = os.path.join(os.path.dirname(sys.modules['msp430.asm'].__file__), 'librarian') 64 | for root, dirs, files in os.walk(d): 65 | for filename in files: 66 | args.outfile.write(' {}\n'.format(os.path.join(root, filename)[1 + len(d):])) 67 | sys.exit(0) 68 | 69 | # load desired snippet 70 | try: 71 | template = pkgutil.get_data('msp430.asm', 'librarian/{}'.format(args.TEMLATE_NAME)).decode('utf-8') 72 | except IOError: 73 | sys.stderr.write('lib: {}: File not found\n'.format(args.TEMLATE_NAME)) 74 | if args.develop: 75 | raise 76 | sys.exit(1) 77 | 78 | # collect predefined symbols 79 | defines = {} 80 | for definition in args.defines: 81 | if '=' in definition: 82 | symbol, value = definition.split('=', 1) 83 | else: 84 | symbol, value = definition, '' 85 | defines[symbol] = value 86 | 87 | # perform text replacements 88 | for key, value in defines.items(): 89 | template = template.replace(key, value) 90 | 91 | # write final result 92 | args.outfile.write(template) 93 | 94 | 95 | if __name__ == '__main__': 96 | main() 97 | -------------------------------------------------------------------------------- /msp430/asm/librarian/asm/adc10.S: -------------------------------------------------------------------------------- 1 | ; -*- coding: utf-8 -*- 2 | ; vi:ft=msp430 3 | ; 4 | ; DOC-SECTION 5 | ; 6 | ; Description 7 | ; ----------- 8 | ; The single_adc10 function enabled the ADC10 module, makes a measurement and 9 | ; switched the module off. 10 | ; 11 | ; C prototype: unsigned single_adc10(unsigned channel); 12 | ; Parameter channel: channel number 13 | ; Return: ADC measurement 14 | ; 15 | ; Module configuration 16 | ; -------------------- 17 | ; The module includes the file "hardware.h" which can be used to 18 | ; provide the following settings. 19 | ; 20 | ; Copyright (c) 2011 Chris Liechti 21 | ; All Rights Reserved. 22 | ; Simplified BSD License (see LICENSE.txt for full text) 23 | ; 24 | ; END-DOC-SECTION 25 | #include "hardware.h" 26 | 27 | .text 28 | ; --------------------------------------------------------------------------- 29 | ; Perform a single ADC10 measurement. 30 | ; R15: input channel 31 | ; --------------------------------------------------------------------------- 32 | single_adc10: 33 | mov R15, &ADC10CTL1 ; get settings from R15 34 | mov #ADC10SHT_3|ADC10ON, &ADC10CTL0 ; enable ADC10 module 35 | ;~ mov.b R15, &ADC10AE0 ; enable input 36 | bis #ENC|ADC10SC, &ADC10CTL0 ; Start sampling 37 | .L1: bit #ADC10BUSY, &ADC10CTL1 ; test if ADC10 is busy 38 | jnz .L1 ; bit set? -> loop 39 | mov &ADC10MEM, R15 ; get result in register 40 | clr &ADC10CTL0 41 | ;~ clr.b &ADC10AE0 42 | ret 43 | 44 | -------------------------------------------------------------------------------- /msp430/asm/librarian/asm/intvec16.S: -------------------------------------------------------------------------------- 1 | ; Vector table with 32 bytes 2 | ; vi:ft=msp430 3 | 4 | ; Interrupt table 5 | .section .vectors 6 | .word __vector_0 7 | .word __vector_2 8 | .word __vector_4 9 | .word __vector_6 10 | .word __vector_8 11 | .word __vector_10 12 | .word __vector_12 13 | .word __vector_14 14 | .word __vector_16 15 | .word __vector_18 16 | .word __vector_20 17 | .word __vector_22 18 | .word __vector_24 19 | .word __vector_26 20 | .word __vector_28 21 | .word __RESET ; POR 22 | ;~ .word vector_30 ; POR 23 | 24 | .text 25 | ; Implementation for unused interrupts 26 | __unused_interrupt: reti 27 | 28 | ; Assign __unused_interrupt to all vectors. As it is only a default, it is 29 | ; possible to provide different values/implementations for each vector. 30 | .weakalias __vector_0, __unused_interrupt 31 | .weakalias __vector_2, __unused_interrupt 32 | .weakalias __vector_4, __unused_interrupt 33 | .weakalias __vector_6, __unused_interrupt 34 | .weakalias __vector_8, __unused_interrupt 35 | .weakalias __vector_10, __unused_interrupt 36 | .weakalias __vector_12, __unused_interrupt 37 | .weakalias __vector_14, __unused_interrupt 38 | .weakalias __vector_16, __unused_interrupt 39 | .weakalias __vector_18, __unused_interrupt 40 | .weakalias __vector_20, __unused_interrupt 41 | .weakalias __vector_22, __unused_interrupt 42 | .weakalias __vector_24, __unused_interrupt 43 | .weakalias __vector_26, __unused_interrupt 44 | .weakalias __vector_28, __unused_interrupt 45 | -------------------------------------------------------------------------------- /msp430/asm/librarian/asm/intvec32.S: -------------------------------------------------------------------------------- 1 | ; Vector table with 64 bytes 2 | ; vi:ft=msp430 3 | 4 | .section .vectors 5 | .word __vector_0 6 | .word __vector_2 7 | .word __vector_4 8 | .word __vector_6 9 | .word __vector_8 10 | .word __vector_10 11 | .word __vector_12 12 | .word __vector_14 13 | .word __vector_16 14 | .word __vector_18 15 | .word __vector_20 16 | .word __vector_22 17 | .word __vector_24 18 | .word __vector_26 19 | .word __vector_28 20 | .word __vector_30 21 | .word __vector_32 22 | .word __vector_34 23 | .word __vector_36 24 | .word __vector_38 25 | .word __vector_40 26 | .word __vector_42 27 | .word __vector_44 28 | .word __vector_46 29 | .word __vector_48 30 | .word __vector_50 31 | .word __vector_52 32 | .word __vector_54 33 | .word __vector_56 34 | .word __vector_58 35 | .word __vector_60 36 | .word __RESET ; POR 37 | 38 | 39 | .text 40 | ; Implementation for unused interrupts 41 | __unused_interrupt: reti 42 | 43 | ; Assign __unused_interrupt to all vectors. As it is only a default, it is 44 | ; possible to provide different values/implementations for each vector. 45 | .weakalias __vector_0, __unused_interrupt 46 | .weakalias __vector_2, __unused_interrupt 47 | .weakalias __vector_4, __unused_interrupt 48 | .weakalias __vector_6, __unused_interrupt 49 | .weakalias __vector_8, __unused_interrupt 50 | .weakalias __vector_10, __unused_interrupt 51 | .weakalias __vector_12, __unused_interrupt 52 | .weakalias __vector_14, __unused_interrupt 53 | .weakalias __vector_16, __unused_interrupt 54 | .weakalias __vector_18, __unused_interrupt 55 | .weakalias __vector_20, __unused_interrupt 56 | .weakalias __vector_22, __unused_interrupt 57 | .weakalias __vector_24, __unused_interrupt 58 | .weakalias __vector_26, __unused_interrupt 59 | .weakalias __vector_28, __unused_interrupt 60 | .weakalias __vector_30, __unused_interrupt 61 | .weakalias __vector_32, __unused_interrupt 62 | .weakalias __vector_34, __unused_interrupt 63 | .weakalias __vector_36, __unused_interrupt 64 | .weakalias __vector_38, __unused_interrupt 65 | .weakalias __vector_40, __unused_interrupt 66 | .weakalias __vector_42, __unused_interrupt 67 | .weakalias __vector_44, __unused_interrupt 68 | .weakalias __vector_46, __unused_interrupt 69 | .weakalias __vector_48, __unused_interrupt 70 | .weakalias __vector_50, __unused_interrupt 71 | .weakalias __vector_52, __unused_interrupt 72 | .weakalias __vector_54, __unused_interrupt 73 | .weakalias __vector_56, __unused_interrupt 74 | .weakalias __vector_58, __unused_interrupt 75 | .weakalias __vector_60, __unused_interrupt 76 | -------------------------------------------------------------------------------- /msp430/asm/librarian/asm/startup.S: -------------------------------------------------------------------------------- 1 | ; -*- coding: utf-8 -*- 2 | ; vi:ft=msp430 3 | ; 4 | ; DOC-SECTION 5 | ; 6 | ; Description 7 | ; ----------- 8 | ; Startup code. It initializes: 9 | ; - stack pointer 10 | ; - .data and .bss sections 11 | ; 12 | ; Copyright (c) 2001-2011 Chris Liechti 13 | ; All Rights Reserved. 14 | ; Simplified BSD License (see LICENSE.txt for full text) 15 | ; 16 | ; END-DOC-SECTION 17 | 18 | .text 19 | 20 | ; Initialize stack pointer 21 | __RESET: mov #_stack, SP 22 | 23 | .Linit_data: ; Copy initial values for variables in data segment 24 | mov #_data_init_end-_data_init_start, R15 25 | tst R15 26 | jz .Linit_bss 27 | .Ldata_loop:dec R15 28 | mov _data_init_start(R15), _data_start(R15) 29 | jnz .Ldata_loop 30 | 31 | .Linit_bss: ; Clear memory of bss segment 32 | mov #_bss_end-_bss_start, R15 33 | tst R15 34 | jz .Lrun 35 | .Lbss_loop: dec R15 36 | clr _bss_start(R15) 37 | jnz .Lbss_loop 38 | 39 | .Lrun: br #main 40 | 41 | -------------------------------------------------------------------------------- /msp430/asm/librarian/asm/timer_a_uart/putchar.S: -------------------------------------------------------------------------------- 1 | ; -*- coding: utf-8 -*- 2 | ; vi:ft=msp430 3 | ; 4 | ; DOC-SECTION 5 | ; 6 | ; Description 7 | ; ----------- 8 | ; Timer UART implementation of putchar. 9 | ; 10 | ; C prototype: int putchar(int c); 11 | ; Parameter c: Character to send (0..255) 12 | ; Returns: >= 0 on success 13 | ; 14 | ; Transmit characters in NRZ format, 8 bits, 1 stop bit, no parity. 15 | ; Timing is done with Timer module, pins are accessed directly 16 | ; (sending on any GPIO possible). 17 | ; 18 | ; Module configuration 19 | ; -------------------- 20 | ; The module includes the file "hardware.h" which can be used to 21 | ; provide the following settings. 22 | ; 23 | ; The code uses the following #defines. When not defined defaults 24 | ; are used: TACCR0/TACCTL0, P1OUT/BIT2, 2400 baud for a timer at 1MHz 25 | ; 26 | ; TAUART_BIT_TICKS 27 | ; Timer of a bit in timer ticks. 28 | ; 29 | ; TAUART_TX_TxR 30 | ; Definition of the timer counter register. 31 | ; 32 | ; TAUART_TX_CCR 33 | ; The capture compare unit used, its counter register. 34 | ; 35 | ; TAUART_TX_CCTL 36 | ; The capture compare unit used, its control register. 37 | ; 38 | ; TAUART_TX_PORT 39 | ; Port register used to transmit. 40 | ; 41 | ; TAUART_TX_PIN 42 | ; Bit mask of pin used to send. 43 | ; 44 | ; TAUART_TX_DINT 45 | ; If defined: lock interrupts during send. This ensures that 46 | ; no other interrupt can disturb the bit timing. But it also 47 | ; prevents full duplex mode. 48 | ; 49 | ; Copyright (c) 2001-2011 Chris Liechti 50 | ; All Rights Reserved. 51 | ; Simplified BSD License (see LICENSE.txt for full text) 52 | ; 53 | ; END-DOC-SECTION 54 | 55 | #include "hardware.h" 56 | 57 | #ifndef TAUART_BIT_TICKS 58 | #define TAUART_BIT_TICKS 416 // ~2400 @ 1e6 59 | #endif // TAUART_BIT_TICKS 60 | 61 | #ifndef TAUART_TX_TxR 62 | #define TAUART_TX_TxR TAR 63 | #endif // TAUART_TX_TxR 64 | 65 | #ifndef TAUART_TX_CCR 66 | #define TAUART_TX_CCR TACCR0 67 | #endif // TAUART_TX_CCR 68 | 69 | #ifndef TAUART_TX_CCTL 70 | #define TAUART_TX_CCTL TACCTL0 71 | #endif // TAUART_TX_CCTL 72 | 73 | #ifndef TAUART_TX_PORT 74 | #define TAUART_TX_PORT P1OUT 75 | #endif // TAUART_TX_PORT 76 | 77 | #ifndef TAUART_RX_PIN 78 | #define TAUART_TX_PIN BIT1 79 | #endif // TAUART_TX_PIN 80 | 81 | .text 82 | ; --------------------------------------------------------------------------- 83 | ; Timer_A UART: send character 84 | ; Parameters: R15 character to be sent 85 | ; Resources: TACCR0, R13 86 | ; 87 | ; x,8,N,1 88 | ; ___ ______________ _______________ 89 | ; | | | | 90 | ; | ST | D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 | SP | 91 | ; |____| |___________________| 92 | ; ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ edges 93 | ; 94 | ; --------------------------------------------------------------------------- 95 | putchar: 96 | mov #10, R13 ; ten bits: Start, 8 Data, Stop 97 | rla R15 ; shift in start bit (0) 98 | #ifdef TAUART_TX_DINT 99 | push SR 100 | dint 101 | #endif // TAUART_TX_DINT 102 | bis #0x0600, R15 ; set 10th bit (STOP) and the next to get a return value of 1 103 | mov &TAUART_TX_TxR, &TAUART_TX_CCR ; copy current time 104 | .Lt1lp: rra R15 ;1 | shift data through carry 105 | jc .Lt1 ;2 | test carry bit 106 | .Lt0: bic.b #TAUART_TX_PIN, &TAUART_TX_PORT ; 5| 107 | jmp .Ltc ; 2| 108 | .Lt1: bis.b #TAUART_TX_PIN, &TAUART_TX_PORT ;5 | 109 | jmp .Ltc ;2 | 110 | .Ltc: add #TAUART_BIT_TICKS, &TAUART_TX_CCR ;| set up one bit delay 111 | clr &TAUART_TX_CCTL ;4 | clear CCIFG ] one bit 112 | .Ltcd: bit #CCIFG, &TAUART_TX_CCTL ;4 | \ time due? ] delay 113 | jz .Ltcd ;2 | / not yet -> loop ] 114 | dec R13 ;1 | decrement bit counter 115 | jnz .Lt1lp ;2 O loop until all bits are transmitted 116 | #ifdef TAUART_TX_DINT 117 | pop SR 118 | #endif // TAUART_TX_DINT 119 | ret 120 | 121 | -------------------------------------------------------------------------------- /msp430/asm/librarian/asm/timer_a_uart/putchar_outmod.S: -------------------------------------------------------------------------------- 1 | ; -*- coding: utf-8 -*- 2 | ; vi:ft=msp430 3 | ; 4 | ; DOC-SECTION 5 | ; 6 | ; Description 7 | ; ----------- 8 | ; Timer UART implementation of putchar. 9 | ; 10 | ; C prototype: int putchar(int c); 11 | ; Parameter c: Character to send (0..255) 12 | ; Returns: >= 0 on success 13 | ; 14 | ; Transmit characters in NRZ format, 8 bits, 1 stop bit, no parity. 15 | ; Timing is done with Timer module, signal is generated with OUTMOD. 16 | ; The user has to ensure that the corresponding pins are configured 17 | ; for module function (DIR=1, SEL=1). 18 | ; 19 | ; .. note:: The CCTL register should be initialized with OUT bit set. 20 | ; Otherwise the first character will not be transmitted 21 | ; correctly. 22 | ; e.g.: ``mov #OUT, &TACCTL0`` 23 | ; 24 | ; 25 | ; Compared to the putchar version that directly accesses a GPIO has 26 | ; this version the advantage that it is more robust when other 27 | ; interrupts run in parallel. Its drawback is that the selection of 28 | ; pins is restricted to pins connected to the timer. 29 | ; 30 | ; Module configuration 31 | ; -------------------- 32 | ; The module includes the file "hardware.h" which can be used to 33 | ; provide the following settings. 34 | ; 35 | ; The code uses the following #defines. When not defined defaults 36 | ; are used: TACCR0/TACCTL0, P1OUT/BIT2, 2400 baud for a timer at 1MHz 37 | ; 38 | ; TAUART_BIT_TICKS 39 | ; Timer of a bit in timer ticks. 40 | ; 41 | ; TAUART_TX_TxR 42 | ; Definition of the timer counter register. 43 | ; 44 | ; TAUART_TX_CCR 45 | ; The capture compare unit used, its counter register. 46 | ; 47 | ; TAUART_TX_CCTL 48 | ; The capture compare unit used, its control register. 49 | ; 50 | ; TAUART_TX_DINT 51 | ; If defined: lock interrupts during send. This ensures that 52 | ; no other interrupt can disturb the bit timing. But it also 53 | ; prevents full duplex mode. 54 | ; 55 | ; Copyright (c) 2001-2011 Chris Liechti 56 | ; All Rights Reserved. 57 | ; Simplified BSD License (see LICENSE.txt for full text) 58 | ; 59 | ; END-DOC-SECTION 60 | 61 | #include "hardware.h" 62 | 63 | #ifndef TAUART_BIT_TICKS 64 | #define TAUART_BIT_TICKS 416 // ~2400 @ 1e6 65 | #endif // TAUART_BIT_TICKS 66 | 67 | #ifndef TAUART_TX_TxR 68 | #define TAUART_TX_TxR TAR 69 | #endif // TAUART_TX_TxR 70 | 71 | #ifndef TAUART_TX_CCR 72 | #define TAUART_TX_CCR TACCR0 73 | #endif // TAUART_TX_CCR 74 | 75 | #ifndef TAUART_TX_CCTL 76 | #define TAUART_TX_CCTL TACCTL0 77 | #endif // TAUART_TX_CCTL 78 | 79 | .text 80 | ; --------------------------------------------------------------------------- 81 | ; Timer_A UART: send character 82 | ; Parameters: R15 character to be sent 83 | ; Resources: TACCR0, R13 84 | ; 85 | ; x,8,N,1 86 | ; ___ ______________ _______________ 87 | ; | | | | 88 | ; | ST | D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 | SP | 89 | ; |____| |___________________| 90 | ; ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ edges 91 | ; 92 | ; --------------------------------------------------------------------------- 93 | putchar: 94 | rla R15 ; shift in start bit (0) 95 | #ifdef TAUART_TX_DINT 96 | push SR 97 | dint 98 | #endif // TAUART_TX_DINT 99 | bis #0x0200, R15 ; set 10th bit (STOP) 100 | mov &TAUART_TX_TxR, &TAUART_TX_CCR ; copy current time 101 | .Lt1lp: 102 | add #TAUART_BIT_TICKS, &TAUART_TX_CCR;| set up one bit delay 103 | mov #OUTMOD0, &TAUART_TX_CCTL ; | OUTMOD_1=set, clear CCIFG 104 | rra R15 ; | shift data through carry 105 | jc .Ltcd ; | test carry bit 106 | bis #OUTMOD2, &TAUART_TX_CCTL ; | modify to get OUTMOD_5=reset 107 | .Ltcd: bit #CCIFG, &TAUART_TX_CCTL ; | \ time due? ] delay 108 | jz .Ltcd ; | / not yet -> loop ] 109 | tst R15 ; | bits left? as the stop bits is 1, this works 110 | jnz .Lt1lp ; O loop until all bits are transmitted 111 | #ifdef TAUART_TX_DINT 112 | pop SR 113 | #endif // TAUART_TX_DINT 114 | mov #1, R15 ; return >= 0 to indicate success 115 | ret 116 | 117 | -------------------------------------------------------------------------------- /msp430/asm/librarian/asm/timer_a_uart/receive_interrupt.S: -------------------------------------------------------------------------------- 1 | ; -*- coding: utf-8 -*- 2 | ; vi:ft=msp430 3 | ; 4 | ; DOC-SECTION 5 | ; 6 | ; Description 7 | ; ----------- 8 | ; Timer UART implementation for reception. 9 | ; 10 | ; Receive characters in NRZ format. Timing is done with Timer module. 11 | ; Pin used for reception must be connected to the Timer. The user 12 | ; is responsible to configure the pin as input and module function 13 | ; (DIR=0, SEL=1). 14 | ; 15 | ; The Timer has to be set up for reception. The following function 16 | ; implements this: 17 | ; 18 | ; C Prototype: void timer_uart_rx_setup(void) 19 | ; 20 | ; To receive data, a function named TAUART_RX_INTERRUPT must be provided 21 | ; (using a #define to change the name is possible). This function must be 22 | ; an interrupt function and it can read the received byte from the 23 | ; variable timer_a_uart_rxd. 24 | ; 25 | ; Module configuration 26 | ; -------------------- 27 | ; The module includes the file "hardware.h" which is expected to 28 | ; provide the following settings. 29 | ; 30 | ; The code uses the following #defines. When not defined defaults 31 | ; are used: TACCR1/TACCTL1, P1OUT/BIT3, 2400 baud for a timer at 1MHz 32 | ; 33 | ; TAUART_BIT_TICKS Timer of a bit in timer ticks. 34 | ; TAUART_RX_TxR Definition of the timer counter register. 35 | ; TAUART_RX_CCR The capture compare unit used, its counter register. 36 | ; TAUART_RX_CCTL The capture compare unit used, its control register. 37 | ; 38 | ; 39 | ; Copyright (c) 2001-2011 Chris Liechti 40 | ; All Rights Reserved. 41 | ; Simplified BSD License (see LICENSE.txt for full text) 42 | ; 43 | ; END-DOC-SECTION 44 | 45 | #include "hardware.h" 46 | 47 | #ifndef TAUART_BIT_TICKS 48 | #define TAUART_BIT_TICKS 416 // ~2400 @ 1e6 49 | #endif // TAUART_BIT_TICKS 50 | 51 | #ifndef TAUART_RX_TxR 52 | #define TAUART_RX_TxR TAR 53 | #endif // TAUART_RX_TxR 54 | 55 | #ifndef TAUART_RX_CCR 56 | #define TAUART_RX_CCR TACCR1 57 | #endif // TAUART_RX_CCR 58 | 59 | #ifndef TAUART_RX_CCTL 60 | #define TAUART_RX_CCTL TACCTL1 61 | #endif // TAUART_RX_CCTL 62 | 63 | #ifndef TAUART_VECTOR 64 | #define TAUART_VECTOR TIMERA1_VECTOR 65 | #endif // TAUART_VECTOR 66 | 67 | 68 | ; variables 69 | .bss 70 | 71 | timer_a_uart_rxd: 72 | .skip 1 ; char var 73 | .Lrxshift: .skip 1 ; char var 74 | .even 75 | .Lrxbit: .skip 2 ; receive state counter 76 | 77 | .text 78 | 79 | ; --------------------------------------------------------------------------- 80 | ; Interrupt handler to receive as Timer_A UART. 81 | ; Timer_A UART: receive character 82 | ; Resources: TACCR1 83 | ; 84 | ; x,8,N,1 85 | ; ___ ______________ _______________ 86 | ; | | | | 87 | ; | ST | D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 | SP | 88 | ; |____| |___________________| 89 | ; ^ ^ ^ ^ ^ ^ ^ ^ ^ interrupts 90 | ; Capture |<------------ Compare ----------->| 91 | ; --------------------------------------------------------------------------- 92 | __vector_{TAUART_VECTOR}: 93 | timer_uart_interrupt: 94 | bic #CCIFG, &TAUART_RX_CCTL ; clear interrupt flag 95 | add .Lrxbit, PC 96 | jmp .Lrxstart ; start bit 97 | jmp .Lrxdatabit ; D0 98 | jmp .Lrxdatabit ; D1 99 | jmp .Lrxdatabit ; D2 100 | jmp .Lrxdatabit ; D3 101 | jmp .Lrxdatabit ; D4 102 | jmp .Lrxdatabit ; D5 103 | jmp .Lrxdatabit ; D6 104 | ; jmp .Lrxlastbit ; D7 that one is following anyway 105 | 106 | .Lrxlastbit: ; last bit, handle byte 107 | bit #SCCI, &TAUART_RX_CCTL ; read last bit 108 | rrc.b .Lrxshift ; and save it 109 | clr .Lrxbit ; reset state 110 | mov #CCIE|CAP|CM_2|CCIS_0|SCS, &TAUART_RX_CCTL ; restore capture mode 111 | mov.b .Lrxshift, timer_a_uart_rxd ; copy received data 112 | br #TAUART_RX_INTERRUPT 113 | 114 | .Lrxstart: ; start bit, initialize 115 | clr .Lrxshift ; clear input buffer 116 | add #(TAUART_BIT_TICKS/2), &TAUART_RX_CCR ; start bit + 1.5 bits -> first bit 117 | mov #CCIE|CCIS_0|SCS, &TAUART_RX_CCTL ; set compare mode, sample bits 118 | jmp .Lrxex ; set state,... 119 | 120 | .Lrxdatabit: ; save data bit 121 | bit #SCCI, &TAUART_RX_CCTL ; measure data bit 122 | rrc.b .Lrxshift ; rotate in data bit 123 | 124 | .Lrxex: add #TAUART_BIT_TICKS, &TAUART_RX_CCR ; one bit delay 125 | incd .Lrxbit ; setup next state 126 | reti 127 | 128 | ; --------------------------------------------------------------------------- 129 | ; Set up for reception. 130 | ; --------------------------------------------------------------------------- 131 | timer_uart_rx_setup: 132 | mov #CCIE|CAP|CM_2|CCIS_0|SCS, &TAUART_RX_CCTL ; capture mode 133 | ret 134 | 135 | -------------------------------------------------------------------------------- /msp430/asm/librarian/asm/write.S: -------------------------------------------------------------------------------- 1 | ; -*- coding: utf-8 -*- 2 | ; vi:ft=msp430 3 | ; 4 | ; DOC-SECTION 5 | ; 6 | ; Description 7 | ; ----------- 8 | ; Write a null terminated string using putchar. 9 | ; 10 | ; C prototype: void write(const char *s); 11 | ; Parameter s: Null terminated message 12 | ; 13 | ; Copyright (c) 2001-2011 Chris Liechti 14 | ; All Rights Reserved. 15 | ; Simplified BSD License (see LICENSE.txt for full text) 16 | ; 17 | ; END-DOC-SECTION 18 | 19 | .text 20 | ; --------------------------------------------------------------------------- 21 | ; Write a null terminated string using the putchar function. 22 | ; R15: pointer to null terminated text 23 | ; --------------------------------------------------------------------------- 24 | write: 25 | mov R15, R14 ; copy pointer 26 | .Lwrite_loop: 27 | mov.b @R14+, R15 ; fetch character 28 | tst R15 ; test for null character 29 | jz .Lwrite_fini ; exit loop on null char 30 | call #putchar ; output character 31 | jmp .Lwrite_loop ; loop 32 | .Lwrite_fini: 33 | ret 34 | 35 | -------------------------------------------------------------------------------- /msp430/bsl/BL_150S_14x.txt: -------------------------------------------------------------------------------- 1 | @0220 2 | 24 02 2E 02 31 40 20 02 2B D2 C0 43 EA FF 32 C2 3 | F2 C0 32 00 00 00 B2 40 80 5A 20 01 F2 40 85 00 4 | 57 00 F2 40 80 00 56 00 E2 D3 21 00 E2 D3 22 00 5 | E2 C3 26 00 E2 C2 2A 00 E2 C2 2E 00 B2 40 10 A5 6 | 2C 01 B2 40 00 A5 28 01 3B C0 3A 00 B0 12 D6 04 7 | 82 43 12 02 09 43 36 40 0A 02 37 42 B0 12 AC 05 8 | C6 4C 00 00 16 53 17 83 F9 23 D2 92 0C 02 0D 02 9 | 28 20 55 42 0B 02 75 90 12 00 80 24 75 90 10 00 10 | 6D 24 B0 12 9C 04 55 42 0B 02 75 90 18 00 31 24 11 | 75 90 1E 00 B8 24 75 90 20 00 17 24 2B B2 11 24 12 | 75 90 16 00 22 24 75 90 14 00 B3 24 75 90 1A 00 13 | 18 24 75 90 1C 00 45 24 04 3C B0 12 36 05 BE 3F 14 | 21 53 B0 12 3C 05 BA 3F 03 43 B0 12 36 05 D2 42 15 | 0E 02 56 00 D2 42 0F 02 57 00 D2 42 10 02 16 02 16 | AD 3F B0 12 36 05 10 42 0E 02 16 42 0E 02 15 43 17 | 07 3C 36 40 FE FF B2 40 06 A5 10 02 35 40 0C 00 18 | B2 40 00 A5 2C 01 92 42 10 02 28 01 B6 43 00 00 19 | 92 B3 2C 01 FD 23 15 83 F3 23 36 90 FE FF CD 27 20 | 37 40 80 00 36 F0 80 FF 36 90 00 11 0E 28 07 57 21 | 36 F0 00 FF 36 90 00 12 08 28 07 57 36 F0 00 FE 22 | 04 3C 16 42 0E 02 17 42 10 02 35 43 75 96 03 20 23 | 17 83 FC 23 B2 3F 82 46 00 02 B3 3F 36 40 E0 FF 24 | 37 40 20 00 B0 12 AC 05 7C 96 01 24 2B D3 17 83 25 | F9 23 2B C2 B0 12 9C 04 2B D2 9F 3F 16 42 0E 02 26 | 17 42 10 02 2B B2 38 24 3B D0 10 00 B0 12 AC 05 27 | 36 90 00 10 06 2C 36 90 00 01 09 2C C6 4C 00 00 28 | 25 3C B2 40 00 A5 2C 01 B2 40 40 A5 28 01 16 B3 29 | 03 20 C2 4C 14 02 1A 3C C2 4C 15 02 86 9A FD FF 30 | 08 24 2B D3 3B B0 20 00 04 20 3B D0 20 00 82 46 31 | 00 02 36 90 01 02 04 28 3B D2 3B B0 10 00 02 24 32 | 3B C0 32 00 1A 42 14 02 86 4A FF FF 16 53 17 83 33 | CD 23 B0 12 9C 04 61 3F B0 12 AC 05 17 83 FC 23 34 | B0 12 9C 04 5E 3F B2 40 F0 0F 0E 02 B2 40 10 00 35 | 10 02 B2 40 80 00 0A 02 D2 42 10 02 0C 02 D2 42 36 | 10 02 0D 02 82 43 12 02 09 43 36 40 0A 02 27 42 37 | 7C 46 B0 12 40 05 17 83 FB 23 16 42 0E 02 17 42 38 | 10 02 36 90 00 01 0A 28 B2 46 14 02 5C 42 14 02 39 | B0 12 40 05 17 83 5C 42 15 02 01 3C 7C 46 B0 12 40 | 40 05 17 83 EE 23 B2 E3 12 02 5C 42 12 02 B0 12 41 | 40 05 5C 42 13 02 B0 12 40 05 E0 3E 18 42 12 02 42 | B0 12 AC 05 C2 4C 12 02 B0 12 AC 05 C2 4C 13 02 43 | 38 E3 3B B2 0A 24 86 9A FE FF 07 24 3B B0 20 00 44 | 04 20 16 53 82 46 00 02 2B D3 18 92 12 02 08 23 45 | 2B B3 06 23 30 41 E2 B2 28 00 FD 27 E2 B2 28 00 46 | FD 23 B2 40 24 02 60 01 E2 B2 28 00 FD 27 15 42 47 | 70 01 05 11 05 11 05 11 82 45 02 02 05 11 82 45 48 | 04 02 B2 80 1E 00 04 02 57 42 16 02 37 80 03 00 49 | 05 11 05 11 17 53 FD 23 35 50 40 A5 82 45 2A 01 50 | 35 42 B2 40 24 02 60 01 92 92 70 01 02 02 FC 2F 51 | 15 83 F7 23 09 43 7C 40 90 00 02 3C 7C 40 A0 00 52 | C2 43 07 02 C9 EC 12 02 19 E3 1B C3 55 42 07 02 53 | 55 45 56 05 00 55 0C 2E 2E 2E 2E 2E 2E 2E 2E 1A 54 | 34 34 92 42 70 01 72 01 B2 50 0C 00 72 01 07 3C 55 | 1B B3 0B 20 82 43 62 01 92 B3 62 01 FD 27 E2 C3 56 | 21 00 0A 3C 4C 11 F6 2B 1B E3 82 43 62 01 92 B3 57 | 62 01 FD 27 E2 D3 21 00 92 52 02 02 72 01 D2 53 58 | 07 02 F0 90 0C 00 61 FC D1 23 30 41 C2 43 09 02 59 | 1B C3 55 42 09 02 55 45 BC 05 00 55 0C 56 56 56 60 | 56 56 56 56 56 36 76 00 E2 B2 28 00 FD 23 92 42 61 | 70 01 72 01 92 52 04 02 72 01 82 43 62 01 92 B3 62 | 62 01 FD 27 E2 B2 28 00 1E 28 2B D3 1C 3C 4C 10 63 | 1A 3C 82 43 62 01 92 B3 62 01 FD 27 E2 B2 28 00 64 | 01 28 1B E3 1B B3 01 24 2B D3 C9 EC 12 02 19 E3 65 | 0A 3C 82 43 62 01 92 B3 62 01 FD 27 E2 B2 28 00 66 | E6 2B 4C 10 1B E3 92 52 02 02 72 01 D2 53 09 02 67 | C0 3F 82 43 62 01 92 B3 62 01 FD 27 E2 B2 28 00 68 | 01 2C 2B D3 30 41 69 | q -------------------------------------------------------------------------------- /msp430/bsl/BL_150S_44x.txt: -------------------------------------------------------------------------------- 1 | @0220 2 | 24 02 2E 02 31 40 20 02 2B D2 C0 43 EA FF 32 C2 3 | F2 C0 32 00 00 00 B2 40 80 5A 20 01 32 D0 40 00 4 | C2 43 50 00 F2 40 98 00 51 00 F2 C0 80 00 52 00 5 | D2 D3 21 00 D2 D3 22 00 D2 C3 26 00 E2 C3 22 00 6 | E2 C3 26 00 B2 40 10 A5 2C 01 B2 40 00 A5 28 01 7 | 3B C0 3A 00 B0 12 DE 04 82 43 12 02 09 43 36 40 8 | 0A 02 37 42 B0 12 B4 05 C6 4C 00 00 16 53 17 83 9 | F9 23 D2 92 0C 02 0D 02 28 20 55 42 0B 02 75 90 10 | 12 00 80 24 75 90 10 00 6D 24 B0 12 A4 04 55 42 11 | 0B 02 75 90 18 00 31 24 75 90 1E 00 B8 24 75 90 12 | 20 00 17 24 2B B2 11 24 75 90 16 00 22 24 75 90 13 | 14 00 B3 24 75 90 1A 00 18 24 75 90 1C 00 45 24 14 | 04 3C B0 12 3E 05 BE 3F 21 53 B0 12 44 05 BA 3F 15 | 03 43 B0 12 3E 05 D2 42 0E 02 50 00 D2 42 0F 02 16 | 51 00 D2 42 10 02 16 02 AD 3F B0 12 3E 05 10 42 17 | 0E 02 16 42 0E 02 15 43 07 3C 36 40 FE FF B2 40 18 | 06 A5 10 02 35 40 0C 00 B2 40 00 A5 2C 01 92 42 19 | 10 02 28 01 B6 43 00 00 92 B3 2C 01 FD 23 15 83 20 | F3 23 36 90 FE FF CD 27 37 40 80 00 36 F0 80 FF 21 | 36 90 00 11 0E 28 07 57 36 F0 00 FF 36 90 00 12 22 | 08 28 07 57 36 F0 00 FE 04 3C 16 42 0E 02 17 42 23 | 10 02 35 43 75 96 03 20 17 83 FC 23 B2 3F 82 46 24 | 00 02 B3 3F 36 40 E0 FF 37 40 20 00 B0 12 B4 05 25 | 7C 96 01 24 2B D3 17 83 F9 23 2B C2 B0 12 A4 04 26 | 2B D2 9F 3F 16 42 0E 02 17 42 10 02 2B B2 38 24 27 | 3B D0 10 00 B0 12 B4 05 36 90 00 10 06 2C 36 90 28 | 00 01 09 2C C6 4C 00 00 25 3C B2 40 00 A5 2C 01 29 | B2 40 40 A5 28 01 16 B3 03 20 C2 4C 14 02 1A 3C 30 | C2 4C 15 02 86 9A FD FF 08 24 2B D3 3B B0 20 00 31 | 04 20 3B D0 20 00 82 46 00 02 36 90 01 02 04 28 32 | 3B D2 3B B0 10 00 02 24 3B C0 32 00 1A 42 14 02 33 | 86 4A FF FF 16 53 17 83 CD 23 B0 12 A4 04 61 3F 34 | B0 12 B4 05 17 83 FC 23 B0 12 A4 04 5E 3F B2 40 35 | F0 0F 0E 02 B2 40 10 00 10 02 B2 40 80 00 0A 02 36 | D2 42 10 02 0C 02 D2 42 10 02 0D 02 82 43 12 02 37 | 09 43 36 40 0A 02 27 42 7C 46 B0 12 48 05 17 83 38 | FB 23 16 42 0E 02 17 42 10 02 36 90 00 01 0A 28 39 | B2 46 14 02 5C 42 14 02 B0 12 48 05 17 83 5C 42 40 | 15 02 01 3C 7C 46 B0 12 48 05 17 83 EE 23 B2 E3 41 | 12 02 5C 42 12 02 B0 12 48 05 5C 42 13 02 B0 12 42 | 48 05 E0 3E 18 42 12 02 B0 12 B4 05 C2 4C 12 02 43 | B0 12 B4 05 C2 4C 13 02 38 E3 3B B2 0A 24 86 9A 44 | FE FF 07 24 3B B0 20 00 04 20 16 53 82 46 00 02 45 | 2B D3 18 92 12 02 08 23 2B B3 06 23 30 41 E2 B3 46 | 20 00 FD 27 E2 B3 20 00 FD 23 B2 40 24 02 60 01 47 | E2 B3 20 00 FD 27 15 42 70 01 05 11 05 11 05 11 48 | 82 45 02 02 05 11 82 45 04 02 B2 80 1E 00 04 02 49 | 57 42 16 02 37 80 03 00 05 11 05 11 17 53 FD 23 50 | 35 50 40 A5 82 45 2A 01 35 42 B2 40 24 02 60 01 51 | 92 92 70 01 02 02 FC 2F 15 83 F7 23 09 43 7C 40 52 | 90 00 02 3C 7C 40 A0 00 C2 43 07 02 C9 EC 12 02 53 | 19 E3 1B C3 55 42 07 02 55 45 5E 05 00 55 0C 2E 54 | 2E 2E 2E 2E 2E 2E 2E 1A 34 34 92 42 70 01 72 01 55 | B2 50 0C 00 72 01 07 3C 1B B3 0B 20 82 43 62 01 56 | 92 B3 62 01 FD 27 D2 C3 21 00 0A 3C 4C 11 F6 2B 57 | 1B E3 82 43 62 01 92 B3 62 01 FD 27 D2 D3 21 00 58 | 92 52 02 02 72 01 D2 53 07 02 F0 90 0C 00 59 FC 59 | D1 23 30 41 C2 43 09 02 1B C3 55 42 09 02 55 45 60 | C4 05 00 55 0C 56 56 56 56 56 56 56 56 36 76 00 61 | E2 B3 20 00 FD 23 92 42 70 01 72 01 92 52 04 02 62 | 72 01 82 43 62 01 92 B3 62 01 FD 27 E2 B3 20 00 63 | 1E 28 2B D3 1C 3C 4C 10 1A 3C 82 43 62 01 92 B3 64 | 62 01 FD 27 E2 B3 20 00 01 28 1B E3 1B B3 01 24 65 | 2B D3 C9 EC 12 02 19 E3 0A 3C 82 43 62 01 92 B3 66 | 62 01 FD 27 E2 B3 20 00 E6 2B 4C 10 1B E3 92 52 67 | 02 02 72 01 D2 53 09 02 C0 3F 82 43 62 01 92 B3 68 | 62 01 FD 27 E2 B3 20 00 01 2C 2B D3 30 41 69 | q 70 | -------------------------------------------------------------------------------- /msp430/bsl/BS_150S_14x.txt: -------------------------------------------------------------------------------- 1 | @0220 2 | 24 02 00 00 C0 43 E3 FF B2 40 10 A5 2C 01 B2 40 3 | 00 A5 28 01 F2 C0 3A 00 08 02 09 43 B0 12 A2 03 4 | B0 12 BA 0D 55 42 0B 02 75 90 12 00 37 24 B0 12 5 | 5C 03 55 42 0B 02 75 90 20 00 17 24 75 90 14 00 6 | 12 24 75 90 1A 00 0B 24 75 90 1C 00 1A 24 04 3C 7 | B0 12 94 0E D9 3F 21 53 B0 12 8C 0E D5 3F B0 12 8 | 94 0E 10 42 0E 02 30 40 76 0D B0 12 94 0E D2 42 9 | 0E 02 56 00 D2 42 0F 02 57 00 D2 42 10 02 09 02 10 | C3 3F 16 42 0E 02 17 42 10 02 35 43 75 96 03 20 11 | 17 83 FC 23 DD 3F 82 46 1E 02 DE 3F 16 42 0E 02 12 | 17 42 10 02 E2 B2 08 02 42 24 F2 D0 10 00 08 02 13 | B0 12 10 0F 36 90 00 10 07 2C 36 90 00 01 0A 2C 14 | D6 42 06 02 00 00 2D 3C B2 40 00 A5 2C 01 B2 40 15 | 40 A5 28 01 16 B3 04 20 D2 42 06 02 1C 02 21 3C 16 | D2 42 06 02 1D 02 86 9A FD FF 0B 24 E2 D3 08 02 17 | B2 B0 20 00 08 02 05 20 B2 D0 20 00 08 02 82 46 18 | 1E 02 36 90 01 02 06 28 F2 D2 08 02 F2 B0 10 00 19 | 08 02 03 24 F2 C0 32 00 08 02 1A 42 1C 02 86 4A 20 | FF FF 16 53 17 83 C4 23 B0 12 5C 03 91 3F B0 12 21 | 10 0F 17 83 FC 23 B0 12 5C 03 8E 3F 18 42 12 02 22 | B0 12 10 0F D2 42 06 02 12 02 B0 12 10 0F D2 42 23 | 06 02 13 02 38 E3 F2 B2 08 02 0C 24 86 9A FE FF 24 | 09 24 B2 B0 20 00 08 02 05 20 16 53 82 46 1E 02 25 | E2 D3 08 02 18 92 12 02 6E 23 E2 B3 08 02 6B 23 26 | 30 41 E2 B2 28 00 FD 27 E2 B2 28 00 FD 23 B2 40 27 | 24 02 60 01 E2 B2 28 00 FD 27 15 42 70 01 05 11 28 | 05 11 05 11 82 45 00 02 05 11 82 45 02 02 B2 80 29 | 1E 00 02 02 57 42 09 02 37 80 03 00 05 11 05 11 30 | 17 53 FD 23 30 40 64 0E 31 | q -------------------------------------------------------------------------------- /msp430/bsl/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsquareplusc/python-msp430-tools/d6400069a9cb91568294eead89191682856a3910/msp430/bsl/__init__.py -------------------------------------------------------------------------------- /msp430/bsl/__main__.py: -------------------------------------------------------------------------------- 1 | from . import target 2 | target.main() 3 | -------------------------------------------------------------------------------- /msp430/bsl/patch.txt: -------------------------------------------------------------------------------- 1 | @0220 2 | 31 40 1A 02 09 43 B0 12 2A 0E B0 12 BA 0D 55 42 3 | 0B 02 75 90 12 00 1F 24 B0 12 BA 02 55 42 0B 02 4 | 75 90 16 00 16 24 75 90 14 00 11 24 B0 12 84 0E 5 | 06 3C B0 12 94 0E 03 3C 21 53 B0 12 8C 0E B2 40 6 | 10 A5 2C 01 B2 40 00 A5 28 01 30 40 42 0C 30 40 7 | 76 0D 30 40 AC 0C 16 42 0E 02 17 42 10 02 E2 B2 8 | 08 02 14 24 B0 12 10 0F 36 90 00 10 06 28 B2 40 9 | 00 A5 2C 01 B2 40 40 A5 28 01 D6 42 06 02 00 00 10 | 16 53 17 83 EF 23 B0 12 BA 02 D3 3F B0 12 10 0F 11 | 17 83 FC 23 B0 12 BA 02 D0 3F 18 42 12 02 B0 12 12 | 10 0F D2 42 06 02 12 02 B0 12 10 0F D2 42 06 02 13 | 13 02 38 E3 18 92 12 02 BF 23 E2 B3 08 02 BC 23 14 | 30 41 15 | q -------------------------------------------------------------------------------- /msp430/bsl/target/__main__.py: -------------------------------------------------------------------------------- 1 | import msp430.bsl.target 2 | msp430.bsl.target.main() 3 | -------------------------------------------------------------------------------- /msp430/bsl/target/fcdprog.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2002 Christopher Wilson 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | from msp430.bsl.target import SerialBSLTarget 9 | 10 | 11 | class FCDProgTarget(SerialBSLTarget): 12 | """\ 13 | Flying Camp Design MSP430 BSL Programmer target 14 | 15 | http://www.flyingcampdesign.com 16 | """ 17 | 18 | def __init__(self): 19 | SerialBSLTarget.__init__(self) 20 | 21 | def add_extra_options(self): 22 | SerialBSLTarget.add_extra_options(self) 23 | 24 | # by default, invert TEST/TCK 25 | if self.parser.has_option("--invert-test"): 26 | option = self.parser.get_option("--invert-test") 27 | option.action = "store_false" 28 | option.default = True 29 | option.help = "do not invert RTS line (default inverted)" 30 | group = self.parser.get_option_group("--invert-test") 31 | self.parser.remove_option("--invert-test") 32 | group.add_option(option) 33 | 34 | # by default, invert RST 35 | if self.parser.has_option("--invert-reset"): 36 | option = self.parser.get_option("--invert-reset") 37 | option.action = "store_false" 38 | option.default = True 39 | option.help = "do not invert DTR line (default inverted)" 40 | group = self.parser.get_option_group("--invert-reset") 41 | self.parser.remove_option("--invert-reset") 42 | group.add_option(option) 43 | 44 | # by default, swap TEST/TCK and RST 45 | if self.parser.has_option("--swap-reset-test"): 46 | option = self.parser.get_option("--swap-reset-test") 47 | option.action = "store_false" 48 | option.default = True 49 | option.help = "do not exchange RST and TEST signals (DTR/RTS) (default swapped)" 50 | group = self.parser.get_option_group("--swap-reset-test") 51 | self.parser.remove_option("--swap-reset-test") 52 | group.add_option(option) 53 | 54 | # by default, use 38400 baud 55 | if self.parser.has_option("--speed"): 56 | option = self.parser.get_option("--speed") 57 | option.default = 38400 58 | option.help = "change baud rate (default %s)" % option.default 59 | group = self.parser.get_option_group("--speed") 60 | self.parser.remove_option("--speed") 61 | group.add_option(option) 62 | 63 | 64 | def main(): 65 | # run the main application 66 | bsl_target = FCDProgTarget() 67 | bsl_target.main() 68 | 69 | if __name__ == '__main__': 70 | main() 71 | -------------------------------------------------------------------------------- /msp430/bsl5/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsquareplusc/python-msp430-tools/d6400069a9cb91568294eead89191682856a3910/msp430/bsl5/__init__.py -------------------------------------------------------------------------------- /msp430/commandline_helper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2017 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Helper to write command line interfaces. 10 | """ 11 | 12 | import argparse 13 | import sys 14 | import msp430 15 | import msp430.memory 16 | 17 | 18 | class BinaryFileType(object): 19 | """\ 20 | handle binary files (filenames) and stdio ('-') like argparse.FileType 21 | but fix stdio for python 3. 22 | """ 23 | def __init__(self, mode='r'): 24 | self._mode = mode 25 | 26 | def __call__(self, string): 27 | if self._mode not in 'rw': 28 | raise ValueError('invalid mode: {}'.format(self._mode)) 29 | if string == '-': 30 | if self._mode == 'r': 31 | fileobj = sys.stdin 32 | else: 33 | fileobj = sys.stdout 34 | try: 35 | return fileobj.buffer # Python 3 36 | except AttributeError: 37 | return fileobj # Python 2 38 | try: 39 | return open(string, self._mode + 'b') 40 | except IOError as e: 41 | raise argparse.ArgumentTypeError('can not open "{}": {}'.format(string, e)) 42 | 43 | def __repr__(self): 44 | return '%s(%s)' % (type(self).__name__, self._mode) 45 | 46 | 47 | 48 | class CommandLineTool(object): 49 | """\ 50 | Command line tool base class with some common functionality: 51 | - quickly add arguments for input and/or output 52 | - main that handles errors and hides tracebacks unless --develop is given 53 | """ 54 | 55 | usage = '%(prog)s' 56 | 57 | def __init__(self): 58 | self.parser = argparse.ArgumentParser( 59 | description=self.description, 60 | formatter_class=argparse.RawDescriptionHelpFormatter) 61 | self.args = None 62 | 63 | def parser_add_input(self, nargs='+'): 64 | """add arguments for hex file input and input format""" 65 | group = self.parser.add_argument_group('Input') 66 | 67 | group.add_argument( 68 | 'SRC', 69 | nargs=nargs, 70 | help='filename or "-" for stdin', 71 | type=BinaryFileType('r')) 72 | 73 | group.add_argument( 74 | '-i', '--input-format', 75 | help='input format name', 76 | choices=msp430.memory.load_formats, 77 | default=None, 78 | metavar='TYPE') 79 | 80 | return group 81 | 82 | def parser_add_output(self, textual=False): 83 | """add arguments for one output and output format""" 84 | group = self.parser.add_argument_group('Output') 85 | 86 | group.add_argument( 87 | '-o', '--output', 88 | type=argparse.FileType('w') if textual else BinaryFileType('w'), 89 | default='-', 90 | help='write result to given file', 91 | metavar='DST') 92 | 93 | if not textual: 94 | group.add_argument( 95 | '-f', '--output-format', 96 | help='output_format format name', 97 | choices=msp430.memory.save_formats, 98 | default='titext', 99 | metavar='TYPE') 100 | 101 | return group 102 | 103 | def parser_add_verbose(self): 104 | """adds --verbose argument""" 105 | self.parser.add_argument( 106 | "-v", "--verbose", 107 | help="print more details", 108 | default=False, 109 | action='store_true') 110 | 111 | def parse_args(self): 112 | """add remaining arguments and parse sys.argv""" 113 | self.parser.add_argument( 114 | '--develop', 115 | action='store_true', 116 | help='show tracebacks on errors (development of this tool)') 117 | 118 | self.args = self.parser.parse_args() 119 | return self.args 120 | 121 | def main(self): 122 | """main that builds the argument parser, calls run() and handles errors""" 123 | try: 124 | self.configure_parser() 125 | self.parse_args() 126 | self.run(self.args) 127 | except SystemExit: 128 | raise 129 | except KeyboardInterrupt: 130 | sys.stderr.write('User aborted.\n') 131 | sys.exit(1) 132 | except Exception as msg: 133 | if self.args is None or self.args.develop: raise 134 | sys.stderr.write('\nAn error occurred:\n{}\n'.format(msg)) 135 | sys.exit(2) 136 | 137 | # ----- override in subclass ----- 138 | 139 | def configure_parser(self): 140 | """update the argument parser here""" 141 | 142 | def run(self): 143 | """override this in actual tool""" 144 | -------------------------------------------------------------------------------- /msp430/gdb/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsquareplusc/python-msp430-tools/d6400069a9cb91568294eead89191682856a3910/msp430/gdb/__init__.py -------------------------------------------------------------------------------- /msp430/gdb/__main__.py: -------------------------------------------------------------------------------- 1 | from . import target 2 | target.main() 3 | -------------------------------------------------------------------------------- /msp430/gdb/target.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2010 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Remote GDB programmer for the MSP430 embedded processor. 10 | """ 11 | 12 | import sys 13 | import logging 14 | from msp430.gdb import gdb 15 | 16 | from optparse import OptionGroup 17 | import msp430.target 18 | 19 | VERSION = "1.0" 20 | 21 | 22 | class GDBTarget(object): 23 | 24 | def __init__(self): 25 | self.gdb = None 26 | 27 | def memory_read(self, address, length): 28 | """Read from memory.""" 29 | return bytearray(self.gdb.read_memory(address, length)) 30 | 31 | def memory_write(self, address, data): 32 | """Write to memory.""" 33 | return self.gdb.write_memory(address, data) 34 | 35 | def mass_erase(self): 36 | """Clear all Flash memory.""" 37 | self.gdb.monitor('erase all') 38 | 39 | def main_erase(self): 40 | """Clear main Flash memory (excl. infomem).""" 41 | self.gdb.monitor('erase') 42 | 43 | def erase(self, address): 44 | """Erase Flash segment containing the given address.""" 45 | self.gdb.monitor('erase segment 0x%x' % address) 46 | 47 | def execute(self, address): 48 | """Start executing code on the target.""" 49 | self.gdb.cont(address) # load PC and execute 50 | 51 | def version(self): 52 | """The 16 bytes of the ROM that contain chip and BSL info are returned.""" 53 | return self.gdb.read_memory(0x0ff0, 16) 54 | 55 | def reset(self): 56 | """Reset the device.""" 57 | self.gdb.monitor('reset') 58 | 59 | def open(self, host_port): 60 | self.close() 61 | self.gdb = gdb.GDBClient(host_port) 62 | 63 | def close(self): 64 | if self.gdb is not None: 65 | self.gdb.close() # release communication port 66 | self.gdb = None 67 | 68 | 69 | class GDB(GDBTarget, msp430.target.Target): 70 | """Combine the GDB backend and the common target code.""" 71 | 72 | def __init__(self): 73 | GDBTarget.__init__(self) 74 | msp430.target.Target.__init__(self) 75 | self.logger = logging.getLogger('GDB') 76 | 77 | def add_extra_options(self): 78 | group = OptionGroup(self.parser, "Connection") 79 | 80 | group.add_option( 81 | "-c", "--connect", 82 | dest="host_port", 83 | help="TCP/IP host name or ip and port of GDB server (default: %default)", 84 | action='store', 85 | default='localhost:2000', 86 | metavar='HOST:PORT') 87 | 88 | self.parser.add_option_group(group) 89 | 90 | def parse_extra_options(self): 91 | host, port = self.options.host_port.split(':') 92 | self.host_port = (host, int(port)) 93 | if self.verbose: 94 | sys.stderr.write("MSP430 remote GDB programmer Version: %s\n" % VERSION) 95 | 96 | def close_connection(self): 97 | self.close() 98 | 99 | def open_connection(self): 100 | self.open(self.host_port) 101 | 102 | 103 | def main(): 104 | # run the main application 105 | gdb_target = GDB() 106 | gdb_target.main() 107 | 108 | if __name__ == '__main__': 109 | main() 110 | -------------------------------------------------------------------------------- /msp430/jtag/HIL.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2004 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Python bindings to the functions in the MSP430 JTAG HIL 10 | (Hardware Interface Library) 11 | 12 | Requires Python 2+, ctypes and HIL.dll/libHIL.so 13 | """ 14 | 15 | import ctypes 16 | 17 | HIL = ctypes.windll.HIL 18 | 19 | Initialize = HIL.HIL_Initialize 20 | Initialize.argtypes = [ctypes.c_char_p] 21 | Initialize.restype = ctypes.c_int 22 | Open = HIL.HIL_Open 23 | Open.argtypes = [] 24 | Open.restype = ctypes.c_int 25 | Connect = HIL.HIL_Connect 26 | Connect.argtypes = [] 27 | Connect.restype = ctypes.c_int 28 | Release = HIL.HIL_Release 29 | Release.argtypes = [] 30 | Release.restype = ctypes.c_int 31 | Close = HIL.HIL_Close 32 | Close.argtypes = [ctypes.c_long] 33 | Close.restype = ctypes.c_int 34 | JTAG_IR = HIL.HIL_JTAG_IR 35 | JTAG_IR.argtypes = [ctypes.c_long] 36 | JTAG_IR.restype = ctypes.c_long 37 | TEST_VPP = HIL.HIL_TEST_VPP 38 | TEST_VPP.argtypes = [ctypes.c_long] 39 | TEST_VPP.restype = ctypes.c_long 40 | JTAG_DR = HIL.HIL_JTAG_DR 41 | JTAG_DR.argtypes = [ctypes.c_long, ctypes.c_long] 42 | JTAG_DR.restype = ctypes.c_long 43 | VCC = HIL.HIL_VCC 44 | VCC.argtypes = [ctypes.c_long] 45 | VCC.restype = ctypes.c_int 46 | TST = HIL.HIL_TST 47 | TST.argtypes = [ctypes.c_long] 48 | TST.restype = ctypes.c_int 49 | TCK = HIL.HIL_TCK 50 | TCK.argtypes = [ctypes.c_long] 51 | TCK.restype = ctypes.c_int 52 | TMS = HIL.HIL_TMS 53 | TMS.argtypes = [ctypes.c_long] 54 | TMS.restype = ctypes.c_int 55 | TDI = HIL.HIL_TDI 56 | TDI.argtypes = [ctypes.c_long] 57 | TDI.restype = ctypes.c_int 58 | TCLK = HIL.HIL_TCLK 59 | TCLK.argtypes = [ctypes.c_long] 60 | TCLK.restype = ctypes.c_int 61 | RST = HIL.HIL_RST 62 | RST.argtypes = [ctypes.c_long] 63 | RST.restype = ctypes.c_int 64 | VPP = HIL.HIL_VPP 65 | VPP.argtypes = [ctypes.c_long] 66 | VPP.restype = ctypes.c_int 67 | DelayMSec = HIL.HIL_DelayMSec 68 | DelayMSec.argtypes = [ctypes.c_ulong] 69 | DelayMSec.restype = ctypes.c_int 70 | StartTimer = HIL.HIL_StartTimer 71 | StartTimer.argtypes = [] 72 | StartTimer.restype = ctypes.c_int 73 | ReadTimer = HIL.HIL_ReadTimer 74 | ReadTimer.argtypes = [] 75 | ReadTimer.restype = ctypes.c_ulong 76 | StopTimer = HIL.HIL_StopTimer 77 | StopTimer.argtypes = [] 78 | StopTimer.restype = ctypes.c_int 79 | ReadTDO = HIL.HIL_ReadTDO 80 | ReadTDO.argtypes = [] 81 | ReadTDO.restype = ctypes.c_long 82 | 83 | if __name__ == '__main__': 84 | Initialize('1') 85 | Connect() 86 | VCC(3000) 87 | 88 | #~ HIL_TST(1) 89 | #~ HIL_DelayMSec(1000) 90 | #~ HIL_TST(0) 91 | 92 | #~ HIL_TCK(1) 93 | #~ HIL_TDI(1) 94 | 95 | #~ for i in range(3): 96 | #~ HIL_DelayMSec(100) 97 | #~ HIL_TMS(1) 98 | #~ HIL_DelayMSec(100) 99 | #~ HIL_TMS(0) 100 | 101 | JTAG_DR(0x1234, 16) 102 | 103 | Release() 104 | Close(1) 105 | -------------------------------------------------------------------------------- /msp430/jtag/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsquareplusc/python-msp430-tools/d6400069a9cb91568294eead89191682856a3910/msp430/jtag/__init__.py -------------------------------------------------------------------------------- /msp430/jtag/__main__.py: -------------------------------------------------------------------------------- 1 | from . import target 2 | target.main() 3 | -------------------------------------------------------------------------------- /msp430/jtag/hilspi.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2004 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Using the MSP430 JTAG parallel port board as SPI interface. 10 | 11 | Requires Python 2+, ctypes and HIL.dll/libHIL.so 12 | """ 13 | 14 | import HIL 15 | #~ import psyco 16 | #~ psyco.full() 17 | 18 | 19 | def init(port='1'): 20 | """open the parallel port and prepare for SPI mode""" 21 | HIL.Initialize(port) 22 | HIL.Connect() 23 | HIL.VCC(3000) 24 | HIL.TST(0) 25 | HIL.TCK(1) 26 | HIL.TDI(1) 27 | HIL.TMS(1) 28 | 29 | 30 | def close(): 31 | """close the parallel port""" 32 | HIL.Release() 33 | HIL.Close(1) 34 | 35 | 36 | def _delay(): 37 | """can be implemented if the SPI data rate has to be lowered""" 38 | #~ HIL.DelayMSec(1) 39 | #~ for i in range(10): HIL.DelayMSec(0) 40 | #~ HIL.DelayMSec(0) 41 | pass 42 | 43 | 44 | def shift(data): 45 | """shift an binary string from/to the slave, returning the 46 | answer string of the same length 47 | """ 48 | answer = [] 49 | for character in data: 50 | shiftout = ord(character) 51 | indata = 0 52 | for i in range(8): 53 | HIL.TCK(0) 54 | HIL.TDI(shiftout & 0x80) 55 | shiftout <<= 1 56 | _delay() 57 | HIL.TCK(1) 58 | _delay() 59 | indata = (indata << 1) | HIL.ReadTDO() 60 | answer.append(chr(indata)) 61 | return ''.join(answer) 62 | 63 | 64 | def sync(): 65 | """read untlil something else as a 0xff arrives. 66 | """ 67 | while shift('\xff') != '\xff': 68 | pass 69 | 70 | 71 | def getNullTeminated(maxlen=80): 72 | """read a null terminated string over SPI.""" 73 | answer = [] 74 | while maxlen: 75 | c = shift('\xff') 76 | if c == '\0': 77 | break 78 | answer.append(c) 79 | maxlen -= 1 80 | return ''.join(answer) 81 | 82 | 83 | #test application 84 | if __name__ == '__main__': 85 | import time 86 | init() 87 | #reset target 88 | HIL.RST(0) 89 | HIL.DelayMSec(10) 90 | HIL.RST(1) 91 | HIL.DelayMSec(10) 92 | 93 | # simple speed test 94 | bytes = 0 95 | t1 = time.time() 96 | for i in range(200): 97 | #~ print '%r' % getNullTeminated() 98 | bytes += len(getNullTeminated()) + 1 99 | dt = time.time() - t1 100 | print("%d bytes in %.2f seconds -> %.2f bytes/second" % (bytes, dt, bytes / dt)) 101 | -------------------------------------------------------------------------------- /msp430/jtag/profile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2002-2010 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Statistical profiler for the MSP430. 10 | 11 | it works by sampling the address bus and counting addresses seen. 12 | the problem there is, that it is not sure that we're reading a valid address 13 | every time. an other issue is the relatively slow sampling rate compared to 14 | the execution speed of the MCU, which means that several runs are need to 15 | get meaningful numbers. 16 | """ 17 | 18 | from msp430.jtag import jtag 19 | import sys 20 | import time 21 | 22 | if __name__ == '__main__': 23 | from optparse import OptionParser 24 | 25 | parser = OptionParser(usage="%prog [OPTIONS]") 26 | 27 | parser.add_option( 28 | "-v", "--verbose", 29 | dest="verbose", 30 | help="show more messages (can be given multiple times)", 31 | default=0, 32 | action='count') 33 | 34 | parser.add_option( 35 | "-o", "--output", 36 | dest="output", 37 | help="write result to given file", 38 | metavar="FILENAME") 39 | 40 | (options, args) = parser.parse_args() 41 | 42 | # prepare output 43 | if options.output is None: 44 | output = sys.stdout 45 | else: 46 | output = open(options.output, 'w') 47 | 48 | jtag.init_backend(jtag.CTYPES_MSPGCC) # doesn't currently work with 3'rd party libs 49 | samples = [0] * 2**16 50 | 51 | try: 52 | jtagobj = jtag.JTAG() 53 | 54 | if options.verbose: 55 | try: 56 | jtagobj.setDebugLevel(options.verbose) 57 | except IOError: 58 | sys.stderr.write("WARNING: Failed to set debug level in backend library\n") 59 | #~ memory.DEBUG = options.verbose 60 | jtag.DEBUG = options.verbose 61 | 62 | jtagobj.open() # try to open port 63 | try: 64 | jtagobj.connect() # try to connect to target 65 | connected = True 66 | jtagobj.reset(1, 0) 67 | sys.stderr.write("profiling... (CTRL-C to stop)\n") 68 | start_time = time.time() 69 | while True: 70 | samples[jtag.MSP430_readMAB()] += 1 71 | finally: 72 | stop_time = time.time() 73 | if sys.exc_info()[:1]: # if there is an exception pending 74 | jtagobj.verbose = 0 # do not write any more messages 75 | if connected: 76 | jtagobj.reset(1, 1) # reset and release target 77 | jtagobj.close() # release communication port 78 | except KeyboardInterrupt: 79 | # write out sample count per address 80 | total = 0 81 | for n, count in enumerate(samples): 82 | if count > 0: 83 | output.write("0x%04x\t%d\n" % (n, count)) 84 | total += count 85 | # write a summary 86 | sys.stderr.write('%d samples in %.2f seconds (%d samples/second)\n' % ( 87 | total, 88 | stop_time - start_time, 89 | total / (stop_time - start_time))) 90 | -------------------------------------------------------------------------------- /msp430/legacy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsquareplusc/python-msp430-tools/d6400069a9cb91568294eead89191682856a3910/msp430/legacy/__init__.py -------------------------------------------------------------------------------- /msp430/listing/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsquareplusc/python-msp430-tools/d6400069a9cb91568294eead89191682856a3910/msp430/listing/__init__.py -------------------------------------------------------------------------------- /msp430/listing/mspgcc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2006-2010 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Helper module to parse [msp]gcc/binutils listing files. 10 | """ 11 | 12 | import re 13 | 14 | regexp_address = re.compile(r'([0-9a-f]+).*\t([0-9a-f]+) (\w+)') 15 | 16 | 17 | def label_address_map(filename): 18 | """\ 19 | Scan the listing and return a dict with variables as keys, address of 20 | them as values. 21 | """ 22 | labels = {} 23 | 24 | for line in open(filename): 25 | # don't read the entire file, just the symbol table at the beginning 26 | if line.startswith("Disassembly"): 27 | break 28 | # match labels 29 | m = regexp_address.match(line) 30 | if m: 31 | address = int(m.group(1), 16) 32 | #~ size = int(m.group(2), 16) 33 | label = m.group(3) 34 | labels[label] = address 35 | return labels 36 | -------------------------------------------------------------------------------- /msp430/memory/bin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2002-2010 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Helper functions to read and write binary files. 10 | """ 11 | 12 | import msp430.memory 13 | 14 | 15 | def load(filelike): 16 | """load data from a (opened) file in binary format""" 17 | memory = msp430.memory.Memory() 18 | memory.append(msp430.memory.Segment(0, filelike.read())) 19 | return memory 20 | 21 | 22 | def save(memory, filelike): 23 | """output binary to given file object""" 24 | for segment in sorted(memory.segments): 25 | # XXX would it be better to fill the gaps between segments? 26 | filelike.write(bytes(segment.data)) 27 | -------------------------------------------------------------------------------- /msp430/memory/convert.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2004-2017 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Simple converter for hex files. 10 | 11 | data can be read from stdin and output on stdout: 12 | usage: cat file.txt | convert - >out.a43 13 | usage: convert file.txt >out.a43 14 | usage: convert file.txt -o out.a43 15 | """ 16 | 17 | 18 | def main(): 19 | import msp430.commandline_helper 20 | 21 | class ConvertTool(msp430.commandline_helper.CommandLineTool): 22 | description = """\ 23 | Simple hex file conversion tool. 24 | 25 | It is also possible to specify multiple input files and create a single, 26 | merged output. 27 | """ 28 | 29 | def configure_parser(self): 30 | self.parser_add_input(nargs='*') 31 | self.parser_add_output() 32 | 33 | def run(self, args): 34 | if not args.SRC: 35 | # if no files are given, read from stdin 36 | args.FILE = [msp430.commandline_helper.BinaryFileType('r')('-')] 37 | # default to TI-Text if no format is given 38 | if args.input_format is None: 39 | args.input_format = 'titext' 40 | 41 | # get input 42 | data = msp430.memory.Memory() 43 | for fileobj in args.SRC: 44 | data.merge(msp430.memory.load(fileobj.name, fileobj, args.input_format)) 45 | 46 | # write ihex file 47 | msp430.memory.save(data, args.output, args.output_format) 48 | 49 | ConvertTool().main() 50 | 51 | if __name__ == '__main__': 52 | main() 53 | -------------------------------------------------------------------------------- /msp430/memory/error.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2002-2010 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Error messages for file handler modules. 10 | """ 11 | 12 | 13 | class FileFormatError(Exception): 14 | """\ 15 | Exception for "file is not in the expected format" messages. 16 | """ 17 | def __init__(self, message, filename=None, lineno=None): 18 | Exception.__init__(self, message) 19 | self.filename = filename 20 | self.lineno = lineno 21 | 22 | def __repr__(self): 23 | return "%s(%s, %s, %s)" % ( 24 | self.__class__.__name__, 25 | Exception.__repr__(self), 26 | self.filename, 27 | self.lineno) 28 | 29 | def __str__(self): 30 | return "%s:%s: %s)" % ( 31 | self.filename, 32 | self.lineno, 33 | Exception.__str__(self)) 34 | -------------------------------------------------------------------------------- /msp430/memory/generate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2004-2017 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Test File generator. 10 | 11 | This tool generates a hex file, of given size, ending on address 12 | 0xffff if no start address is given. 13 | 14 | USAGE: generate.py -l size_in_bytes 15 | """ 16 | 17 | from msp430 import memory 18 | import struct 19 | import random 20 | 21 | 22 | def main(): 23 | import msp430.commandline_helper 24 | 25 | class GeneratorTool(msp430.commandline_helper.CommandLineTool): 26 | description = """\ 27 | Test File generator. 28 | 29 | This tool generates a hex file, of given size, ending on address 30 | 0xffff if no start address is given. 31 | """ 32 | 33 | def configure_parser(self): 34 | group = self.parser.add_argument_group('Values') 35 | 36 | group.add_argument( 37 | "-l", "--length", 38 | help="number of bytes to generate", 39 | default=1024, 40 | type=int) 41 | 42 | group.add_argument( 43 | "-s", "--start-address", 44 | help="start address of data generated", 45 | default=None, 46 | type=int) 47 | 48 | group = group.add_mutually_exclusive_group() 49 | 50 | group.add_argument( 51 | "-c", "--count", 52 | help="use address as data", 53 | action="store_true", 54 | default=False) 55 | 56 | group.add_argument( 57 | "--const", 58 | help="use given 16 bit number as data (default=0x3fff)", 59 | default=0x3fff, # JMP $ 60 | type=int) 61 | 62 | group.add_argument( 63 | "--random", 64 | help="fill with random numbers", 65 | action="store_true", 66 | default=False) 67 | 68 | self.parser_add_output() 69 | 70 | def run(self, args): 71 | # get input 72 | mem = memory.Memory() # prepare downloaded data 73 | 74 | # if no start address is given, align the data towards the end of the 64k 75 | # address room 76 | if args.start_address is None: 77 | args.start_address = 0x10000 - args.length 78 | 79 | # create data 80 | addresses = range(args.start_address, args.start_address + args.length, 2) 81 | if args.count: 82 | data = b''.join(struct.pack(" 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Helper functions to read and write intel hex files. 10 | """ 11 | 12 | import sys 13 | import struct 14 | import msp430.memory 15 | import msp430.memory.error 16 | 17 | 18 | def load(filelike): 19 | """load data from a (opened) file in Intel-HEX format""" 20 | memory = msp430.memory.Memory() 21 | segmentdata = bytearray() 22 | currentAddr = 0 23 | startAddr = 0 24 | extendAddr = 0 25 | for n, l in enumerate(filelike): 26 | if not l.strip(): 27 | continue # skip empty lines 28 | if l[0:1] != b':': 29 | raise msp430.memory.error.FileFormatError( 30 | "line not valid intel hex data: '%s...'" % l[0:10], 31 | filename=getattr(filelike, "name", ""), 32 | lineno=n + 1) 33 | l = l.strip() # fix CR-LF issues... 34 | length = int(l[1:3], 16) 35 | address = int(l[3:7], 16) + extendAddr 36 | type = int(l[7:9], 16) 37 | #~ check = int(l[-2:], 16) 38 | if type == 0x00: 39 | if currentAddr != address: 40 | if segmentdata: 41 | memory.segments.append(msp430.memory.Segment(startAddr, segmentdata)) 42 | startAddr = currentAddr = address 43 | segmentdata = bytearray() 44 | for i in range(length): 45 | segmentdata.append(int(l[9 + 2 * i:11 + 2 * i], 16)) 46 | currentAddr = length + currentAddr 47 | elif type == 0x02: 48 | extendAddr = int(l[9:13], 16) << 4 49 | elif type == 0x04: 50 | extendAddr = int(l[9:13], 16) << 16 51 | elif type in (0x01, 0x03, 0x05): 52 | pass 53 | else: 54 | sys.stderr.write("Ignored unknown field (type 0x%02x) in ihex file.\n" % type) 55 | if segmentdata: 56 | memory.segments.append(msp430.memory.Segment(startAddr, segmentdata)) 57 | return memory 58 | 59 | 60 | def save(memory, filelike): 61 | """write a string containing intel hex to given file object""" 62 | last_upper_address_bits = 0 63 | for seg in sorted(memory.segments): 64 | address = seg.startaddress 65 | data = seg.data 66 | start = 0 67 | while start < len(data): 68 | # check for addresses >64k and output offset command when the value 69 | # changes 70 | upper_address_bits = address >> 16 71 | if last_upper_address_bits != upper_address_bits: 72 | filelike.write(_ihexline(address, struct.pack(">H", upper_address_bits), record_type=4)) # set offset 73 | last_upper_address_bits = upper_address_bits 74 | # write data line 75 | end = start + 16 76 | if end > len(data): 77 | end = len(data) 78 | filelike.write(_ihexline(address, data[start:end])) 79 | start += 16 80 | address += 16 81 | filelike.write(_ihexline(0, [], end=True)) # append no data but an end line 82 | 83 | 84 | def _ihexline(address, buffer, end=False, record_type=0): 85 | """internal use: generate a line with intel hex encoded data""" 86 | out = [] 87 | if end: # special override if end parameter is given 88 | record_type = 1 89 | out.append(b':%02X%04X%02X' % (len(buffer), address & 0xffff, record_type)) 90 | sum = len(buffer) + ((address >> 8) & 255) + (address & 255) + (record_type & 255) 91 | for b in bytearray(buffer): 92 | out.append(b'%02X' % (b & 255)) 93 | sum += b & 255 94 | out.append(b'%02X\r\n' % ((-sum) & 255)) 95 | return b''.join(out) 96 | -------------------------------------------------------------------------------- /msp430/memory/titext.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2001-2017 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | Helper functions to read and write TI-Text files. 10 | """ 11 | 12 | import msp430.memory 13 | import msp430.memory.error 14 | 15 | 16 | def load(filelike): 17 | """load data from a (opened) file in TI-Text format""" 18 | memory = msp430.memory.Memory() 19 | startAddr = 0 20 | segmentdata = bytearray() 21 | # TXT-File is parsed line by line 22 | for n, line in enumerate(filelike): 23 | if not line: 24 | break # EOF 25 | l = line.strip() 26 | if l[0:1] == b'q': 27 | break 28 | elif l[0:1] == b'@': # if @ => new address => send frame and set new addr. 29 | # create a new segment 30 | if segmentdata: 31 | memory.segments.append(msp430.memory.Segment(startAddr, segmentdata)) 32 | startAddr = int(l[1:], 16) 33 | segmentdata = bytearray() 34 | else: 35 | for i in l.split(): 36 | try: 37 | segmentdata.append(int(i, 16)) 38 | except ValueError as e: 39 | raise msp430.memory.error.FileFormatError( 40 | 'File is no valid TI-Text: {}'.format(e), 41 | filename=getattr(filelike, 'name', ''), 42 | lineno=n + 1) 43 | if segmentdata: 44 | memory.segments.append(msp430.memory.Segment(startAddr, segmentdata)) 45 | return memory 46 | 47 | 48 | def save(memory, filelike): 49 | """output TI-Text to given file object""" 50 | for segment in sorted(memory.segments): 51 | filelike.write('@{:04x}\n'.format(segment.startaddress).encode('ascii')) 52 | data = bytearray(segment.data) 53 | for i in range(0, len(data), 16): 54 | filelike.write('{}\n'.format( 55 | ' '.join(['{:02x}'.format(x) for x in data[i:i + 16]]) 56 | ).encode('ascii')) 57 | filelike.write(b'q\n') 58 | -------------------------------------------------------------------------------- /msp430/ram_usage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2017 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """ 9 | This is a little tool to parse msp430-readelf's output and format it nicely. 10 | It can be useful to get an overview of the RAM usage and free stack memory. 11 | 12 | Requires: 13 | Python 2.3+ 14 | mspgcc, msp430-readelf on the path 15 | 16 | Chris 17 | """ 18 | 19 | import os 20 | import re 21 | import sys 22 | 23 | 24 | def main(): 25 | from optparse import OptionParser 26 | 27 | parser = OptionParser() 28 | 29 | parser.add_option( 30 | "-d", "--detailed", 31 | dest="detailed", default=False, 32 | help="print a detailed list of labels", 33 | action="store_true") 34 | 35 | parser.add_option( 36 | "-c", "--compact", 37 | dest="compact", 38 | default=False, 39 | help="print a compact list of used bytes", 40 | action="store_true") 41 | 42 | parser.add_option( 43 | "-q", "--quiet", 44 | action="store_false", 45 | dest="verbose", 46 | default=True, 47 | help="don't print status messages to stdout") 48 | 49 | parser.add_option( 50 | "--min-stack", 51 | action="store", 52 | dest="min_stack", 53 | type="int", 54 | default=None, 55 | help="fail if free space for stack is not as large as this") 56 | 57 | (options, args) = parser.parse_args() 58 | 59 | if len(args) != 1: 60 | parser.error("missing object file name") 61 | 62 | # regexp to parse lines like the following one 63 | # 959: 000002aa 0 OBJECT GLOBAL DEFAULT 6 rxdata 64 | re_obj = re.compile(r':[ \t]+([0-9a-f]+)[ \t]+([0-9a-f]+)[ \t]+(\w+)[ \t]+.* (.*)$') 65 | 66 | # read labeled object from readelf dump 67 | objs = {} 68 | syms = os.popen('msp430-readelf -a -W "%s"' % args[0]) 69 | for line in syms: 70 | #~ print ">", line, 71 | m = re_obj.search(line) 72 | if m: 73 | objs[m.group(4)] = ((int(m.group(1), 16), int(m.group(2)), m.group(3))) 74 | if syms.close(): 75 | raise IOError("msp430-readelf failed") 76 | 77 | # store labels by address 78 | mmap = {} 79 | #~ print 'adr size name' 80 | for name, (address, size, type) in objs.items(): 81 | #~ print '0x%04x %3d %s %s' % (address, size, name, type) 82 | if type == 'OBJECT': 83 | if size == 0: 84 | size = 1 # make sure zero sized objects are shown too 85 | for x in range(size): 86 | if x == 0: 87 | #first line 88 | desc = '%s%s (%d)' % ( 89 | name, 90 | (size > 1) and '[%s]' % x or '', 91 | size, 92 | ) 93 | else: 94 | # other lines 95 | desc = '%s%s' % ( 96 | ' ' * len(name), 97 | (size > 1) and '[%s]' % x or '' 98 | ) 99 | # concatenate if there is more than one label 100 | if (address + x) in mmap: 101 | desc = '%s | %s' % (mmap[address + x], desc) 102 | mmap[address + x] = desc 103 | 104 | # print labels sorted by address, only RAM 105 | free = 0 106 | for address in range(objs['__data_start'][0], objs['__stack'][0]): 107 | if address in mmap: 108 | name = mmap[address] 109 | else: 110 | name = ' -' * 20 111 | free += 1 112 | if options.detailed: 113 | print('0x%04x: %s' % (address, name)) 114 | 115 | if options.compact: 116 | for address in range(objs['__data_start'][0], objs['__stack'][0], 16): 117 | print('0x%04x: %s' % ( 118 | address, 119 | ''.join([a in mmap and '*' or '.' 120 | for a in range(address, address + 16)]) 121 | )) 122 | 123 | # scan backwards for continous memory, starting from the stack init 124 | stackmem = 0 125 | address = objs['__stack'][0] 126 | while address >= objs['__data_start'][0] and address not in mmap: 127 | address -= 1 128 | stackmem += 1 129 | 130 | # calc total and print summary 131 | size = objs['__stack'][0] - objs['__data_start'][0] 132 | print('RAM usage summary:') 133 | print('%d of %d bytes used (%d free)' % (size - free, size, free)) 134 | print('the stack can grow up to %d bytes (continous memory at end of RAM)' % ( 135 | stackmem & 0xfffe # round size, even number 136 | )) 137 | 138 | if options.min_stack is not None: 139 | if (stackmem & 0xfffe) < options.min_stack: 140 | print("ERROR: Stack size is smaller than the given value (--min-stack=%d)" % (options.min_stack,)) 141 | sys.exit(2) 142 | 143 | if __name__ == '__main__': 144 | main() 145 | -------------------------------------------------------------------------------- /msp430/shell/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsquareplusc/python-msp430-tools/d6400069a9cb91568294eead89191682856a3910/msp430/shell/__init__.py -------------------------------------------------------------------------------- /msp430/shell/watch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2011-2017 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | """\ 9 | This tool repeatedly checks the size and modification time of a file. When a 10 | change is detected it can run the specified command. 11 | 12 | Example of usage: automatically download to MCU a file when it has changed (due 13 | to a new, successful compilation run). 14 | """ 15 | 16 | import os 17 | import stat 18 | import sys 19 | import time 20 | import datetime 21 | import subprocess 22 | 23 | 24 | def get_file_stats(filename): 25 | """get the size and modification time of a file""" 26 | if os.path.exists(filename): 27 | stats = os.stat(filename) 28 | return stats[stat.ST_SIZE], stats[stat.ST_MTIME] 29 | else: 30 | return (0, 0) 31 | 32 | 33 | def watch(filenames, callback): 34 | """repeatedly check the given files and run the callback when one has changed""" 35 | last_stats = [get_file_stats(filename) for filename in filenames] 36 | while True: 37 | stats = [get_file_stats(filename) for filename in filenames] 38 | if stats != last_stats: 39 | last_stats = stats 40 | callback() 41 | time.sleep(2) 42 | 43 | 44 | def main(): 45 | import argparse 46 | 47 | parser = argparse.ArgumentParser( 48 | epilog='example: %(prog)s test.txt --execute "echo --"') 49 | 50 | parser.add_argument( 51 | "FILENAME", 52 | nargs="+") 53 | 54 | parser.add_argument( 55 | "-x", "--execute", 56 | metavar="COMMAND", 57 | help="run this command when watched file(s) changed, -- is replaced by first FILENAME") 58 | 59 | args = parser.parse_args() 60 | 61 | if args.execute: 62 | cmd = args.execute.replace('--', args.FILENAME[0]) 63 | sys.stderr.write("watch: command line will be: {!r}\n".format(cmd)) 64 | else: 65 | cmd = None 66 | 67 | def execute(): 68 | sys.stderr.write('watch: file(s) changed {}\n'.format(datetime.datetime.now())) 69 | if cmd is not None: 70 | #~ sys.stderr.write("watch: execute: %r\n" % cmd) 71 | subprocess.call(cmd, shell=True) 72 | 73 | try: 74 | watch(args.FILENAME, callback=execute) 75 | except KeyboardInterrupt: 76 | sys.stdout.write('\n') 77 | 78 | if __name__ == '__main__': 79 | main() 80 | -------------------------------------------------------------------------------- /msp430/tool.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # command line stub 5 | # 6 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 7 | # (C) 2011-2017 Chris Liechti 8 | # 9 | # SPDX-License-Identifier: BSD-3-Clause 10 | 11 | import sys 12 | 13 | COMMANDS = { 14 | 'jtag': 'msp430.jtag.target', 15 | 'dco': 'msp430.jtag.dco', 16 | 'gdb': 'msp430.gdb.target', 17 | 'bsl': 'msp430.bsl.target', 18 | 'bsl5.uart': 'msp430.bsl5.uart', 19 | 'bsl5.hid': 'msp430.bsl5.hid', 20 | 'hexdump': 'msp430.memory.hexdump', 21 | 'compare': 'msp430.memory.compare', 22 | 'convert': 'msp430.memory.convert', 23 | 'generate': 'msp430.memory.generate', 24 | 'cmd': 'msp430.shell.command', 25 | 'watch': 'msp430.shell.watch', 26 | 'as': 'msp430.asm.as', 27 | 'ld': 'msp430.asm.ld', 28 | 'cpp': 'msp430.asm.cpp', 29 | 'dis': 'msp430.asm.disassemble', 30 | } 31 | 32 | 33 | def usage_error(): 34 | sys.stderr.write( 35 | 'Command line stub for python-msp430-tools\n' 36 | 'USAGE: {prog} COMMAND [args]\n' 37 | 'Supported COMMANDs are:\n' 38 | '{tools}' 39 | '\n'.format( 40 | prog=sys.argv[0], 41 | tools='\n'.join('- {}'.format(x) for x in sorted(COMMANDS.keys())))) 42 | sys.exit(1) 43 | 44 | 45 | def main(): 46 | if len(sys.argv) < 2: 47 | usage_error() 48 | else: 49 | command = sys.argv.pop(1) 50 | # patch argv so that help texts are correct 51 | sys.argv[0] = '{} {}'.format(sys.argv[0], command) 52 | try: 53 | module_name = COMMANDS[command] 54 | except KeyError: 55 | # unsupported command 56 | usage_error() 57 | else: 58 | __import__(module_name) 59 | module = sys.modules[module_name] 60 | #~ sys.stderr.write('running main() from %r\n' % module) 61 | module.main() 62 | 63 | if __name__ == '__main__': 64 | main() 65 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyserial 2 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal=1 3 | 4 | [flake8] 5 | max-line-length = 120 6 | ignore = E265, E126, E241 7 | 8 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # This file is part of https://github.com/zsquareplusc/python-msp430-tools 5 | # (C) 2017 Chris Liechti 6 | # 7 | # SPDX-License-Identifier: BSD-3-Clause 8 | # 9 | # This is a setup script for pythons distutils. It will install the 10 | # python-msp430-tools extension when run as: python setup.py install 11 | from setuptools import setup, find_packages 12 | import sys 13 | import glob 14 | 15 | setup( 16 | name="python-msp430-tools", 17 | description="Python MSP430 Tools", 18 | version="0.9.2", 19 | author="Chris Liechti", 20 | author_email="cliechti@gmx.net", 21 | url="https://github.com/zsquareplusc/python-msp430-tools", 22 | packages=find_packages(), 23 | package_dir={'msp430': 'msp430'}, 24 | package_data={'msp430': [ 25 | 'asm/definitions/msp430-mcu-list.txt', 26 | 'bsl/BL_150S_14x.txt', 27 | 'bsl/BL_150S_44x.txt', 28 | 'bsl/BS_150S_14x.txt', 29 | 'bsl/patch.txt', 30 | 'bsl5/RAM_BSL.00.06.05.34.txt', 31 | ]}, 32 | entry_points={ 33 | 'console_scripts': [ 34 | 'msp430-bsl = msp430.bsl.target:main', 35 | 'msp430-bsl-fcdprog = msp430.bsl.target.fcdprog:main', 36 | 'msp430-bsl-legacy = msp430.legacy.bsl_main:main', 37 | 'msp430-bsl-telosb = msp430.bsl.target.telosb:main', 38 | 'msp430-compare = msp430.memory.compare:main', 39 | 'msp430-convert = msp430.memory.convert:main', 40 | 'msp430-downloader = msp430.downloader:main', 41 | #~ 'msp430-gdb = msp430.gdb.target:main', 42 | 'msp430-generate = msp430.memory.generate:main', 43 | 'msp430-hexdump = msp430.memory.hexdump:main', 44 | 'msp430-jtag = msp430.jtag.target:main', 45 | 'msp430-jtag-legacy = msp430.legacy.jtag:main', 46 | 'msp430-ram-usage = msp430.ram_usage:main', 47 | 'msp430-tool = msp430.tool:main', 48 | ], 49 | }, 50 | license="Simplified BSD License", 51 | long_description=open('README.rst').read(), 52 | classifiers = [ 53 | # 'Development Status :: 5 - Production/Stable', 54 | 'Development Status :: 4 - Beta', 55 | 'Intended Audience :: Developers', 56 | 'Intended Audience :: End Users/Desktop', 57 | 'License :: OSI Approved :: BSD License', 58 | 'Natural Language :: English', 59 | 'Operating System :: OS Independent', 60 | 'Programming Language :: Python', 61 | 'Topic :: Software Development :: Embedded Systems', 62 | 'Topic :: Software Development :: Assemblers', 63 | 'Topic :: Software Development :: Libraries', 64 | ], 65 | ) 66 | -------------------------------------------------------------------------------- /win32/downloader.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsquareplusc/python-msp430-tools/d6400069a9cb91568294eead89191682856a3910/win32/downloader.ico -------------------------------------------------------------------------------- /win32/downloader.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsquareplusc/python-msp430-tools/d6400069a9cb91568294eead89191682856a3910/win32/downloader.xcf -------------------------------------------------------------------------------- /win32/setup-combined-tools-py2exe.py: -------------------------------------------------------------------------------- 1 | # setup script for py2exe to create the executeable of all the python tools 2 | # this setup uses one shared zip file for the library to save space 3 | # 4 | # $Id: setup-combined-tools-py2exe.py,v 1.5 2008/06/05 12:49:59 cliechti Exp $ 5 | 6 | from distutils.core import setup 7 | import glob, sys, py2exe, os, zipfile 8 | 9 | sys.path.insert(0, os.path.abspath('..')) 10 | os.chdir('..') 11 | print "changed directory to %s" % os.path.abspath(os.curdir) 12 | 13 | sys.argv.append("py2exe") 14 | #~ sys.argv.append("--xref") 15 | 16 | setup( 17 | name = 'http://mspgcc.sourceforge.net', 18 | author="Chris Liechti", 19 | author_email="cliechti@gmx.net", 20 | url="http://launchpad.net/python-msp430-tools/", 21 | 22 | version = '0.7', 23 | options = { "py2exe": 24 | { 25 | 'dist_dir': 'bin', 26 | 'excludes': [ 27 | 'os2emxpath', '_parjtag','pdb', 'pyreadline', 'plistlib', 'doctest', 28 | #~ 'IronPythonConsole', 'System', 'System.Windows.Forms.Clipboard', 'clr', 29 | 'modes.editingmodes', 'startup', 'Carbon', 'Carbon.Files', 'wx', 30 | # pyserial, other platforms 31 | 'serial.serialjava', 'serial.serialcli', 'serial.serialposix', 32 | 'serial.tools.list_ports_posix', 33 | ], 34 | 'packages': ['msp430', 'msp430.asm', 'msp430.memory', 'msp430.shell', 35 | 'msp430.gdb', 'msp430.jtag', 'msp430.bsl', 'msp430.bsl.target', 'msp430.bsl5'], 36 | 'includes': [ 37 | 'pywinusb', 'EasyDialogs', 38 | 'serial.urlhandler.protocol_hwgrep', 'serial.urlhandler.protocol_rfc2217', 39 | 'serial.urlhandler.protocol_socket', 'serial.urlhandler.protocol_loop', 40 | ], 41 | 'dll_excludes': [ 42 | # misc windows stuff 43 | 'OLEAUT32.dll', 'USER32.dll', 'SHELL32.dll', 'KERNEL32.dll', 44 | 'ADVAPI32.dll', 'WS2_32.dll', 'VERSION.dll', 'ole32.dll', 45 | 'RPCRT4.dll', 'COMDLG32.dll', 'WSOCK32.dll', 'COMCTL32.dll', 46 | 'WINSPOOL.DRV', 'GDI32.dll', 'gdiplus.dll', 'WINMM.dll', 47 | # our own 48 | 'HIL.dll', 'MSP430.dll', 'MSP430mspgcc.dll', 49 | # win7 50 | 'API-MS-Win-Core-LocalRegistry-L1-1-0.dll', 51 | 'API-MS-Win-Core-ProcessThreads-L1-1-0.dll', 52 | 'API-MS-Win-Security-Base-L1-1-0.dll', 53 | 'POWRPROF.dll', 54 | # other files 55 | 'MSVCP90.dll', 56 | 'MSVCRTR90.dll', 57 | ], 58 | 'optimize': 2, 59 | } 60 | }, 61 | console = [ 62 | "scripts/msp430-bsl", 63 | "scripts/msp430-jtag", 64 | "scripts/msp430-tool", 65 | ], 66 | windows = [ 67 | { 68 | 'script': "scripts/msp430-downloader", 69 | 'icon_resources': [(0x0001, 'win32/downloader.ico')] 70 | }, 71 | ], 72 | zipfile = "lib/shared.zip", 73 | ) 74 | 75 | # py2exe does not look at the package_data option of distutils. add files manually 76 | package_data = [ 77 | 'msp430/asm/definitions/msp430-mcu-list.txt', 78 | 'msp430/bsl/BL_150S_14x.txt', 79 | 'msp430/bsl/BL_150S_44x.txt', 80 | 'msp430/bsl/BS_150S_14x.txt', 81 | 'msp430/bsl/patch.txt', 82 | 'msp430/bsl5/RAM_BSL.00.06.05.34.txt', 83 | ] 84 | 85 | print "appending package data..." 86 | archive = zipfile.PyZipFile("bin/lib/shared.zip", 'a') 87 | for path in package_data: 88 | archive.write( 89 | path, 90 | path, 91 | compress_type=zipfile.ZIP_DEFLATED 92 | ) 93 | 94 | --------------------------------------------------------------------------------