fast reading files by STM32F103C8T6

mkeyno
Wed Jul 13, 2016 9:41 am
hi guys , I really appreciated for any help or hint about STM feature and capability for lighting project, actually I ran the POV project with teensy 3.1 which is read the image from SD card and show to LED strip line by line . for get benefits of new ESP webserver and websocket lib features I’ve moved to run the POV on ESP, however reading image files from SPIFF was so slow, whereas need to, at least, read 2.5 Mbyte/s , I’m thinking maybe it’d be good idea to upload and manage the animation show by ESP and let the slave devise such STM32F103C8T6 handle the POV algorithm, do you think STM chip with 64K Byte Flash & 20KByte SRAM could handle such task? I might add I’m using fastLED lib and hopefully can run on your STM lib
any tips really appreciated

RogerClark
Wed Jul 13, 2016 9:10 pm
Could you elabourate on what POV means in your context.

Re:File transfer speed

2.5 M bytes per sec is a very high data rate for SPI transfer to SD card.

See
http://elm-chan.org/docs/mmc/mmc_e.html

We can overclock the SPI to 36MHz but I dont know if any SD cards go that fast.

I suspct you would need to use SDIO, but that feature is not available on the STM32F103C8 and we dont have a SDIO library for the libmaple core.

I am sure a F4 series MCU could process that much data from SDIO, but as there currently isn’t an SDIO library, You should probably try to get hold of a Raspberry Pi Zero or another high speed unix board e.g. Orange Pi


martinayotte
Wed Jul 13, 2016 9:41 pm
@mkeyno, I remember seeing your discussion on ESP gitter…

About your tests with a Teensy 3.1, which performance did you achieved ?


ahull
Wed Jul 13, 2016 10:34 pm
You might also consider something like a SPI Flash chip rather than an SD card.
Something like these.

martinayotte
Wed Jul 13, 2016 10:42 pm
… and also avoid any filesystem’s layer, since your needs is simply to get huge array of RGB with a known length.

mkeyno
Mon Jul 18, 2016 12:07 pm
so sorry for late respond , I’ve just notified , and many thanks you all for reply and leave you notes,
@ RogerClark , POV is the vision come with rotation of one line of LED to product the whole image , I did it with teensy3.1 connected to SD card which is simply read image, line by line and put in LED strip , to get benefits of ESP feature , I’ve tried to use SPIFF for hosting the image files and webserver feature to upload the images , however after couple of tried and many discuss in ESP gitter room , noticed the ESP not fast enough to read the image and beside file fragmentation hold the speed back to optimum
in best try I reach around 60ms for each frame , for 25 frame/s I should deliver 144 LED pixel * 3 byte RGB data * 200 line of image = about 85Kbyte for each frame and about 2 Mbyte/s
I thought with STMF103 DMA feature can reach such performance whereas it is connected to ESP module as slave module , I’m not yet decide to test it but some guys told me may ESP32 with two extra separated core with free DMA feature could handle it
if you guys have any experience for SD card fast reading by STMF103 I’ve really appreciated to have your hints

racemaniac
Mon Jul 18, 2016 12:17 pm
mkeyno wrote:so sorry for late respond , I’ve just notified , and many thanks you all for reply and leave you notes,
@ RogerClark , POV is the vision come with rotation of one line of LED to product the whole image , I did it with teensy3.1 connected to SD card which is simply read image, line by line and put in LED strip , to get benefits of ESP feature , I’ve tried to use SPIFF for hosting the image files and webserver feature to upload the images , however after couple of tried and many discuss in ESP gitter room , noticed the ESP not fast enough to read the image and beside file fragmentation hold the speed back to optimum
in best try I reach around 60ms for each frame , for 25 frame/s I should deliver 144 LED pixel * 3 byte RGB data * 200 line of image = about 85Kbyte for each frame and about 2 Mbyte/s
I thought with STMF103 DMA feature can reach such performance whereas it is connected to ESP module as slave module , I’m not yet decide to test it but some guys told me may ESP32 with two extra separated core with free DMA feature could handle it
if you guys have any experience for SD card fast reading by STMF103 I’ve really appreciated to have your hints

