Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timing issue on GIGA on M4 #726

Closed
pedromsousalima opened this issue Sep 11, 2023 · 1 comment · Fixed by #741
Closed

Timing issue on GIGA on M4 #726

pedromsousalima opened this issue Sep 11, 2023 · 1 comment · Fixed by #741

Comments

@pedromsousalima
Copy link

pedromsousalima commented Sep 11, 2023

It was noticed that the GIGA is inconsistent tracking time across different cores. This was seen on multiple GIGA boards until now we have found no exception.
When using functions like micros() and tracking time on both cores separately a significant discrepancy is noticeable. Specifically, the M7 core seems to be ticking quicker than real-time.
This was not replicable on Portenta boards.

@pedromsousalima pedromsousalima changed the title Timing issue on GIGA between M4 and M7 Timing issue on GIGA on M7 Sep 11, 2023
@facchinm facchinm changed the title Timing issue on GIGA on M7 Timing issue on GIGA on M4 Oct 23, 2023
@facchinm
Copy link
Member

@pedromsousalima I investigated the issue and indeed there's a problem lurking in the M4 "variant sharing".
Basically, all boards with M4 coprocessor share the same variant but GIGA is the only one with a 16Mhz crystal instead than a 25MHz.
This explains the micros() difference, since the timebase is extracted by HAL_RCC_GetSysClockFreq() which in fact always returns 25000000.
I'll try to find a workaround that doesn't hurt the whole system.

In the meantime, let me suggest to avoid adding links to internal documentation when posting on public github, since they are useless for people that may want to help in the investigation.

For reference, here's the code to show the issue

#include "Arduino.h"
#include "SerialRPC.h"

#ifdef CORE_CM4
void setup() {
  SerialRPC.begin(115200);
}

void loop() {
  SerialRPC.println(millis());
  SerialRPC.println(micros());
  delay(1000);
}
#endif

#ifdef CORE_CM7
void setup() {
  Serial.begin(115200);
  SerialRPC.begin();
}

void loop() {
  String data = "";
  while (SerialRPC.available()) {
    data += (char)SerialRPC.read();
  }
  if (data != "") {
    Serial.write(data.c_str(), data.length());
  }
  data = "";
  while (Serial.available()) {
    data += (char)Serial.read();
  }
  if (data != "") {
    SerialRPC.write(data.c_str(), data.length());
  }
}
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants