OptaLite: issues with Serial.Print()

I am building my project using opta lites.
I am testing the multicore functionality, as I will drive the ethernet/Modbus from CM7 and input/outputs from CM4 using RPC between them.

To start building tests, I've written the following simple test code:
Core M7 boots the coprocessor, prints two lines on the serial when running the setup() and blinks led D0.

Core M4 just turns on Leds D2 and D3.

After programming both cores, Serial.println() is never seen in the serial console. LED_D0 is blinking, Leds D2-D3 are turned on. but the serial print is never written.

Any idea on what's missing here?

#ifdef CORE_CM4
void setup() {
  // put your setup code here, to run once:
  pinMode(LED_D2, OUTPUT);
  pinMode(LED_D3, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(LED_D2, HIGH);
  digitalWrite(LED_D3, HIGH);
}
#else
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println(" Main core booted. Booting Secondary core...");
  bootM4();
  Serial.println("Secondary core booted.");
}

void loop() {
  // put your main code here, to run repeatedly:
}
#endif

I'm not familiar with the Opta range of boards. I suspect that they have native USB in which case setup should be as below if you don't want to miss the first messages.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while(!Serial);
  Serial.println(" Main core booted. Booting Secondary core...");
  bootM4();
  Serial.println("Secondary core booted.");
}

while(!Serial); make the code wait till an application (e.g. Serial Monitor) opens a connection.

There might be a few pitfalls. E.g. closing serial monitor can bring your board to a near grinding halt because it can't get rid of the data (it's not like e.g. an Uno that just pumps the data out to nowhere). You can prevent that by checking if there is space to send data using Serial.availableForWrite)

1 Like