IO performance of SD, SPI SD, and FLASH: (pyboard)
(taking advantage of the thread subject)
Here are some anecdotal results comparing write/read speeds of SD, SPI SD, and FLASH on pyboard. In the following thread,
http://forum.micropython.org/viewtopic. ... 3395#p3665
it was noted that the
SD firmware (sdcard.c) disables IRQ's so pyb.millis() and pyb.micros() will not be accurate, so I have used timer2 to count microseconds. Comparing performance with pyb.micros() vs timer2, it also appears that
"time is lost" when doing FLASH IO, perhaps too much being done in HAL_FLASH_IRQHandler() (further analysis required, or insights from developers). The following code was used to time IO operations.
https://github.com/manitou48/pyboard/bl ... sdperf2.py
SD performance varies by the make and model of the SD card. For these tests, I was using a SanDisk Ultra Plus 16GB microSD. The SPI SD tests used the same microSD in a SD carrier on a SD card breakout board (on a breadboard with jumpers to pyboard). The pyboard SPI SD driver (sdcard.py) uses a baudrate of 100000 hz for initial configuration, and then a default data baudrate of 1320000 hz (for SPI 1, max rate is 42mhz with power-of-2 prescale values, so default rate is actually 1.31250 MHz). Measurements were made writing/reading one or more 512-byte blocks, and timing a full open/write/close and open/read/close file operations.
Some nice graphs would be best, but the tabular data will have to do for now. Data rate is in megabits/second (mbs) based on timer2. Block is 512 bytes.
Code: Select all
data rates (mbs)
test SDIO SPI SD(@42mhz) FLASH
-----------------------------------------------------------------------------------------------------
block write 0.05 2.0 0.06 mbs
block read 11.6 5.8 52
40-block file create 0.05 1.3 0.11
40-block file read 9.7 4.5 45 mbs
The 40-block file data rates(write/read in megabits/sec mbs) for other SPI clocks are
.47/.91 mbs @1.3mhz, .38/2.4 mbs @5.25mhz, .84/3.3 mbs @10.5mhz, .92/4 mbs @21mhz
-------------------------------------------
NOTES:
1. The FLASH uses a 64Kbyte RAM cache so some block times can be quite fast (memcpy() speeds).
2. The firmware sdcard.c uses 4-bit parallel SDIO interface to the microSD. I might have expected higher block data rates ....
3. The pyb.micros() loss of time is evident on file/block write's. For example, pyb.micros() measure the 40-block FLASH file create at 744904 us, where timer2 reports 1258763 us.
4. Often at high SPI clock rates and breadboard connectors, errors may occur in the SPI data stream. I did verify some of the blocks read back and observed 0 errors (YMMV).
5.
raw SPI peformance (unconnected)
Timing 1000 spi.send(buffer) (where buffer is a 1000-byte array), the pyboard's, SPI 1 performance at various SPI CLK speeds is
Code: Select all
6115 ms 1.308258 mbs @ 2000000 Hz
3067 ms 2.608412 mbs @ 3000000
1544 ms 5.181347 mbs @ 6000000
782 ms 10.23018 mbs @ 11000000
403 ms 19.85112 mbs @ 21000000
212 ms 37.73585 mbs @ 42000000 Hz
(mbs is megabits/second) The max speed for SPI 2 is 24 MHz.
-----------------------
EDITS:
1. instrumented HAL_FLASH_IRQHandler() with timer2 to measure time spent in handler -- 0. time is being lost elsewhere...
2. time appears to be lost in flash.c doing flash_erase(), part of the write sequence. sys_tick_get_microseconds() measures 1072 us, timer2 measures 156072 us for a 16KB sector. Perhaps, not surprisingly,
during flash-erase any code running out of flash will be stalled, micros/millis updates will be lost during erase. RAM-based code could run ... For a 64KB-sector erase, sys_tick_get_microseconds() reports 1261 us, timer2 reports 576261 us.