Toyomasa Watarai / Mbed 2 deprecated Hello-FM25W256

Dependencies:   FM25W256 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Cypress FM25W256 F-RAM component library test program
00002  *
00003  * Copyright (c) 2016 ARM Limited
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  *  *
00017  *  @author  Toyomasa Watarai
00018  *  @version 1.0
00019  *  @date    5-March-2016
00020  *
00021  *  http://www.cypress.com/products/nonvolatile-ram
00022  *  http://www.cypress.com/documentation/datasheets/fm25w256-256-kbit-32-k-8-serial-spi-f-ram?source=search&keywords=FM25W256&cat=technical_documents
00023  *
00024  */
00025 
00026 #include "mbed.h"
00027 #include "FM25W256.h"
00028 
00029 Serial pc(USBTX, USBRX);
00030 #if defined(TARGET_LPC1114)
00031 FM25W256 f_ram(dp2, dp1, dp6, dp18);
00032 #elif defined(TARGET_LPC1768)
00033 FM25W256 f_ram(p5, p6, p7, p8);
00034 #endif
00035 
00036 void read_test()
00037 {
00038     uint16_t adrs = 0;
00039     for(int i=0; i<16; i++) {
00040         pc.printf("0x%04X : ", i * 16);
00041         for(int j=0; j<16; j++) {
00042             pc.printf("%02X ", f_ram.read(adrs++));
00043         }
00044         pc.printf("\n");
00045     }
00046 }
00047     
00048 void write_test()
00049 {
00050     uint8_t buf[16];
00051     for(int i=0; i<16; i++) {
00052         buf[i] = (15 - i);
00053     }
00054     f_ram.write(0, buf, 16);
00055 }
00056 
00057 void write_protect_test()
00058 {
00059     f_ram.set_write_protect(FM25W256::BANK_ALL);
00060 
00061     pc.printf("[write data]\n");
00062     pc.printf("0x0000 : ");
00063     uint8_t buf[16];
00064     for(int i=0; i<16; i++) {
00065         buf[i] = i;
00066         pc.printf("%02X ", buf[i]);
00067     }
00068     pc.printf("\n");
00069     f_ram.write(0, buf, 16);
00070 
00071     pc.printf("[read data]\n");
00072     read_test();
00073 
00074     f_ram.clear_write_protect();
00075 }
00076 
00077 int main()
00078 {
00079     pc.printf("\nFM25W256 test program - write test? (y/n) ");
00080     if (pc.getc() == 'y') {
00081         write_test();
00082     }
00083 
00084     pc.printf("\nFM25W256 test program - read test? (y/n) ");
00085     if (pc.getc() == 'y') {
00086         pc.printf("\n");
00087         read_test();
00088     }
00089     
00090     pc.printf("\nFM25W256 test program - write protect test? (y/n) ");
00091     if (pc.getc() == 'y') {
00092         pc.printf("\n");
00093         write_protect_test();
00094     }
00095 
00096     while(1) {
00097     }
00098 }