diff --git a/examples/nucleo_f042k6/lp503x/main.cpp b/examples/nucleo_f042k6/lp503x/main.cpp index 8cc9e41828..3245db712a 100644 --- a/examples/nucleo_f042k6/lp503x/main.cpp +++ b/examples/nucleo_f042k6/lp503x/main.cpp @@ -12,6 +12,7 @@ #include using namespace Board; +using namespace std::chrono_literals; /* * Example to demonstrate LP503x driver @@ -51,7 +52,7 @@ main() RF_CALL_BLOCKING(leds.setChannelBrightness(channel, brightness)); } - modm::delayMilliseconds(1000); + modm::delay(1s); // Configure outputs 0-5 (rgb led 0-1) in bank mode using LedBankMode = modm::lp503x::LedBankMode; @@ -66,8 +67,8 @@ main() // Blink leds in bank mode while(true) { RF_CALL_BLOCKING(leds.setBankBrightness(255)); - modm::delayMilliseconds(500); + modm::delay(0.5s); RF_CALL_BLOCKING(leds.setBankBrightness(0)); - modm::delayMilliseconds(500); + modm::delay(0.5s); } } diff --git a/examples/nucleo_f446re/flash/main.cpp b/examples/nucleo_f446re/flash/main.cpp new file mode 100644 index 0000000000..4cefe0267c --- /dev/null +++ b/examples/nucleo_f446re/flash/main.cpp @@ -0,0 +1,76 @@ +/* + * 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 +#include + +using namespace std::chrono_literals; + +#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; + } + + for (uintptr_t offset{0}, sector{255}; offset < Flash::Size; offset += 1) + { + const uint8_t nsector = Flash::getSector(offset); + if (sector != nsector) { + MODM_LOG_INFO << "Sector " << nsector << " found at boundary " << + (Flash::Origin + offset) << modm::endl; + sector = nsector; + } + } + + { + uint32_t err{0}; + const uint8_t sector_start = Flash::getSector(Flash::Size/2); + const uint8_t sector_end = Flash::getSector(Flash::Size); + MODM_LOG_INFO << "Erasing sectors [" << sector_start << ", " << sector_end << ")" << modm::endl; + MODM_LOG_INFO.flush(); + modm::delay(1s); + + const modm::PreciseTimestamp start = modm::PreciseClock::now(); + + for (uint8_t sector{sector_start}; sector < sector_end; sector++) + err |= Flash::erase(sector); + + 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; +} diff --git a/examples/nucleo_f446re/flash/project.xml b/examples/nucleo_f446re/flash/project.xml new file mode 100644 index 0000000000..69f785966e --- /dev/null +++ b/examples/nucleo_f446re/flash/project.xml @@ -0,0 +1,12 @@ + + modm:nucleo-f446re + + + + + modm:platform:gpio + modm:platform:flash + modm:processing:timer + modm:build:scons + + diff --git a/examples/nucleo_g071rb/flash/main.cpp b/examples/nucleo_g071rb/flash/main.cpp new file mode 100644 index 0000000000..f1b685b5a5 --- /dev/null +++ b/examples/nucleo_g071rb/flash/main.cpp @@ -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 +#include + +#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; +} diff --git a/examples/nucleo_g071rb/flash/project.xml b/examples/nucleo_g071rb/flash/project.xml new file mode 100644 index 0000000000..d1d5f56b79 --- /dev/null +++ b/examples/nucleo_g071rb/flash/project.xml @@ -0,0 +1,12 @@ + + modm:nucleo-g071rb + + + + + modm:platform:gpio + modm:platform:flash + modm:processing:timer + modm:build:scons + +