Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Anchor10383311038331 Getting Started Anchor10039721003972The following section shows an example on how to get started in a typical case comprising the following: Anchor10039731003973

  • The generic controller layer implementation (included with the NAND driver)

...

...

  • The 1-bit software ECC implementation (included with the NAND driver)

...

  • The static part layer implementation (included with the NAND driver)

...

...

  • Your BSP layer implementation to adapt the driver to your specific platform

...

In case you need additional information and details regarding the different layers, please refer to the section 13-2 “Architecture Overview” on page 169 Architecture Overview.

Anchor10039811003981To use the NAND driver, you must include the following ten files in the build, in addition to the generic file system files:anchor10039821003982

  • fs_dev_nand.c (\Micrium\Software\uC-FS\Dev\NAND.)

...

  • fs_dev_nand.h (\Micrium\Software\uC-FS\Dev\NAND.)

...

  • fs_dev_nand_ctrlr_gen.c (\Micrium\Software\uC-FS\Dev\NAND\Ctrlr)

...

...

  • fs_dev_nand_ctrlr_gen.h (\Micrium\Software\uC-FS\Dev\NAND\Ctrlr)

...

  • fs_dev_nand_part_static.c (\Micrium\Software\uC-FS\Dev\NAND\Part)

...

  • fs_dev_nand_part_static.h (\Micrium\Software\uC-FS\Dev\NAND\Part)

...

  • ecc_hamming.c (\Micrium\Software\uC-CRC\Source)

...

...

  • ecc_hamming.h (\Micrium\Software\uC-CRC\Source)

...

  • ecc.h (\Micrium\Software\uC-CRC\Source)

...

  • Your BSP layer implementation (derived from fs_dev_nand_ctrlr_gen_bsp.c in \Micrium\Software\uC-FS\Dev\NAND\BSP\Template).

...

1046592The example in Listing 13-1 shows Listing - Opening a NAND device volume shows how to open a single NAND volume. The file system initialization function (FS_Init()) must have previously been called.anchor

Code Block

...

language

...

#include <ecc_hamming.h> #include <fs.h> #include
HTML Table
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
Anchor
10451791045179
Anchor
10451801045180
Anchor
10451811045181
cpp

...

#include

#include  <fs_vol.h>
#include

#include  <fs_dev_nand.h>
#include

#include  <fs_dev_nand_ctrlr_gen.h>
#include

#include  <fs_dev_nand_ctrlr_gen_soft_ecc.h>
#include

#include  <fs_dev_nand_part_static.h>
 

 
FS_NAND_FREE_SPARE_MAP  App_SpareMap[2] = { { 1,
63}, {-1, -1} };   static CPU_BOOLEAN
 63},
                                            {-1, -1} };
 
