From 267c99850a0795b1563725c33674f2c62f6942a8 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Thu, 20 Jan 2022 12:18:33 +0000 Subject: stm32_syscfg: convert to modern. Includes the f4, l0 and wb. f4 renames MEMRM to MEMRMP to be both consistent with other parts and consistent with ref man. Retested on the WB, but l0 and f4 code was simply moved. For yaml files, given how varied syscfg is, we default to using the family name as the type, but still allow overriding via explicit type in the yaml file if desired. Signed-off-by: Karl Palsson --- .gitignore | 1 + SConscript | 1 + platforms/stm32/f4.yaml | 4 ++++ platforms/stm32/l0.yaml | 4 ++++ platforms/stm32/wb.yaml | 4 ++++ rcc/syscfg.h | 19 ------------------- syscfg/SConscript | 23 +++++++++++++++++++++++ syscfg/stm32_syscfg.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ syscfg/syscfg.h | 47 ----------------------------------------------- 9 files changed, 81 insertions(+), 66 deletions(-) delete mode 100644 rcc/syscfg.h create mode 100644 syscfg/SConscript create mode 100644 syscfg/stm32_syscfg.h delete mode 100644 syscfg/syscfg.h diff --git a/.gitignore b/.gitignore index 8db6560..f70630d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ pwr/pwr.h rcc/flash.h rcc/rcc.h rcc/rcc_enums.h +syscfg/syscfg.h timer/timer.h usb/usb.h uart/uart.h diff --git a/SConscript b/SConscript index 1d228cb..27a885c 100644 --- a/SConscript +++ b/SConscript @@ -13,6 +13,7 @@ env.Append( env.SConscript('interrupt/SConscript'), env.SConscript('pwr/SConscript'), env.SConscript('rcc/SConscript'), + env.SConscript('syscfg/SConscript'), env.SConscript('timer/SConscript'), env.SConscript('uart/SConscript'), env.SConscript('usb/SConscript'), diff --git a/platforms/stm32/f4.yaml b/platforms/stm32/f4.yaml index f9ff092..fdcef98 100644 --- a/platforms/stm32/f4.yaml +++ b/platforms/stm32/f4.yaml @@ -54,6 +54,10 @@ GPIOI: offset: 0x40022000 + stm32_syscfg: + SYSCFG: + offset: 0x40013800 + stm32_timer: TIM1: offset: 0x40010000 diff --git a/platforms/stm32/l0.yaml b/platforms/stm32/l0.yaml index e20984d..cfba79b 100644 --- a/platforms/stm32/l0.yaml +++ b/platforms/stm32/l0.yaml @@ -16,3 +16,7 @@ offset: 0x50000c00 GPIOH: offset: 0x50001c00 + + stm32_syscfg: + SYSCFG: + offset: 0x40010000 diff --git a/platforms/stm32/wb.yaml b/platforms/stm32/wb.yaml index 5fdb127..d3590a5 100644 --- a/platforms/stm32/wb.yaml +++ b/platforms/stm32/wb.yaml @@ -76,6 +76,10 @@ type: wb offset: 0x58000400 + stm32_syscfg: + SYSCFG: + offset: 0x40010000 + stm32_timer: TIM1: offset: 0x40012C00 diff --git a/rcc/syscfg.h b/rcc/syscfg.h deleted file mode 100644 index 74c3a07..0000000 --- a/rcc/syscfg.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef SYSCFG_H -#define SYSCFG_H - -#include - -struct SYSCFG_t { - volatile uint32_t MEMRM; - volatile uint32_t PMC; - volatile uint32_t EXTICR[4]; - volatile uint32_t CMPCR; -}; - -#if defined(STM32F4) -static SYSCFG_t& SYSCFG = *(SYSCFG_t*)0x40013800; -#endif - -void rcc_init(); - -#endif diff --git a/syscfg/SConscript b/syscfg/SConscript new file mode 100644 index 0000000..190bacb --- /dev/null +++ b/syscfg/SConscript @@ -0,0 +1,23 @@ +Import('env') + +headers = [] +instances = [] +sources = [] +aliases = {} + +periph = env['PLATFORM_SPEC'].get('periph', {}) + +if 'stm32_syscfg' in periph: + headers.append('stm32_syscfg.h') + for name, data in periph['stm32_syscfg'].items(): + # allow overrides, but default to family for syscfg, it's a little special + ptype = data.get('type', env['PLATFORM_SPEC']['meta']['family']) + instances.append({ + 'type': 'STM32_SYSCFG_t' % ptype, + 'name': name, + 'args': [data['offset']], + }) + +env.Jinja2('syscfg.h', '../templates/periph_instances.h.j2', headers = headers, instances = instances, aliases = aliases) + +Return('sources') diff --git a/syscfg/stm32_syscfg.h b/syscfg/stm32_syscfg.h new file mode 100644 index 0000000..cb3c505 --- /dev/null +++ b/syscfg/stm32_syscfg.h @@ -0,0 +1,44 @@ +#pragma once + +#include + +struct STM32_SYSCFG_reg_f4_t { + volatile uint32_t MEMRMP; + volatile uint32_t PMC; + volatile uint32_t EXTICR[4]; + volatile uint32_t CMPCR; +}; + + +struct STM32_SYSCFG_reg_l0_t { + volatile uint32_t CFGR1; + volatile uint32_t CFGR2; + volatile uint32_t EXTICR[4]; + volatile uint32_t COMP1_CTRL; + volatile uint32_t COMP2_CTRL; + volatile uint32_t CFGR3; +}; + +struct STM32_SYSCFG_reg_wb_t { + volatile uint32_t MEMRMP; + volatile uint32_t CFGR1; + volatile uint32_t EXTICR[4]; + volatile uint32_t SCSR; + volatile uint32_t CFGR2; + volatile uint32_t SWPR; + volatile uint32_t SKR; + volatile uint32_t SWPR2; + uint32_t _reserved1[53]; // basicallly, vrefbuf is in this slot! + volatile uint32_t IMR1; + volatile uint32_t IMR2; + volatile uint32_t C2IMR1; + volatile uint32_t C2IMR2; + volatile uint32_t SIPCR; +}; + + +template +class STM32_SYSCFG_t : public mmio_ptr { + public: + using mmio_ptr::ptr; +}; diff --git a/syscfg/syscfg.h b/syscfg/syscfg.h deleted file mode 100644 index 0006f7b..0000000 --- a/syscfg/syscfg.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef SYSCFG_H -#define SYSCFG_H - -#include - -#if defined(STM32L0) - -struct SYSCFG_t { - volatile uint32_t CFGR1; - volatile uint32_t CFGR2; - volatile uint32_t EXTICR1; - volatile uint32_t EXTICR2; - volatile uint32_t EXTICR3; - volatile uint32_t EXTICR4; - volatile uint32_t COMP1_CTRL; - volatile uint32_t COMP2_CTRL; - volatile uint32_t CFGR3; -}; - -static SYSCFG_t& SYSCFG = *(SYSCFG_t*)0x40010000; - -#endif - -#if defined(STM32WB) - -struct SYSCFG_t { - volatile uint32_t MEMRMP; - volatile uint32_t CFGR1; - volatile uint32_t EXTICR[4]; - volatile uint32_t SCSR; - volatile uint32_t CFGR2; - volatile uint32_t SWPR; - volatile uint32_t SKR; - volatile uint32_t SWPR2; - uint32_t _reserved1[53]; // basicallly, vrefbuf is in this slot! - volatile uint32_t IMR1; - volatile uint32_t IMR2; - volatile uint32_t C2IMR1; - volatile uint32_t C2IMR2; - volatile uint32_t SIPCR; -}; - -static SYSCFG_t& SYSCFG = *(SYSCFG_t*)0x40010000; - -#endif - -#endif -- cgit v1.2.3