arduino / ArduinoCore-mbed

347 stars 203 forks source link

BUG: (possible bug) does PORTENTA_H7_M4 work as an if define? #511

Closed hpssjellis closed 2 years ago

hpssjellis commented 2 years ago

Try this code on both cores of the PortentaH7? The blue LED should flash and serial monitor should send info using RPC from M4 to M7, BUT when I change

   #if defined(PORTENTA_H7_M4) || defined(CORE_CM4)

to

   #if defined(PORTENTA_H7_M4) || defined(NOT_CORE_CM4)

it doesn't work, even though PORTENTA_H7_M4 is defined in the boards.txt file.

Can someone confirm this bug @sebromero perhaps and does anyone have a solution? Sketch following works on both cores.


#include "RPC.h"  // comes with the mbed board installation

void setup() {
   #if defined(PORTENTA_H7_M7) || defined(CORE_CM7)
      bootM4(); 
      Serial.begin(115200);
   #endif 

   RPC.begin();
   pinMode(LEDB, OUTPUT);
   digitalWrite(LEDB, HIGH); // on board Blue LED off to start
}

void loop() { 
   #if defined(PORTENTA_H7_M7) || defined(CORE_CM7)
      while (RPC.available()) {
         Serial.write(RPC.read()); 
      }  
   #endif 

   #if defined(PORTENTA_H7_M4) || defined(CORE_CM4)  // change CORE_CM4 to NOT_CORE_CM4
     RPC.println("From Portenta M4 Core, A0: "+String(analogRead(A0)) ); 
     digitalWrite(LEDB, !digitalRead(LEDB)); //flip flop the blue LED
     delay(500);
   #endif 
}
per1234 commented 2 years ago

Hi @hpssjellis. The board identification macros are ARDUINO_PORTENTA_H7_M4 and ARDUINO_PORTENTA_H7_M7 (note the ARDUINO_ "namespace" prefix on the macros).

This is defined by the combination of the build.board property: https://github.com/arduino/ArduinoCore-mbed/blob/0fc6d7417ff8d648258bf4b1508759f300ae3ab2/boards.txt#L168

https://github.com/arduino/ArduinoCore-mbed/blob/0fc6d7417ff8d648258bf4b1508759f300ae3ab2/boards.txt#L77

in combination with the -D flag in the compilation recipes:

https://github.com/arduino/ArduinoCore-mbed/blob/0fc6d7417ff8d648258bf4b1508759f300ae3ab2/platform.txt#L76

hpssjellis commented 2 years ago

LOL, thanks @per1234

That explains a lot.

This is now closed.