Created Mon, 13 Aug 2012 08:46:57 +0000 by kllsamui
Mon, 13 Aug 2012 08:46:57 +0000
in arduino 0023 F() was a external library function, from arduino 1 on its integrated ( and heavily used by me)
pls test and possibly help me with the small problem of backward compatibility
void setup()
{
Serial.begin(115200); //KLL
#if defined(__PIC32MX__)
Serial.println(F("I am the chipKIT MAX32"));
Serial.println(F("but in chipKIX MAX32 i have no RAM problem, but i also dont want to edit all my code and delete the F() "));
Serial.println(F("so for chipKIX MAX32 i declare a dummy F() function"));
#endif
#if defined(__AVR__)
Serial.println(F("I am the ARDUINO UNO"));
Serial.println(F("this is long text i want in FLASH when i use the arduino uno, because SRAM too small"));
#endif
}
void loop()
{
} // end loop
// but on arduino 1.0.1 get ERROR as if compiler switch dont work???
/*
F_test:0: error: expected unqualified-id before 'reinterpret_cast'
F_test:0: error: expected `)' before 'reinterpret_cast'
F_test:0: error: expected initializer before 'reinterpret_cast'
F_test:0: error: expected unqualified-id before ')' token
*/
#if defined(__PIC32MX__)
char* F(char input[]) {
return input;
}
#endif
#if defined(__AVR__)
#endif
Mon, 13 Aug 2012 10:49:48 +0000
On the Arduino the F() function isn't a function but a macro.
You should un-define it before redefining it. Something like:
#if defined(__PIC32MX__)
#if defined F
#undef F
#define F(X) (X)
#endif
#endif
ought to work. Make sure this is either in your program or included in your program BEFORE you use any calls to F().
Alternatively, you could get more fancy and actually implement the PSV functionality properly. Something like:
#define F(X) ((char __attribute__((space(psv))) *)X)
Mon, 13 Aug 2012 12:54:03 +0000
very confusing for me???
MPIDE for PIC32 don't know a F("long text in flash") ( get error ) so i made a dummy one AND IT WORKS on PIC32
on ARDUINO1.0.1 for arduino uno i dont want undefine/redefine anything i dont understand why the compiler even check that code because ITS NOT FOR ARDUINO UNO.
anyhow i tested in ARDUINO1.0.1
#if defined(PIC32MX) #if defined F #undef F
and it not helped for above error.
its anyhow only a temporary workaround ( by a beginner ) so what is the long term plan about this, i think its understandable that someone want load his arduino 1.0.1 sketch on PIC32 without editing for hours and get a code what will never run on arduino again.
Mon, 13 Aug 2012 14:17:23 +0000
its anyhow only a temporary workaround ( by a beginner ) so what is the long term plan about this, i think its understandable that someone want load his arduino 1.0.1 sketch on PIC32 without editing for hours and get a code what will never run on arduino again.
Long term fix would be for someone at Digilent to implement the F() macro in the core for us.
The problem might be where you are doing the defining. You should ensure that it is the very first thing in your sketch. The following works on both my UNO (1.0.1) and my UNO32 (00023):
#if defined(__PIC32MX__)
#define F(X) ((char __attribute__((space(psv))) *)X)
#endif
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println(F("This is printed from flash"));
delay(1000);
}
Mon, 13 Aug 2012 14:55:52 +0000
thanks a lot, works perfect
Tue, 14 Aug 2012 05:06:40 +0000
Shouldn't it really be like this:
#if defined(__PIC32MX__)
#if defined F
#undef F
#endif
#define F(X) (X)
#endi
to ensure that if F is not defined that it gets defined. i.e. don't you always want F to be a null macro?
--- bill