mkeyno
Mon Jul 18, 2016 12:21 pm
martinayotte wrote:… and also avoid any filesystem’s layer, since your needs is simply to get huge array of RGB with a known length.

mkeyno
Mon Jul 18, 2016 12:34 pm
racemaniac wrote:
I’ve recently been encountering similar requirements with streaming small soundsamples i wanted to play on my maple mini, and to be honest, i never even bothered with SD cards… The current dma implementation is fast, but blocking, you can try altering that, but if you look at the code, the SD card filesystem overhead is HUGE (also the inconsistency of how & when it responds due to internal management doesn’t bode well either).
I don’t know how much data you need, but i ended up just buying some spi flash chips (the biggest ones i have are 1Gb (=128MByte)), and it’s sooo much easier working with them. A simple protocol to read data from them, i made a custom “filesystem” (the first 1k of the flash chip contains metadata & addresses of what is stored where, and i keep it into memory). And then i was able to quickly write a simple framework that allows me to stream many channels of wav audio data from the flash chip at the full speed of the SPI port, and nicely in the background with DMA :).

So unless you realy need gigabytes of data, you should really consider the flash chip option. The only usage of an SD card in my project was to load the data into the flash chip XD.


stevestrong
Mon Jul 18, 2016 12:38 pm
mkeyno wrote:… 144 LED pixel * 3 byte RGB data * 200 line of image …

stevestrong
Mon Jul 18, 2016 12:41 pm
Also, if you don’t use the whole spectrum of 3*RGB(8bits)=24 bits for one LED, then you could maybe compress the color data information.

mkeyno
Mon Jul 18, 2016 12:44 pm
stevestrong wrote:mkeyno wrote:… 144 LED pixel * 3 byte RGB data * 200 line of image …

stevestrong
Mon Jul 18, 2016 12:56 pm
Hmmm, can a Teensy3.1 reach such a SD read-out speed and the STM32 not? I wonder why…

racemaniac
Mon Jul 18, 2016 12:58 pm
mkeyno wrote:racemaniac wrote:
I’ve recently been encountering similar requirements with streaming small soundsamples i wanted to play on my maple mini, and to be honest, i never even bothered with SD cards… The current dma implementation is fast, but blocking, you can try altering that, but if you look at the code, the SD card filesystem overhead is HUGE (also the inconsistency of how & when it responds due to internal management doesn’t bode well either).
I don’t know how much data you need, but i ended up just buying some spi flash chips (the biggest ones i have are 1Gb (=128MByte)), and it’s sooo much easier working with them. A simple protocol to read data from them, i made a custom “filesystem” (the first 1k of the flash chip contains metadata & addresses of what is stored where, and i keep it into memory). And then i was able to quickly write a simple framework that allows me to stream many channels of wav audio data from the flash chip at the full speed of the SPI port, and nicely in the background with DMA :).

So unless you realy need gigabytes of data, you should really consider the flash chip option. The only usage of an SD card in my project was to load the data into the flash chip XD.


mkeyno
Mon Jul 18, 2016 1:00 pm
stevestrong wrote:Hmmm, can a Teensy3.1 reach such a SD read-out speed and the STM32 not? I wonder why…

mkeyno
Mon Jul 18, 2016 1:04 pm
racemaniac wrote:
I don’t know much about the ESP capabilities. But for the stm32: the SPI port can at max do 32Mhz, that’s 32 MegaBIT/s, so 4Megabyte per second. No software implementation will come close to that. And you can look into the SDFAT thread about benchmarks of sd cards on the maple mini, i think they barely surpassed 1Megabyte/s…. if you want 2.5 megabyte/s speed, i’d suggest going for a flashchip and an stm32 handling the data & controlling the leds. you’ll need something with either a hardware port, or a much higher cpu speed than the esp/stm32 to get such datarates, and sd cards addressed via spi won’t get it either….

