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
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?)