USB -> LPC1768 -> AT45DB*

17 Nov 2011

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

17 Nov 2011

Hello, do You mean connect mbed to PC via D+ and D- pins (USB) and be able to load song to mbed like to mp3 player? I think it is possible with As I understand in this example mbed is acting as Mass storage class USB device to host with attached SD filesystem so I think it should be possible to change to flash filesystem instead of SD. I hope this will help.

17 Nov 2011

Yes, exactly my thought. D+/- to AT45DB*, just as device with memory.

Then after disconnect, should be able to play just one wave file.

17 Nov 2011

Actually, it would be exactly as the magic interface works, but has anyone written a program for this?

17 Nov 2011

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");

void no_memory () {
    printf("panic: can't allocate to memory!\r\n");

void msc_evt (uint8_t endpoint) {
    switch (endpoint) {
        case EPBULK_OUT:
        case EPBULK_IN:
        case 0xFF:

int main() {

    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);



    while (1) {

        myled = 1;
        myled = 0;

        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;

                myled4 = 1;
                pc.printf ("Done .. \r\n");
                pc.printf ("Fail .. \r\n");
                myled2 = myled3 = myled4 = K = 0;


i think a DETATCH, is required ?



17 Nov 2011

Christian Lerche wrote:

Actually, it would be exactly as the magic interface works, but has anyone written a program for this?

I think mbed probably is not interesting to share this AT45DB* interface library because after any one can make a clone with not only NXP MCU but with any other MCU which is what they do not want. I am guess? If I am wrong and there is another reason then I would like to know it if it is not a secret.

17 Nov 2011

Well, that would make sense, but someone probably had the idea, and were maybe writing something. I will try the posted program, and see if I can get it up and running :-)

17 Nov 2011

Correct me if I misunderstood anything but I thought that idea was about connecting mbed to host PC via D+ and D- alias USB and mbed acting as Mass storage to PC host to be able to load files to flash chip attached as filesystem storage space used for this mass storage class device.

I think it is something different than magic interface on mbed does. I think You still need to load new program to mbed via mini USB B connector on mbed itself.

My idea is that this magic interface act as Serial and Mass storage to PC and after reset bootloads lpc1768 chip with new firmware. So it is different from mbed as USB Mass storage device (as flash disk) in my opinion.

If I am wrong, please correct me.

17 Nov 2011

Correct little llumpu. The idea is to make the mbed act as a Mass Storage Device, with a SPI flash.

This could then be used on the LPC1768 IC, as storage, for audio files, playing them when it was told.

Just like any MP3/Wave player, but instead of loading the files onto a USB thumb drive, the LPC1768 would be like a flash drive.


17 Nov 2011

Well, now I tried the program, but nothing pops up, when connecting the D+/D- connectors (of course, +5V and GND is connected as well), I've connected a SD card to the SPI, and still nothing comes up on the computer. ANy ideas?

17 Nov 2011

My one worked first time, with no problems at all :>

I used a Sparkfun/coolcomponents

no mods, and it worked just fine. a USB Mass storage device poped up, (after 20 - 30 seconds)

I added some files (autorun.inf & an icon)

the programm read the first charictor or a text file -> terminal. and the program created a text file,

dont know why yours dont work :(

  • Ceri
19 Nov 2011

NXP have allready published an App note called " LPC1700 , USB secondary bootloader " that uses NXP's part of internal flash as mass storage device for firmware placement , so when you reset the device and press another key , the file placed in internal flash becomes new firmware . The extra feature of magic chip , if I understand things well , is that "magic " bootloader selects the newest firmware upon a lot of firmwares stored in an external SPI flash making life for new developers very easy !!! , but you can always use the public USB bootloader available by this app note for your production boards, if you are not interested in selecting from different firmware files ,but just one. look for AN10866

20 Nov 2011

It works! I've connected to mbed to EA Baseboard, tried the USCMSC program, and it works! Next, added the wavplayer function from EA_Wavplayer, and the project works! :D

20 Nov 2011

Thanks guys!

20 Nov 2011

Hello, nice to hear that things works, do You plan to share code with us?

20 Nov 2011

Of course. Just gotta clean it up a bit. :-)

19 Oct 2016

Hi, people I'm working on playing an audio file from flash, but i stuck in the middle where i need to show the external spi flash as a mass storage device so that i can copy files into it and play. can any body share the source code for showing spi flash as a mass storage device. I've tried searching, and with USB msc device example, it is with sdcard. I tried to replace sdcard functions with SST25VF016B flash functions, but its not working.

Best regards Nithin S