From b5cd432df8f336c90d530b5d55fda7f2c25472c2 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Tue, 3 May 2022 22:41:45 +0000 Subject: adc: convert to new style Converted the old STM32 headers to new style and copied offsets to platform data. Signed-off-by: Karl Palsson --- .gitignore | 1 + SConscript | 1 + adc/SConscript | 30 ++++++++++++++++++ adc/adc.h | 41 ------------------------ adc/adc_f3.h | 62 ------------------------------------ adc/stm32_adc.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ platforms/stm32/f1.yaml | 11 +++++++ platforms/stm32/f3.yaml | 20 ++++++++++++ platforms/stm32/f7.yaml | 11 +++++++ platforms/stm32/wb.yaml | 8 +++++ 10 files changed, 165 insertions(+), 103 deletions(-) create mode 100644 adc/SConscript delete mode 100644 adc/adc.h delete mode 100644 adc/adc_f3.h create mode 100644 adc/stm32_adc.h diff --git a/.gitignore b/.gitignore index f9eef22..8ece78f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ docs # Generated source files: ld_scripts/generated.ld +adc/adc.h dma/dma.h exti/exti.h gpio/gpio.h diff --git a/SConscript b/SConscript index ab72ddc..7d3ff74 100644 --- a/SConscript +++ b/SConscript @@ -7,6 +7,7 @@ env.SConscript('ld_scripts/SConscript') env.Append( LIB_SOURCES = [ + env.SConscript('adc/SConscript'), env.SConscript('dma/SConscript'), env.SConscript('exti/SConscript'), env.SConscript('gpio/SConscript'), diff --git a/adc/SConscript b/adc/SConscript new file mode 100644 index 0000000..ae2fd2b --- /dev/null +++ b/adc/SConscript @@ -0,0 +1,30 @@ +Import('env') + +headers = [] +instances = [] +sources = [] +aliases = {} +type_aliases = {} + +periph = env['PLATFORM_SPEC'].get('periph', {}) + +if 'stm32_adc' in periph: + headers.append('stm32_adc.h') + for name, data in periph['stm32_adc'].items(): + if name.find("COMMON") > 0: + instances.append({ + 'type': 'STM32_ADC_COMMON_t' % data['type'], + 'name': name, + 'args': [data['offset']], + }) + else: + instances.append({ + 'type': 'STM32_ADC_t' % data['type'], + 'name': name, + 'args': [data['offset']], + }) + + +env.Jinja2('adc.h', '../templates/periph_instances.h.j2', headers = headers, instances = instances, aliases = aliases, type_aliases = type_aliases) + +Return('sources') diff --git a/adc/adc.h b/adc/adc.h deleted file mode 100644 index 01a2293..0000000 --- a/adc/adc.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef ADC_H -#define ADC_H - -#include - -struct ADC_t { - volatile uint32_t SR; - volatile uint32_t CR1; - volatile uint32_t CR2; - volatile uint32_t SMPR1; - volatile uint32_t SMPR2; - volatile uint32_t JOFR1; - volatile uint32_t JOFR2; - volatile uint32_t JOFR3; - volatile uint32_t JOFR4; - volatile uint32_t HTR; - volatile uint32_t LTR; - volatile uint32_t SQR1; - volatile uint32_t SQR2; - volatile uint32_t SQR3; - volatile uint32_t JSQR; - volatile uint32_t JDR1; - volatile uint32_t JDR2; - volatile uint32_t JDR3; - volatile uint32_t JDR4; - volatile uint32_t DR; -}; - -#if defined(STM32F1) -static ADC_t& ADC1 = *(ADC_t*)0x40012400; -static ADC_t& ADC2 = *(ADC_t*)0x40012800; -static ADC_t& ADC3 = *(ADC_t*)0x40013c00; -#elif defined(STM32F4) - -#elif defined(STM32F7) -static ADC_t& ADC1 = *(ADC_t*)0x40012000; -static ADC_t& ADC2 = *(ADC_t*)0x40012100; -static ADC_t& ADC3 = *(ADC_t*)0x40012200; -#endif - -#endif diff --git a/adc/adc_f3.h b/adc/adc_f3.h deleted file mode 100644 index a225ebf..0000000 --- a/adc/adc_f3.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef ADC_F3_H -#define ADC_F3_H - -#include - -struct ADC_t { - volatile uint32_t ISR; - volatile uint32_t IER; - volatile uint32_t CR; - volatile uint32_t CFGR; - volatile uint32_t CFGR2; - volatile uint32_t SMPR1; - volatile uint32_t SMPR2; - uint32_t _reserved1; - volatile uint32_t TR1; - volatile uint32_t TR2; - volatile uint32_t TR3; - uint32_t _reserved2; - volatile uint32_t SQR1; - volatile uint32_t SQR2; - volatile uint32_t SQR3; - volatile uint32_t SQR4; - volatile uint32_t DR; - uint32_t _reserved3[2]; - volatile uint32_t JSQR; - uint32_t _reserved4[4]; - volatile uint32_t OFR1; - volatile uint32_t OFR2; - volatile uint32_t OFR3; - volatile uint32_t OFR4; - uint32_t _reserved5[4]; - volatile uint32_t JDR1; - volatile uint32_t JDR2; - volatile uint32_t JDR3; - volatile uint32_t JDR4; - uint32_t _reserved6[4]; - volatile uint32_t AWD2CR; - volatile uint32_t AWD3CR; - uint32_t _reserved7[2]; - volatile uint32_t DIFSEL; - volatile uint32_t CALFACT; -}; - -struct ADC_COMMON_t { - volatile uint32_t CSR; - uint32_t _reserved1; - volatile uint32_t CCR; -}; - -#if defined(STM32F3) -static ADC_t& ADC1 = *(ADC_t*)0x50000000; -static ADC_t& ADC2 = *(ADC_t*)0x50000100; -static ADC_t& ADC3 = *(ADC_t*)0x50000400; -static ADC_t& ADC4 = *(ADC_t*)0x50000500; -static ADC_COMMON_t& ADC_COMMON1 = *(ADC_COMMON_t*)0x50000300; -static ADC_COMMON_t& ADC_COMMON3 = *(ADC_COMMON_t*)0x50000700; -#elif defined(STM32WB) -static ADC_t& ADC1 = *(ADC_t*)0x50040000; -static ADC_COMMON_t& ADC_COMMON1 = *(ADC_COMMON_t*)0x50040300; -#endif - -#endif diff --git a/adc/stm32_adc.h b/adc/stm32_adc.h new file mode 100644 index 0000000..6216581 --- /dev/null +++ b/adc/stm32_adc.h @@ -0,0 +1,83 @@ +#pragma once + +#include + +struct STM32_ADC_reg_v1_t { + volatile uint32_t SR; + volatile uint32_t CR1; + volatile uint32_t CR2; + volatile uint32_t SMPR1; + volatile uint32_t SMPR2; + volatile uint32_t JOFR1; + volatile uint32_t JOFR2; + volatile uint32_t JOFR3; + volatile uint32_t JOFR4; + volatile uint32_t HTR; + volatile uint32_t LTR; + volatile uint32_t SQR1; + volatile uint32_t SQR2; + volatile uint32_t SQR3; + volatile uint32_t JSQR; + volatile uint32_t JDR1; + volatile uint32_t JDR2; + volatile uint32_t JDR3; + volatile uint32_t JDR4; + volatile uint32_t DR; +}; + + +struct STM32_ADC_reg_v2_t { + volatile uint32_t ISR; + volatile uint32_t IER; + volatile uint32_t CR; + volatile uint32_t CFGR; + volatile uint32_t CFGR2; + volatile uint32_t SMPR1; + volatile uint32_t SMPR2; + uint32_t _reserved1; + volatile uint32_t TR1; + volatile uint32_t TR2; + volatile uint32_t TR3; + uint32_t _reserved2; + volatile uint32_t SQR1; + volatile uint32_t SQR2; + volatile uint32_t SQR3; + volatile uint32_t SQR4; + volatile uint32_t DR; + uint32_t _reserved3[2]; + volatile uint32_t JSQR; + uint32_t _reserved4[4]; + volatile uint32_t OFR1; + volatile uint32_t OFR2; + volatile uint32_t OFR3; + volatile uint32_t OFR4; + uint32_t _reserved5[4]; + volatile uint32_t JDR1; + volatile uint32_t JDR2; + volatile uint32_t JDR3; + volatile uint32_t JDR4; + uint32_t _reserved6[4]; + volatile uint32_t AWD2CR; + volatile uint32_t AWD3CR; + uint32_t _reserved7[2]; + volatile uint32_t DIFSEL; + volatile uint32_t CALFACT; +}; + +struct STM32_ADC_COMMON_reg_v2_t { + volatile uint32_t CSR; + uint32_t _reserved1; + volatile uint32_t CCR; +}; + +template +class STM32_ADC_t : public mmio_ptr { + public: + using mmio_ptr::ptr; +}; + +template +class STM32_ADC_COMMON_t : public mmio_ptr { + public: + using mmio_ptr::ptr; +}; diff --git a/platforms/stm32/f1.yaml b/platforms/stm32/f1.yaml index 7e6919d..e4806b9 100644 --- a/platforms/stm32/f1.yaml +++ b/platforms/stm32/f1.yaml @@ -1,5 +1,16 @@ # This is incomplete, just preserving register addresses! - periph: + stm32_adc: + ADC1: + type: v1 + offset: 0x40012400 + ADC2: + type: v1 + offset: 0x40012800 + ADC3: + type: v1 + offset: 0x40013c00 + stm32_flash: FLASH: type: f1 diff --git a/platforms/stm32/f3.yaml b/platforms/stm32/f3.yaml index 6586a7d..03f2498 100644 --- a/platforms/stm32/f3.yaml +++ b/platforms/stm32/f3.yaml @@ -67,6 +67,26 @@ origin: 0x10000000 periph: + stm32_adc: + ADC1: + type: v2 + offset: 0x50000000 + ADC2: + type: v2 + offset: 0x50000100 + ADC3: + type: v2 + offset: 0x50000400 + ADC4: + type: v2 + offset: 0x50000500 + ADC_COMMON1: + type: v2 + offset: 0x50000300 + ADC_COMMON3: + type: v2 + offset: 0x50000700 + stm32_dma: DMA1: type: v1 diff --git a/platforms/stm32/f7.yaml b/platforms/stm32/f7.yaml index 82f6520..e54247f 100644 --- a/platforms/stm32/f7.yaml +++ b/platforms/stm32/f7.yaml @@ -18,6 +18,17 @@ size: 320k periph: + stm32_adc: + ADC1: + type: v1 + offset: 0x40012000 + ADC2: + type: v1 + offset: 0x40012100 + ADC3: + type: v1 + offset: 0x40012200 + stm32_flash: FLASH: type: f4 diff --git a/platforms/stm32/wb.yaml b/platforms/stm32/wb.yaml index e4cf2bb..241c467 100644 --- a/platforms/stm32/wb.yaml +++ b/platforms/stm32/wb.yaml @@ -28,6 +28,14 @@ size: 10k periph: + stm32_adc: + ADC1: + type: v2 + offset: 0x50040000 + ADC_COMMON1: + type: v2 + offset: 0x50040300 + stm32_dma: DMA1: type: v1 -- cgit v1.2.3