I am trying to use the KPIT gcc for the Renesas M16 cpu. The compiler restricts pointers to 16 bits and so all strings are copied from ROM to RAM at start up. This fills my RAM. The chip has some data ROM available in the first 64K and this would be addressable by the small pointers if I can get the compiler to place the strings there. I can't find compiler switches to control the placement of the strings so I tried the following:
static const char fmt[] __attribute__ ((section ("nrodata")));
static const char fmt[]="Hello World";
which seems to work if placed outside function in the file. However, within a function the same code gives the error: "storage size of 'fmt' isn't known" for the first line. The reason I want it to work in functions is that I'm considering changing all the printf() calls to a macro like:
#define PRINTF(fmt,args...) do { \
static const char _fmt_[] __attribute__ ((section ("nrodata"))); \
static const char _fmt_[]=#fmt; \
printf(_fmt_ , ##args); \
} while (0)
to get the strings into the right section.
Does anyone know how I can get the strings into a particular section?
Based on the GCC documentation you should be able to specify the attribute in the same line as the variable definition, such as:
static const char __attribute__ ((section ("nrodata"))) fmt[]="Hello World";
It does say you may do this only for global variables, but it looks like it may be allowed for static variables as with your example code. (I don't have your compiler so I can't actually try it)