Hello program for the FM25W256 library

Dependencies:   FM25W256 mbed

Committer:
MACRUM
Date:
Sat Mar 05 14:06:46 2016 +0000
Revision:
2:980e3d46d20e
Parent:
1:be908b1aafe6
Child:
3:d4a2357f06e3
Add more test functions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 2:980e3d46d20e 1 /* Cypress FM25W256 F-RAM component library test program
MACRUM 2:980e3d46d20e 2 *
MACRUM 2:980e3d46d20e 3 * Copyright (c) 2016 ARM Limited
MACRUM 2:980e3d46d20e 4 *
MACRUM 2:980e3d46d20e 5 * Licensed under the Apache License, Version 2.0 (the "License");
MACRUM 2:980e3d46d20e 6 * you may not use this file except in compliance with the License.
MACRUM 2:980e3d46d20e 7 * You may obtain a copy of the License at
MACRUM 2:980e3d46d20e 8 *
MACRUM 2:980e3d46d20e 9 * http://www.apache.org/licenses/LICENSE-2.0
MACRUM 2:980e3d46d20e 10 *
MACRUM 2:980e3d46d20e 11 * Unless required by applicable law or agreed to in writing, software
MACRUM 2:980e3d46d20e 12 * distributed under the License is distributed on an "AS IS" BASIS,
MACRUM 2:980e3d46d20e 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 2:980e3d46d20e 14 * See the License for the specific language governing permissions and
MACRUM 2:980e3d46d20e 15 * limitations under the License.
MACRUM 2:980e3d46d20e 16 * *
MACRUM 2:980e3d46d20e 17 * @author Toyomasa Watarai
MACRUM 2:980e3d46d20e 18 * @version 1.0
MACRUM 2:980e3d46d20e 19 * @date 5-March-2016
MACRUM 2:980e3d46d20e 20 *
MACRUM 2:980e3d46d20e 21 * http://www.cypress.com/products/nonvolatile-ram
MACRUM 2:980e3d46d20e 22 * http://www.cypress.com/documentation/datasheets/fm25w256-256-kbit-32-k-8-serial-spi-f-ram?source=search&keywords=FM25W256&cat=technical_documents
MACRUM 2:980e3d46d20e 23 *
MACRUM 2:980e3d46d20e 24 */
MACRUM 2:980e3d46d20e 25
MACRUM 0:3efb18460968 26 #include "mbed.h"
MACRUM 1:be908b1aafe6 27 #include "FM25W256.h"
MACRUM 0:3efb18460968 28
MACRUM 0:3efb18460968 29 Serial pc(USBTX, USBRX);
MACRUM 1:be908b1aafe6 30 FM25W256 f_ram(dp2, dp1, dp6, dp18);
MACRUM 0:3efb18460968 31
MACRUM 0:3efb18460968 32 void read_test()
MACRUM 0:3efb18460968 33 {
MACRUM 0:3efb18460968 34 uint16_t adrs = 0;
MACRUM 0:3efb18460968 35 for(int i=0; i<16; i++) {
MACRUM 0:3efb18460968 36 pc.printf("0x%04X : ", i * 16);
MACRUM 0:3efb18460968 37 for(int j=0; j<16; j++) {
MACRUM 1:be908b1aafe6 38 pc.printf("%02X ", f_ram.read(adrs++));
MACRUM 0:3efb18460968 39 }
MACRUM 0:3efb18460968 40 pc.printf("\n");
MACRUM 0:3efb18460968 41 }
MACRUM 0:3efb18460968 42 }
MACRUM 0:3efb18460968 43
MACRUM 0:3efb18460968 44 void write_test()
MACRUM 0:3efb18460968 45 {
MACRUM 1:be908b1aafe6 46 uint8_t buf[16];
MACRUM 1:be908b1aafe6 47 for(int i=0; i<16; i++) {
MACRUM 1:be908b1aafe6 48 buf[i] = (15 - i);
MACRUM 0:3efb18460968 49 }
MACRUM 1:be908b1aafe6 50 f_ram.write(0, buf, 16);
MACRUM 0:3efb18460968 51 }
MACRUM 0:3efb18460968 52
MACRUM 2:980e3d46d20e 53 void write_protect_test()
MACRUM 2:980e3d46d20e 54 {
MACRUM 2:980e3d46d20e 55 f_ram.set_write_protect(FM25W256::BANK_ALL);
MACRUM 2:980e3d46d20e 56
MACRUM 2:980e3d46d20e 57 pc.printf("[write data]\n");
MACRUM 2:980e3d46d20e 58 pc.printf("0x0000 : ");
MACRUM 2:980e3d46d20e 59 uint8_t buf[16];
MACRUM 2:980e3d46d20e 60 for(int i=0; i<16; i++) {
MACRUM 2:980e3d46d20e 61 buf[i] = i;
MACRUM 2:980e3d46d20e 62 pc.printf("%02X ", buf[i]);
MACRUM 2:980e3d46d20e 63 }
MACRUM 2:980e3d46d20e 64 pc.printf("\n");
MACRUM 2:980e3d46d20e 65 f_ram.write(0, buf, 16);
MACRUM 2:980e3d46d20e 66
MACRUM 2:980e3d46d20e 67 pc.printf("[read data]\n");
MACRUM 2:980e3d46d20e 68 read_test();
MACRUM 2:980e3d46d20e 69
MACRUM 2:980e3d46d20e 70 f_ram.clear_write_protect();
MACRUM 2:980e3d46d20e 71 }
MACRUM 2:980e3d46d20e 72
MACRUM 0:3efb18460968 73 int main()
MACRUM 0:3efb18460968 74 {
MACRUM 0:3efb18460968 75 pc.printf("\nFM25W256 test program - write test? (y/n) ");
MACRUM 0:3efb18460968 76 if (pc.getc() == 'y') {
MACRUM 0:3efb18460968 77 write_test();
MACRUM 0:3efb18460968 78 }
MACRUM 0:3efb18460968 79
MACRUM 0:3efb18460968 80 pc.printf("\nFM25W256 test program - read test? (y/n) ");
MACRUM 0:3efb18460968 81 if (pc.getc() == 'y') {
MACRUM 0:3efb18460968 82 pc.printf("\n");
MACRUM 0:3efb18460968 83 read_test();
MACRUM 0:3efb18460968 84 }
MACRUM 2:980e3d46d20e 85
MACRUM 2:980e3d46d20e 86 pc.printf("\nFM25W256 test program - write protect test? (y/n) ");
MACRUM 2:980e3d46d20e 87 if (pc.getc() == 'y') {
MACRUM 2:980e3d46d20e 88 pc.printf("\n");
MACRUM 2:980e3d46d20e 89 write_protect_test();
MACRUM 2:980e3d46d20e 90 }
MACRUM 0:3efb18460968 91
MACRUM 0:3efb18460968 92 while(1) {
MACRUM 0:3efb18460968 93 }
MACRUM 0:3efb18460968 94 }