Flash objects: how to know when Garbage Collector will run?


#1

I have an application that periodically updates a few values in flash memory. I understand that this will mark the previous values as ‘erased’ and write new flash objects as a form of write balancing, and only once the entire memory falls short of a write will the actual erasure occur.

Is there a way for me to detect how many bytes are ‘really’ free (i.e. not used nor ‘erased’)? More specifically, I’m trying to think of a way to tell whether I’m approaching the Garbage Collector process running.


#2

Hiya,

Are you using the ‘Config’ flash, or the ‘Application and Data’ Flash?

Note that the ‘Config’ flash only has about 128k (I think) of data available - even though you can have around 2560 flash object handles. You can use adl_flhGetFreeMem() and adl_flhGetUsedSize() to work out how much flash is available. Also please read the note at the end of section 3.8.3 about having to use AT+WOPEN=3 to erase flash objects.

I’ve also found that you need a queue to write lots of data to the config flash, or you WILL trip the hardware watchdog. Have a look at the caution at the end of section 3.8.2.1, and there used to be a sample that described this process as well.

There is a lot more room in the A&D flash, and you also get the opportunity to call the garbage collector yourself. Have a look a the 'Application & Data Storage Service - or if your firmware is recent enough, there is also a ‘Filesystem’ api - which I haven’t used yet.

ciao, Dave


#3

I didn’t realise there were other types of flash we could use - I’ve just been calling the flash functions like adl_flhWrite(). I’ll look at the Application & Data Storage section that you mentioned.

I’ve been calling adl_flhGetFreeMem() and adl_flhGetUsedSize() and they’ve been returning 130,591 bytes and 481 bytes respectively, regardless of how many times I update the values of flash objects. I’m assuming that it’s not actually considering bytes marked erased when it calculates these.

My application doesn’t write much data to flash but it will eventually cause the Garbage Collector to fire up. If I can implement some sort of countdown (GC in x bytes) that would allow me to pay special attention to whether it trips a watchdog reset or do something bad.