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

rutger eng1 at breematic.nl
Mon Sep 13 22:20:17 CEST 2010


  Hello Ole,

Thanks for your very quick response.
It works !!
I use a AVR ATMEGA128 and tested it with the following testcode :


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

/*
     if (UFlashFormat(&devUFlash0, &flashAt45dib0, &spiBus0Avr))
     {
         puts("formating failed");
     }
     else
     {
         puts("formating ok !");
     }
*/



     FILE * pFile;
     char mystring [100];


     /*pFile = fopen("UFLASH0:my_file.txt", "w+");

     if (pFile!=NULL)
     {
         puts ("writing file");
         fputs ("hello nut world",pFile);
         fclose (pFile);
     }*/


     pFile = fopen("UFLASH0:my_file.txt", "r");
     if (pFile != NULL)
     {
         puts ("reading file");
         fgets (mystring,100,pFile);
         puts (mystring);
         fclose (pFile);
     }


There was a small problem that I have to solve later :
file reading and writing didn't work just after formatting.
I had to reboot after formatting and then skip formatting.


Thanks Ole,

regards,

Rutger



Op 13-9-2010 11:07, Ole Reinhardt schreef:
> 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
>
>
>
>
> Geen virus gevonden in het binnenkomende-bericht.
> Gecontroleerd door AVG - www.avg.com
> Versie: 9.0.851 / Virusdatabase: 271.1.1/3132 - datum van uitgifte: 09/13/10 08:35:00
>




More information about the En-Nut-Discussion mailing list