summaryrefslogtreecommitdiff
path: root/rcc
diff options
context:
space:
mode:
authorKarl Palsson <karlp@tweak.net.au>2021-09-17 22:02:25 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2022-01-26 23:40:29 +0100
commit1b5215b679d541f0902ad1d39f0ceb6c36250401 (patch)
tree56e89b17184d97fc06ed66afcdd6ea1f60b7a37d /rcc
parent2d8a1c0489da61996bb4787a53353585d0413a03 (diff)
flash: convert to new style
Diffstat (limited to 'rcc')
-rw-r--r--rcc/SConscript18
-rw-r--r--rcc/flash.cpp10
-rw-r--r--rcc/flash_methods.h5
-rw-r--r--rcc/stm32_flash.h (renamed from rcc/flash.h)39
4 files changed, 46 insertions, 26 deletions
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<STM32_FLASH_reg_%s_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_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 <stdint.h>
+
+void flash_init();
diff --git a/rcc/flash.h b/rcc/stm32_flash.h
index f848b0f..8adc3a3 100644
--- a/rcc/flash.h
+++ b/rcc/stm32_flash.h
@@ -1,10 +1,10 @@
-#ifndef FLASH_H
-#define FLASH_H
+#pragma once
#include <stdint.h>
+#include <mmio/mmio.h>
-struct FLASH_t {
- #if defined(STM32F0) || defined(STM32F1) || defined(STM32F3)
+// Also f0 and f3
+struct STM32_FLASH_reg_f1_t {
volatile uint32_t ACR;
volatile uint32_t KEYR;
volatile uint32_t OPTKEYR;
@@ -14,14 +14,18 @@ struct FLASH_t {
volatile uint32_t RESERVED;
volatile uint32_t OBR;
volatile uint32_t WRPR;
- #elif defined(STM32F4)
+};
+
+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;
- #elif defined(STM32L0)
+};
+
+struct STM32_FLASH_reg_l0_t {
volatile uint32_t ACR;
volatile uint32_t PECR;
volatile uint32_t PDKEYR;
@@ -31,7 +35,9 @@ struct FLASH_t {
volatile uint32_t SR;
volatile uint32_t OPTR;
volatile uint32_t WRPROT;
- #elif defined(STM32WB)
+};
+
+struct STM32_FLASH_reg_wb_t {
volatile uint32_t ACR;
volatile uint32_t KEYR;
volatile uint32_t OPTKEYR;
@@ -53,19 +59,10 @@ struct FLASH_t {
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
+template <typename T>
+class STM32_FLASH_t : public mmio_ptr<T> {
+ public:
+ using mmio_ptr<T>::ptr;
+};