Helloworld program for the S25FL216K flash memory in combination with USBFileSystem

Dependencies:   S25FL216K_USBFileSystem mbed

This HelloWorld program is for the serial flash memory mounted on the Wi-Go board. If yours isn't mounted on it, then you probably will need some other pin definitions.

To use this program plugin both the openSDA USB port and the KL25Z USB port. Use your favourite terminal program to listen to the com-port generated on the openSDA USB port. The KL25Z USB port will emulate a USB MSD device.

Load this program, reset the board. If everything goes correctly a pop-up will appear that the drive needs to be formatted (tested on Windows 8, but I assume it is similar on other OS'). This is because the flash memory is completely empty, no filesystem is available. Just use standard settings (512 byte sector size), and format the drive. When this is done reset the board again.

This time it should load without popup, and after a small pause the flash drive should appear on your computer. On it is a single file, open the file, write something, save the file. Whatever you wrote should appear in your terminal program.

Aditionally the other way around also works, write something in your terminal program, hit enter, and a file is created with whatever you wrote in it. IMPORTANT: In TeraTerm you need to have transmit settings on CR+LF! (Found in Setup > Terminal).

Committer:
Sissors
Date:
Wed Jul 31 19:21:41 2013 +0000
Revision:
0:5e431050adf7
Child:
1:e8698224bb08
v1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 0:5e431050adf7 1 #include "mbed.h"
Sissors 0:5e431050adf7 2 #include "Flash_USBFileSystem.h"
Sissors 0:5e431050adf7 3
Sissors 0:5e431050adf7 4 DigitalOut myled(LED1);
Sissors 0:5e431050adf7 5 FlashUSB flash(PTD6, PTD7, PTB11, PTE4);
Sissors 0:5e431050adf7 6
Sissors 0:5e431050adf7 7 void usbCallback(bool available)
Sissors 0:5e431050adf7 8 {
Sissors 0:5e431050adf7 9 if (available) {
Sissors 0:5e431050adf7 10 FILE *fp = fopen("/USB/usbtest.txt", "r");
Sissors 0:5e431050adf7 11 char buffer[100];
Sissors 0:5e431050adf7 12 fgets (buffer, 100, fp);
Sissors 0:5e431050adf7 13 printf("%s\r\n", buffer);
Sissors 0:5e431050adf7 14 fclose(fp);
Sissors 0:5e431050adf7 15 }
Sissors 0:5e431050adf7 16 }
Sissors 0:5e431050adf7 17
Sissors 0:5e431050adf7 18 int main()
Sissors 0:5e431050adf7 19 {
Sissors 0:5e431050adf7 20 flash.attachUSB(&usbCallback);
Sissors 0:5e431050adf7 21
Sissors 0:5e431050adf7 22 wait(0.1);
Sissors 0:5e431050adf7 23 printf("Hello World!\r\n");
Sissors 0:5e431050adf7 24
Sissors 0:5e431050adf7 25 FILE *fp = fopen("/USB/usbtest.txt", "w");
Sissors 0:5e431050adf7 26
Sissors 0:5e431050adf7 27 if(fp == NULL) {
Sissors 0:5e431050adf7 28 printf("Could not open file, assuming unformatted disk!\r\n");
Sissors 0:5e431050adf7 29 printf("Click in the nice popup window to format disk with default settings!\r\n");
Sissors 0:5e431050adf7 30 } else {
Sissors 0:5e431050adf7 31 wait(0.2);
Sissors 0:5e431050adf7 32 fprintf(fp, "Type your text here!");
Sissors 0:5e431050adf7 33 fclose(fp);
Sissors 0:5e431050adf7 34 }
Sissors 0:5e431050adf7 35
Sissors 0:5e431050adf7 36 //Connect USB
Sissors 0:5e431050adf7 37 flash.connect();
Sissors 0:5e431050adf7 38 while(1) {
Sissors 0:5e431050adf7 39 wait(0.2);
Sissors 0:5e431050adf7 40 myled = !myled;
Sissors 0:5e431050adf7 41 }
Sissors 0:5e431050adf7 42
Sissors 0:5e431050adf7 43 }