Wire.h not found on arduino giga M4 core

Hi,
I'm trying to compile a test program that will read the USB stick on the M4 core to play a WAV file. I have been able to do it successfully on the M7 core but when compiled to the M4 core the error Wire.h no such file or directory occurs.

C:\Users\zawi\iCloudDrive\test\USB\M4\M4.ino:1:10: fatal error: Wire.h: No such file or directory
 #include <RPC.h>
          ^~~~~~~ 
compilation terminated.

exit status 1

Compilation error: Wire.h: No such file or directory

The code on the two different cores is:

M7:

#include <RPC.h>
#include <Wire.h>
void setup() {
  // put your setup code here, to run once:
  RPC.begin();
}

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

}

M4:

#include <Wire.h>
#include <Arduino_AdvancedAnalog.h>
#include <DigitalOut.h>
#include <Arduino_USBHostMbed5.h>
#include <FATFileSystem.h>
#include <RPC.h>





int sample_size = 0;
int samples_count = 0;


void music(){
  /* Enable power for HOST USB connector. */
  pinMode(PA_15, OUTPUT);
  digitalWrite(PA_15, HIGH);
  while (!msd.connect()) delay(100);//waiting for usb to be connected to usb port

  RPC.println("M4 - Mounting USB device ...");
  int const rc_mount = usb.mount(&msd);
  if (rc_mount)
  {
    RPC.print("M4 - Error mounting USB device ");
    RPC.println(rc_mount);
    return;
  }

  RPC.println("M4 - Opening audio file ...");

  /* 16-bit PCM Mono 16kHz realigned noise reduction */
  file = fopen("/USB_DRIVE/AUDIO_SAMPLE.wav", "rb");
  if (file == nullptr)
  {
    RPC.print("M4 - Error opening audio file: ");
    RPC.println(strerror(errno));
    return;
  }

  SRPC.println("M4 - Reading audio header ...");
  struct wav_header_t
  {
    char chunkID[4]; //"RIFF" = 0x46464952
    unsigned long chunkSize; //28 [+ sizeof(wExtraFormatBytes) + wExtraFormatBytes] + sum(sizeof(chunk.id) + sizeof(chunk.size) + chunk.size)
    char format[4]; //"WAVE" = 0x45564157
    char subchunk1ID[4]; //"fmt " = 0x20746D66
    unsigned long subchunk1Size; //16 [+ sizeof(wExtraFormatBytes) + wExtraFormatBytes]
    unsigned short audioFormat;
    unsigned short numChannels;
    unsigned long sampleRate;
    unsigned long byteRate;
    unsigned short blockAlign;
    unsigned short bitsPerSample;
  };

  wav_header_t header;
  fread(&header, sizeof(header), 1, file);

  RPC.println("WAV File Header read:");
  char msg[64] = {0};
  snprintf(msg, sizeof(msg), "File Type: %s", header.chunkID);
  RPC.println(msg);
  snprintf(msg, sizeof(msg), "File Size: %ld", header.chunkSize);
  RPC.println(msg);
  snprintf(msg, sizeof(msg), "WAV Marker: %s", header.format);
  RPC.println(msg);
  snprintf(msg, sizeof(msg), "Format Name: %s", header.subchunk1ID);
  RPC.println(msg);
  snprintf(msg, sizeof(msg), "Format Length: %ld", header.subchunk1Size);
  RPC.println(msg);
  snprintf(msg, sizeof(msg), "Format Type: %hd", header.audioFormat);
  RPC.println(msg);
  snprintf(msg, sizeof(msg), "Number of Channels: %hd", header.numChannels);
  RPC.println(msg);
  snprintf(msg, sizeof(msg), "Sample Rate: %ld", header.sampleRate);
  RPC.println(msg);
  snprintf(msg, sizeof(msg), "Sample Rate * Bits/Sample * Channels / 8: %ld", header.byteRate);
  RPC.println(msg);
  snprintf(msg, sizeof(msg), "Bits per Sample * Channels / 8: %hd", header.blockAlign);
  RPC.println(msg);
  snprintf(msg, sizeof(msg), "Bits per Sample: %hd", header.bitsPerSample);
  RPC.println(msg);

  /* Find the data section of the WAV file. */
  struct chunk_t
  {
    char ID[4];
    unsigned long size;
  };

  chunk_t chunk;
  snprintf(msg, sizeof(msg), "id\t" "size");
  RPC.println(msg);
  /* Find data chunk. */
  while (true)
  {
    fread(&chunk, sizeof(chunk), 1, file);
    snprintf(msg, sizeof(msg), "%c%c%c%c\t" "%li", chunk.ID[0], chunk.ID[1], chunk.ID[2], chunk.ID[3], chunk.size);
    RPC.println(msg);
    if (*(unsigned int *) &chunk.ID == 0x61746164)
      break;
    /* Skip chunk data bytes. */
    fseek(file, chunk.size, SEEK_CUR);
  }

  /* Determine number of samples. */
  sample_size = header.bitsPerSample / 8;
  samples_count = chunk.size * 8 / header.bitsPerSample;
  snprintf(msg, sizeof(msg), "Sample size = %i", sample_size); Serial.println(msg);
  snprintf(msg, sizeof(msg), "Samples count = %i", samples_count); Serial.println(msg);

  /* Configure the advanced DAC. */
  if (!dac1.begin(AN_RESOLUTION_12, header.sampleRate, 256, 16))
  {
    RPC.println("Failed to start DAC1 !");
    return;
  }
}

void setup() {
  RPC.begin();
  RPC.println("M4 CORE BOOTED");

  //music player startup procedure
  AdvancedDAC dac1(A12);

  USBHostMSD msd;
  mbed::FATFileSystem usb("USB_DRIVE");

  FILE * file = nullptr;

}

void loop() {

}

The minimal sketch:

#include <Wire.h>
#include <RPC.h>

int sample_size = 0;
int samples_count = 0;

void setup() {
  RPC.begin();
  Wire.begin();
  RPC.println("M4 CORE BOOTED");
}

void loop() {
}

Does compile for the M4 of the Giga.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.