USB Serial Connection Hanging on CODEC Loopback Tests

Hello,

I received my Daisy Seed recently and have a project planned, and wanted to first test the CODEC completely, so thought to feed a DAC output to the audio in and see the data over USB serial. Then I could plot in python or something. On “blink” programs or simpler ones, I am able to flash, then connect over PuTTY and see the usb serial output. However, once I integrate the audio functionality, when I attempt to connect over PuTTY, the program seems to hang. I click “Open” in the software, and I don’t get an error message, but the window just goes away. Minutes later I get a “the semaphore timeout period has expired” message. Below is my code, I see the board get to the 3 LED blinks, but then nothing. I have attempted to debug with AI as I am not the most experienced programmer, thus why it looks the way it does. Thank you, any help is appreciated.

‘’'#include “daisy_seed.h”
#include “daisysp.h”
#include
#include

using namespace daisy;
using namespace daisysp;

// Global objects
DaisySeed hw;
Oscillator osc;

// Configuration constants
constexpr float SAMPLE_RATE = 48000.0f;
constexpr float TEST_FREQ = 1000.0f; // 1kHz test signal
constexpr float AMPLITUDE = 0.5f; // 0.5 for 1Vpp
constexpr size_t BUFFER_SIZE = 512; // Buffer for serial transmission

// Buffers for storing samples
float input_buffer[BUFFER_SIZE];
float output_buffer[BUFFER_SIZE];
volatile size_t buffer_index = 0;
volatile bool buffer_ready = false;

// Timing variables
uint32_t last_serial_time = 0;
constexpr uint32_t SERIAL_INTERVAL_MS = 2000; // Send data every 2 seconds

// Audio callback - your original working callback
void AudioCallback(AudioHandle::InputBuffer in,
AudioHandle::OutputBuffer out,
size_t size)
{
for (size_t i = 0; i < size; i++)
{
// Generate test signal (sine wave)
float sig = osc.Process();

    // Apply amplitude scaling
    sig *= AMPLITUDE;
    
    // Output to both channels
    out[0][i] = sig;
    out[1][i] = sig;
    
    // Read input from both channels (average them)
    float input_sample = (in[0][i] + in[1][i]) * 0.5f;
    
    // Store samples in buffer
    if (!buffer_ready && buffer_index < BUFFER_SIZE)
    {
        output_buffer[buffer_index] = sig;
        input_buffer[buffer_index] = input_sample;
        buffer_index++;
        
        if (buffer_index >= BUFFER_SIZE)
        {
            buffer_ready = true;
            buffer_index = 0;
        }
    }
}

}

// Function to send data over USB serial
void SendSerialData()
{
if (!buffer_ready)
return;

// Send header
hw.PrintLine("DATA_START");
hw.PrintLine("SIZE:%d", BUFFER_SIZE);
hw.PrintLine("SAMPLE_RATE:%.1f", SAMPLE_RATE);
hw.PrintLine("TEST_FREQ:%.1f", TEST_FREQ);
hw.PrintLine("AMPLITUDE:%.3f", AMPLITUDE);

// Send first 64 samples to avoid overwhelming serial
for (size_t i = 0; i < 64 && i < BUFFER_SIZE; i++)
{
    // Convert to voltage representation (assuming ±1.0 = ±2V)
    float out_voltage = output_buffer[i] * 2.0f;
    float in_voltage = input_buffer[i] * 2.0f;
    
    hw.PrintLine("%d,%.4f,%.4f", (int)i, out_voltage, in_voltage);
}

hw.PrintLine("DATA_END");
buffer_ready = false; // Reset for next buffer

}

int main(void)
{
// Initialize hardware
hw.Configure();
hw.Init();

// STEP 1: Initialize AUDIO FIRST (we know this works)
hw.SetAudioBlockSize(256); // Large buffer for stability

// Configure the oscillator
osc.Init(SAMPLE_RATE);
osc.SetWaveform(Oscillator::WAVE_SIN);
osc.SetFreq(TEST_FREQ);
osc.SetAmp(1.0f);

// Start audio processing
hw.StartAudio(AudioCallback);

// LED blink to show audio is running (like your test)
for(int i = 0; i < 3; i++) {
    hw.SetLed(true);
    System::Delay(200);
    hw.SetLed(false);
    System::Delay(200);
}

// STEP 2: Initialize SERIAL SECOND (after audio is stable)
// Give audio system time to stabilize
System::Delay(2000);

// Start serial - non-blocking first
hw.StartLog(false);
System::Delay(1000);

// Send initial messages (these will be buffered until connection)
hw.PrintLine("=================================");
hw.PrintLine("Daisy Seed Audio Loopback Test");
hw.PrintLine("=================================");
hw.PrintLine("Audio system: RUNNING");
hw.PrintLine("Serial system: READY");
hw.PrintLine("Test Signal: %.1f Hz Sine Wave", TEST_FREQ);
hw.PrintLine("Amplitude: %.1f Vpp", AMPLITUDE * 4.0f);
hw.PrintLine("Sample Rate: %.1f Hz", SAMPLE_RATE);
hw.PrintLine("Buffer Size: %d samples", BUFFER_SIZE);
hw.PrintLine("Audio Block Size: 256 samples");
hw.PrintLine("---------------------------------");
hw.PrintLine("Connect Audio Out to Audio In");
hw.PrintLine("Data will be sent every %d ms", SERIAL_INTERVAL_MS);
hw.PrintLine("Connect to serial monitor to see data");
hw.PrintLine("---------------------------------");

// Initialize timing
last_serial_time = System::GetNow();
uint32_t counter = 0;

// Main loop
while(1) 
{
    System::Delay(100);
    
    // Check if it's time to send serial data
    uint32_t current_time = System::GetNow();
    if (current_time - last_serial_time >= SERIAL_INTERVAL_MS)
    {
        const float time_s = current_time * 1.0e-3f;
        hw.PrintLine("");
        hw.PrintLine("=== Sample Set %u at %.2f seconds ===", counter, time_s);
        
        SendSerialData();
        
        last_serial_time = current_time;
        counter++;
    }
    
    // LED pattern: fast blink = both audio and serial working
    hw.SetLed(true);
    System::Delay(50);
    hw.SetLed(false);
    System::Delay(50);
}

}‘’’

Suggestion: use code tags around your code to maintain formatting.