racemaniac
Mon Jul 18, 2016 1:22 pm
mkeyno wrote:racemaniac wrote:
I don’t know much about the ESP capabilities. But for the stm32: the SPI port can at max do 32Mhz, that’s 32 MegaBIT/s, so 4Megabyte per second. No software implementation will come close to that. And you can look into the SDFAT thread about benchmarks of sd cards on the maple mini, i think they barely surpassed 1Megabyte/s…. if you want 2.5 megabyte/s speed, i’d suggest going for a flashchip and an stm32 handling the data & controlling the leds. you’ll need something with either a hardware port, or a much higher cpu speed than the esp/stm32 to get such datarates, and sd cards addressed via spi won’t get it either….

mkeyno
Mon Jul 18, 2016 1:48 pm
racemaniac wrote:Something like this for example: https://www.winbond.com/resource-files/ … _rev_g.pdf
There are many flash chips you can find on sites like aliexpress, all with similar protocols & features :).

stevestrong
Mon Jul 18, 2016 2:08 pm
mkeyno wrote: I don’t know exactly how ESP can’t reach to best performance

racemaniac
Mon Jul 18, 2016 2:36 pm
mkeyno wrote:racemaniac wrote:Something like this for example: https://www.winbond.com/resource-files/ … _rev_g.pdf
There are many flash chips you can find on sites like aliexpress, all with similar protocols & features :).

martinayotte
Mon Jul 18, 2016 3:13 pm
racemaniac wrote:the ESP doesn’t have a hardware spi port

racemaniac
Mon Jul 18, 2016 3:22 pm
martinayotte wrote:racemaniac wrote:the ESP doesn’t have a hardware spi port

stevestrong
Mon Jul 18, 2016 6:26 pm
martinayotte wrote:This can also be done with a SDCard without formatting it (no FAT16, no FAT32), simply accessing sectors by sectors as raw data stream, it will speed up things.

martinayotte
Mon Jul 18, 2016 7:52 pm
Still using low level part of SdFat, there are function like readBlock() and readBlocks() to read 512bytes sectors from the card.
I’ve never done that with SDCard yet, but should be doable. The thing I’ve done which is a bit similar is reading an SPIFlash on STM32 using readBytes()

mkeyno
Mon Jul 18, 2016 9:59 pm
racemaniac wrote:
the ESP doesn’t have a hardware spi port, so you indeed won’t be able to get high datarates from it…
So your best bet is to use an stm32 as slave to do the heavy lifting for you

why the esp btw? can you wirelessly send it new pictures?


martinayotte
Mon Jul 18, 2016 11:14 pm
I’m still convince that it can be done with ESP8266 simply by skipping the SPIFFS and using plain raw data stored in the flash, reading chunks using memcpy_P(), a bit like and PROGMEM is used.
To verify that, we need to write some kind of benchmark, then, if results are good, hookup your WS2801 RGB LED strip.

mkeyno
Tue Jul 19, 2016 6:25 am
martinayotte wrote:Still using low level part of SdFat, there are function like readBlock() and readBlocks() to read 512bytes sectors from the card.
I’ve never done that with SDCard yet, but should be doable. The thing I’ve done which is a bit similar is reading an SPIFlash on STM32 using readBytes()

mkeyno
Tue Jul 19, 2016 6:29 am
martinayotte wrote:I’m still convince that it can be done with ESP8266 simply by skipping the SPIFFS and using plain raw data stored in the flash, reading chunks using memcpy_P(), a bit like and PROGMEM is used.
To verify that, we need to write some kind of benchmark, then, if results are good, hookup your WS2801 RGB LED strip.

martinayotte
Tue Jul 19, 2016 4:17 pm
I did a small flashRead() performance test on ESP, and the following code gave be a throughput of 16MB/sec for 1MBytes length :

