1+ /*
2+ * Copyright (c) 2020, Niklas Hauser
3+ *
4+ * This file is part of the modm project.
5+ *
6+ * This Source Code Form is subject to the terms of the Mozilla Public
7+ * License, v. 2.0. If a copy of the MPL was not distributed with this
8+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+ */
10+
11+ #include < modm/board.hpp>
12+ #include < modm/processing.hpp>
13+
14+ #undef MODM_LOG_LEVEL
15+ #define MODM_LOG_LEVEL modm::log::INFO
16+
17+ // ----------------------------------------------------------------------------
18+ int
19+ main ()
20+ {
21+ Board::initialize ();
22+
23+ MODM_LOG_INFO << " \n\n Reboot\n " ;
24+ if (not Flash::unlock ()) {
25+ MODM_LOG_INFO << " Flash unlock failed!" << modm::endl;
26+ }
27+
28+ {
29+ uint32_t err{0 };
30+ MODM_LOG_INFO << " Erasing sectors [32, 64)" << modm::endl;
31+ MODM_LOG_INFO.flush ();
32+ modm::delay (1s);
33+
34+ const modm::PreciseTimestamp start = modm::PreciseClock::now ();
35+
36+ for (uint8_t page{32 }; page < 64u ; page++)
37+ err |= Flash::erase (page);
38+
39+ const auto diff = (modm::PreciseClock::now () - start);
40+ MODM_LOG_INFO << " Erasing done in " << diff << " with errors: " << err << modm::endl;
41+ MODM_LOG_INFO << " Erasing with " << (Flash::Size/2 / (diff.count () >> 10 ) ) << " kiB/s" << modm::endl;
42+ MODM_LOG_INFO.flush ();
43+ }
44+
45+
46+ {
47+ uint32_t err{0 };
48+ const modm::PreciseTimestamp start = modm::PreciseClock::now ();
49+ for (uint32_t dst_addr{Flash::OriginAddr + Flash::Size/2 }, src_addr{Flash::OriginAddr};
50+ src_addr < (Flash::OriginAddr + Flash::Size/2 );
51+ src_addr += sizeof (Flash::MaxWordType), dst_addr += sizeof (Flash::MaxWordType))
52+ {
53+ err |= Flash::program (dst_addr, *(Flash::MaxWordType*)src_addr);
54+ }
55+
56+ const auto diff = (modm::PreciseClock::now () - start);
57+ MODM_LOG_INFO << " Programming done in " << diff << " with errors: " << err << modm::endl;
58+ MODM_LOG_INFO << " Programming with " << (Flash::Size/2 / (diff.count () >> 10 ) ) << " kiB/s" << modm::endl;
59+ }
60+
61+ while (1 ) ;
62+ return 0 ;
63+ }
0 commit comments