Rowley CrossWorks AVR C Compiler and PSTR()

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The PSTR() macro is commonly used with avr-gcc to place anonymous strings in flash. e.g.

printf_P(PSTR("This string is in flash\n"));

You can re-arrange the macro for CodeVision or ImageCraft and still get the desired behaviour.

According to the Rowley docs, you should also be able to cast these strings by:

#define PSTR(s) (const __code char *)(s)

But I have no success. The anonymous string is STILL copied into SRAM, and printf_c() is given the SRAM address. So it prints a string from flash with the SRAM address. (printf_c() is the Rowley equivalent of printf_P() )

A workaround is to name all the anonymous strings. This correctly places them in flash:

const __code char anon1[] = "string 1 in flash";
const __code char anon2[] = "string 2 in flash";
...
printf_c(anon1);
...

Does anyone know how to get the PSTR() macro to work ?

Otherwise, I can get Rowley to compile most of my code.

1.  #if defined(__CROSSWORKS) ... identify Compiler
2.  #include             // calls reqd chip.h
    #if defined(__ATtiny2313_h) ... identify MCU
3.  TCNT1 is called TCNT1W ... for 16 bit access
4.  #define ISR(num) void ISR_##num(void) __interrupt [num]

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yippee I have done it.

#define PSTR(s) C""s     // C "" "string" ---- OK !
#define PSTR(s) C ## s   // C "string"    ---- NBG
#define PSTR(s) C ## (s) // C             ---- error

Rowley uses a special extension C"string" to force "string" into code space anonymously. The pre-processor would add a space between the token C and "string" and the Compiler would not get the single token.

David.