Go Down

Topic: #ifdef SAMD_SERIES does not work for the Due, but #ifdef __SAM3X8E__ does (??) (Read 375 times) previous topic - next topic

dsyleixa

hi,
I tried to use dtostrf() for the Due, so I tried

#ifdef SAMD_SERIES
   #include "avr/dtostrf.h"
#endif

which did not work (error: 'dtostrf' was not declared in this scope),
but

#ifdef __SAM3X8E__
   #include "avr/dtostrf.h"
#endif

worked (IDE 1.8.8 ):

Code: [Select]
    char buf[40]; 

    Serial.print("dtostrf test ");
    dtostrf(3.456, 7, 4, buf);
    Serial.println(buf);


what am I missing?

is there perhaps a macro #define which targets either ARM Cortex board?
   

ard_newbie

dtostrf() works if you add its definition ( I don't know why this is not already in Wstring.h):

Code: [Select]

char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
  char fmt[20];
  sprintf(fmt, "%%%d.%df", width, prec);
  sprintf(sout, fmt, val);
  return sout;
}
void setup() {
  // put your setup code for core 0 here, to run once:
  Serial.begin(250000);
  char buf[40];

  Serial.print("dtostrf test ");
  dtostrf(3.456, 7, 4, buf);
  Serial.println(buf);
}

void loop() {

}





dsyleixa

my point is not just about dtostrf, instead it's a general issue about SAMD_SERIES.

I need to have this preprocessor directive also for different other source codes.

So what am I missing about SAMD_SERIES ?

is there perhaps a macro #define which targets either ARM Cortex board?

pert

By "either ARM Cortex board", do you mean the Due and the Arduino SAMD Boards?

If so, you can do this:
Code: [Select]
#if defined(__SAM3X8E__) || defined(__SAMD21G18A__)

dsyleixa

yes, that's what I do currently.
I'm using M0/Zero, M3/Due and Adafruit M4.

But no macro which works for all ARMs?

pert

"All ARMs" covers a lot of ground. I don't know of a standardized macro to identify any microcontroller that uses an ARM core. However, if you want a single macro that will match the Due, any of the Arduino SAMD Boards, and any of the Adafruit SAMD boards, as well as any other of the SAM chips, you can use the SAM macro.


pert

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per

Go Up