I think this works,
i have given it a quick test,
using an SD card,
and I can write to the SD card,
in explorer,
and in the while loop, it also writes to SD card,
Although; the file does not get 'Refreshed'
untill a Reset, or power cycle,
Nearly there though..
#include "mbed.h"
#include "dbg.h"
#include "USBMSC.h"
#include "msc_bot.h"
#include "SDFileSystem.h"
#include <new>
Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
SDFileSystem sd(p5, p6, p7, p8, "sd");
USBMSC usbdev;
//USBMSC usbdev(0xFFFF, 0x0003, 0x0100);
int K = 0;
extern "C"
void HardFault_Handler() {
printf("Hard Fault!\n");
exit(-1);
}
void no_memory () {
printf("panic: can't allocate to memory!\r\n");
exit(-1);
}
void msc_evt (uint8_t endpoint) {
switch (endpoint) {
case EPBULK_OUT:
MSCBotBulkOut();
break;
case EPBULK_IN:
MSCBotBulkIn();
break;
case 0xFF:
MSCBotReset();
break;
}
}
int main() {
pc.baud(115200);
set_new_handler(no_memory); // new handler function
FILE *fp = fopen("/sd/test.txt", "r");
if (fp) {
int c;
c = fgetc(fp);
pc.printf("file: %c\r\n", c);
fclose(fp);
}
MSCBotReset();
usbdev.attach(&msc_evt);
pc.printf("begin\r\n");
while (1) {
myled = 1;
wait(0.5);
myled = 0;
wait(0.5);
pc.printf("Count = %d\r\n",K);
if (K++ > 30)
{
myled2 = 1;
fp = fopen ("/sd/Active.txt", "a");
if (fp)
{
fprintf (fp, "Hard Created ..");
fclose (fp);
myled3 = 1;
MSCBotReset();
myled4 = 1;
usbdev.attach(&msc_evt);
pc.printf ("Done .. \r\n");
}
else
{
pc.printf ("Fail .. \r\n");
}
myled2 = myled3 = myled4 = K = 0;
}
}
}
i think a DETATCH, is required ?
Cheers
Ceri
Hi, people.
I'm in the middle of a project, where I need to play an audio file, from a filesystem. From what I've been setting up, I can play audio files, directly from the filesystem onboard the mbed. The idea is to create a board, with onboard flash (AT45DB*), and use this as a filesystem.
How would I go about this custom board, connecting it to a computer, and transfer files directly to the AT45DB* IC? Anyone have some code?
I've tried searching, and with USB, I'm not that clever.
Best regards, Lerche