static  CPU_BOOLEAN  App_FS_AddNAND (void)
{ /* (1) */ FS_NAND_CFG cfg_nand =

{
                                                      (1)
    FS_NAND_CFG                     cfg_nand     = FS_NAND_DfltCfg;

    FS_NAND_CTRLR_GENERIC_CFG       cfg_ctrlr    = FS_NAND_CtrlrGen_DfltCfg;

    FS_NAND_CTRLR_GEN_SOFT_ECC_CFG  cfg_soft_ecc = FS_NAND_CtrlrGen_SoftEcc_DfltCfg;

    FS_NAND_PART_STATIC_CFG         cfg_part     = FS_NAND_PartStatic_DfltCfg;
FS_ERR err;

    FS_ERR                          err;
    FS_DevDrvAdd((FS_DEV_API *)&FS_NAND,
/* (2) */ &err); if ((err !=
              (2)
                               &err);
    if ((err != FS_ERR_NONE) &&

        (err != FS_ERR_DEV_DRV_ALREADY_ADDED))
{
 {
        APP_TRACE_DBG(("    ...could not add driver w/err = %d\r\n\r\n", err));
return

        return (DEF_FAIL);
} /* (3) */ cfg_part.BlkCnt = 2048; cfg_part.PgPerBlk = 64; cfg_part.PgSize = 2048; cfg_part.SpareSize = 64; cfg_part.SupportsRndPgPgm = DEF_NO; cfg_part.NbrPgmPerPg = 4; cfg_part.BusWidth = 8;

    }
                                                      (3)
    cfg_part.BlkCnt           = 2048;
    cfg_part.PgPerBlk         = 64;
    cfg_part.PgSize           = 2048;
    cfg_part.SpareSize        = 64;
    cfg_part.SupportsRndPgPgm = DEF_NO;
    cfg_part.NbrPgmPerPg      = 4;
    cfg_part.BusWidth         = 8;
    cfg_part.ECC_NbrCorrBits  = 1;

    cfg_part.ECC_CodewordSize = 512 + 16;

    cfg_part.DefectMarkType   = DEFECT_SPARE_L_1_PG_1_OR_N_ALL_0;

    cfg_part.MaxBadBlkCnt     = 40;

    cfg_part.MaxBlkErase      = 100000;

    cfg_part.FreeSpareMap     = &spare_map[0];
  /* (4) */ cfg_ctrlr.CtrlrExt = &

 
                                                      (4)
    cfg_ctrlr.CtrlrExt    = &FS_NAND_CtrlrGen_SoftECC;

    cfg_ctrlr.CtrlrExtCfg = &soft_ecc_cfg;
  /* (5) */

 
                                                      (5)
    cfg_soft_ecc.ECC_ModulePtr = (ECC_CALC *)&Hamming_ECC;
  /* (6) */ cfg_nand.BSPPtr = (void

 
                                                      (6)
    cfg_nand.BSPPtr                 = (void              *)&FS_NAND_BSP_SAM9M10;

    cfg_nand.CtrlrPtr               = (FS_NAND_CTRLR_API *)&FS_NAND_CtrlrGeneric;

    cfg_nand.CtrlrCfgPtr            = &cfg_ctrlr;

    cfg_nand.PartPtr
= (FS_
                = (FS_NAND_PART_API  *)&FS_NAND_PartStatic;

    cfg_nand.PartCfgPtr             = &cfg_part;

    cfg_nand.SecSize
= 512;
                = 512;
    cfg_nand.BlkCnt                 = 2038u;

    cfg_nand.BlkIxFirst             = 10u;

    cfg_nand.UB_CntMax              = 10u;

    cfg_nand.RUB_MaxAssoc           = 2u;

    cfg_nand.AvailBlkTblEntryCntMax =
10u;   /* (7) */ FSDev_Open(
 10u;
 
                                                      (7)
    FSDev_Open(        "nand:0:",
/* (a) */ (void
                       (a) 
               (void *)&cfg_nand,
/* (b) */ &err); switch (err) { case FS_ERR_NONE:
                       (b)
                       &err);
       switch (err) {             
        case FS_ERR_NONE:
             APP_TRACE_DBG(("    ...opened device.\r\n"));
break; case

             break;

        case FS_ERR_DEV_INVALID_LOW_FMT:
case

        case FS_ERR_DEV_INCOMPATIBLE_LOW_PARAMS:
case

        case FS_ERR_DEV_CORRUPT_LOW_FMT:

             APP_TRACE_DBG(("    ...opened device (not low-level formatted).\r\n"));
#if

#if (FS_CFG_RD_ONLY_EN == DEF_ENABLED)

             FS_NAND_LowFmt("nand:0:", &err);
/* (8) */ if (err !=
         (8)
             if (err != FS_ERR_NONE)
{
 {
                APP_TRACE_DBG(("    ...low-level format failed.\r\n"));
return 0; } #else

                return 0;
             }
#else
             APP_TRACE_DBG(("
.
    ...opening device failed w/err = %d.\r\n\r\n", err));
return 0; #endif break;   case

             return 0;
#endif
             break;
 
        case FS_ERR_DEV_ALREADY_OPEN:
break;   case

             break;
 
        case FS_ERR_DEV:
case

        case FS_ERR_DEV_IO:
case

        case FS_ERR_DEV_TIMEOUT:
case

        case FS_ERR_DEV_NOT_PRESENT:
default:

        default:
             APP_TRACE_DBG(("    ...opening device failed w/err = %d.\r\n\r\n", err));
return

             return (DEF_FAIL);
} /* (9) */

    }
                                                      (9)    
    FSVol_Open("nand:0:",
/* (a) */
                               (a)
               "nand:0:",
/* (b) */ 0, /* (c) */ &err);*/ switch (err) { case FS_ERR_NONE:
                               (b)
                0,                                      (c)
                &err);*/
    switch (err) {
        case FS_ERR_NONE:
             APP_TRACE_DBG(("    ...opened volume (mounted).\r\n"));
break;   case

             break;
 
        case FS_ERR_PARTITION_NOT_FOUND:             /* Volume error.
*/
            */
             APP_TRACE_DBG(("    ...opened device (not formatted).\r\n"));
#if

#if (FS_CFG_RD_ONLY_EN == DEF_DISABLED)

             FSVol_Fmt("nand:0:", (void *)0, &err);
/* (10) */ if (err !=
   (10)
             if (err != FS_ERR_NONE)
{
 {
                APP_TRACE_DBG(("    ...format failed.\r\n"));
return

                return (DEF_FAIL);
} #else

             }
#else
             APP_TRACE_DBG(("    ...opening device failed w/err = %d.\r\n\r\n", err));
return 0; #endif break;
titleListing - Opening a NAND device volume
linenumberstrue
#include  <ecc_hamming.h>
#include  <fs.h>
#include  <fs_err.h>
Anchor
10451821045182
Anchor
10451831045183
Anchor
10451841045184
Anchor
10451851045185
Anchor
10451861045186
Anchor
10451871045187
Anchor
10451881045188
Anchor
10451891045189
Anchor
10451901045190
Anchor
10451911045191
Anchor
10451921045192
Anchor
10451931045193
Anchor
10451941045194
Anchor
10451951045195
Anchor
10451961045196
Anchor
10451971045197
Anchor
10451981045198
Anchor
10451991045199
Anchor
10452001045200
Anchor
10452011045201
Anchor
10452021045202
Anchor
10452031045203
Anchor
10452041045204
Anchor
10452051045205
HTML Table
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
Anchor
10452091045209
Anchor
10452101045210
Anchor
10452111045211
Anchor
10452121045212
Anchor
10452131045213
Anchor
10452141045214
Anchor
10452151045215
Anchor
10452161045216
Anchor
10452171045217
Anchor
10452181045218
Anchor
10452191045219
Anchor
10452201045220
Anchor
10452211045221
Anchor
10452221045222
Anchor
10452231045223
Anchor
10452241045224
Anchor
10452251045225
Anchor
10452261045226
Anchor
10452271045227
Anchor
10452281045228
Anchor
10452291045229
Anchor
10452301045230
Anchor
10452311045231
Anchor
10452321045232
Anchor
10452331045233
Anchor
10452341045234
Anchor
10452351045235
Anchor
10452361045236
Anchor
10452371045237
Anchor
10452381045238
Anchor
10452391045239
Anchor
10452401045240
Anchor
10452411045241
Anchor
10452421045242
Anchor
10452431045243
Anchor
10452441045244
Anchor
10452451045245
Anchor
10452461045246
Anchor
10452471045247
Anchor
10452481045248
Anchor
10452491045249
Anchor
10452501045250
Anchor
10452511045251
HTML Table
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
Anchor
10452601045260
Anchor
10452611045261
Anchor
10452621045262
Anchor
10452631045263
Anchor
10452641045264
Anchor
10452651045265
Anchor
10452661045266
Anchor
10452671045267
Anchor
10452681045268
Anchor
10452691045269
Anchor
10452701045270
Anchor
10452711045271
Anchor
10452721045272
Anchor
10452731045273
Anchor
10452741045274
Anchor
10452751045275
Anchor
10452761045276
Anchor
10452771045277
Anchor
10452781045278
Anchor
10452791045279
Anchor
10452801045280
Anchor
10452811045281
Anchor
10452821045282
Anchor
10452831045283
Anchor
10452841045284
Anchor
10452851045285
Anchor
10452861045286
Anchor
10452871045287
Anchor
10452881045288
Anchor
10452891045289
Anchor
10452901045290
Anchor
10452911045291
Anchor
10452921045292
Anchor
10452931045293
Anchor
10452941045294
Anchor
10452951045295
Anchor
10452961045296
Anchor
10452971045297
Anchor
10452981045298
Anchor
10452991045299
Anchor
10453001045300
Anchor
10453011045301
Anchor
10453021045302
Anchor
10453031045303
Anchor
10453041045304
Anchor
10453051045305
Anchor
10453061045306
Anchor
10453071045307
Anchor
10453081045308
Anchor
10453091045309

...

case FS_ERR_DEV: /* Device error. */ case

             return 0;
#endif
             break;

        case FS_ERR_DEV:                             /* Device error.            */
        case FS_ERR_DEV_IO:
case

        case FS_ERR_DEV_TIMEOUT:
case

        case FS_ERR_DEV_NOT_PRESENT:

             APP_TRACE_DBG(("    ...opened volume (unmounted).\r\n"));
return

             return (DEF_FAIL);
    default: APP_

 
 
        default:
             APP_TRACE_DBG(("    ...opening volume failed w/err = %d.\r\n\r\n", err));
return

             return (DEF_FAIL);
}   return (DEF_OK); }
HTML Table
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
Anchor
10453121045312
Anchor
10453131045313
Anchor
10453141045314
Anchor
10453151045315
Anchor
10453161045316
Anchor
10453171045317
Anchor
10453181045318
Anchor
10453191045319
Anchor
10453201045320
Anchor
10453211045321
Anchor
10453221045322
Anchor
10453231045323
Anchor
10453241045324
Anchor
10453251045325
Anchor
10453261045326

...


    }
 
    return (DEF_OK);
}


Panel

(1) Declare and initialize configuration structures. Structures should be initialized to allow for forward compatibility in case some new fields in those structures are added in future µC/FS versions.

...

(2) Register the NAND device

...

driver FS_NAND.

...

(3) The NAND part layer configuration structure should be initialized. For more information about these parameters,

...

see Statically configured part

...

layer.

...

(4) The NAND controller layer configuration structure should be initialized. For more information about these parameters,

...

see Generic Controller Layer

...

Implementation. Please note that you might need to use a different controller layer. If this is the case, the configuration might be different (

...

see Controller Layer).

...

(5) The NAND generic controller software ECC extension should be initialized. For more information about these parameters, see

...

Listing - NAND translation layer configuration structure. Please note that if you are using a different controller layer implementation, there probably won’t be a controller extension layer. Also, if using the generic controller, you might need to use a different extension. Refer

...

to Table - Generic controller layer extensions provided for a list of available controller extensions.

...

(6) The NAND translation layer structure should be initialized. For more information about these parameters,

...

see Translation Layer Configuration.

(7) FSDev_Open()

...

 opens/initializes a file system device. The parameters are the device name (a) and a pointer to a device driver-specific configuration structure (b). The device name (a) is composed of a device driver name (“nand”), a single colon, an ASCII-formatted integer (the unit number) and another colon.

...

(8) FS_NAND_LowFmt()

...

 low-level formats a NAND. If the NAND has never been used with µC/FS, it must be low-level formatted before being used. Low-level formatting will create and initialize the low-level driver metadata on the device.

...

(9) FSVol_Open()

...

 opens/mounts a volume. The parameters are the volume name (a), the device name (b) and the index of the partition that will be opened (c). There is no restriction on the volume name (a); however, it is typical to give the volume the same name as the underlying device. If the default partition is to be opened, or if the device is not partition, then the partition number (c) should be 0.

...

(10) FSVol_Fmt()

...

 formats a file system device. If the NAND has just been low-level formatted, there will be no file system on the corresponding volume after it is opened (it will be unformatted). The volume must be formatted before files can be created or accessed.

...


If the NAND initialization succeeds, the file system traces (if a sufficiently high trace level is configured) will produce an output similar to Listing 13-1 Listing - NAND detection trace output. See section E-9 “Trace Configuration” on page 507 Trace Configuration about configuring the trace level.anchor

Code Block

...

HTML Table
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
Anchor
10448971044897
language

...

= FS INITIALIZATION =

=                        FS INITIALIZATION                        =
===================================================================
Initializing

Initializing FS...

    ===========================================================
Adding/opening NAND volume "nand:0:"... NAND Ctrlr Gen: found NAND manuf id=2c, dev id=aa. FS_NAND_Open(): Using default blk cnt (all blocks): 2048. FS_NAND_Open(): Default number of entries in avail blk tbl. NAND FLASH FOUND: Name : "nand:0:" Sec Size : 2048 bytes Size : 127360 sectors Update blks: 10 FS_NAND_LowMountHandler(): Low level mount succeeded. ...opened device. FSPartition_RdEntry(): Found possible partition: Start: 0 sector Size : 0 sectors Type : 00 FS_FAT_VolOpen(): File system found: Type : FAT16 Sec size: 2048 B Clus size: 4 sec Vol size: 127360 sec # Clus : 31822 # FATs : 2 ...opened volume (mounted). ...init succeeded.
    
    Adding/opening NAND volume "nand:0:"...
NAND Ctrlr Gen: found NAND manuf id=2c, dev id=aa.
FS_NAND_Open(): Using default blk cnt (all blocks): 2048.
FS_NAND_Open(): Default number of entries in avail blk tbl.
NAND FLASH FOUND: Name       : "nand:0:"
                  Sec Size   : 2048 bytes
                  Size       : 127360 sectors
                  Update blks: 10
FS_NAND_LowMountHandler(): Low level mount succeeded.
    ...opened device.
FSPartition_RdEntry(): Found possible partition: Start: 0 sector
                                                 Size : 0 sectors
                                                 Type : 00
FS_FAT_VolOpen(): File system found: Type     : FAT16 
                                     Sec  size: 2048 B  
                                     Clus size: 4 sec
                                     Vol  size: 127360 sec
                                     # Clus   : 31822    
                                     # FATs   : 2    
    ...opened volume (mounted).
...init succeeded.
===================================================================

===================================================================
cpp
titleListing - NAND detection trace output
linenumberstrue
===================================================================
=
Anchor
10448981044898
Anchor
10448991044899
Anchor
10449001044900
Anchor
10449011044901
Anchor
10449021044902
Anchor
10449031044903
Anchor
10449041044904
Anchor
10449051044905
Anchor
10449061044906
Anchor
10449071044907
Anchor
10449081044908
Anchor
10449091044909
Anchor
10449101044910
Anchor
10449111044911
Anchor
10449121044912
Anchor
10449131044913
Anchor
10449141044914
Anchor
10449151044915
Anchor
10449161044916
Anchor
10449171044917
Anchor
10449181044918
Anchor
10449191044919
Anchor
10449201044920
Anchor
10449211044921
Anchor
10449221044922
Anchor
10449231044923
Anchor
10449241044924

...


...

Handling different use-cases

...

If the above example does not apply to your situation, we strongly recommend you read the sections about the different layers. This will help you determine if other existing implementations are suitable for you, or if you need to develop your own implementation of some of those layers.