Hi,
I am working on Freescale ARM Cortex M4 device MK60N512VMD100 using IDE Keil uVision v4.50.0.0
I have defined values of on-chip IROM1 (Start: 0x0 Size: 0x80000) and on-chip IRAM1 (Start: 0x1FFF0000 Size: 0x10000).
Now I want to access these values from inside source code (*.c or *.s) file.
Please advice
Thanks and Best Regards Waseem
You can read memory location on ROM using a simple pointer:
unsigned int my_value; . // This example is to read address 0x0000C004 my_value = *(unsigned int*)(0x0000C004); . .
Now to write, you cannot do it directly, you need to use IAP funcionality.
I think you should check the working with scatter files (.sct) - you will need such special relocation definition files also, if you want to use memory spaces which are not automatically zero'ed on start.
Not really true.
A program can use pointers to access RAM memory that haven't been specified in the project file. And if the RAM range isn't specified in the project file, then the startup code will not perform any zeroing. So no extra magic needed in any scatter file.
Extra magic is when someone adds normal variables in the C code, and want the linker to locate these variables in a specific memory region and not zero this region on boot.
Obviously, zeroing isn't relevant for the flash memory ranges.
To use non-zero initilized data, I followed the following instruction:
http://www.keil.com/support/docs/3480.htm
(See also: http://www.keil.com/support/man/docs/armcc/armcc_babbeaeh.htm)
These instructions all use scatter files.
Is there also some other more easy possibility to use data without non-initialized to zero?
(But it would be important for me, that the linker locates the data automatically - I would not like any idea where I would have to define absolute addresses in my C/C++ modules, as I have very many of them).
A single pointer to a large struct is a simple way to map lots of data without involving a linker and without having to care about a lot of absolute addersses. The compiler keeps track of the individual offsets of the members of the struct, while the program must specifically assign a suitable value to the pointer.
Ok, so you would propose a global struct at adress 0x20000000, and then define that IRAM1 should start only at 0x20000100? (if the struct size for sure is less than 0x100)
Would this then work without scatter file? (so that then this global struct at address 0x20000000 will NOT be initialized to zero, but I anyway can access it in my software without any restrictions?)
Yes - if you do want to ignore scatter files and make use of RAM that isn't initialized on boot, then you could either set a slightly higher start address in the project settings and use a pointer set to the true start of RAM. Or set a slightly smaller size of the RAM region in the project, and set the pointer to point at the end of RAM minus the reserved size.
Just note that depending on used processor, there could be a boot loader in the processor that makes use of some RAM before handing over to your application. In that case, you must make sure that your decision where to place your protected data is not colliding with the memory being overwritten by that boot loader.
Another good option is to move all your special variables into a separate C file, and use a scatter file to locate all data for this C file to a specific memory range.
You must take the decision which solution you find best. With fixed variables, it is a bit smoother to use a scatter file. The pointer solution is a bit nicer if you have more dynamic needs - like possibly storing some log data of varying size in this region, allowing you to read crash messages from the log after a watchdog reset.
With an ARM chip, the cost is quite low for going the route with a pointer to a struct. If using a 8051 processor, then introduction of pointers can be very expensive.
Thank you, this is very interesting.
Just one point: You write that it is easy to specify in the scatter file, that all data of a specific c file should be at a specific memory range. Can you give an example for this? (do you specify the name of the c/c++ module in the scatter file, or do you need to define some segment name and then specify this segment name in the c file at the variables definition?)