-
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.
[examples] Add DevEBox STM32F4XX Flash example
- Loading branch information
1 parent
c2193b2
commit 8082f69
Showing
4 changed files
with
151 additions
and
1 deletion.
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
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,136 @@ | ||
/* | ||
* Copyright (c) 2020, Sascha Schade | ||
* Copyright (c) 2018, Raphael Lehmann | ||
* | ||
* 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/debug/logger.hpp> | ||
|
||
#include <modm/driver/storage/block_device_spiflash.hpp> | ||
|
||
using namespace Board; | ||
|
||
modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice; | ||
|
||
// Set all four logger streams to use the UART | ||
modm::log::Logger modm::log::debug(loggerDevice); | ||
modm::log::Logger modm::log::info(loggerDevice); | ||
modm::log::Logger modm::log::warning(loggerDevice); | ||
modm::log::Logger modm::log::error(loggerDevice); | ||
|
||
// Set the log level | ||
#undef MODM_LOG_LEVEL | ||
#define MODM_LOG_LEVEL modm::log::DEBUG | ||
|
||
Board::w25q16::StorageDevice storageDevice; | ||
|
||
void printMemoryContent(const uint8_t* address, std::size_t size) { | ||
for (std::size_t ii = 0; ii < size; ii++) { | ||
MODM_LOG_INFO.printf("%x", address[ii]); | ||
} | ||
} | ||
|
||
uint8_t bufferA[Board::w25q16::BlockSize]; | ||
uint8_t bufferB[Board::w25q16::BlockSize]; | ||
uint8_t bufferC[Board::w25q16::BlockSize]; | ||
|
||
constexpr uint32_t TestMemorySize = 8*1024; | ||
|
||
void doMemoryTest() | ||
{ | ||
LedGreen::set(); | ||
MODM_LOG_INFO << "Starting memory test!" << modm::endl; | ||
|
||
for (uint16_t iteration = 0; iteration < 4; iteration++) { | ||
uint8_t* pattern = (iteration % 2 == 0) ? bufferA : bufferB; | ||
|
||
if (not RF_CALL_BLOCKING(storageDevice.erase(0, TestMemorySize))) { | ||
MODM_LOG_INFO << "Error: Unable to erase device."; | ||
return; | ||
} | ||
|
||
for (uint32_t ii = 0; ii < TestMemorySize; ii += Board::w25q16::BlockSize) { | ||
if (not RF_CALL_BLOCKING(storageDevice.program(pattern, ii, Board::w25q16::BlockSize))) { | ||
MODM_LOG_INFO << "Error: Unable to write data."; | ||
return; | ||
} | ||
MODM_LOG_INFO << "."; | ||
} | ||
|
||
for (uint32_t ii = 0; ii < TestMemorySize; ii += Board::w25q16::BlockSize) { | ||
if (not RF_CALL_BLOCKING(storageDevice.read(bufferC, ii, Board::w25q16::BlockSize))) { | ||
MODM_LOG_INFO << "Error: Unable to read data."; | ||
return; | ||
} | ||
else if (std::memcmp(pattern, bufferC, Board::w25q16::BlockSize)) { | ||
MODM_LOG_INFO << "ii=" << ii << modm::endl; | ||
MODM_LOG_INFO << "Error: Read '"; | ||
printMemoryContent(bufferC, Board::w25q16::BlockSize); | ||
MODM_LOG_INFO << "', expected: '"; | ||
printMemoryContent(pattern, Board::w25q16::BlockSize); | ||
MODM_LOG_INFO << "'." << modm::endl; | ||
return; | ||
} | ||
} | ||
MODM_LOG_INFO << "." << modm::endl; | ||
} | ||
|
||
MODM_LOG_INFO << modm::endl << "Finished!" << modm::endl; | ||
LedGreen::reset(); | ||
} | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
Board::initializeW25q16(); | ||
|
||
Usart1::connect<GpioInputA9::Tx>(); | ||
Usart1::initialize<Board::SystemClock, 115200_Bd>(); | ||
|
||
// Use the logging streams to print some messages. | ||
// Change MODM_LOG_LEVEL above to enable or disable these messages | ||
MODM_LOG_DEBUG << "debug" << modm::endl; | ||
MODM_LOG_INFO << "info" << modm::endl; | ||
MODM_LOG_WARNING << "warning" << modm::endl; | ||
MODM_LOG_ERROR << "error" << modm::endl; | ||
|
||
bool initializeSuccess = false; | ||
|
||
MODM_LOG_INFO << "Erasing complete flash chip... (This may take a while)" << modm::endl; | ||
|
||
if (not RF_CALL_BLOCKING(storageDevice.initialize())) { | ||
MODM_LOG_INFO << "Error: Unable to initialize device."; | ||
} | ||
else if (not RF_CALL_BLOCKING(storageDevice.erase(0, Board::w25q16::MemorySize))) { | ||
MODM_LOG_INFO << "Error: Unable to erase device."; | ||
} | ||
else { | ||
auto id = RF_CALL_BLOCKING(storageDevice.readId()); | ||
MODM_LOG_INFO << "deviceId=" << id.deviceId << " manufacturerId=" << id.manufacturerId; | ||
MODM_LOG_INFO << " deviceType=" << id.deviceType << modm::endl; | ||
|
||
MODM_LOG_INFO << "status=" << static_cast<uint8_t>(RF_CALL_BLOCKING(storageDevice.readStatus())) << modm::endl; | ||
|
||
MODM_LOG_INFO << "Press USER button to start the memory test." << modm::endl; | ||
initializeSuccess = true; | ||
} | ||
|
||
while (true) | ||
{ | ||
if (initializeSuccess and Button::read()) | ||
{ | ||
doMemoryTest(); | ||
} | ||
} | ||
|
||
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,2 @@ | ||
# Replace this with your custom programmer | ||
source [find interface/stlink.cfg] |
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:devebox-stm32f4xx</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/stm32f4xx_devebox/flash</option> | ||
<option name="modm:build:openocd.cfg">openocd.cfg</option> | ||
</options> | ||
<modules> | ||
<module>modm:debug</module> | ||
<module>modm:platform:uart:1</module> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |