Setting bytes in absolute address - Forums Re: Setting bytes in absolute address It DID! (/&%§§!!!)  Resort posted lines when you have got some spare time



Sun, 17 Nov 2013 09:59:21 -0600
Re: Setting bytes in absolute address @Dana

Setting aside memory or rather giving addresses to objects (variables,functions etc) is the job of the linker, not the compiler, so the latter doesn't know anything about the final addresses.

With that in mind I question if any statement in C-code should be allowed / needed to specify an absolute address for an object.

On the other hand there seems to be a need for objects at absolute addresses. Cypress uses for the internal PSoC registers constructs like these (copy from an ADC_???.c)






where "CYDEV_RESET_CR4" is defined as a hex value giving the absolute address of the register. Since there is no need to "put aside" any memory (the register just exists on that location) everything is ok and the linker does not need to get informed.
The remaining question is: How to "put aside" memory.

GCC has indeed defined the __attribute__ for variables which allows quite a lot of different settings, look here for further details. See, that the "used" attribute will prevent the variable beeing optimized-out and so free you from explicitly reference the variable as HL suggested. Unfortunately there are no attibutes that get passed to the linker to set an absolute address. So an additional step is needed as HL points out for telling the linker where to allocate a newly defined section. 

Bob (Hoping for forum sw doesn't clobber my post)



/* PRES-A related registers */

Sun, 17 Nov 2013 09:56:34 -0600
Re: Setting bytes in absolute address  one may use this to access external shared RAM that is used as mail box between processors. But cannot think of special usage with internal RAM.

Sun, 17 Nov 2013 05:24:28 -0600
Re: Setting bytes in absolute address @Bob, doesn't that approach with a pointer not tell the compiler to

set aside that memory ? Make it immune to other processes, etc... ?


Still larning C, Dana.

Sat, 16 Nov 2013 21:51:58 -0600
Re: Setting bytes in absolute address To be independent of compiler and target device I would suggest you to use a different approach which does not use any exotic instructions like __attribute__. Instead I would use a pointer to my data and assign the wanted address to that pointer. Since you even can use a pointer to a struct it can make the life really easier.


What is the benefit of accessing a(ny) variable at a constant address in SRam?



Sat, 16 Nov 2013 07:37:26 -0600
Re: Setting bytes in absolute address Hi All,

This is a good information to be shared with others.

The same syntax can be used to store variables (not constants) in SRAM too. However you need to ensure the variable is not initialized during declaration.

For a 64 kB PSoC 5LP part, the possible RAM locations at which the variable can be located will be from 0x1FFF8000 to 0x20007FFF.




Sat, 16 Nov 2013 06:36:51 -0600
Re: Setting bytes in absolute address Good to hear that

Thu, 10 Nov 2011 05:29:12 -0600
Re: Setting bytes in absolute address that's absolutely right lleung !

After using the variable in the code, i was able to see the required value in the specified memory location when i ran it in the debug mode.


thanks a lot !

Thu, 10 Nov 2011 02:38:18 -0600
Re: Setting bytes in absolute address One more thing is that the compiler would omit the code if it was not used.

In your code, you should use/refer to it at least once directly(not via a pointer).


Thu, 10 Nov 2011 01:10:47 -0600
Re: Setting bytes in absolute address you can check the memory data in the psoc creator after downloading the code to the chip.

you can also check the hex file, the content should be around line 3076

Thu, 10 Nov 2011 01:02:21 -0600
Re: Setting bytes in absolute address thank you very much for your quick reply.

i tried the same code in a sample project and tried to verify in debug mode. but i wasn't able to see the 0xAA at the location 0x30000. is it the right way to verify, or is there anything i am missing out?

thanks once again.

Thu, 10 Nov 2011 00:50:26 -0600
Re: Setting bytes in absolute address Please also notice that you can not do this after 0x3fffc( or the last 4 byte of your chip). The compiler will fail.

I think that's because the ARM is 32 bit machine so the last address it can use is should be the last but 4.



Thu, 10 Nov 2011 00:40:46 -0600
Re: Setting bytes in absolute address Put this in the source file.

unsigned char ucCRCdata __attribute__ ((section (".CRCDATA"))) = 0xAA;

And go to the psoc creator

build setting -> linker -> command line

in the custom flags, add






Thu, 10 Nov 2011 00:34:45 -0600
Re: Setting bytes in absolute address hey lleung

can you please share with us how u were able to do it?

i tried _at_ but in vain.


Thu, 10 Nov 2011 00:24:39 -0600
Re: Setting bytes in absolute address  Don't worry, I figured out how to do this..


Wed, 09 Nov 2011 05:51:06 -0600