Click drivers from MBN

No problem. Go ahead !

1 Like

Btw, we’ve updated the repo with 5 new drivers (and sample code, of course) :

4 Likes

@Dat_Tran unique ID click might be the one you were going to test. It was added, thanks @Bec_a_Fuel

8 new drivers added to the repo :

Minor tweaks to the BMP280 driver as well.

5 Likes

Two drivers added :

The 7Seg driver will work with the three versions of this module : small, medium and large sizes of Led display.

5 Likes

This one is not really a “Click driver” but… it is a memory driver for the QSpi memory area of the chips that have one (i.e. SC20260) :wink:

It works either as standalone driver, to store values in the Qspi area, or it can be used with our TinyFileSystem driver to have a fast 16MB drive.

Standalone code :

private static readonly Byte[] Data = new Byte[3];

        public static void TestQspiMemory(Boolean eraseFirstBlock)
        {
            var qspi = new QspiMemory();

            if (eraseFirstBlock)
                qspi.EraseBlock(0, 1);

            Debug.WriteLine("Address 1 before : " + qspi.ReadByte(1));
            qspi.WriteByte(1, 124);
            Debug.WriteLine("Address 1 after : " + qspi.ReadByte(1));

            qspi.WriteData(10, new Byte[] { 110, 111, 112 }, 0, 3);
            qspi.ReadData(10, Data, 0, 3);
            Debug.WriteLine("Read 3 bytes starting @10 (should be 110, 111, 112) : " + Data[0] + ", " + Data[1] + ", " + Data[2]);
        }

Result :

Address 1 before : 0
Address 1 after : 124
Read 3 bytes starting @10 (should be 110, 111, 112) : 110, 111, 112

The same driver used by TinyFileSystem :

private static void TestTFS()
        {
            var _tfs = new TinyFileSystem(new QspiMemory());
            if (_tfs.CheckIfFormatted())
            {
                Debug.WriteLine("Filesystem OK. Mounting...");
                _tfs.Mount();
                Debug.WriteLine("Mounted. Now reading settings.dat file...");
                if (!_tfs.Exists("settings.dat"))
                    return;
                using (Stream fs = _tfs.Open("settings.dat", FileMode.Open))
                using (var rdr = new StreamReader(fs))
                {
                    System.String line;
                    while ((line = rdr.ReadLine()) != null)
                    {
                        Debug.WriteLine(line);
                    }
                }
                TinyFileSystem.DeviceStats stats = _tfs.GetStats();
                Debug.WriteLine($"Stats");
                Debug.WriteLine($"\tBytes free :\t{stats.BytesFree}");
                Debug.WriteLine($"\tBytes orphaned :\t{stats.BytesOrphaned}");
            }
            else
            {
                Debug.WriteLine("Formatting");
                _tfs.Format();
                Debug.WriteLine("Creating file");
                using (Stream fs = _tfs.Create("settings.dat"))
                {
                    using (var wr = new StreamWriter(fs))
                    {
                        wr.WriteLine("<settings>");
                        wr.WriteLine("InitialPosX=200");
                        wr.WriteLine("InitialPosY=150");
                        wr.WriteLine("</settings>");
                        wr.Flush();
                        fs.Flush();
                    }
                }
                Debug.WriteLine("FileCreated");
            }
        }

Result, after a first run that has formatted the file system :

Filesystem OK. Mounting…
Mounted. Now reading settings.dat file…
<settings>
InitialPosX=200
InitialPosY=150
</settings>
Stats
Bytes free : 16773120
Bytes orphaned : 3072

Be aware that formatting the TFS takes some time. I did not measure but that’s roughly around 30 seconds. This is expected.

3 Likes

Can you please send us your cluster, sector config, full project is the best :)). I remember it is longer than 1min when we tested.

Excerpt from our driver :

public override Int32 Capacity => 0x01000000;
public override Int32 PageSize => 0x100;
public override Int32 SectorSize => 0x1000;
public override Int32 BlockSize => 0x10000;

Result :

Formatting
Formatting done, seconds elapsed : 37.7617295
Creating file
FileCreated

By the way, TFS does not work correctly on your SC20260D dev board :open_mouth: TFS thinks it’s not formatted even right after formatting it.
It does however work on our RAM board, which is using SC20260E SOM. Weird…

What’s your email address, so that I can send a test project ?

if erase then write total 100ms a sector, 4096 sector will take 400 seconds. it may faster 100ms but 10ms is very fast, maybe that is why work not correct on yours.

any way, we will check. my config is page and sector size are same 4096. It is slow when format but we tried read write few file just fine.

Oh, when you use whole 16MB then our drive detect all chip and switch to erase chip instead of sector. Maybe that why faster We will check.

Timings to erase one sector and then fill it (4096 bytes) :

SC20260D dev board :

  • One sector erased, 27.6893 milliseconds elapsed
  • One complete sector written, 15.1688 milliseconds elapsed

RAM board (SC20260E SOM) :

  • One sector erased, 22.4835 milliseconds elapsed
  • One complete sector written, 15.2799 milliseconds elapsed

And I repeat : TFS IS working with QSPI on our board but not on yours, not the opposite.

I still don’t have your email address :wink:

dat.tran@gh…

sorry, I just read quickly and wondering why yours is only about 30 second ;)))

Email sent.

And indeed, EraseChip is only 32 ms, so way faster that erasing sectors or blocks one by one.

FYI, regarding the TFS/QSPI not working on SC20260D dev board, I have “rev B” on both PCB and SOM. If it matters.

Results with external Flash enabled for deployment :

Formatting
Formatting done, seconds elapsed : 18.8917007
Creating file
FileCreated
Filesystem OK. Mounting…
Mounted. Now reading settings.dat file…

InitialPosX=200
InitialPosY=150

Stats
Bytes free : 8386560
Bytes orphaned : 1024

8MB file system, roughly half the time to format the drive, everything looks good to me :wink:

1 Like

Could you please confirm that the project I’ve sent is working on your latest revision of SC20260D dev board ?
I presume that my “Rev B” one may have issues, thus preventing this driver to work. I just want to know.

“Rev B” should work fine.

Your problem is Erase(uint address, …);

We use address, not sector, mean you have to pass 16 * 1024 * 1024 for length, not 4096.

That why it is so fast and doesn’t work.

I have no idea why your board work.

Hmmm… Formatting the FileSystem is using EraseChip() in the driver, which is translated to _qspi.Erase(0, sectorCount, TimeSpan.FromSeconds(1)); , to use your Erase() method.

SectorCount is Capacity/SectorSize, which gives 16 * 1024 * 1024 / 4096 = 4096, so I don’t see anything wrong in this code.
Or did I misunderstand the “count” parameter ? What is the meaning of this parameter ?

But this does not explain why it does work nicely on our board and not on the dev board :frowning:

_qspi.Erase(0, 16 * 1024 * 1024, TimeSpan.FromSeconds(100));

So it would mean that you can erase one byte only at a particular address ? Quite strange, to me, to be honest…

We have

Read(address, count…)
Write(address, count…)

So that is reason we have
Erase(address, count…)

Although Erase(sector, count…) is proper way in this cases.
And erase will erase entire of sector.