This is a mbed 5.2 Release

Dependencies:   USBDevice

Fork of mbed-os-test by Jerry Bradshaw

Committer:
jbradshaw
Date:
Tue Oct 25 15:22:11 2016 +0000
Revision:
0:e4a10ed6eb92
tewt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jbradshaw 0:e4a10ed6eb92 1 /*******************************************************************************
jbradshaw 0:e4a10ed6eb92 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
jbradshaw 0:e4a10ed6eb92 3 *
jbradshaw 0:e4a10ed6eb92 4 * Permission is hereby granted, free of charge, to any person obtaining a
jbradshaw 0:e4a10ed6eb92 5 * copy of this software and associated documentation files (the "Software"),
jbradshaw 0:e4a10ed6eb92 6 * to deal in the Software without restriction, including without limitation
jbradshaw 0:e4a10ed6eb92 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
jbradshaw 0:e4a10ed6eb92 8 * and/or sell copies of the Software, and to permit persons to whom the
jbradshaw 0:e4a10ed6eb92 9 * Software is furnished to do so, subject to the following conditions:
jbradshaw 0:e4a10ed6eb92 10 *
jbradshaw 0:e4a10ed6eb92 11 * The above copyright notice and this permission notice shall be included
jbradshaw 0:e4a10ed6eb92 12 * in all copies or substantial portions of the Software.
jbradshaw 0:e4a10ed6eb92 13 *
jbradshaw 0:e4a10ed6eb92 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
jbradshaw 0:e4a10ed6eb92 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
jbradshaw 0:e4a10ed6eb92 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
jbradshaw 0:e4a10ed6eb92 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
jbradshaw 0:e4a10ed6eb92 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
jbradshaw 0:e4a10ed6eb92 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
jbradshaw 0:e4a10ed6eb92 20 * OTHER DEALINGS IN THE SOFTWARE.
jbradshaw 0:e4a10ed6eb92 21 *
jbradshaw 0:e4a10ed6eb92 22 * Except as contained in this notice, the name of Maxim Integrated
jbradshaw 0:e4a10ed6eb92 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
jbradshaw 0:e4a10ed6eb92 24 * Products, Inc. Branding Policy.
jbradshaw 0:e4a10ed6eb92 25 *
jbradshaw 0:e4a10ed6eb92 26 * The mere transfer of this software does not imply any licenses
jbradshaw 0:e4a10ed6eb92 27 * of trade secrets, proprietary technology, copyrights, patents,
jbradshaw 0:e4a10ed6eb92 28 * trademarks, maskwork rights, or any other form of intellectual
jbradshaw 0:e4a10ed6eb92 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
jbradshaw 0:e4a10ed6eb92 30 * ownership rights.
jbradshaw 0:e4a10ed6eb92 31 *******************************************************************************
jbradshaw 0:e4a10ed6eb92 32 */
jbradshaw 0:e4a10ed6eb92 33 #include "Test_S25FS512.h"
jbradshaw 0:e4a10ed6eb92 34 #include "Test_Utilities.h"
jbradshaw 0:e4a10ed6eb92 35
jbradshaw 0:e4a10ed6eb92 36 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 37 void test_S25FS512(void (*outputString)(const char *)) {
jbradshaw 0:e4a10ed6eb92 38 char tempStr[32];
jbradshaw 0:e4a10ed6eb92 39 uint8_t page[264];
jbradshaw 0:e4a10ed6eb92 40 int totalPass = 1;
jbradshaw 0:e4a10ed6eb92 41 int pass;
jbradshaw 0:e4a10ed6eb92 42 int status;
jbradshaw 0:e4a10ed6eb92 43 int i;
jbradshaw 0:e4a10ed6eb92 44 uint8_t data[128];
jbradshaw 0:e4a10ed6eb92 45 S25FS512 *s25FS512;
jbradshaw 0:e4a10ed6eb92 46
jbradshaw 0:e4a10ed6eb92 47 s25FS512 = Peripherals::s25FS512();
jbradshaw 0:e4a10ed6eb92 48
jbradshaw 0:e4a10ed6eb92 49 // display header
jbradshaw 0:e4a10ed6eb92 50 outputString("Testing S25FS512|");
jbradshaw 0:e4a10ed6eb92 51
jbradshaw 0:e4a10ed6eb92 52 // read id test
jbradshaw 0:e4a10ed6eb92 53 s25FS512->readIdentification(data, sizeof(data));
jbradshaw 0:e4a10ed6eb92 54 s25FS512->readIdentification(data, sizeof(data));
jbradshaw 0:e4a10ed6eb92 55 if ((data[1] == 0x01) && (data[2] == 0x02) && (data[3] == 0x19) &&
jbradshaw 0:e4a10ed6eb92 56 (data[4] == 0x4D)) {
jbradshaw 0:e4a10ed6eb92 57 sprintf(tempStr, "Read ID: Pass ");
jbradshaw 0:e4a10ed6eb92 58 outputString(tempStr);
jbradshaw 0:e4a10ed6eb92 59 } else {
jbradshaw 0:e4a10ed6eb92 60 sprintf(tempStr, "Read ID: Fail ");
jbradshaw 0:e4a10ed6eb92 61 outputString(tempStr);
jbradshaw 0:e4a10ed6eb92 62 totalPass = 0;
jbradshaw 0:e4a10ed6eb92 63 }
jbradshaw 0:e4a10ed6eb92 64 sprintf(tempStr, "(%02X%02X%02X%02X)|", data[1], data[2], data[3], data[4]);
jbradshaw 0:e4a10ed6eb92 65 outputString(tempStr);
jbradshaw 0:e4a10ed6eb92 66
jbradshaw 0:e4a10ed6eb92 67 if (totalPass == 1) {
jbradshaw 0:e4a10ed6eb92 68 // format sector 0
jbradshaw 0:e4a10ed6eb92 69 outputString("Formatting Sector 0, ");
jbradshaw 0:e4a10ed6eb92 70 s25FS512->sectorErase_Helper(0);
jbradshaw 0:e4a10ed6eb92 71
jbradshaw 0:e4a10ed6eb92 72 // verify format sector 0
jbradshaw 0:e4a10ed6eb92 73 outputString("Verifying Format of Sector 0: ");
jbradshaw 0:e4a10ed6eb92 74 s25FS512->readPages_Helper(0, 0, page, 0);
jbradshaw 0:e4a10ed6eb92 75 pass = s25FS512->isPageEmpty(page);
jbradshaw 0:e4a10ed6eb92 76 _printPassFail(pass, 1, outputString);
jbradshaw 0:e4a10ed6eb92 77 totalPass &= pass;
jbradshaw 0:e4a10ed6eb92 78
jbradshaw 0:e4a10ed6eb92 79 // fill page with pattern
jbradshaw 0:e4a10ed6eb92 80 for (i = 0; i < 256; i++) {
jbradshaw 0:e4a10ed6eb92 81 page[i] = i;
jbradshaw 0:e4a10ed6eb92 82 }
jbradshaw 0:e4a10ed6eb92 83 // write to page 0
jbradshaw 0:e4a10ed6eb92 84 outputString("Writing Page 0 to pattern, ");
jbradshaw 0:e4a10ed6eb92 85 s25FS512->writePage_Helper(0, page, 0);
jbradshaw 0:e4a10ed6eb92 86 // clear pattern in memory
jbradshaw 0:e4a10ed6eb92 87 for (i = 0; i < 256; i++) {
jbradshaw 0:e4a10ed6eb92 88 page[i] = 0x00;
jbradshaw 0:e4a10ed6eb92 89 }
jbradshaw 0:e4a10ed6eb92 90 // read back page and verify
jbradshaw 0:e4a10ed6eb92 91 outputString("Read Page Verify: ");
jbradshaw 0:e4a10ed6eb92 92 s25FS512->readPages_Helper(0, 0, page, 0);
jbradshaw 0:e4a10ed6eb92 93 // compare memory for pattern
jbradshaw 0:e4a10ed6eb92 94 pass = 1;
jbradshaw 0:e4a10ed6eb92 95 for (i = 0; i < 256; i++) {
jbradshaw 0:e4a10ed6eb92 96 if (page[i] != i)
jbradshaw 0:e4a10ed6eb92 97 pass = 0;
jbradshaw 0:e4a10ed6eb92 98 }
jbradshaw 0:e4a10ed6eb92 99 _printPassFail(pass, 1, outputString);
jbradshaw 0:e4a10ed6eb92 100 totalPass &= pass;
jbradshaw 0:e4a10ed6eb92 101
jbradshaw 0:e4a10ed6eb92 102 // format sector 0 to clean up after tests
jbradshaw 0:e4a10ed6eb92 103 s25FS512->sectorErase_Helper(0);
jbradshaw 0:e4a10ed6eb92 104 } else {
jbradshaw 0:e4a10ed6eb92 105 outputString("Read Id Failed, Skipping rest of test|");
jbradshaw 0:e4a10ed6eb92 106 }
jbradshaw 0:e4a10ed6eb92 107
jbradshaw 0:e4a10ed6eb92 108 // final results
jbradshaw 0:e4a10ed6eb92 109 outputString("Result: ");
jbradshaw 0:e4a10ed6eb92 110 _printPassFail(totalPass, 0, outputString);
jbradshaw 0:e4a10ed6eb92 111 }