summaryrefslogtreecommitdiff
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
parent2d8a1c0489da61996bb4787a53353585d0413a03 (diff)
flash: convert to new style
-rw-r--r--.gitignore1
-rw-r--r--platforms/stm32/f0.yaml5
-rw-r--r--platforms/stm32/f1.yaml5
-rw-r--r--platforms/stm32/f3.yaml5
-rw-r--r--platforms/stm32/f4.yaml5
-rw-r--r--platforms/stm32/l0.yaml5
-rw-r--r--platforms/stm32/wb.yaml5
-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
11 files changed, 77 insertions, 26 deletions
diff --git a/.gitignore b/.gitignore
index 6686751..f024703 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@ interrupt/interrupt.h
interrupt/interrupt_enums.h
interrupt/default_handlers.cpp
interrupt/vectors_*.cpp
+rcc/flash.h
rcc/rcc.h
rcc/rcc_enums.h
gpio/gpio.h
diff --git a/platforms/stm32/f0.yaml b/platforms/stm32/f0.yaml
index 58c90b5..68e02b4 100644
--- a/platforms/stm32/f0.yaml
+++ b/platforms/stm32/f0.yaml
@@ -1,5 +1,10 @@
# This is incomplete, just preserving register addresses!
- periph:
+ stm32_flash:
+ FLASH:
+ type: f1
+ offset: 0x40022000
+
stm32_gpio:
GPIOA:
offset: 0x48000000
diff --git a/platforms/stm32/f1.yaml b/platforms/stm32/f1.yaml
index a71a319..7e6919d 100644
--- a/platforms/stm32/f1.yaml
+++ b/platforms/stm32/f1.yaml
@@ -1,5 +1,10 @@
# This is incomplete, just preserving register addresses!
- periph:
+ stm32_flash:
+ FLASH:
+ type: f1
+ offset: 0x40022000
+
stm32_gpio:
GPIOA:
offset: 0x40010800
diff --git a/platforms/stm32/f3.yaml b/platforms/stm32/f3.yaml
index 7877cd7..52b00bd 100644
--- a/platforms/stm32/f3.yaml
+++ b/platforms/stm32/f3.yaml
@@ -75,6 +75,11 @@
type: v1
offset: 0x40020400
+ stm32_flash:
+ FLASH:
+ type: f1
+ offset: 0x40022000
+
stm32_gpio:
GPIOA:
offset: 0x48000000
diff --git a/platforms/stm32/f4.yaml b/platforms/stm32/f4.yaml
index 5f222c7..2aca27c 100644
--- a/platforms/stm32/f4.yaml
+++ b/platforms/stm32/f4.yaml
@@ -29,6 +29,11 @@
size: 64k
periph:
+ stm32_flash:
+ FLASH:
+ type: f4
+ offset: 0x40023c00
+
stm32_gpio:
GPIOA:
offset: 0x40020000
diff --git a/platforms/stm32/l0.yaml b/platforms/stm32/l0.yaml
index f8e8414..e20984d 100644
--- a/platforms/stm32/l0.yaml
+++ b/platforms/stm32/l0.yaml
@@ -1,5 +1,10 @@
# This is incomplete, just preserving register addresses!
- periph:
+ stm32_flash:
+ FLASH:
+ type: l0
+ offset: 0x40022000
+
stm32_gpio:
GPIOA:
offset: 0x50000000
diff --git a/platforms/stm32/wb.yaml b/platforms/stm32/wb.yaml
index cb1d5fb..d8fb1f3 100644
--- a/platforms/stm32/wb.yaml
+++ b/platforms/stm32/wb.yaml
@@ -28,6 +28,11 @@
size: 10k
periph:
+ stm32_flash:
+ FLASH:
+ type: wb
+ offset: 0x58004000
+
stm32_gpio:
GPIOA:
offset: 0x48000000
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;
+};