char mem[1024];
uint32_t flashStartAddress = (uint32_t)&_SPIFFS_start - 0x40200000;
uint32_t begin = millis();
uint32_t elapsed = 0;
p.println("Flash Mem Perf Test :");
for (int i = 0; i < 1024; i++) {
ESP.flashRead(flashStartAddress, (uint32_t *)&mem, sizeof(mem) / sizeof(uint32_t));
flashStartAddress += sizeof(mem) / sizeof(uint32_t);
}
elapsed = millis() - begin;
p.printf("\nelapsed time = %u \r\n", elapsed);
p.printf("throughput = %u bytes/sec \r\n", 1024 * 1024 * 1000 / elapsed);


mkeyno
Thu Jul 21, 2016 4:45 am
martinayotte wrote:I did a small flashRead() performance test on ESP, and the following code gave be a throughput of 16MB/sec for 1MBytes length :

char mem[1024];
uint32_t flashStartAddress = (uint32_t)&_SPIFFS_start - 0x40200000;
uint32_t begin = millis();
uint32_t elapsed = 0;
p.println("Flash Mem Perf Test :");
for (int i = 0; i < 1024; i++) {
ESP.flashRead(flashStartAddress, (uint32_t *)&mem, sizeof(mem) / sizeof(uint32_t));
flashStartAddress += sizeof(mem) / sizeof(uint32_t);
}
elapsed = millis() - begin;
p.printf("\nelapsed time = %u \r\n", elapsed);
p.printf("throughput = %u bytes/sec \r\n", 1024 * 1024 * 1000 / elapsed);


martinayotte
Thu Jul 21, 2016 12:43 pm
The only part of the sketch that is missing and maybe you a struggling into is this that should be on top of the sketch :

extern "C" uint32_t _SPIFFS_start;


mkeyno
Wed Jul 27, 2016 12:30 pm
dear @martinayotte , I’ve made sketch base on your hints and other guys in gitter and uploaded in my repohttps://github.com/mkeyno/ESP_fast_reading , although it seems the speed performance is increased but it throw exception when try to using the read data from flash , can you check the sketch , it if fully tested and ready to upload
Thanks

martinayotte
Wed Jul 27, 2016 3:41 pm
Unfortunately, I can’t test easily, since I don’t have such RGB strips.
I can try to extract piece of code to debug, but I’m not sure which one : is it the raw reads pushed to LEDs or the copy from SPIFFS to raw writes ?
For the exceptions you still see, did you use the ExceptionDecoder to get meaningful stack trace ?

mkeyno
Wed Jul 27, 2016 4:39 pm
martinayotte wrote:Unfortunately, I can’t test easily, since I don’t have such RGB strips.
I can try to extract piece of code to debug, but I’m not sure which one : is it the raw reads pushed to LEDs or the copy from SPIFFS to raw writes ?
For the exceptions you still see, did you use the ExceptionDecoder to get meaningful stack trace ?

martinayotte
Wed Jul 27, 2016 8:35 pm
Do you means that you don’t have exception anymore ?

mkeyno
Fri Jul 29, 2016 9:03 am
martinayotte wrote:Do you means that you don’t have exception anymore ?

martinayotte
Fri Jul 29, 2016 1:19 pm
Which memcpy giving you exception ?
Is it a memcpy() that you are doing with a raw Flash address ?
If Yes, then I can tell you that this is not allowed, you need to memcpy_P() instead.

mkeyno
Wed Aug 10, 2016 1:42 am
martinayotte wrote:Which memcpy giving you exception ?
Is it a memcpy() that you are doing with a raw Flash address ?
If Yes, then I can tell you that this is not allowed, you need to memcpy_P() instead.

martinayotte
Wed Aug 10, 2016 1:44 pm
ESP.flashRead(_index,(uint32_t *)& LED_BUFFER, sizeof(LED_BUFFER));

Leave a Reply

Your email address will not be published. Required fields are marked *