How to manage the memory using the simulink?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to manage the memory using the simulink?

1,426 Views
edenli
Contributor V

Hi Daniel,

Friend,I feel like i am a little confused.How to manage the memory using the simulink? 

I generate the C- code shown as below:

/* S-Function (MemWrite_564xl_fcn): '<Root>/DataMemWrite' */

 

 /* Memory Address Write */
 /* Memory Address : Base Address + Offset */
 /* Memory Address : 0x40002C88; */
{
 uint32_T * (write_mem_address);
 write_mem_address = (uint32_T *)0x40002C88;
 *(write_mem_address) = Calibiate1;
}

What you means is that the Address that i write has been other program occupied.

 

How can i make sure which memory segment has not been used?

 

The attachment is my Model.

Original Attachment has been moved to: CCP_CAN.mdl.zip

0 Kudos
1 Reply

1,054 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi edenli‌,

There are at least 2 methods i could think of right now:

- #1: quick in and dirty is to declare a reserved buffer in Simulink with a size you control. Since in Simulink you control the read/write into such buffer you could easily implement what you want with writes and reads to any specific index in the buffer.

Am saying is a quick and dirty since you do not control the start address of the buffer - depending on your Simulink modification that might change and you might need to re-adapt the start address of the DataMemWrite/Read Blocks (the offsets remains unchanged). If you use instead DataMemWrite/Read the standard Simulink Read/WriteStore blocks - then everything would be ok and you could forget about address changing due to adding new stuff in the model.

How to declare a 100 uint32 size buffer called myReservedSpace in Simulink:

pastedImage_1.png

pastedImage_2.png

How to implement the model

pastedImage_4.png

How to check the memory allocation:

pastedImage_3.png

- #2: the "profi" method would be to use a reserved memory area in the SRAM that have fixed start address and size.

For that you need to modify the Toolbox standard linker command files ( from here: {toolbox install dir}\rappid564xl\src\cw_specific_files\) by spliting the existing SRAM memory into 3 (right now there are 2 areas). So you need to add a new one: before int_sram or after int_sram. The stack_ram would be better to be kept last in order to avoid stack overflow issues.

pastedImage_7.png

Here is an example: cortex m3 - How can I make an empty section with GNU ld? - Stack Overflow 

 

Once you have defined the area, you could take the start address of it an then using the DataMemWrite/Read you could control what you place in the that area.

Hope this helps!

Daniel

0 Kudos