From 7cf97498dda6724f89c36719c288e1312f52f27e Mon Sep 17 00:00:00 2001 From: Daniel Fekete Date: Wed, 26 Jul 2017 19:42:18 +0200 Subject: [PATCH] flash: add test code --- .../FlashVariablesTest/FlashVariablesTest.ino | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 STM32/libraries/HardwareTest/examples/FlashVariablesTest/FlashVariablesTest.ino diff --git a/STM32/libraries/HardwareTest/examples/FlashVariablesTest/FlashVariablesTest.ino b/STM32/libraries/HardwareTest/examples/FlashVariablesTest/FlashVariablesTest.ino new file mode 100644 index 0000000..f60d5e7 --- /dev/null +++ b/STM32/libraries/HardwareTest/examples/FlashVariablesTest/FlashVariablesTest.ino @@ -0,0 +1,62 @@ +/* Testing of writing random variables to Flash like EEPROM +* +* It uses RAM just for the test, and to see how the underlying storage changes when writing. +*/ + +#include "FlashVariables.h" + +RamFlashPage page0(64); +RamFlashPage page1(64); + +// number of variables that can be stored +#define VIRTUAL_STORAGE_LENGTH 4 +// 1 byte data +#define DATA_BYTES 1 + +FlashVariables vars(&page0, &page1); + +void setup() { + Serial.begin(115200); + + delay(1000); + Serial.println("Press a key to test"); +} + +uint8_t check[VIRTUAL_STORAGE_LENGTH]; + +void loop() { + + while(Serial.read() == -1); + + uint8_t data; + + int address = random(VIRTUAL_STORAGE_LENGTH); + data = random(256); + + Serial.printf("Set variable %d= %d\n", address, data); + + check[address] = data; + + if (!vars.write(address, &data)) { + Serial.printf("Failed to write"); + while(1); + } + + Serial.print("Page 0 content: "); + page0.print(Serial, 4); + + Serial.print("Page 1 content: "); + page1.print(Serial, 4); + for(int i=0; i