From 1b5215b679d541f0902ad1d39f0ceb6c36250401 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Fri, 17 Sep 2021 20:02:25 +0000 Subject: flash: convert to new style --- rcc/SConscript | 18 ++++++++++++++ rcc/flash.cpp | 10 ++++---- rcc/flash.h | 71 ----------------------------------------------------- rcc/flash_methods.h | 5 ++++ rcc/stm32_flash.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 76 deletions(-) delete mode 100644 rcc/flash.h create mode 100644 rcc/flash_methods.h create mode 100644 rcc/stm32_flash.h (limited to 'rcc') diff --git a/rcc/SConscript b/rcc/SConscript index f72d4be..a5c82f3 100644 --- a/rcc/SConscript +++ b/rcc/SConscript @@ -27,4 +27,22 @@ if 'rcc' in periph: env.Jinja2('rcc.h', '../templates/periph_instances.h.j2', headers = headers, instances = instances, aliases = aliases) + +headers = [] +instances = [] +aliases = {} + +if 'stm32_flash' in periph: + headers.append('flash_methods.h') + headers.append('stm32_flash.h') + for name, data in periph['stm32_flash'].items(): + instances.append({ + 'type': 'STM32_FLASH_t' % data['type'], + 'name': name, + 'args': [data['offset']], + }) + +env.Jinja2('flash.h', '../templates/periph_instances.h.j2', headers = headers, instances = instances, aliases = aliases) + + Return('sources') diff --git a/rcc/flash.cpp b/rcc/flash.cpp index e17b6a1..988764f 100644 --- a/rcc/flash.cpp +++ b/rcc/flash.cpp @@ -7,23 +7,23 @@ void flash_init() { #if defined(STM32F1) || defined(STM32F3) // Set flash latency. - FLASH.ACR = 0x12; + FLASH->ACR = 0x12; #elif defined(STM32F4) // Set flash latency. - FLASH.ACR = 0x107; + FLASH->ACR = 0x107; - while(FLASH.ACR != 0x107); + while(FLASH->ACR != 0x107); #elif defined(STM32F0) || defined(STM32L0) // SET flash latency. - FLASH.ACR = 1 << 0; + FLASH->ACR = 1 << 0; #elif defined(STM32WB) // Prefetch and both caches, plus 3WS for 64MHz - FLASH.ACR = 0x700 | 3; + FLASH->ACR = 0x700 | 3; #endif } diff --git a/rcc/flash.h b/rcc/flash.h deleted file mode 100644 index f848b0f..0000000 --- a/rcc/flash.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef FLASH_H -#define FLASH_H - -#include - -struct FLASH_t { - #if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) - volatile uint32_t ACR; - volatile uint32_t KEYR; - volatile uint32_t OPTKEYR; - volatile uint32_t SR; - volatile uint32_t CR; - volatile uint32_t AR; - volatile uint32_t RESERVED; - volatile uint32_t OBR; - volatile uint32_t WRPR; - #elif defined(STM32F4) - volatile uint32_t ACR; - volatile uint32_t KEYR; - volatile uint32_t OPTKEYR; - volatile uint32_t SR; - volatile uint32_t CR; - volatile uint32_t OPTCR; - #elif defined(STM32L0) - volatile uint32_t ACR; - volatile uint32_t PECR; - volatile uint32_t PDKEYR; - volatile uint32_t PEKEYR; - volatile uint32_t PRGKEYR; - volatile uint32_t OPTKEYR; - volatile uint32_t SR; - volatile uint32_t OPTR; - volatile uint32_t WRPROT; - #elif defined(STM32WB) - volatile uint32_t ACR; - volatile uint32_t KEYR; - volatile uint32_t OPTKEYR; - volatile uint32_t SR; - volatile uint32_t CR; - volatile uint32_t ECCR; - volatile uint32_t OPTR; - volatile uint32_t PCROP1ASR; - volatile uint32_t PCROP1AER; - volatile uint32_t WRP1AR; - volatile uint32_t WRP1BR; - volatile uint32_t PCROP1BSR; - volatile uint32_t PCROP1BER; - volatile uint32_t IPCCBR; - volatile uint32_t _reserved1[8]; - volatile uint32_t C2ACR; - volatile uint32_t C2SR; - volatile uint32_t C2CR; // 0x64 - volatile uint32_t _reserved2[7]; - volatile uint32_t SFR; // 0x80 - volatile uint32_t SRRVR; - #endif -}; - -#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) -static FLASH_t& FLASH = *(FLASH_t*)0x40022000; -#elif defined(STM32F4) -static FLASH_t& FLASH = *(FLASH_t*)0x40023c00; -#elif defined(STM32L0) -static FLASH_t& FLASH = *(FLASH_t*)0x40022000; -#elif defined(STM32WB) -static FLASH_t& FLASH = *(FLASH_t*)0x58004000; -#endif - -void flash_init(); - -#endif diff --git a/rcc/flash_methods.h b/rcc/flash_methods.h new file mode 100644 index 0000000..0a28e32 --- /dev/null +++ b/rcc/flash_methods.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +void flash_init(); diff --git a/rcc/stm32_flash.h b/rcc/stm32_flash.h new file mode 100644 index 0000000..8adc3a3 --- /dev/null +++ b/rcc/stm32_flash.h @@ -0,0 +1,68 @@ +#pragma once + +#include +#include + +// Also f0 and f3 +struct STM32_FLASH_reg_f1_t { + volatile uint32_t ACR; + volatile uint32_t KEYR; + volatile uint32_t OPTKEYR; + volatile uint32_t SR; + volatile uint32_t CR; + volatile uint32_t AR; + volatile uint32_t RESERVED; + volatile uint32_t OBR; + volatile uint32_t WRPR; +}; + +struct STM32_FLASH_reg_f4_t { + volatile uint32_t ACR; + volatile uint32_t KEYR; + volatile uint32_t OPTKEYR; + volatile uint32_t SR; + volatile uint32_t CR; + volatile uint32_t OPTCR; +}; + +struct STM32_FLASH_reg_l0_t { + volatile uint32_t ACR; + volatile uint32_t PECR; + volatile uint32_t PDKEYR; + volatile uint32_t PEKEYR; + volatile uint32_t PRGKEYR; + volatile uint32_t OPTKEYR; + volatile uint32_t SR; + volatile uint32_t OPTR; + volatile uint32_t WRPROT; +}; + +struct STM32_FLASH_reg_wb_t { + volatile uint32_t ACR; + volatile uint32_t KEYR; + volatile uint32_t OPTKEYR; + volatile uint32_t SR; + volatile uint32_t CR; + volatile uint32_t ECCR; + volatile uint32_t OPTR; + volatile uint32_t PCROP1ASR; + volatile uint32_t PCROP1AER; + volatile uint32_t WRP1AR; + volatile uint32_t WRP1BR; + volatile uint32_t PCROP1BSR; + volatile uint32_t PCROP1BER; + volatile uint32_t IPCCBR; + volatile uint32_t _reserved1[8]; + volatile uint32_t C2ACR; + volatile uint32_t C2SR; + volatile uint32_t C2CR; // 0x64 + volatile uint32_t _reserved2[7]; + volatile uint32_t SFR; // 0x80 + volatile uint32_t SRRVR; +}; + +template +class STM32_FLASH_t : public mmio_ptr { + public: + using mmio_ptr::ptr; +}; -- cgit v1.2.3