Skip to content

Commit

Permalink
[stm32] Flash driver enabled for F1 family
Browse files Browse the repository at this point in the history
Signed-off-by: delphi <cpp.create@gmail.com>
  • Loading branch information
asmfreak committed Oct 10, 2021
1 parent 38120ec commit 088f289
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Please [discover modm's peripheral drivers for your specific device][discover].
</tr><tr>
<td align="left">Internal Flash</td>
<td align="center">○</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">○</td>
<td align="center">○</td>
<td align="center">✅</td>
Expand Down
6 changes: 6 additions & 0 deletions src/modm/platform/flash/stm32/flash.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()) ;
Expand Down
10 changes: 3 additions & 7 deletions src/modm/platform/flash/stm32/flash.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public:
inline static void
enable()
{
%% if not has_sectors
%% if not has_sectors and family == "g0"
Rcc::enable<Peripheral::Flash>();
%% endif
}

inline static void
disable()
{
%% if not has_sectors
%% if not has_sectors and family == "g0"
Rcc::disable<Peripheral::Flash>();
%% endif

Expand All @@ -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();
Expand Down
11 changes: 10 additions & 1 deletion src/modm/platform/flash/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,19 +31,28 @@ 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),
"size": int(flash["size"]),
"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")
Expand Down

0 comments on commit 088f289

Please sign in to comment.