From 26b36a2887aa9f07e4683e72a9eaf8200d443a90 Mon Sep 17 00:00:00 2001 From: Sebastian Renner Date: Wed, 10 Jul 2019 14:02:57 +0200 Subject: [PATCH] First steps for stm middleware --- templates/blackpill/flash.jlink | 7 +++++++ templates/blackpill/middleware.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 templates/blackpill/flash.jlink create mode 100755 templates/blackpill/middleware.py diff --git a/templates/blackpill/flash.jlink b/templates/blackpill/flash.jlink new file mode 100644 index 0000000..1156f9e --- /dev/null +++ b/templates/blackpill/flash.jlink @@ -0,0 +1,7 @@ +if SWD +speed 4000 +device STM32F103C8 +loadbin build/blackpill.bin 0x8000000 +r +g +exit diff --git a/templates/blackpill/middleware.py b/templates/blackpill/middleware.py new file mode 100755 index 0000000..22ea859 --- /dev/null +++ b/templates/blackpill/middleware.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 + +import os +import sys +import struct +import serial +from subprocess import Popen, PIPE, run + +def flash(): + run("JLinkExe flash.jlink", shell=True, check=True) + +def read(channel, l): + if channel == 'ser': + data = ser.read(l) + elif channel == 'std': + data = sys.stdin.read(l) + else: + raise Exception("read() complains: no sai channelino") + if len(data) != l: + raise Exception("could not read %d bytes of data (got %d)" % (l, len(data))) + return data + +def write(channel, data, direction): + if channel == 'ser': + l = ser.write(data) + elif channel == 'std': + l = sys.stdout.write(data) + else: + raise Exception("write() complains: no sai channelino") + if len(data) != l: + raise Exception("could not write %d bytes of data (put %d)" % (len(data), l)) + +def obtain(channel): + l = read(channel, 4) + print(l) + (l, ) = struct.unpack("