[ABANDONED] emFile writing is time inefficient - ways to speed it up?

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • [ABANDONED] emFile writing is time inefficient - ways to speed it up?

      Hello community,

      I'm trying to write to the microSD card on a PSoC 5LP as fast as I can. Unfortunately, there seems to be a considerable amount of time spent in the FS_Write function - about 250ms


      My CPU speed is 48MHz, while my SPI's is 24MHz, although I have tested it at 12MHz - which made it write even slower. I am also batch writing large buffers of 27648 bytes to the SD card at once. These factors should increase my aggregate write speed, as shown on SEGGER's performance chart below:
      IMAGE here


      Since it usually takes 0.25 seconds to complete this batch write, the write speed is 27648 / 0.25 = 110.592 KBps despite running the SPI at 24MHz and batch writing ~28 KB at a time. To clarify, the faster clock rate and larger buffers that I'm using do in fact make the write time faster according to my tests. Since the write speed is supposed to be 262.56 KBps when the CPU speed is 48MHz, SPI speed is 12MHz, and batchs of 8KB are being written, I should be writing to the SD even faster than that. My optimisation level is also set to "speed".

      I write a pin high before writing and pull it low afterwards to see how long it takes:
      IMAGE here
      About 250ms.

      I measured that the bytes being written are only 1625ns apart, which is definitely fast enough, but unfortunately, the bytes are being written in groups of 13 for some reason. There's a lot of time in between these groups.
      IMAGE here
      Each one of those spikes are a byte, but as you can see, the bytes stop coming after 13.

      If you zoom out further, you can see the distance between the clumps of bytes - about 75μs:
      IMAGE here

      If these gaps didn't exist, and each byte was 1625ns apart, I would expect to have a data rate of approximately 615KBps, but instead I'm seeing ~111KBps.

      In case my code has anything to do with it, I'll briefly outline how it works:

      • Interrupt triggers 10000 times a second, reading a 24 bit number from each of the channels of an ADC, and writing each number to a buffer dedicated to that channel (e.g. channel 2's number is written to sample_buffer2).
      • Each interrupt, it checks if the first or second half of the buffers are full. If one is, set a variable that indicates which half to write in the main loop.
      • In the main loop, call FS_Write for the full half of the buffers, each channel/buffer writes to a different TXT file. Any samples received during this time are stored in the vacant half of the buffers.
      • New TXT files are created after a period of time (1 hour or 36,000,000 samples)
      • Repeat
      It seems like a waste of time having these enormous gaps, and I'm not sure why they're in groups of 13. Is there any way to increase my write speed to at least the expected "262.56 KBps" on the official performance chart?

      Thanks,
      - Phoenix

      (I asked the same question on the cypress forum, and was told to come here, if you need more info/context, go here)