-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[example] Add flash examples for STM32G4
- Loading branch information
1 parent
c67fcbc
commit f7dff92
Showing
6 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2020, Niklas Hauser | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <modm/board.hpp> | ||
#include <modm/processing.hpp> | ||
|
||
#undef MODM_LOG_LEVEL | ||
#define MODM_LOG_LEVEL modm::log::INFO | ||
|
||
// ---------------------------------------------------------------------------- | ||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
MODM_LOG_INFO << "\n\nReboot\n"; | ||
if (not Flash::unlock()) { | ||
MODM_LOG_INFO << "Flash unlock failed!" << modm::endl; | ||
} | ||
|
||
{ | ||
uint32_t err{0}; | ||
MODM_LOG_INFO << "Erasing sectors [32, 64)" << modm::endl; | ||
MODM_LOG_INFO.flush(); | ||
modm::delay(1s); | ||
|
||
const modm::PreciseTimestamp start = modm::PreciseClock::now(); | ||
|
||
for (uint8_t page{32}; page < 64u; page++) | ||
err |= Flash::erase(page); | ||
|
||
const auto diff = (modm::PreciseClock::now() - start); | ||
MODM_LOG_INFO << "Erasing done in " << diff << " with errors: " << err << modm::endl; | ||
MODM_LOG_INFO << "Erasing with " << (Flash::Size/2 / (diff.count() >> 10) ) << "kiB/s" << modm::endl; | ||
MODM_LOG_INFO.flush(); | ||
} | ||
|
||
|
||
{ | ||
uint32_t err{0}; | ||
const modm::PreciseTimestamp start = modm::PreciseClock::now(); | ||
for (uint32_t dst_addr{Flash::OriginAddr + Flash::Size/2}, src_addr{Flash::OriginAddr}; | ||
src_addr < (Flash::OriginAddr + Flash::Size/2); | ||
src_addr += sizeof(Flash::MaxWordType), dst_addr += sizeof(Flash::MaxWordType)) | ||
{ | ||
err |= Flash::program(dst_addr, *(Flash::MaxWordType*)src_addr); | ||
} | ||
|
||
const auto diff = (modm::PreciseClock::now() - start); | ||
MODM_LOG_INFO << "Programming done in " << diff << " with errors: " << err << modm::endl; | ||
MODM_LOG_INFO << "Programming with " << (Flash::Size/2 / (diff.count() >> 10) ) << "kiB/s" << modm::endl; | ||
} | ||
|
||
while(1) ; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<library> | ||
<extends>modm:nucleo-g431kb</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_g431kb/flash</option> | ||
</options> | ||
<modules> | ||
<module>modm:platform:gpio</module> | ||
<module>modm:platform:flash</module> | ||
<module>modm:processing:timer</module> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2020, Niklas Hauser | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <modm/board.hpp> | ||
#include <modm/processing.hpp> | ||
|
||
#undef MODM_LOG_LEVEL | ||
#define MODM_LOG_LEVEL modm::log::INFO | ||
|
||
// ---------------------------------------------------------------------------- | ||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
MODM_LOG_INFO << "\n\nReboot\n"; | ||
if (not Flash::unlock()) { | ||
MODM_LOG_INFO << "Flash unlock failed!" << modm::endl; | ||
} | ||
|
||
{ | ||
uint32_t err{0}; | ||
MODM_LOG_INFO << "Erasing sectors [32, 64)" << modm::endl; | ||
MODM_LOG_INFO.flush(); | ||
modm::delay(1s); | ||
|
||
const modm::PreciseTimestamp start = modm::PreciseClock::now(); | ||
|
||
for (uint8_t page{32}; page < 64u; page++) | ||
err |= Flash::erase(page); | ||
|
||
const auto diff = (modm::PreciseClock::now() - start); | ||
MODM_LOG_INFO << "Erasing done in " << diff << " with errors: " << err << modm::endl; | ||
MODM_LOG_INFO << "Erasing with " << (Flash::Size/2 / (diff.count() >> 10) ) << "kiB/s" << modm::endl; | ||
MODM_LOG_INFO.flush(); | ||
} | ||
|
||
|
||
{ | ||
uint32_t err{0}; | ||
const modm::PreciseTimestamp start = modm::PreciseClock::now(); | ||
for (uint32_t dst_addr{Flash::OriginAddr + Flash::Size/2}, src_addr{Flash::OriginAddr}; | ||
src_addr < (Flash::OriginAddr + Flash::Size/2); | ||
src_addr += sizeof(Flash::MaxWordType), dst_addr += sizeof(Flash::MaxWordType)) | ||
{ | ||
err |= Flash::program(dst_addr, *(Flash::MaxWordType*)src_addr); | ||
} | ||
|
||
const auto diff = (modm::PreciseClock::now() - start); | ||
MODM_LOG_INFO << "Programming done in " << diff << " with errors: " << err << modm::endl; | ||
MODM_LOG_INFO << "Programming with " << (Flash::Size/2 / (diff.count() >> 10) ) << "kiB/s" << modm::endl; | ||
} | ||
|
||
while(1) ; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<library> | ||
<extends>modm:nucleo-g431rb</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_g431rb/flash</option> | ||
</options> | ||
<modules> | ||
<module>modm:platform:gpio</module> | ||
<module>modm:platform:flash</module> | ||
<module>modm:processing:timer</module> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2020, Niklas Hauser | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <modm/board.hpp> | ||
#include <modm/processing.hpp> | ||
|
||
#undef MODM_LOG_LEVEL | ||
#define MODM_LOG_LEVEL modm::log::INFO | ||
|
||
// ---------------------------------------------------------------------------- | ||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
MODM_LOG_INFO << "\n\nReboot\n"; | ||
if (not Flash::unlock()) { | ||
MODM_LOG_INFO << "Flash unlock failed!" << modm::endl; | ||
} | ||
|
||
{ | ||
uint32_t err{0}; | ||
MODM_LOG_INFO << "Erasing sectors [32, 64)" << modm::endl; | ||
MODM_LOG_INFO.flush(); | ||
modm::delay(1s); | ||
|
||
const modm::PreciseTimestamp start = modm::PreciseClock::now(); | ||
|
||
for (uint8_t page{32}; page < 64u; page++) | ||
err |= Flash::erase(page); | ||
|
||
const auto diff = (modm::PreciseClock::now() - start); | ||
MODM_LOG_INFO << "Erasing done in " << diff << " with errors: " << err << modm::endl; | ||
MODM_LOG_INFO << "Erasing with " << (Flash::Size/2 / (diff.count() >> 10) ) << "kiB/s" << modm::endl; | ||
MODM_LOG_INFO.flush(); | ||
} | ||
|
||
|
||
{ | ||
uint32_t err{0}; | ||
const modm::PreciseTimestamp start = modm::PreciseClock::now(); | ||
for (uint32_t dst_addr{Flash::OriginAddr + Flash::Size/2}, src_addr{Flash::OriginAddr}; | ||
src_addr < (Flash::OriginAddr + Flash::Size/2); | ||
src_addr += sizeof(Flash::MaxWordType), dst_addr += sizeof(Flash::MaxWordType)) | ||
{ | ||
err |= Flash::program(dst_addr, *(Flash::MaxWordType*)src_addr); | ||
} | ||
|
||
const auto diff = (modm::PreciseClock::now() - start); | ||
MODM_LOG_INFO << "Programming done in " << diff << " with errors: " << err << modm::endl; | ||
MODM_LOG_INFO << "Programming with " << (Flash::Size/2 / (diff.count() >> 10) ) << "kiB/s" << modm::endl; | ||
} | ||
|
||
while(1) ; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<library> | ||
<extends>modm:nucleo-g474re</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_g474re/flash</option> | ||
</options> | ||
<modules> | ||
<module>modm:platform:gpio</module> | ||
<module>modm:platform:flash</module> | ||
<module>modm:processing:timer</module> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |