Reading data from external flash with minimum internal RAM

Thread Starter

praveen4u83

Joined Oct 31, 2022
1
Hi Friends/Experts

I am designing a feature which periodically saves the log information in SPI external flash 1MB which is interfaced with microcontroller which has 1MB flash and 256K RAM. Each log have information like - time in UTC, one sensor number, user ID, sensor value before and after, units of sensor and CRC of each entry of log.

Though this MCU has 256k ram but actually RAM available for our application is 196K. Remaining RAM is occupied by the secure bootloader and secure partition manager.
The external flash is also partitioned for other storage purpose and for storing this logs we have allocated 8K from 1MB. So total 340 logs are stored in external flash with 24 bytes of log size. Daily 4 logs may be written into the external flash so that around 80 days of the information can be saved into external flash.

These 340 logs are stored based on the date & time which is saved in UTC format.

Once logs are stored in external flash, user wants to read the logs based on the date and time selected from the utility. Now due to limitation of internal RAM I cant read complete 8K of logs (340) from external flash and save temporarily in MCU internal RAM and process the user request.

Is there any other way or logic which I can process the user request to read the log from external flash for his interested date and time.

with regards,
Praveen Palaparthi
 

Papabravo

Joined Feb 24, 2006
21,228
Store the data in the external 1MB flash memory in such a way that it can be randomly accessed. In your RAM you can maintain a small "directory" of where particular logs are located. To retrieve information, you go the directory, use a key from the directory to find the entry you are looking for and go to that address in the external flash. Should be straight forward to code that up. If you lose the contents of the directory in RAM you should be able to recreate it by reading the whole 1MB a piece at a time to reconstruct it. The alternative would be to write the directory to the external memory every time you update it. This may result in endurance issues. Read the datasheet.
 

Ian0

Joined Aug 7, 2020
9,846
If you are writing 4 logs per day, are they exactly 6 hours apart?
If so, you need not store the time, you can calculate the address from the time and vice versa
 

BobaMosfet

Joined Jul 1, 2009
2,113
Hi Friends/Experts

I am designing a feature which periodically saves the log information in SPI external flash 1MB which is interfaced with microcontroller which has 1MB flash and 256K RAM. Each log have information like - time in UTC, one sensor number, user ID, sensor value before and after, units of sensor and CRC of each entry of log.

Though this MCU has 256k ram but actually RAM available for our application is 196K. Remaining RAM is occupied by the secure bootloader and secure partition manager.
The external flash is also partitioned for other storage purpose and for storing this logs we have allocated 8K from 1MB. So total 340 logs are stored in external flash with 24 bytes of log size. Daily 4 logs may be written into the external flash so that around 80 days of the information can be saved into external flash.

These 340 logs are stored based on the date & time which is saved in UTC format.

Once logs are stored in external flash, user wants to read the logs based on the date and time selected from the utility. Now due to limitation of internal RAM I cant read complete 8K of logs (340) from external flash and save temporarily in MCU internal RAM and process the user request.

Is there any other way or logic which I can process the user request to read the log from external flash for his interested date and time.

with regards,
Praveen Palaparthi
Yes- yes compression, and paging. In limited memory environments, you need to create a mini-memory manager that can page smaller page sizes (like 2K) in and out. A compression method may give you additional headroom (like Huffman- which is very simple)

This was an approach we used back in the day with DEC PDP-8a/e/s systems with only 4K of RAM total.
 
Last edited:
Top