SPI NOR Flash Single IO Nucleo F767ZI Helloworld 1Gb NOR Flash S70FL01GS
Fork of SPI_FLASH_MEM by
main.cpp@4:7f58f3f34f3e, 2018-05-21 (annotated)
- Committer:
- shivanandgowdakr
- Date:
- Mon May 21 10:28:05 2018 +0000
- Revision:
- 4:7f58f3f34f3e
- Parent:
- 2:f62261b0ef55
SPI NOR Flash Single IO Nucleo F767ZI Helloworld; ; 1Gb read write erase
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shivanandgowdakr | 2:f62261b0ef55 | 1 | |
shivanandgowdakr | 2:f62261b0ef55 | 2 | // SPI Single IO NOR Flash Library for Nucleo F767ZI Interfacing |
shivanandgowdakr | 2:f62261b0ef55 | 3 | |
shivanandgowdakr | 2:f62261b0ef55 | 4 | |
shivanandgowdakr | 2:f62261b0ef55 | 5 | |
bcostm | 0:21b36798fd00 | 6 | #include "mbed.h" |
shivanandgowdakr | 4:7f58f3f34f3e | 7 | #include "S70FL01GS.h" |
shivanandgowdakr | 2:f62261b0ef55 | 8 | #include <string> |
shivanandgowdakr | 2:f62261b0ef55 | 9 | |
shivanandgowdakr | 2:f62261b0ef55 | 10 | Serial pc(USBTX, USBRX); // tx, rx |
shivanandgowdakr | 2:f62261b0ef55 | 11 | |
shivanandgowdakr | 2:f62261b0ef55 | 12 | int main() |
shivanandgowdakr | 2:f62261b0ef55 | 13 | { |
shivanandgowdakr | 4:7f58f3f34f3e | 14 | S70FL01GS flash(PA_7, PA_6, PA_5, PA_4); |
shivanandgowdakr | 2:f62261b0ef55 | 15 | pc.printf("SPI init done\r\n\r\n"); |
shivanandgowdakr | 2:f62261b0ef55 | 16 | uint8_t buffer[100]= {0}; |
shivanandgowdakr | 2:f62261b0ef55 | 17 | // Read Identification information Related to chip. |
shivanandgowdakr | 2:f62261b0ef55 | 18 | |
shivanandgowdakr | 2:f62261b0ef55 | 19 | flash.Read_Identification(buffer); |
shivanandgowdakr | 2:f62261b0ef55 | 20 | for(int i=0; i<80; i++) { |
shivanandgowdakr | 2:f62261b0ef55 | 21 | printf(" ID is %X\r\n",buffer[i]); |
shivanandgowdakr | 2:f62261b0ef55 | 22 | } |
shivanandgowdakr | 2:f62261b0ef55 | 23 | |
shivanandgowdakr | 2:f62261b0ef55 | 24 | wait(1); |
shivanandgowdakr | 2:f62261b0ef55 | 25 | // Reading Flash Memory Status Register1 contents. |
shivanandgowdakr | 2:f62261b0ef55 | 26 | |
shivanandgowdakr | 2:f62261b0ef55 | 27 | uint8_t STATUS_REGISTER1= flash.readRegister(); |
shivanandgowdakr | 2:f62261b0ef55 | 28 | pc.printf(" STATUS REGISTER1 CONTENTS:%X\r\n\r\n",STATUS_REGISTER1); |
shivanandgowdakr | 2:f62261b0ef55 | 29 | |
shivanandgowdakr | 2:f62261b0ef55 | 30 | wait(1); |
shivanandgowdakr | 2:f62261b0ef55 | 31 | |
shivanandgowdakr | 2:f62261b0ef55 | 32 | flash.clearRegister(); |
shivanandgowdakr | 2:f62261b0ef55 | 33 | |
shivanandgowdakr | 2:f62261b0ef55 | 34 | uint8_t Read_Value=flash.readRegister(); |
shivanandgowdakr | 2:f62261b0ef55 | 35 | pc.printf(" reading value here %s\r\n\n",Read_Value); |
shivanandgowdakr | 2:f62261b0ef55 | 36 | |
shivanandgowdakr | 2:f62261b0ef55 | 37 | STATUS_REGISTER1= flash.readRegister(); |
shivanandgowdakr | 2:f62261b0ef55 | 38 | pc.printf(" STATUS REGISTER1 CONTENTS:%X\r\n\r\n",STATUS_REGISTER1); |
shivanandgowdakr | 2:f62261b0ef55 | 39 | wait(1); |
shivanandgowdakr | 2:f62261b0ef55 | 40 | |
shivanandgowdakr | 2:f62261b0ef55 | 41 | printf("Read_Value : %X",Read_Value); |
shivanandgowdakr | 2:f62261b0ef55 | 42 | |
shivanandgowdakr | 2:f62261b0ef55 | 43 | // write a stream of characters to arbitrary address 0x168 |
shivanandgowdakr | 2:f62261b0ef55 | 44 | char stri[] = "Shivanand Gowda Ramaiah"; |
shivanandgowdakr | 2:f62261b0ef55 | 45 | |
shivanandgowdakr | 2:f62261b0ef55 | 46 | pc.printf("Writing String Here: %s\r\n",stri); |
shivanandgowdakr | 2:f62261b0ef55 | 47 | |
shivanandgowdakr | 2:f62261b0ef55 | 48 | |
shivanandgowdakr | 2:f62261b0ef55 | 49 | flash.writeStream(0x00, stri, 22); //Writing Strings in three Differnt addresses. |
shivanandgowdakr | 2:f62261b0ef55 | 50 | flash.writeStream(22, stri, 22); |
shivanandgowdakr | 2:f62261b0ef55 | 51 | flash.writeStream(44, stri, 22); |
shivanandgowdakr | 2:f62261b0ef55 | 52 | |
shivanandgowdakr | 2:f62261b0ef55 | 53 | // |
shivanandgowdakr | 2:f62261b0ef55 | 54 | // uint8_t a=flash.readRegister(); |
shivanandgowdakr | 2:f62261b0ef55 | 55 | // read stream from 0x168 |
shivanandgowdakr | 2:f62261b0ef55 | 56 | char str2[22] = {0}; |
shivanandgowdakr | 2:f62261b0ef55 | 57 | char str3[22] = {0}; |
shivanandgowdakr | 2:f62261b0ef55 | 58 | char str4[22] = {0}; |
shivanandgowdakr | 2:f62261b0ef55 | 59 | pc.printf("Before String Here: %s\r\n",str2); |
shivanandgowdakr | 2:f62261b0ef55 | 60 | flash.readStream(0x00, str2, 22); |
shivanandgowdakr | 2:f62261b0ef55 | 61 | pc.printf("After Read 1 String Here: %s\r\n",str2); |
shivanandgowdakr | 2:f62261b0ef55 | 62 | flash.readStream(22, str4, 22); |
shivanandgowdakr | 2:f62261b0ef55 | 63 | pc.printf("After Read 2 String Here: %s\r\n",str2); |
shivanandgowdakr | 2:f62261b0ef55 | 64 | flash.readStream(44, str3, 22); |
shivanandgowdakr | 2:f62261b0ef55 | 65 | pc.printf("After Read 3 String Here: %s\r\n",str2); |
shivanandgowdakr | 2:f62261b0ef55 | 66 | // |
shivanandgowdakr | 2:f62261b0ef55 | 67 | // for(int i=0; i<20;i++) |
shivanandgowdakr | 2:f62261b0ef55 | 68 | // pc.printf("Printing byte by byte %c\r\n",str2[i]); |
shivanandgowdakr | 2:f62261b0ef55 | 69 | |
shivanandgowdakr | 2:f62261b0ef55 | 70 | |
shivanandgowdakr | 2:f62261b0ef55 | 71 | flash.sectorErase(0x00); |
bcostm | 0:21b36798fd00 | 72 | while(1) { |
shivanandgowdakr | 2:f62261b0ef55 | 73 | uint8_t busy=flash.checkIfBusy(); |
shivanandgowdakr | 2:f62261b0ef55 | 74 | if(busy==0) { |
shivanandgowdakr | 2:f62261b0ef55 | 75 | pc.printf("Not Busy any More \r\n"); |
shivanandgowdakr | 2:f62261b0ef55 | 76 | break; |
shivanandgowdakr | 2:f62261b0ef55 | 77 | } else if (busy==1) |
shivanandgowdakr | 2:f62261b0ef55 | 78 | pc.printf("Busy Now \r\n"); |
bcostm | 0:21b36798fd00 | 79 | } |
shivanandgowdakr | 2:f62261b0ef55 | 80 | |
shivanandgowdakr | 2:f62261b0ef55 | 81 | pc.printf("Exited from program \r\n"); |
shivanandgowdakr | 2:f62261b0ef55 | 82 | return 0; |
shivanandgowdakr | 2:f62261b0ef55 | 83 | |
bcostm | 0:21b36798fd00 | 84 | } |