[Resolved]- Both IDE's: Error: Could not compile. Please review your code

Code that compiled cleanly just a couple of days ago suddenly does not compile anymore. Targeting electron with 0.4.8. Started seeing this yesterday. Hoped it would get fixed overnight. Still broken as of this morning.

Anyone else seeing this today?

I don’t think there’s a systematic issue with the compiler right not, since my apps seem to be compiling OK. Is it possible for you share your code so that we can try to reproduce?

this code has been working:

#define IDLE      0
#define ENABLED   1
#define DEBOUNCE  2
#define POURING   3
#define COMPLETED 4
#define MAXWAIT 500
#define OK      200
#define BUSY    100
#define ERROR    -1

// inputs
int btnSecret  = D0;
int btnBRB     = D1;  // Stella's button is on D1

// outputs
int relay1     = D3;
int relay2     = D4;
int enabledLED = D7;

// tuneables/globals
int delayMS      = 200;
int default_mode = IDLE;
int mode         = default_mode;
int productRelay = relay1; // since there is only one for now
int pouring      = 0;
int pourTime     = 15;     // pour time = pourTime * delayMS / 10 seconds
int waitTimer    = 0;


void setup() {
    pinMode(btnBRB,     INPUT_PULLUP);
    pinMode(btnSecret,  INPUT_PULLUP);

    pinMode(enabledLED, OUTPUT);
    pinMode(relay1,     OUTPUT);
    pinMode(relay2,     OUTPUT);

    Particle.function("nitroCmd",nitroCMD);
}

void loop() {
    switch (mode) {
    case IDLE:
        enable();
        break;

    case ENABLED:
        wait();
        break;

    case DEBOUNCE:
        debounce();
        break;

    case POURING:
        pour();
        break;
    }

    delay(delayMS);
}

void resetMode() {
    pouring   = 0;
    waitTimer = 0;
    mode      = default_mode;
    digitalWrite(enabledLED, LOW);
    digitalWrite(productRelay, LOW);
}

void enable() {
    log("mode", "enabled");
    digitalWrite(enabledLED, HIGH);
    mode      = ENABLED;
    waitTimer = 0;
}

void wait() {
    if ( pourButtonPressed() ) {
        mode = DEBOUNCE;
    } else if ( waitTimer >= MAXWAIT ) {
        log("mode", "timeout");
        resetMode();
    } else {
        waitTimer++;
    }
}

void debounce() {
    log("mode", "debounce");
    if ( pourButtonPressed() ) {
        startPour();
    } else {
        log("mode", "back to enabled");
        waitTimer++;
        mode = ENABLED;
    }
}

bool pourButtonPressed() {
    int val = digitalRead(btnBRB);
    return (val == LOW);
}

bool secretButtonPressed() {
    int val = digitalRead(btnSecret);
    return (val == LOW);
}

void startPour() {
    log("pour", "started");
    digitalWrite(productRelay, HIGH);
    mode = POURING;
    pouring = 0;
}

void pour() {
    pouring++;
    if ( pouring > pourTime ) {
        completePour();
    }
}

void completePour() {
    log("pour", "ended");
    resetMode();
}

// External Functions
int nitroCMD(String command) {
    log("nitroCmd", command);
    if ( mode != IDLE ) {
        return BUSY;
    } else if ( mode == IDLE ) {
        enable();
        return OK;
    }
    return ERROR;
}

void log(String label, String value) {
    return;
    Particle.publish(label, value);
}

without the quotes of course

Hi @nitroJames

