Particle Dev compile error: not included in this scope


#1

I had a working application. I didnt work on it for few weeks and now I’m back and I saw that there was a firmware upgrade from 0.4.7 to 0.4.9.

I’m using Particle Dev and I’m not able to compile my program anymore because I have the error ‘Serial’ was not declared in this scope but few lines higher that that, there is an include of the application.h.

What changed so this application wont compile anymore because of this error?

Here is the code:

#ifndef _SD2_CARD_CONFIG
#define _SD2_CARD_CONFIG

#include "application.h"
#include "spark_wiring.h"

#define SD_SPI_NUMBER    1                    /* Specify HardwareSPI number */

/* For Maple families, Maple rev5, etc */
#    define SD_CHIP_SELECT_PIN    A2            /* for Spark Core SPI CS pin */
    //#define SPI_LOW_CLOCK    SPI_281_250KHZ    /* = SPI_HALF_SPEED */
#    define SPI_LOW_CLOCK    SPI_4_5MHZ        /* = SPI_HALFL_SPEED */

/* High speed */
//#    define SPI_HIGH_CLOCK    SPI_4_5MHZ        /* = SPI_FULL_SPEED */
#    define SPI_HIGH_CLOCK    SPI_9MHZ        /* = SPI_FULL_SPEED */
//#    define SPI_HIGH_CLOCK    SPI_18MHZ        /* = SPI_FULL_SPEED */

/* Select output device for print() function */
#    define SERIAL_DEVICE    0                /* 0:SerialUSB  1=: Serial UART device */
#    if SERIAL_DEVICE == 0
#        define Serial Serial                /* Use USB CDC port */
#        define BPS_9600        /* Nothing */
#        define BPS_115200     /* Nothing */
#    else
#        define Serial Serial1                /* Specify serial device, "Serial1" or "Serial2" or "Serial3" */
#        define BPS_9600        9600
#        define BPS_115200     115200
#    endif

//#define SPI_SPEED_UP                        /* Enable read/write speed up option */


//define SPI_DMA        /* Do not enable this line, no checked, experiment, dangerous */


#endif /* __SD2CARD_CONFIG_H__ */

#2

#include "spark_wiring.h" should go, it should all be included via application.h (BTW you might start using Particle.h instead too).

I’m not too sure this is a good idea

#define Serial Serial
// or
#define Serial Serial1

Try not to reuse a commonly used symbol as macro - this is a recipe for mayhem.
Rather come up with your own private unique symbol for the macro.


#3

It changed nothing.

I un-commented spark_wiring.h and added Particle.h


#4

Seen my edit above?

The pickle you’ve brought yourself into with redefining a “keyword” is rooted in the fact that with 0.4.9 Serial already is a macro, so once you redefine the macro you hide the original definition of the macro and hence have lost access to the original.


Best way to transfer large data from Photon
#5

I am facing exactly the same problem!

I had working code that compiled for both core and photon. Last compiled for core on 28 Dec.

Now the same code doesn’t compile anymore. See this screenshot.

Using this SD card lib:


As recommended by @ScruffR


#7

Since we are in the fortunate position to have @whg in the forum who is the master of SD cards on embedded systems I’d now recommend using his library.

The discussion about the new features in that lib can be found here
Try SdFat, a Library for SD Cards


#8

Thanks, this make a lot of sense!


#9

Thanks @ScruffR (and @whg of course :smiley: ) - the SdFat lib compile and works for both core & photon.