From 088f2890e7e02625c518f557e1f715c8e1b00f5a Mon Sep 17 00:00:00 2001 From: delphi Date: Sun, 10 Oct 2021 16:21:52 +0300 Subject: [PATCH] [stm32] Flash driver enabled for F1 family Signed-off-by: delphi --- README.md | 2 +- src/modm/platform/flash/stm32/flash.cpp.in | 6 ++++++ src/modm/platform/flash/stm32/flash.hpp.in | 10 +++------- src/modm/platform/flash/stm32/module.lb | 11 ++++++++++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ca06abd3e3..18556d8683 100644 --- a/README.md +++ b/README.md @@ -324,7 +324,7 @@ Please [discover modm's peripheral drivers for your specific device][discover]. Internal Flash ○ -○ +✅ ○ ○ ✅ diff --git a/src/modm/platform/flash/stm32/flash.cpp.in b/src/modm/platform/flash/stm32/flash.cpp.in index 72b528f3e2..dca2f54e7b 100644 --- a/src/modm/platform/flash/stm32/flash.cpp.in +++ b/src/modm/platform/flash/stm32/flash.cpp.in @@ -89,8 +89,14 @@ Flash::erase(uint8_t index) FLASH->CR = FLASH_CR_STRT | FLASH_CR_SER | uint32_t(size) | ((index << FLASH_CR_SNB_Pos) & FLASH_CR_SNB_Msk); %% else +%% if family == "g0" FLASH->CR = FLASH_CR_STRT | FLASH_CR_PER | ((index << FLASH_CR_PNB_Pos) & FLASH_CR_PNB_Msk); +%% else + FLASH->CR = FLASH_CR_PER; + FLASH->AR = index; + FLASH->CR = FLASH_CR_STRT; +%% endif %% endif while(isBusy()) ; diff --git a/src/modm/platform/flash/stm32/flash.hpp.in b/src/modm/platform/flash/stm32/flash.hpp.in index a27b530f68..66de84bb50 100644 --- a/src/modm/platform/flash/stm32/flash.hpp.in +++ b/src/modm/platform/flash/stm32/flash.hpp.in @@ -40,7 +40,7 @@ public: inline static void enable() { -%% if not has_sectors +%% if not has_sectors and family == "g0" Rcc::enable(); %% endif } @@ -48,7 +48,7 @@ public: inline static void disable() { -%% if not has_sectors +%% if not has_sectors and family == "g0" Rcc::disable(); %% endif @@ -60,11 +60,7 @@ public: static inline bool isBusy() -%% if has_sectors - { return FLASH->SR & FLASH_SR_BSY; } -%% else - { return FLASH->SR & FLASH_SR_BSY1; } -%% endif + { return FLASH->SR & {{ busy_bit }}; } static bool unlock(); diff --git a/src/modm/platform/flash/stm32/module.lb b/src/modm/platform/flash/stm32/module.lb index f7c266d61c..4d08718477 100644 --- a/src/modm/platform/flash/stm32/module.lb +++ b/src/modm/platform/flash/stm32/module.lb @@ -17,7 +17,7 @@ def init(module): def prepare(module, options): device = options[":target"] - if device.identifier.family not in ["g0", "f4"]: + if device.identifier.family not in ["g0", "f1", "f4"]: return False if not device.has_driver("flash:stm32*"): return False @@ -31,12 +31,19 @@ def build(env): memories = listify(env[":target"].get_driver("core")["memory"]) flash = next(filter(lambda m: m["name"] == "flash", memories)) + family = target.family if target.family in ["f4"]: block_shift = 17 ftype = "sector" + busy_bit = "FLASH_SR_BSY" + elif target.family in ["f1"]: + block_shift = 10 + ftype = "page" + busy_bit = "FLASH_SR_BSY" elif target.family in ["g0"]: block_shift = 11 ftype = "page" + busy_bit = "FLASH_SR_BSY1" env.substitutions = { "start": int(flash["start"], 16), @@ -44,6 +51,8 @@ def build(env): "type": ftype, "shift": block_shift, "has_sectors": ftype == "sector", + "busy_bit": busy_bit, + "family": family } env.outbasepath = "modm/src/modm/platform/flash" env.template("flash.hpp.in")