summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2021-01-16 01:20:58 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2021-01-16 01:20:58 +0100
commit9921c9db409ad5b00fe4a43a2459e2fd2de6b0cf (patch)
treeb0f3bc73144d87112f746d04b3bc7a69cc3e0953
parentd834303f5e642266874b1c99be04dcb9149fefb1 (diff)
usb: Generate instances from platform spec.
-rw-r--r--SConscript1
-rw-r--r--build/scons_tools/tool_jinja2.py2
-rw-r--r--platforms/stm32/f4.yaml13
-rw-r--r--templates/periph_instances.h.j211
-rw-r--r--usb/SConscript19
-rw-r--r--usb/usb.h22
6 files changed, 46 insertions, 22 deletions
diff --git a/SConscript b/SConscript
index 8613407..7511f19 100644
--- a/SConscript
+++ b/SConscript
@@ -4,6 +4,7 @@ Import('env')
Export('env')
env.SConscript('ld_scripts/SConscript')
+env.SConscript('usb/SConscript')
env.Append(
LIB_SOURCES = Glob('*.cpp') + Glob('*/*.cpp'),
diff --git a/build/scons_tools/tool_jinja2.py b/build/scons_tools/tool_jinja2.py
index c85c559..edea043 100644
--- a/build/scons_tools/tool_jinja2.py
+++ b/build/scons_tools/tool_jinja2.py
@@ -5,6 +5,8 @@ loader = jinja2.FileSystemLoader('.')
jinja2_env = jinja2.Environment(
loader = loader,
+ trim_blocks = True,
+ lstrip_blocks = True,
)
jinja2_env.filters['hex'] = lambda value: '%#x' % value
diff --git a/platforms/stm32/f4.yaml b/platforms/stm32/f4.yaml
index a2b28f7..dccffe9 100644
--- a/platforms/stm32/f4.yaml
+++ b/platforms/stm32/f4.yaml
@@ -21,6 +21,19 @@
origin: 0x10000000
size: 64k
+ periph:
+ uart_stm32:
+ USART1:
+ offset: 0x40011000
+ USART2:
+ offset: 0x40004400
+
+ dwc_otg:
+ OTG_FS:
+ offset: 0x50000000
+ OTG_HS:
+ offset: 0x40040000
+
define:
- STM32F4
diff --git a/templates/periph_instances.h.j2 b/templates/periph_instances.h.j2
new file mode 100644
index 0000000..d4b682f
--- /dev/null
+++ b/templates/periph_instances.h.j2
@@ -0,0 +1,11 @@
+#pragma once
+
+{% for header in headers %}#include "{{ header }}"{% endfor %}
+
+{% for instance in instances %}
+static {{ instance.type }} {{ instance.name }}{
+ {% for arg in instance.args %}
+ {{ arg | hex }},
+ {% endfor %}
+};
+{% endfor %}
diff --git a/usb/SConscript b/usb/SConscript
new file mode 100644
index 0000000..81d84d4
--- /dev/null
+++ b/usb/SConscript
@@ -0,0 +1,19 @@
+Import('env')
+
+headers = []
+instances = []
+
+periph = env['PLATFORM_SPEC'].get('periph', {})
+
+if 'dwc_otg' in periph:
+ headers.append('dwc_otg.h')
+ for name, data in periph['dwc_otg'].items():
+ instances.append({
+ 'type': 'DWC_OTG_t',
+ 'name': name,
+ 'args': [data['offset']],
+ })
+
+env.Jinja2('usb.h', '../templates/periph_instances.h.j2', headers = headers, instances = instances)
+
+Return()
diff --git a/usb/usb.h b/usb/usb.h
deleted file mode 100644
index b1385b6..0000000
--- a/usb/usb.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef USB_H
-#define USB_H
-
-#if defined(STM32F1) || defined(STM32F3)
-#include "f1_usb.h"
-
-static F1_USB_t USB(0x40005c00, 0x40006000);
-
-#elif defined(STM32F4)
-#include "dwc_otg.h"
-
-static DWC_OTG_t OTG_FS(0x50000000);
-static DWC_OTG_t OTG_HS(0x40040000);
-
-#elif defined(STM32F0) || defined(STM32L0)
-#include "l0_usb.h"
-
-static L0_USB_t USB(0x40005c00, 0x40006000);
-
-#endif
-
-#endif