Hi, I have a system profile structure (set of system properties), saved in a serial dataflash. Size of a profile is about 16K. At power-up I need to extract from this profile another structure - slave profile (6K), and send it to the slave microcontroller over CAN. In order to do that at a certain point I need to initialize both structures in ram. And this is the only time when these structures are used.
The question is - what is the optimum way to allocate memory for these structures ? I am using STM32F107 with 64K of ram. If I initialize structures locally, in a 'parsing / slave initializing' function, I need to assign additional 22K to the stack, and I loose them for the application. By initializing these structures globally I also loose 22K of ram.
Would really appreciate considerations on this subject.
Gennady
"And significant part of this application is a communication with multiple slaves / ethernet, so i need quite a few global buffers placed in ram. And again, the only purpose for placing this structures in ram is parsing structure."
Then your problem is a no-problem.
Create a single 22k+ block that you use for the temporary storage of this structure.
When you have sent it to the slave(s), you can then reuse this block for quite a number of your receive and transmit buffers.
One way you can do it is to use pointers.
Another way is to create a union:
union { struct { uint8_t my_eth0_rx_buf[ETH_RX_SIZE]; uint8_t my_eth0_tx_buf[ETH_TX_SIZE]; uint8_t my_xx_rx_buf[XX_RX_SIZE]; uint8_t my_xx_tx_buf[XX_TX_SIZE]; ... } bufs; struct { .... } temporary_ridiculously_large_slave_struct; } my_buffers;
But the big issue - why should the master parse the slave configuration? Wouldn't it be better if the master sends the raw array of bytes from EEPROM to the slaves and have them parse it?
A file server does not parse the Word documents you store on it. It just sends them out and it's up to the receiving machine to see if the file really is a valid Word document. So the file server doesn't need to be updated if you suddenly decides to store a document for a newer version of Word or a document for Microsoft Excel.
If there are a few parameters in this 22kB large block that the server needs to know about, then you should let the slaves decode the information and then report back the relevant parameters to the "file server". So the master sends an unknown blob and then gets back "our timeout settings are 1500ms" and "our addresses are xxx".