Question about esp_partition component

micron
Posts: 8
Joined: Thu Nov 09, 2023 7:09 pm

Question about esp_partition component

Postby micron » Sat Jan 13, 2024 1:27 am

I have a program that uses an I2S microphone, an I2S amplifier, and a storage medium to hold what's being recorded.

I have a custom board into which I plug a Waveshare esp32-s3 pico board. My custom board has an 8MB flash chip on it. I use stacking headers on the custom board so that I can attach a Waveshare 240x320 LCD display.

Using my 8MB external flash, driven by the spi_flash component, I can record and play back with sample rates up to 96K; it is flawless. On the display, I have an "oscilloscope" presentation of the audio being recorded or played back. Again it works great.

Now, I wanted to use a partition on the esp-32 flash, instead of needing to always mount my custom board between the processor and display. I created a 12MB partition and use the esp_partition component to erase, read, and write to it.

I made a run-time configuration option to switch between external flash or local partition, so everything but the actual read/writes is identical. Switching to partition flash, it gets weird.

On playback from the partition, it does not sound great, kind of like gargling. There is also a steady thumping sound - like tap dancing, and the playback is noticeably faster. The scope display looks O.K. and I don't see anything that looks like a "thump".

I could theorize that the thumping is interference between the CPU fetches and my reading the partition, so I put my functions in IRAM, but it made no difference. As for why it gargles and plays back faster, I'm totally stumped.

Are there any issues or considerations when reading/writing in a partition at fast rates? I've look through the docs, but don't see anything about that. I'm new to the ESP-IDF, so maybe someone more experienced could point me.

MicroController
Posts: 1729
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Question about esp_partition component

Postby MicroController » Sat Jan 13, 2024 9:49 am

You may be losing (blocks of) samples when recording because during erases/writes to the flash all other tasks and all non-IRAM ISRs are halted.

micron
Posts: 8
Joined: Thu Nov 09, 2023 7:09 pm

Re: Question about esp_partition component

Postby micron » Sat Jan 13, 2024 10:00 pm

MicroController wrote:
Sat Jan 13, 2024 9:49 am
You may be losing (blocks of) samples when recording because during erases/writes to the flash all other tasks and all non-IRAM ISRs are halted.
O.K. thanks! I figured there might be an issue reading from a flash that also is the execution space of other processes.

I pre-erase the partition before recording, so it should only be doing write operations during record. I accidentally discovered that the esp_partition component was not doing any automatic pre-write erases when I recorded over an existing recording and the result was a blend of the two recordings.

Interesting that when I played back a 96K recording at 32K, the recorded material was affected, but the "tap dance" still did its number at its regular rate. That makes me believe that the taps are getting into the playback stream, but are not actually in the recording.

In any case, I started experimenting with the number of samples per flash read/write. If I made the number lower, the gargling got worse, if I made it too big, I ran out of malloc memory. In the end, 4K samples ( 16 bit ea ) seemed a sweet spot. Also by slowing the sample rate for each successive test, I ended up at 24K sample rate working O.K.

I guess I'll just have to accept that 24K is the max sample rate when using the partition for recording.

In spite of the trouble trying to use the partition, I'm still blown away at how easy it was to use the "out-of-the-box" components for the esp_partition, spi_flash, and ST7789 display driver! I am enjoying this esp32!

So here it is...
Attachments
IMG_0244.JPG
IMG_0244.JPG (1.16 MiB) Viewed 47003 times

Who is online

Users browsing this forum: No registered users and 109 guests