I reformatted your code using the C/C++ formating directives with grave accent that look like this:

 ```cpp
   code here

Can you post the compiler error output?

Have you tried adding a few blank lines at the start of your code?  The preprocessor may be having hard time.

You are calling Particle.publish() from inside a a Particle.function() via your log function.  I don't think that is a good practice in general since you have not let the cloud handling code acknowledge the function and return a value when you are trying to publish.  A better way is the set a flag in the Particle.function that sends the publish once control returns to loop().  That is clearly not your compiler problem but I wanted to mention it.
In file included from ../services/inc/debug.h:1:0,
                 from ../wiring/inc/spark_wiring.h:36,
                 from ./inc/application.h:36,
                 from stellafreepour-v1.cpp:14:
../services/inc/service_debug.h:116:0: warning: "ERROR" redefined [enabled by default]
 #define ERROR(fmt, ...)
 ^
stellafreepour-v1.cpp:10:0: note: this is the location of the previous definition
 #define ERROR    -1
 ^
stellafreepour-v1.cpp:10:18: error: expected identifier before '-' token
 #define ERROR    -1
                  ^

../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include/stm32f2xx.h:288:15: note: in expansion of macro 'ERROR'
 typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
               ^
stellafreepour-v1.cpp:10:18: error: expected '}' before '-' token
 #define ERROR    -1
                  ^

../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include/stm32f2xx.h:288:15: note: in expansion of macro 'ERROR'
 typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
               ^
stellafreepour-v1.cpp:10:18: error: expected unqualified-id before '-' token
 #define ERROR    -1
                  ^

../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include/stm32f2xx.h:288:15: note: in expansion of macro 'ERROR'
 typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
               ^
In file included from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/platform_config.h:41:0,
                 from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/hw_config.h:32,
                 from ../hal/src/stm32f2xx/platform_headers.h:17,
                 from ./inc/application.h:32,
                 from stellafreepour-v1.cpp:14:
../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include/stm32f2xx.h:288:44: error: 'ErrorStatus' does not name a type
 typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
                                            ^

In file included from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/stm32f2xx_conf.h:38:0,
                 from ../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include/stm32f2xx.h:6924,
                 from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/platform_config.h:41,
                 from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/hw_config.h:32,
                 from ../hal/src/stm32f2xx/platform_headers.h:17,
                 from ./inc/application.h:32,
                 from stellafreepour-v1.cpp:14:
../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_cryp.h:276:1: error: 'ErrorStatus' does not name a type
 ErrorStatus CRYP_SaveContext(CRYP_Context* CRYP_ContextSave,
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_cryp.h:289:1: error: 'ErrorStatus' does not name a type
 ErrorStatus CRYP_AES_ECB(uint8_t Mode,
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_cryp.h:294:1: error: 'ErrorStatus' does not name a type
 ErrorStatus CRYP_AES_CBC(uint8_t Mode,
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_cryp.h:300:1: error: 'ErrorStatus' does not name a type
 ErrorStatus CRYP_AES_CTR(uint8_t Mode,
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_cryp.h:307:1: error: 'ErrorStatus' does not name a type
 ErrorStatus CRYP_TDES_ECB(uint8_t Mode,
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_cryp.h:312:1: error: 'ErrorStatus' does not name a type
 ErrorStatus CRYP_TDES_CBC(uint8_t Mode,
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_cryp.h:319:1: error: 'ErrorStatus' does not name a type
 ErrorStatus CRYP_DES_ECB(uint8_t Mode,
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_cryp.h:324:1: error: 'ErrorStatus' does not name a type
 ErrorStatus CRYP_DES_CBC(uint8_t Mode,
 ^

In file included from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/stm32f2xx_conf.h:46:0,
                 from ../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include/stm32f2xx.h:6924,
                 from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/platform_config.h:41,
                 from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/hw_config.h:32,
                 from ../hal/src/stm32f2xx/platform_headers.h:17,
                 from ./inc/application.h:32,
                 from stellafreepour-v1.cpp:14:
../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_hash.h:225:1: error: 'ErrorStatus' does not name a type
 ErrorStatus HASH_SHA1(uint8_t *Input, uint32_t Ilen, uint8_t Output[20]);
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_hash.h:226:1: error: 'ErrorStatus' does not name a type
 ErrorStatus HMAC_SHA1(uint8_t *Key, uint32_t Keylen,
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_hash.h:231:1: error: 'ErrorStatus' does not name a type
 ErrorStatus HASH_MD5(uint8_t *Input, uint32_t Ilen, uint8_t Output[16]);
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_hash.h:232:1: error: 'ErrorStatus' does not name a type
 ErrorStatus HMAC_MD5(uint8_t *Key, uint32_t Keylen,
 ^

In file included from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/stm32f2xx_conf.h:48:0,
                 from ../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include/stm32f2xx.h:6924,
                 from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/platform_config.h:41,
                 from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/hw_config.h:32,
                 from ../hal/src/stm32f2xx/platform_headers.h:17,
                 from ./inc/application.h:32,
                 from stellafreepour-v1.cpp:14:
../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_i2c.h:665:1: error: 'ErrorStatus' does not name a type
 ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, uint32_t I2C_EVENT);
 ^

In file included from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/stm32f2xx_conf.h:51:0,
                 from ../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include/stm32f2xx.h:6924,
                 from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/platform_config.h:41,
                 from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/hw_config.h:32,
                 from ../hal/src/stm32f2xx/platform_headers.h:17,
                 from ./inc/application.h:32,
                 from stellafreepour-v1.cpp:14:
../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_rcc.h:447:1: error: 'ErrorStatus' does not name a type
 ErrorStatus RCC_WaitForHSEStartUp(void);
 ^

In file included from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/stm32f2xx_conf.h:53:0,
                 from ../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include/stm32f2xx.h:6924,
                 from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/platform_config.h:41,
                 from ../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/hw_config.h:32,
                 from ../hal/src/stm32f2xx/platform_headers.h:17,
                 from ./inc/application.h:32,
                 from stellafreepour-v1.cpp:14:
../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_rtc.h:567:1: error: 'ErrorStatus' does not name a type
 ErrorStatus RTC_DeInit(void);
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_rtc.h:570:1: error: 'ErrorStatus' does not name a type
 ErrorStatus RTC_Init(RTC_InitTypeDef* RTC_InitStruct);
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_rtc.h:573:1: error: 'ErrorStatus' does not name a type
 ErrorStatus RTC_EnterInitMode(void);
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_rtc.h:575:1: error: 'ErrorStatus' does not name a type
 ErrorStatus RTC_WaitForSynchro(void);
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_rtc.h:576:1: error: 'ErrorStatus' does not name a type
 ErrorStatus RTC_RefClockCmd(FunctionalState NewState);
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_rtc.h:579:1: error: 'ErrorStatus' does not name a type
 ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct);
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_rtc.h:582:1: error: 'ErrorStatus' does not name a type
 ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct);
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_rtc.h:590:1: error: 'ErrorStatus' does not name a type
 ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState);
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_rtc.h:596:1: error: 'ErrorStatus' does not name a type
 ErrorStatus RTC_WakeUpCmd(FunctionalState NewState);
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_rtc.h:606:1: error: 'ErrorStatus' does not name a type
 ErrorStatus RTC_CoarseCalibConfig(uint32_t RTC_CalibSign, uint32_t Value);
 ^

../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_rtc.h:607:1: error: 'ErrorStatus' does not name a type
 ErrorStatus RTC_CoarseCalibCmd(FunctionalState NewState);
 ^

In file included from ./inc/application.h:32:0,
                 from stellafreepour-v1.cpp:14:
../hal/src/stm32f2xx/platform_headers.h:25:1: error: expected declaration before '}' token
 }
 ^

make[1]: *** [../build/target/user/platform-10stellafreepour-v1.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.

OK so you redefined the #define for ERROR and the rest of the code that needs to get compiled along with your code doesn’t like that. If you change yours to MYERROR or somesuch, it should fix it. Another approach would be to #undef ERROR at the bottom of your file.

I don’t know why you are seeing this now and not in the past.

For the formatting, the three grave accents ``` need to have their own line with nothing else to work.
And for your code, instead of these defines

#define IDLE      0
#define ENABLED   1
#define DEBOUNCE  2
#define POURING   3
#define COMPLETED 4

I’d rathet use an enum

enum Modes
{ mIDLE
, mENABLED
, mDEBOUNCE
, mPOURING   
, mCOMPLETED
, mERROR = -1
};

#defined should always be used very sparingly and the names should be as unique as possible, not to interfere with other commonly used terms.

If I remove that line of code, I still get errors. Something changed. I’m a Rubyist, not a C++ guy, so I am probably doing lots of things that aren’t smart. I appreciate your comments and will take them to heart.

All, Thanks for the comments and contributions! I implemented the enum and renamed some of the #defined names and the code compiles now. Tis a mystery why this problem didn’t appear before now. Now I have to go test to make sure the code actually works now that it compiles!

All better now.

3 Likes