PlatformIO Community

Teensy 4.1 Audio.h

Hello,

i have a problem with building my project in VSCode and PlattformIO. I am using the Teensy Audio.h library to play a sound after some time. This code works under the Arduino IDE, but under VSCode i get some errors about multible definitions from the Audio.h library.

Here is my Code:

#include <TimeAlarms.h>
#include <Audio.h>

// Timer
#include <TimeLib.h>
#include <TimeAlarms.h>

const int chipSelect = BUILTIN_SDCARD;

static AudioPlaySdWav playWav1;
static AudioOutputI2S audioOutput;

static AudioConnection patchCord1(playWav1, 0, audioOutput, 0);
static AudioConnection patchCord2(playWav1, 1, audioOutput, 1);

IntervalTimer timer;
AlarmId id;

// Use these with the Teensy 3.5 & 3.6 SD card
#define SDCARD_CS_PIN BUILTIN_SDCARD
#define SDCARD_MOSI_PIN 11 // not actually used
#define SDCARD_SCK_PIN 13  // not actually used

void playFile(const char *filename)
{
  Serial.print("Playing file: ");
  Serial.println(filename);

  if (SD.exists("alert.wav"))
  {
    Serial.println("alert.wav exists.");
  }
  else
  {
    Serial.println("alert.wav doesn't exist.");
  }

  playWav1.play(filename);

  // A brief delay for the library read WAV info
  delay(25);

  // Simply wait for the file to finish playing.
  while (playWav1.isPlaying())
  {
    // uncomment these lines if you audio shield
    // has the optional volume pot soldered
    //float vol = analogRead(15);
    //vol = vol / 1024;
    // sgtl5000_1.volume(vol);
  }
}

