[En-Nut-Discussion] how to use AT45DB serial Dataflash and filesysem

Ole Reinhardt ole.reinhardt at embedded-it.de
Mon Sep 13 11:07:14 CEST 2010


Hello Rutger,

> Can anybody provide a simple example on how to use the serial flash.
> In the new beta release 2.09 I have found the UFLASH filesystem but I'm 
> not sure how to use it.

I just have a very simple example how to mount the filesystem. But when
mounted you can just use it like any other filesystem with some
limitations like the fact that directories are not realy implemented.
The mounting itself is indeed quite different from the mounting of e.g.
MMC devices.


The following function mounts the dataflash attached to SPI Bus 0,
Chipselect 0. If you want to connect the dataflash to another SPI bus or
chipselect change 

flashAt45dib0 ==> flashAt45dibX for the chipselect
spiBus0At91   ==> spiBusXAt91 for the SPI Bus accordingly

int init_dataflash(void)
{
    if (UFlashAttach(&devUFlash0, &flashAt45dib0, &spiBus0At91)) {
        puts("Attaching serial flash failed");
    }
    if (NutRegisterDevice(&devUFlash0, 0, 0)) {
        puts("Mounting UFLASH0 failed");
    } else {
        puts("Mounting UFLASH0: OK!");
    }
    
    return 0;
}

In this sample I supposed you use the AT91 SPI Bus driver. Take any
other SPI Bus driver for your board as needed.



To open a file just use the fopen call below:

fd = fopen("UFLASH0:my_file.txt", "r+b");


A clean / empty filesystem consists of all pages in the flash cleared
(factory default). To "format" (clear) the flash you can use

UFlashFormat(&devUFlash0, &flashAt45dib0, &spiBus0At91);


Hope this helps a little,

regards,

Ole Reinhardt

-- 

Thermotemp GmbH, Embedded-IT

Embedded Hard-/ Software and Open Source Development, 
Integration and Consulting

http://www.embedded-it.de

Geschäftsstelle Siegen - Steinstraße 67 - D-57072 Siegen - 
tel +49 (0)271 5513597, +49 (0)271-73681 - fax +49 (0)271 736 97

Hauptsitz - Hademarscher Weg 7 - 13503 Berlin
Tel +49 (0)30 4315205 - Fax +49 (0)30 43665002
Geschäftsführer: Jörg Friedrichs, Ole Reinhardt
Handelsregister Berlin Charlottenburg HRB 45978 UstID DE 156329280 




More information about the En-Nut-Discussion mailing list