All Forums > Programming Questions

Cannot compile existing Arduino project.

(1/2) > >>

TeslaFan:
Hello!

Saw "Wiring" at Sparkfun and thought I'd see if I could switch to it from Arduino 22.

It tanks on this line of code, there's nothing special about it... I call strcpy_P dozens of times. This time is neither the first nor last. s_table[38] exists and will fit into pstr_text.


--- Code: ---strcpy_P(pstr_text,(char*)pgm_read_word(&(s_table[38]))); //"com%dtype"

--- End code ---

The error I get is:


--- Code: ---CommManager.cpp:921: error: error: can't find a register in class 'BASE_POINTER_REGS' while reloading 'asm'
--- End code ---

Then I get a list of:

--- Code: ---CommManager.cpp:921: error: error: 'asm' operand has impossible constraints
--- End code ---

that correspond to subsequent calls to strcpy_P but... not to ALL of them. And there are no syntax errors that I can see.

I could post more code, or even the entire program, but it's fairly large. The problem seems centered around PROGMEM, but doesn't start until after about 32 calls to strcpy_P.

bhagman:
You might want to move over to Constant Types... this will make your code more portable too.

http://wiring.org.co/reference/

I'm guessing from the little bit I see, that you have a set of flash strings you want to use.

You can use ConstantString or, if you want to inline strings, just Constant.

http://wiring.org.co/reference/ConstantString.html

I'd have to see more of your code to see why it would be failing - that line of code doesn't look like it should cause a problem, but it might have to do with the #includes - I'm not sure.

TeslaFan:
Ok, I replaced all the calls to strcpy_P to use the Constant data type.

That worked great with Serial.println(Constant("text to Print");

but fails with any form of strcpy() or sprintf()

Apparently, casting the Constant() as a (const char*) just returns a pointer to the object, not to the string it references.

If I can't use strcpy() or sprintf() with a text string stored in FLASH, then I'm dead in the water.

How do I use Constant() with strcpy() and sprintf()?

bhagman:
Right.

We need to define more functions to work with ConstantTypes.

Try this:


--- Code: ---void constantscpy(char *dest, ConstantString src)
{
  int i;
  for (i = 0; i < src.length(); i++)
    dest[i] = src[i];
  dest[i] = 0;
}

void setup()
{
  ConstantString s[3] = { Constant("One"),
                          Constant("Two"),
                          Constant("Three") };

  char d[40];

  Serial.begin(9600);
 
  constantscpy(d, s[2]);
 
  Serial.println(d);
}

void loop()
{

}

--- End code ---

Also, you'll note that you can not globally define the ConstantString array.  You really shouldn't anyway.  :)

Try that in your code and let me know how it goes.


You could also go the route of using Strings.  It would be interesting to see how well it would work for you.

TeslaFan:
thanks! That worked fine.

I like how the string definition gets placed where it's used, but I don't like that it's probably instantiating and destroying the wrapper object for the string every time it executes that function. Please tell me that ConstantString is totally static and doesn't dynamically construct anything.

I like how one IDE can support multiple architectures, but it seems to compile a lot slower. That might be an issue with 3rd party boards that have large libraries to support the board's unique features.

Navigation

[0] Message Index

[#] Next page

Go to full version