void initAudio()
{
  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(10);

  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN)))
  {
    // stop here, but print a message repetitively
    while (1)
    {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  Serial.println("SD card ready");
  if (SD.exists("alert.wav"))
  {
    Serial.println("alert.wav exists.");
  }
  else
  {
    Serial.println("alert.wav doesn't exist.");
  }
}

void printDigits(int digits)
{
  Serial.print(":");
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void alarm()
{
  Serial.println("Alarm: alert.wav");
  playFile("alert.wav"); // filenames are always uppercase 8.3 format
}

void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
}

void initTimer()
{
  Serial.println("initTimer");
  timer.begin(digitalClockDisplay, 100000 * 10);
}

void initAlarm()
{
  Serial.println("initAlarm");
  setTime(8, 29, 0, 1, 1, 11);        // set time to Saturday 8:29:00am Jan 1 2011
  Alarm.alarmRepeat(8, 30, 0, alarm); // 5:45pm every day
  Alarm.timerRepeat(15, alarm);       // timer for every 15 seconds
}

void loop()
{
  Alarm.delay(1); // wait one second between clock display
}

void setup()
{
  Serial.begin(9600);
  while (!Serial)
    ; // wait for Arduino Serial Monitor

  initAudio();
  initAlarm();
  initTimer();
}

The Env:

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
lib_deps = 

The Build Log:

Processing teensy41 (platform: teensy; board: teensy41; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy41.html
PLATFORM: Teensy (4.13.1) > Teensy 4.1
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 7.75MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:
 - framework-arduinoteensy 1.154.0 (1.54)
 - tool-teensy 1.154.210805 (1.54)
 - toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 92 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Audio> 1.3
|   |-- <SerialFlash>
|   |   |-- <SPI> 1.0
|   |-- <SPI> 1.0
|   |-- <Wire> 1.0
|   |-- <SD> 2.0.0
|   |   |-- <SdFat> 2.0.5-beta.1
|   |   |   |-- <SPI> 1.0
|-- <TimeAlarms>
|   |-- <Time> 1.6.1
|-- <Time> 1.6.1
Building in release mode
Compiling .pio\build\teensy41\src\main.cpp.o
Linking .pio\build\teensy41\firmware.elf
.pio\build\teensy41\lib88d\libAudio.a(output_i2s.cpp.o): In function `set_arm_clock(unsigned long)':
output_i2s.cpp:(.text._Z13set_arm_clockm+0x0): multiple definition of `set_arm_clock(unsigned long)'
.pio\build\teensy41\src\main.cpp.o:main.cpp:(.text._Z13set_arm_clockm+0x0): first defined here
c:/users/n3ur0/.platformio/packages/toolchain-gccarmnoneeabi@1.50401.190816/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions  
.pio\build\teensy41\lib88d\libAudio.a(output_i2s.cpp.o):(.data.F_BUS_ACTUAL+0x0): multiple definition of `F_BUS_ACTUAL'
.pio\build\teensy41\src\main.cpp.o:(.data.F_BUS_ACTUAL+0x0): first defined here
.pio\build\teensy41\lib88d\libAudio.a(output_i2s.cpp.o):(.data.F_CPU_ACTUAL+0x0): multiple definition of `F_CPU_ACTUAL'
.pio\build\teensy41\src\main.cpp.o:(.data.F_CPU_ACTUAL+0x0): first defined here
.pio\build\teensy41\lib88d\libAudio.a(play_sd_wav.cpp.o): In function `set_arm_clock(unsigned long)':
play_sd_wav.cpp:(.text._Z13set_arm_clockm+0x0): multiple definition of `set_arm_clock(unsigned long)'
.pio\build\teensy41\src\main.cpp.o:main.cpp:(.text._Z13set_arm_clockm+0x0): first defined here
.pio\build\teensy41\lib88d\libAudio.a(play_sd_wav.cpp.o):(.data.F_BUS_ACTUAL+0x0): multiple definition of `F_BUS_ACTUAL'
.pio\build\teensy41\src\main.cpp.o:(.data.F_BUS_ACTUAL+0x0): first defined here
.pio\build\teensy41\lib88d\libAudio.a(play_sd_wav.cpp.o):(.data.F_CPU_ACTUAL+0x0): multiple definition of `F_CPU_ACTUAL'
.pio\build\teensy41\src\main.cpp.o:(.data.F_CPU_ACTUAL+0x0): first defined here
.pio\build\teensy41\libFrameworkArduino.a(AudioStream.cpp.o): In function `set_arm_clock(unsigned long)':
AudioStream.cpp:(.text._Z13set_arm_clockm+0x0): multiple definition of `set_arm_clock(unsigned long)'
.pio\build\teensy41\src\main.cpp.o:main.cpp:(.text._Z13set_arm_clockm+0x0): first defined here
.pio\build\teensy41\libFrameworkArduino.a(AudioStream.cpp.o):(.data.F_BUS_ACTUAL+0x0): multiple definition of `F_BUS_ACTUAL'
.pio\build\teensy41\src\main.cpp.o:(.data.F_BUS_ACTUAL+0x0): first defined here
.pio\build\teensy41\libFrameworkArduino.a(AudioStream.cpp.o):(.data.F_CPU_ACTUAL+0x0): multiple definition of `F_CPU_ACTUAL'
.pio\build\teensy41\src\main.cpp.o:(.data.F_CPU_ACTUAL+0x0): first defined here
.pio\build\teensy41\libFrameworkArduino.a(clockspeed.c.o):(.data.F_BUS_ACTUAL+0x0): multiple definition of `F_BUS_ACTUAL'
.pio\build\teensy41\src\main.cpp.o:(.data.F_BUS_ACTUAL+0x0): first defined here
.pio\build\teensy41\libFrameworkArduino.a(clockspeed.c.o):(.data.F_CPU_ACTUAL+0x0): multiple definition of `F_CPU_ACTUAL'
.pio\build\teensy41\src\main.cpp.o:(.data.F_CPU_ACTUAL+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\teensy41\firmware.elf] Error 1

Does anyone had a similar problem? Is there a possibility to fix this issue without editing the 3rd Party package?

Greetings

Ok, it looks like that the AudioStream.h includes the clockspeed.c library. There are definitions that are somehow defined in the startup.c and in the core_pins.h of the cores/teensy4.

When i comment out:
// #include "clockspeed.c"

It builds the project. Now i would test if the code stil runs on my teensy