Hi all, please help me understand data compressor.
I do not understand, why compressor compress the constants in flash. I believed that only compressed are the data in flash, that are used to initialised variables in ram with a given value. Why even the data in ram are compressed? But what I do not understand in all, what are my data in flash (const volatile - because can be changed by programing flash from the code in run time).
C++ code: #define SECTOR_ADDR_for_Config 0x080E0000 const volatile DISTA_konfigurace_flash_typ F __attribute__((at(SECTOR_ADDR_for_Config)))= { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ..... up to 1024 bytes
MAPFILE: Load Region LR$$.ARM.__AT_0x080E0000 (Base: 0x080e0000, Size: 0x00000400, Max: 0x00000400, ABSOLUTE, COMPRESSED[0x00000190])
Execution Region ER$$.ARM.__AT_0x080E0000 (Base: 0x080e0000, Size: 0x00000400, Max: 0x00000400, ABSOLUTE, UNINIT, COMPRESSED[0x00000190])
Base Addr Size Type Attr Idx E Section Name Object
0x080e0000 0x00000400 Data RW 311 .ARM.__AT_0x080E0000 dista_konfigurace.o
Can anyone help? Thank you, Ludek
You are tricking the linker into thinking it is RAM data - because normal flash data isn't volatile, except when the flash block gets an erase command.
So the linker thinks it should have a compressed copy in flash (to save space) and extract to RAM on each reboot.
Next thing: volatile is about asynchronous changes. The compiler has access to very few registers. So just calling normal functions (assuming you don't inline them or bend your back backwards to get maximum global optimization) would normally be enough to avoid issues with caching. And many processors have dedicated instructions to force barriers.
Once more: consider using a scatter file.
I will give explanation. I am using const in order to preven accidental write to the variables. I use const in order to be able to initialise variable. Because it is configuration that had to be present everytime, even without power.
I need to exchange this configuration via Ethernet. So if it is not volatile, some optimalisation can take place and use variable values as direct operands and the effect of configuration exchange will not take place.
That is why const volatile. And it has to be on a given address, because, it is in different flash bank allowing me to erase this part no affecting the program code. And finally, I am changing also firware remotely and configuration stay untouched.
I can live with compress off solution, but I am courious, why the data are compresed in this flash region. I gives me no sense, and even do not understand what linker planed to do with this compressed data in this place.
thank you for your patience, Ludek
So maybe you could explain the concept of having volatile (asynchronously changeable) data in a non-modifyable flash address?
I think you are tricking yourself when you play with const volatile and then gives an absolute address in flash.
To do advanced stuff, it's better to use the scatter file and specify that a segment or object file should have data stored using a specific policy. And then make sure you give good load and execution regions to use.
I am using STM32F407 RAM start at 0x2000 0000 Flash start at 0x0800 0000 , size 1MB
I could see, that writing const only, shows that section has attribute RO. Adding const volatile the section is market as RW and compression on the data is applied. What I do not understand, why are data, that are already on its place compressed. The structure that varible represent does not fit any more and its members contain incorrect data, since the decompression is not performed and even has no sense to be performed.
thank you for help.
Ludek
Thank you for so clearly describing which processor you are using, and which memory address ranges that represents flash and RAM. That really did help a lot when trying to understand your post...
View all questions in Keil forum