Last active
April 3, 2018 23:02
-
-
Save jeffbk/43d5fa871385728d602125c550636ce7 to your computer and use it in GitHub Desktop.
GCC ARM Utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Created by .ignore support plugin (hsz.mobi) | |
### Python template | |
# Byte-compiled / optimized / DLL files | |
__pycache__/ | |
*.py[cod] | |
*$py.class | |
# C extensions | |
*.so | |
# Distribution / packaging | |
.Python | |
build/ | |
develop-eggs/ | |
dist/ | |
downloads/ | |
eggs/ | |
.eggs/ | |
lib/ | |
lib64/ | |
parts/ | |
sdist/ | |
var/ | |
wheels/ | |
*.egg-info/ | |
.installed.cfg | |
*.egg | |
MANIFEST | |
# PyInstaller | |
# Usually these files are written by a python script from a template | |
# before PyInstaller builds the exe, so as to inject date/other infos into it. | |
*.manifest | |
*.spec | |
# Installer logs | |
pip-log.txt | |
pip-delete-this-directory.txt | |
# Unit test / coverage reports | |
htmlcov/ | |
.tox/ | |
.coverage | |
.coverage.* | |
.cache | |
nosetests.xml | |
coverage.xml | |
*.cover | |
.hypothesis/ | |
# Translations | |
*.mo | |
*.pot | |
# Django stuff: | |
*.log | |
.static_storage/ | |
.media/ | |
local_settings.py | |
# Flask stuff: | |
instance/ | |
.webassets-cache | |
# Scrapy stuff: | |
.scrapy | |
# Sphinx documentation | |
docs/_build/ | |
# PyBuilder | |
target/ | |
# Jupyter Notebook | |
.ipynb_checkpoints | |
# pyenv | |
.python-version | |
# celery beat schedule file | |
celerybeat-schedule | |
# SageMath parsed files | |
*.sage.py | |
# Environments | |
.env | |
.venv | |
env/ | |
venv/ | |
ENV/ | |
env.bak/ | |
venv.bak/ | |
# Spyder project settings | |
.spyderproject | |
.spyproject | |
# Rope project settings | |
.ropeproject | |
# mkdocs documentation | |
/site | |
# mypy | |
.mypy_cache/ | |
### macOS template | |
# General | |
.DS_Store | |
.AppleDouble | |
.LSOverride | |
# Icon must end with two \r | |
Icon | |
# Thumbnails | |
._* | |
# Files that might appear in the root of a volume | |
.DocumentRevisions-V100 | |
.fseventsd | |
.Spotlight-V100 | |
.TemporaryItems | |
.Trashes | |
.VolumeIcon.icns | |
.com.apple.timemachine.donotpresent | |
# Directories potentially created on remote AFP share | |
.AppleDB | |
.AppleDesktop | |
Network Trash Folder | |
Temporary Items | |
.apdisk | |
.idea/ | |
cova_build_log.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cproj2cmake.py | |
# Parses a .crpoject file generated by STM32CubeMX (sw4stm32) and generates CMakeListsGenerated.txt | |
# which is included in a CMakeLists.txt for a CLion embedded project. | |
import argparse | |
import xml.etree.cElementTree as ET | |
import sys | |
import os | |
def parse_root(filename): | |
with open(filename, 'r') as myfile: | |
xml = myfile.read() | |
return ET.fromstring(xml) | |
def parse_cproject(filename): | |
print "Parsing %s" % filename | |
root = parse_root(filename) | |
project = {} | |
options = root.findall( | |
".//tool/option[@superClass='gnu.c.compiler.option.preprocessor.def.symbols']/listOptionValue") | |
defines = {o.get("value") for o in options} | |
# remove quotes in define | |
defines = {d.replace("\"", "") for d in defines} | |
project["Defines"] = sorted(defines) | |
print "Defines" | |
for d in defines: | |
print " - %s" % d | |
options = root.findall(".//tool/option[@superClass='gnu.c.compiler.option.include.paths']/listOptionValue") | |
# Correct relative file path for include file | |
includes = {o.get("value").replace("../", "") for o in options} | |
project["Includes"] = sorted(includes) | |
print "Includes" | |
for i in includes: | |
print " - %s" % i | |
entries = root.findall(".//sourceEntries/entry") | |
sources = {e.get("name") for e in entries} | |
project["Sources"] = sorted(sources) | |
print "Sources" | |
for s in sources: | |
print " - %s" % s | |
return project | |
def generate_cmake(project): | |
filename = "CMakeListsGenerated.txt" | |
print "Writing %s" % filename | |
with open(filename, 'w') as cmake_file: | |
program_name = os.path.split(sys.argv[0])[-1] | |
hashes = "#" * 80 | |
hashes = "%s\n" % hashes | |
cmake_file.write(hashes) | |
cmake_file.write("# NOTE: This file was generated by %s! DO NOT MODIFY!!!\n" % program_name) | |
cmake_file.write(hashes) | |
cmake_file.write("\n") | |
for define in project["Defines"]: | |
# escape parenthesis for cmake file | |
define = define.replace("(", "\(").replace(")", "\)") | |
cmake_file.write("add_definitions(-D%s)\n" % define) | |
cmake_file.write("\n") | |
for include in project["Includes"]: | |
cmake_file.write("include_directories(%s)\n" % include) | |
cmake_file.write("\n") | |
sources = project["Sources"] | |
sources = map(lambda s: "%s/*" % s, sources) | |
cmake_file.write("file(GLOB_RECURSE CUBEMX_SOURCES %s)\n" % " ".join(sources)) | |
def main(): | |
parser = argparse.ArgumentParser(description='Generate CMakeListGenerated from a sw4stm32 .cproject file') | |
parser.add_argument('file', nargs=1, type=str, help='the .cproject file to read') | |
args = parser.parse_args() | |
cproject_file = args.file[0] | |
project = parse_cproject(cproject_file) | |
generate_cmake(project) | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z ${GCC_ARM_HOME} ]; then | |
echo "GCC_ARM_HOME is not set"; | |
exit 1; | |
fi | |
if [ -z "$1" ] | |
then | |
echo "No script file supplied"; | |
exit 1; | |
fi | |
${GCC_ARM_HOME}/bin/arm-none-eabi-gdb -x "$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import xml.etree.cElementTree as ET | |
import os | |
def parse_root(filename): | |
with open(filename, 'r') as myfile: | |
xml = myfile.read() | |
return ET.fromstring(xml) | |
def make_relative(projdir, filename): | |
filename = filename.replace("\\", "/") | |
filename = filename.replace("$PROJ_DIR$", projdir) | |
filename = filename.replace("/iar/", "/gcc/") | |
return os.path.relpath(filename, os.path.dirname(projdir)) | |
def parse_iar_project(filename): | |
projdir = os.path.dirname(os.path.abspath(filename)) | |
root = parse_root(filename) | |
group_nodes = root.findall("./group") | |
project = {} | |
groups = {} | |
for gn in group_nodes: | |
groupname = gn.find("./name").text | |
if groupname == "Doc": | |
continue | |
else: | |
print groupname | |
filename_nodes = gn.findall(".//file/name") | |
filenames = [make_relative(projdir, node.text) for node in filename_nodes] | |
groups[groupname] = sorted(filenames) | |
for filename in filenames: | |
print " - %s" % filename | |
project["SourceFileGroups"] = groups | |
define_nodes = root.find(".//configuration/settings/data/option[name='CCDefines']").findall("./state") | |
defines = [dn.text for dn in define_nodes] | |
project["Defines"] = sorted(defines) | |
print "Defines" | |
for d in defines: | |
print " - %s" % d | |
include_nodes = root.find(".//configuration/settings/data/option[name='CCIncludePath2']").findall("./state") | |
includes = [make_relative(projdir, node.text) for node in include_nodes] | |
project["Includes"] = sorted(includes) | |
print "Includes" | |
for include in includes: | |
print " - %s" % include | |
return project | |
def generate_cmake(name, project): | |
with open("CMakeLists.txt", 'w') as cmake_file: | |
cmake_file.write("cmake_minimum_required(VERSION 3.5)\n") | |
cmake_file.write("project(%s CXX C ASM)\n" % name) | |
cmake_file.write("\n") | |
for definition in project["Defines"]: | |
cmake_file.write("add_definitions(-D%s)\n" % definition) | |
cmake_file.write("\n") | |
groups = project["SourceFileGroups"] | |
for group in groups: | |
cmake_file.write("file(GLOB_RECURSE %s_Sources\n" % group) | |
for filename in groups[group]: | |
cmake_file.write(" %s\n" % filename) | |
cmake_file.write(")\n") | |
cmake_file.write("\n") | |
for include in project["Includes"]: | |
cmake_file.write("include_directories(%s)\n" % include) | |
cmake_file.write("\n") | |
cmake_file.write("add_executable(${PROJECT_NAME}.elf ") | |
for group in groups: | |
cmake_file.write("${%s_Sources} " % group) | |
cmake_file.write("${LINKER_SCRIPT})\n\n") | |
cmake_file.write("\n") | |
cmake_file.write("target_link_libraries(${PROJECT_NAME}.elf)\n") | |
cmake_file.write('set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${CMAKE_BINARY_DIR}/${PROJECT_NAME}.map")\n') | |
cmake_file.write('set(HEX_FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.hex)\n') | |
cmake_file.write('set(BIN_FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin)\n') | |
cmake_file.write('add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD\n \ | |
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}\n \ | |
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}\n \ | |
COMMENT "Building ${HEX_FILE} \\nBuilding ${BIN_FILE}")') | |
def main(): | |
# Need $PROJ_DIR$ | |
parser = argparse.ArgumentParser(description='Create a gnu / cmake project from an iar project file') | |
parser.add_argument('-f', '--file', help='The path to the iar project file ', required=True) | |
args = parser.parse_args() | |
project = parse_iar_project(args.file) | |
filename = os.path.basename(args.file) | |
project_name = os.path.splitext(filename)[0] | |
generate_cmake(project_name, project) | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import signal | |
import serial | |
import sys | |
import argparse | |
def signal_handler(signal, frame): | |
global interrupted | |
interrupted = True | |
signal.signal(signal.SIGINT, signal_handler) | |
def stream(device, baudrate): | |
global interrupted | |
interrupted = False | |
with serial.Serial(port=device, baudrate=baudrate, timeout=0.5) as ser: | |
while not interrupted: | |
try: | |
char = ser.read(1) | |
if char: | |
sys.stdout.write(char) | |
sys.stdout.flush() | |
except Exception as e: | |
raise e; | |
def main(): | |
parser = argparse.ArgumentParser(description='Stream serial port to stdout') | |
parser.add_argument('device', nargs=1, type=str, help='the device to stream') | |
parser.add_argument('-b', '--baud', nargs=1, type=int, help='baud rate', required=False, default=115200) | |
args = parser.parse_args() | |
stream(args.device[0], args.baud) | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import signal | |
import serial | |
import sys | |
import argparse | |
import re | |
class Color: | |
WHITE = '\x1b[0;30m' | |
RED = '\x1b[0;31m' | |
GREEN = '\x1b[0;32m' | |
YELLOW = '\x1b[0;33m' | |
BLUE = '\x1b[0;34m' | |
PURPLE = '\x1b[0;35m' | |
TEAL = '\x1b[0;36m' | |
DARK_GRAY = '\x1b[0;37m' | |
LIGHT_GRAY = '\x1b[0;38m' | |
BOLD_WHITE = '\x1b[1;30m' | |
BOLD_RED = '\x1b[1;31m' | |
BOLD_GREEN = '\x1b[1;32m' | |
BOLD_YELLOW = '\x1b[1;33m' | |
BOLD_BLUE = '\x1b[1;34m' | |
BOLD_PURPLE = '\x1b[1;35m' | |
BOLD_TEAL = '\x1b[1;36m' | |
BOLD_DARK_GRAY = '\x1b[1;37m' | |
BOLD_LIGHT_GRAY = '\x1b[1;38m' | |
def signal_handler(signal, frame): | |
global interrupted | |
interrupted = True | |
signal.signal(signal.SIGINT, signal_handler) | |
def stream(device, baudrate): | |
global interrupted | |
interrupted = False | |
colorDict = { | |
'A' : Color.BOLD_TEAL, | |
'V' : Color.DARK_GRAY, | |
'D' : Color.LIGHT_GRAY, | |
'I' : Color.LIGHT_GRAY, | |
'W' : Color.BOLD_YELLOW, | |
'E' : Color.BOLD_RED, | |
} | |
with serial.Serial(port=device, baudrate=baudrate, timeout=0.5) as ser: | |
regex = re.compile(r"^\d{2}[:]\d{2}[:]\d{2}[.]\d{3}\s+\d+ ([AVDIWE]).+[:]") | |
lineBuffer = "" | |
while not interrupted: | |
try: | |
char = ser.read(1) | |
if char: | |
lineBuffer += char | |
if char == '\n': | |
match = regex.search(lineBuffer); | |
if match and match.group(1): | |
color = colorDict.get(match.group(1), None) | |
if color: | |
sys.stdout.write(color) | |
sys.stdout.write(lineBuffer) | |
sys.stdout.flush() | |
lineBuffer = "" | |
except Exception as e: | |
raise e; | |
def main(): | |
parser = argparse.ArgumentParser(description='Stream serial port to stdout') | |
parser.add_argument('device', nargs=1, type=str, help='the device to stream') | |
parser.add_argument('-b', '--baud', nargs=1, type=int, help='baud rate', required=False, default=115200) | |
args = parser.parse_args() | |
stream(args.device[0], args.baud) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment