From 410e38651052038e34843b17269d61e75720f0ba Mon Sep 17 00:00:00 2001 From: jaseg Date: Thu, 23 Jan 2020 14:38:36 +0100 Subject: board bringup: adc, usart working --- gm_platform/fw/Makefile | 111 + gm_platform/fw/Scope.ipynb | 906 +++ gm_platform/fw/adc.c | 125 + gm_platform/fw/adc.h | 28 + gm_platform/fw/base.c | 25 + gm_platform/fw/cmsis_exports.c | 48 + gm_platform/fw/cobs.c | 293 + gm_platform/fw/cobs.h | 23 + gm_platform/fw/global.h | 52 + gm_platform/fw/main.bin | Bin 0 -> 6552 bytes gm_platform/fw/main.c | 175 + gm_platform/fw/main.c.bak | 162 + gm_platform/fw/main.elf | Bin 0 -> 180992 bytes gm_platform/fw/main.hex | 414 ++ gm_platform/fw/main.lst | 4459 ++++++++++++++ gm_platform/fw/main.map | 457 ++ gm_platform/fw/openocd.cfg | 17 + gm_platform/fw/packet_interface.c | 46 + gm_platform/fw/packet_interface.h | 6 + gm_platform/fw/scope.gdb | 12 + gm_platform/fw/serial.c | 139 + gm_platform/fw/serial.h | 44 + gm_platform/fw/startup_stm32f030x6.s | 273 + gm_platform/fw/stm32_flash.ld | 136 + gm_platform/fw/system_stm32f0xx.c | 336 ++ gm_platform/fw/tools/gen_cmsis_exports.py | 30 + gm_platform/platform/bottom_overlay.png | Bin 0 -> 1440177 bytes gm_platform/platform/case_label.pdf | Bin 0 -> 39283 bytes gm_platform/platform/case_label.svg | 636 ++ gm_platform/platform/case_label_print.pdf | Bin 0 -> 39614 bytes gm_platform/platform/case_label_print.svg | 573 ++ .../platform/case_side_iec_socket_helper.pdf | 70 + .../platform/case_side_iec_socket_helper.svg | 128 + .../platform/case_side_usb_socket_helper.pdf | 69 + .../platform/case_side_usb_socket_helper.svg | 146 + gm_platform/platform/converter_clip.scad | 24 + gm_platform/platform/converter_clip.stl | 1990 +++++++ .../platform/gerber_grid_meas_platform_v01.zip | Bin 0 -> 1378530 bytes gm_platform/platform/hiig_logo_binary.png | Bin 0 -> 33736 bytes gm_platform/platform/lid_switch_plunger.stl | 2158 +++++++ gm_platform/platform/lid_switch_plunger_flex.scad | 61 + gm_platform/platform/lid_switch_plunger_flex.stl | 6078 ++++++++++++++++++++ gm_platform/platform/line_meas_divider.asc | 51 + gm_platform/platform/line_pol_det.asc | 92 + gm_platform/platform/platform.sch | 2 + gm_platform/platform/top_overlay.png | Bin 0 -> 461124 bytes gm_platform/platform/zip_tie_anchor.scad | 31 + gm_platform/platform/zip_tie_anchor.stl | 4370 ++++++++++++++ 48 files changed, 24796 insertions(+) create mode 100644 gm_platform/fw/Makefile create mode 100644 gm_platform/fw/Scope.ipynb create mode 100644 gm_platform/fw/adc.c create mode 100644 gm_platform/fw/adc.h create mode 100644 gm_platform/fw/base.c create mode 100644 gm_platform/fw/cmsis_exports.c create mode 100644 gm_platform/fw/cobs.c create mode 100644 gm_platform/fw/cobs.h create mode 100644 gm_platform/fw/global.h create mode 100755 gm_platform/fw/main.bin create mode 100644 gm_platform/fw/main.c create mode 100644 gm_platform/fw/main.c.bak create mode 100755 gm_platform/fw/main.elf create mode 100644 gm_platform/fw/main.hex create mode 100644 gm_platform/fw/main.lst create mode 100644 gm_platform/fw/main.map create mode 100644 gm_platform/fw/openocd.cfg create mode 100644 gm_platform/fw/packet_interface.c create mode 100644 gm_platform/fw/packet_interface.h create mode 100644 gm_platform/fw/scope.gdb create mode 100644 gm_platform/fw/serial.c create mode 100644 gm_platform/fw/serial.h create mode 100644 gm_platform/fw/startup_stm32f030x6.s create mode 100644 gm_platform/fw/stm32_flash.ld create mode 100644 gm_platform/fw/system_stm32f0xx.c create mode 100644 gm_platform/fw/tools/gen_cmsis_exports.py create mode 100644 gm_platform/platform/bottom_overlay.png create mode 100644 gm_platform/platform/case_label.pdf create mode 100644 gm_platform/platform/case_label.svg create mode 100644 gm_platform/platform/case_label_print.pdf create mode 100644 gm_platform/platform/case_label_print.svg create mode 100644 gm_platform/platform/case_side_iec_socket_helper.pdf create mode 100644 gm_platform/platform/case_side_iec_socket_helper.svg create mode 100644 gm_platform/platform/case_side_usb_socket_helper.pdf create mode 100644 gm_platform/platform/case_side_usb_socket_helper.svg create mode 100644 gm_platform/platform/converter_clip.scad create mode 100644 gm_platform/platform/converter_clip.stl create mode 100644 gm_platform/platform/gerber_grid_meas_platform_v01.zip create mode 100644 gm_platform/platform/hiig_logo_binary.png create mode 100644 gm_platform/platform/lid_switch_plunger.stl create mode 100644 gm_platform/platform/lid_switch_plunger_flex.scad create mode 100644 gm_platform/platform/lid_switch_plunger_flex.stl create mode 100644 gm_platform/platform/line_meas_divider.asc create mode 100644 gm_platform/platform/line_pol_det.asc create mode 100644 gm_platform/platform/top_overlay.png create mode 100644 gm_platform/platform/zip_tie_anchor.scad create mode 100644 gm_platform/platform/zip_tie_anchor.stl (limited to 'gm_platform') diff --git a/gm_platform/fw/Makefile b/gm_platform/fw/Makefile new file mode 100644 index 0000000..ea874eb --- /dev/null +++ b/gm_platform/fw/Makefile @@ -0,0 +1,111 @@ +# Megumin LED display firmware +# Copyright (C) 2018 Sebastian Götte +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +CUBE_PATH ?= $(wildcard ~)/resource/STM32CubeF0 +CMSIS_PATH ?= $(CUBE_PATH)/Drivers/CMSIS +CMSIS_DEV_PATH ?= $(CMSIS_PATH)/Device/ST/STM32F0xx +HAL_PATH ?= $(CUBE_PATH)/Drivers/STM32F0xx_HAL_Driver + +MAC_ADDR ?= 0xdeadbeef + +CC := arm-none-eabi-gcc +LD := arm-none-eabi-ld +OBJCOPY := arm-none-eabi-objcopy +OBJDUMP := arm-none-eabi-objdump +SIZE := arm-none-eabi-size + +CFLAGS = -g -Wall -Wextra -std=gnu11 -O0 -fdump-rtl-expand +CFLAGS += -mlittle-endian -mcpu=cortex-m0 -march=armv6-m -mthumb +#CFLAGS += -ffunction-sections -fdata-sections +LDFLAGS = -nostartfiles +#LDFLAGS += -specs=rdimon.specs -DSEMIHOSTING +LDFLAGS += -Wl,-Map=main.map -nostdlib +#LDFLAGS += -Wl,--gc-sections +LIBS = -lgcc +#LIBS += -lrdimon + +# Technically we're using an STM32F030F4, but apart from the TSSOP20 package that one is largely identical to the +# STM32F030*6 and there is no separate device header provided for it, so we're faking a *6 device here. This is +# even documented in stm32f0xx.h. Thanks ST! +CFLAGS += -DSTM32F030x6 -DHSE_VALUE=8000000 + +LDFLAGS += -Tstm32_flash.ld +CFLAGS += -I$(CMSIS_DEV_PATH)/Include -I$(CMSIS_PATH)/Include -I$(HAL_PATH)/Inc -Iconfig -Wno-unused -I../common +LDFLAGS += -L$(CMSIS_PATH)/Lib/GCC -larm_cortexM0l_math + +################################################### + +.PHONY: program clean + +all: main.elf + +.clang: + echo flags = $(CFLAGS) > .clang + +cmsis_exports.c: $(CMSIS_DEV_PATH)/Include/stm32f030x6.h $(CMSIS_PATH)/Include/core_cm0.h + python3 tools/gen_cmsis_exports.py $^ > $@ + +%.o: %.c + $(CC) -c $(CFLAGS) -o $@ $^ +# $(CC) -E $(CFLAGS) -o $(@:.o=.pp) $^ + +%.o: %.s + $(CC) -c $(CFLAGS) -o $@ $^ +# $(CC) -E $(CFLAGS) -o $(@:.o=.pp) $^ + +%.dot: %.elf + r2 -a arm -qc 'aa;agC' $< 2>/dev/null >$@ + +sources.tar.xz: main.c Makefile + tar -caf $@ $^ + +# don't ask... +sources.tar.xz.zip: sources.tar.xz + zip $@ $^ + +sources.c: sources.tar.xz.zip + xxd -i $< | head -n -1 | sed 's/=/__attribute__((section(".source_tarball"))) =/' > $@ + +main.elf: main.c adc.c serial.c cobs.c startup_stm32f030x6.s system_stm32f0xx.c $(HAL_PATH)/Src/stm32f0xx_ll_utils.c base.c cmsis_exports.c + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) + $(OBJCOPY) -O ihex $@ $(@:.elf=.hex) + $(OBJCOPY) -O binary $@ $(@:.elf=.bin) + $(OBJDUMP) -St $@ >$(@:.elf=.lst) + $(SIZE) $@ + +program: main.elf openocd.cfg + openocd -f openocd.cfg -c "program $< verify reset exit" + +8b10b_test_encode: 8b10b_test_encode.c 8b10b.c + gcc -o $@ $^ + +8b10b_test_decode: 8b10b_test_decode.c 8b10b.c + gcc -o $@ $^ + +protocol_test: protocol.c protocol_test.c + gcc -o $@ -O0 -Wall -Wextra -g -I../common $^ + +clean: + rm -f **.o + rm -f main.elf main.hex main.bin main.map main.lst + rm -f **.expand + rm -f cmsis_exports.c + rm -f sources.tar.xz + rm -f sources.tar.xz.zip + rm -f sources.c + rm -f *.dot + rm -f protocol_test + diff --git a/gm_platform/fw/Scope.ipynb b/gm_platform/fw/Scope.ipynb new file mode 100644 index 0000000..1022e56 --- /dev/null +++ b/gm_platform/fw/Scope.ipynb @@ -0,0 +1,906 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "from matplotlib import pyplot as plt\n", + "%matplotlib notebook\n", + "import numpy as np\n", + "import struct\n", + "import math" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [], + "source": [ + "def plot_data(offx=0, end=-1, signed=False, channels=1):\n", + " with open('/tmp/scope_dump.bin', 'rb') as f:\n", + " raw_data = f.read()\n", + " data = struct.unpack(f'<{len(raw_data)//2}{\"h\" if signed else \"H\"}', raw_data)\n", + " \n", + " fig, axs = plt.subplots(channels*2, 1, squeeze=False, sharex=True, figsize=(10, 5))\n", + " axs = axs.flatten()\n", + " for i, (ax_t, ax_f) in enumerate(zip(axs[0::2], axs[1::2])):\n", + " le_slice = data[offx:][:end][i::channels]\n", + " ax_t.plot(np.linspace(0, len(le_slice)/1000, len(le_slice)),\n", + " [math.nan if x==-255 else x for x in le_slice])\n", + " ax_t.grid() \n", + " \n", + " ax_f.specgram(le_slice, Fs=1000)\n", + " ax_f.grid()\n", + " \n", + " return data" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "data": { + "application/javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "window.mpl = {};\n", + "\n", + "\n", + "mpl.get_websocket_type = function() {\n", + " if (typeof(WebSocket) !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof(MozWebSocket) !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert('Your browser does not have WebSocket support.' +\n", + " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.');\n", + " };\n", + "}\n", + "\n", + "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = (this.ws.binaryType != undefined);\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById(\"mpl-warnings\");\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent = (\n", + " \"This browser does not support binary websocket messages. \" +\n", + " \"Performance may be slow.\");\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = $('
');\n", + " this._root_extra_style(this.root)\n", + " this.root.attr('style', 'display: inline-block');\n", + "\n", + " $(parent_element).append(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", + " fig.send_message(\"send_image_mode\", {});\n", + " if (mpl.ratio != 1) {\n", + " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", + " }\n", + " fig.send_message(\"refresh\", {});\n", + " }\n", + "\n", + " this.imageObj.onload = function() {\n", + " if (fig.image_mode == 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function() {\n", + " fig.ws.close();\n", + " }\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "}\n", + "\n", + "mpl.figure.prototype._init_header = function() {\n", + " var titlebar = $(\n", + " '
');\n", + " var titletext = $(\n", + " '
');\n", + " titlebar.append(titletext)\n", + " this.root.append(titlebar);\n", + " this.header = titletext[0];\n", + "}\n", + "\n", + "\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._init_canvas = function() {\n", + " var fig = this;\n", + "\n", + " var canvas_div = $('
');\n", + "\n", + " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", + "\n", + " function canvas_keyboard_event(event) {\n", + " return fig.key_event(event, event['data']);\n", + " }\n", + "\n", + " canvas_div.keydown('key_press', canvas_keyboard_event);\n", + " canvas_div.keyup('key_release', canvas_keyboard_event);\n", + " this.canvas_div = canvas_div\n", + " this._canvas_extra_style(canvas_div)\n", + " this.root.append(canvas_div);\n", + "\n", + " var canvas = $('');\n", + " canvas.addClass('mpl-canvas');\n", + " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", + "\n", + " this.canvas = canvas[0];\n", + " this.context = canvas[0].getContext(\"2d\");\n", + "\n", + " var backingStore = this.context.backingStorePixelRatio ||\n", + "\tthis.context.webkitBackingStorePixelRatio ||\n", + "\tthis.context.mozBackingStorePixelRatio ||\n", + "\tthis.context.msBackingStorePixelRatio ||\n", + "\tthis.context.oBackingStorePixelRatio ||\n", + "\tthis.context.backingStorePixelRatio || 1;\n", + "\n", + " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", + "\n", + " var rubberband = $('');\n", + " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", + "\n", + " var pass_mouse_events = true;\n", + "\n", + " canvas_div.resizable({\n", + " start: function(event, ui) {\n", + " pass_mouse_events = false;\n", + " },\n", + " resize: function(event, ui) {\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " stop: function(event, ui) {\n", + " pass_mouse_events = true;\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " });\n", + "\n", + " function mouse_event_fn(event) {\n", + " if (pass_mouse_events)\n", + " return fig.mouse_event(event, event['data']);\n", + " }\n", + "\n", + " rubberband.mousedown('button_press', mouse_event_fn);\n", + " rubberband.mouseup('button_release', mouse_event_fn);\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband.mousemove('motion_notify', mouse_event_fn);\n", + "\n", + " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", + " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", + "\n", + " canvas_div.on(\"wheel\", function (event) {\n", + " event = event.originalEvent;\n", + " event['data'] = 'scroll'\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " mouse_event_fn(event);\n", + " });\n", + "\n", + " canvas_div.append(canvas);\n", + " canvas_div.append(rubberband);\n", + "\n", + " this.rubberband = rubberband;\n", + " this.rubberband_canvas = rubberband[0];\n", + " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", + " this.rubberband_context.strokeStyle = \"#000000\";\n", + "\n", + " this._resize_canvas = function(width, height) {\n", + " // Keep the size of the canvas, canvas container, and rubber band\n", + " // canvas in synch.\n", + " canvas_div.css('width', width)\n", + " canvas_div.css('height', height)\n", + "\n", + " canvas.attr('width', width * mpl.ratio);\n", + " canvas.attr('height', height * mpl.ratio);\n", + " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", + "\n", + " rubberband.attr('width', width);\n", + " rubberband.attr('height', height);\n", + " }\n", + "\n", + " // Set the figure to an initial 600x600px, this will subsequently be updated\n", + " // upon first draw.\n", + " this._resize_canvas(600, 600);\n", + "\n", + " // Disable right mouse context menu.\n", + " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", + " return false;\n", + " });\n", + "\n", + " function set_focus () {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "}\n", + "\n", + "mpl.figure.prototype._init_toolbar = function() {\n", + " var fig = this;\n", + "\n", + " var nav_element = $('
')\n", + " nav_element.attr('style', 'width: 100%');\n", + " this.root.append(nav_element);\n", + "\n", + " // Define a callback function for later on.\n", + " function toolbar_event(event) {\n", + " return fig.toolbar_button_onclick(event['data']);\n", + " }\n", + " function toolbar_mouse_event(event) {\n", + " return fig.toolbar_button_onmouseover(event['data']);\n", + " }\n", + "\n", + " for(var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " // put a spacer in here.\n", + " continue;\n", + " }\n", + " var button = $('