Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Kconfig.sof
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ rsource "Kconfig.xtos"

rsource "src/Kconfig"

if ZEPHYR_SOF_MODULE
rsource "Kconfig.zephyr-log"
endif
rsource "Kconfig.zephyr-log"

menu "Debug"

Expand Down
33 changes: 32 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,42 @@ endif()
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
project(sample_sof)

if(NOT ZEPHYR_SOF_MODULE)
add_subdirectory(../zephyr sof_zephyr)
endif()

target_sources(app PRIVATE
src/main.c
)

target_sources_ifdef(CONFIG_USB_DEVICE_STACK_NEXT app PRIVATE
src/usbd_init.c
)

zephyr_library_include_directories(app PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../src/arch/xtensa/include
${CMAKE_CURRENT_SOURCE_DIR}/../src/include
)

if(CONFIG_XTENSA)
zephyr_library_include_directories(app PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../src/arch/xtensa/include
)
endif()

if(CONFIG_SOF_FULL_ZEPHYR_APPLICATION AND NOT CONFIG_XTENSA)
target_include_directories(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/../zephyr/include
${CMAKE_CURRENT_SOURCE_DIR}/../src/platform/${PLATFORM}/include
${PROJECT_BINARY_DIR}/include/generated
)

target_link_libraries(app PRIVATE SOF -Wl,--start-group modules_sof sof_kernel -Wl,--end-group)
if(TARGET uuid_reg_h)
add_dependencies(app uuid_reg_h modules_sof sof_kernel)
endif()
endif()

if(COMMAND sof_append_relative_path_definitions)
sof_append_relative_path_definitions(app)
endif()
5 changes: 5 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ choice COMPILER_CODEGEN_VLIW
endchoice

source "Kconfig.zephyr"
osource "samples/subsys/usb/common/Kconfig.sample_usbd"

if !ZEPHYR_SOF_MODULE
rsource "../zephyr/Kconfig"
endif

if SOC_FAMILY_INTEL_ADSP
rsource "boards/intel_adsp/Kconfig.defconfig"
Expand Down
88 changes: 88 additions & 0 deletions app/boards/teensy41.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Target Platform & SOF Core

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is too large, all the zephyr changes should go to zephyr, this can go to my fork atm and be referenced viw a local west url in this pr.

CONFIG_PLATFORM_TEENSY41=y
CONFIG_SOF_FULL_ZEPHYR_APPLICATION=y
CONFIG_IPC_MAJOR_4=y
CONFIG_COMP_BASEFW_IPC4=n
CONFIG_CROSS_CORE_STREAM=n
CONFIG_STATIC_PIPELINE=y
CONFIG_ZEPHYR_NATIVE_DRIVERS=y
CONFIG_SYS_HEAP_BIG_ONLY=y
CONFIG_BUILD_OUTPUT_HEX=y
CONFIG_BUILD_OUTPUT_BIN=y

# Zephyr DAI & DMA Drivers for NXP i.MX RT1062
CONFIG_DAI=y
CONFIG_DAI_NXP_SAI=y
CONFIG_DAI_NXP_SPDIF=y
CONFIG_PINCTRL=y
CONFIG_DMA=y
CONFIG_DMA_MCUX_EDMA=y
CONFIG_DMA_TCD_QUEUE_SIZE=8
CONFIG_DMA_MCUX_USE_DTCM_FOR_DMA_DESCRIPTORS=n

# Audio Processing Modules & ARM SIMD Optimizations
CONFIG_COMP_VOLUME=y
CONFIG_VOLUME_ARM_SIMD=y
CONFIG_COMP_IIR=y
CONFIG_EQ_IIR_ARM_SIMD=y
CONFIG_FILTER_ARM_SIMD=y
CONFIG_COMP_FIR=y
CONFIG_COMP_DRC=y
CONFIG_DRC_ARM_SIMD=y
CONFIG_COMP_CROSSOVER=y
CONFIG_COMP_DCBLOCK=y
CONFIG_DCBLOCK_ARM_SIMD=y
CONFIG_COMP_MULTIBAND_DRC=y
CONFIG_COMP_TDFB=y
CONFIG_COMP_USB_AUDIO=y
CONFIG_COMP_LEVEL_MULTIPLIER=y
CONFIG_COMP_SEL=y
CONFIG_COMP_MUX=y
CONFIG_COMP_MIXIN_MIXOUT=y
CONFIG_MIXIN_MIXOUT_ARM_SIMD=y
CONFIG_FORMAT_CONVERT_ARM_SIMD=y

# USB Device Stack Next & UAC2 Class
CONFIG_USB_DEVICE_STACK_NEXT=y
CONFIG_CDC_ACM_SERIAL_INITIALIZE_AT_BOOT=n
CONFIG_USBD_AUDIO2_CLASS=y
CONFIG_UDC_ENABLE_SOF=y
CONFIG_UDC_NXP_EHCI=y
CONFIG_UDC_BUF_COUNT=64
CONFIG_UDC_BUF_POOL_SIZE=16384
CONFIG_UDC_WORKQUEUE_PRIORITY=-10
CONFIG_UDC_NXP_EVENT_COUNT=16
CONFIG_UDC_WORKQUEUE_STACK_SIZE=2048
CONFIG_LL_THREAD_PRIORITY=0

# USB Device Identification
CONFIG_SAMPLE_USBD_VID=0x16C0
CONFIG_SAMPLE_USBD_PID=0x04D2
CONFIG_SAMPLE_USBD_MANUFACTURER="PJRC"
CONFIG_SAMPLE_USBD_PRODUCT="SOF Teensy 4.1 Audio A"

# System Resources & Memory
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_USBD_THREAD_STACK_SIZE=4096
CONFIG_ISR_STACK_SIZE=4096
CONFIG_HW_STACK_PROTECTION=n
CONFIG_HEAP_MEM_POOL_SIZE=8192
CONFIG_TICKLESS_KERNEL=n
CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000

# Logging
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_MAX_LEVEL=4
CONFIG_SOF_LOG_LEVEL_INF=y
CONFIG_DAI_LOG_LEVEL_INF=y
CONFIG_USBD_UAC2_LOG_LEVEL_INF=y
CONFIG_UDC_DRIVER_LOG_LEVEL_INF=y
CONFIG_LOG_MODE_DEFERRED=y
CONFIG_LOG_BUFFER_SIZE=4096
CONFIG_LOG_MODE_OVERFLOW=y
CONFIG_LOG_BACKEND_UART=n
CONFIG_LOG_PROCESS_THREAD=n
CONFIG_EARLY_CONSOLE=n
CONFIG_SCHEDULE_LL_STATS_LOG=n
99 changes: 99 additions & 0 deletions app/boards/teensy41.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2026 Sound Open Firmware (SOF) Project
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/dt-bindings/usb/audio.h>

/ {
uac2_card: usb_audio2 {
compatible = "zephyr,uac2";
status = "okay";
full-speed;
high-speed;
audio-function = <AUDIO_FUNCTION_IO_BOX>;

uac_aclk: aclk {
compatible = "zephyr,uac2-clock-source";
clock-type = "internal-programmable";
frequency-control = "host-programmable";
sampling-frequencies = <48000>;
sof-synchronized;
};

/* Playback from Host (ISO OUT) */
i2s_out_terminal: i2s_out_terminal {
compatible = "zephyr,uac2-input-terminal";
clock-source = <&uac_aclk>;
terminal-type = <USB_TERMINAL_STREAMING>;
front-left;
front-right;
};

i2s_fu: i2s_fu {
compatible = "zephyr,uac2-feature-unit";
data-source = <&i2s_out_terminal>;
mute-control = "host-programmable";
volume-control = "host-programmable";
};

i2s_speaker: i2s_speaker {
compatible = "zephyr,uac2-output-terminal";
data-source = <&i2s_fu>;
clock-source = <&uac_aclk>;
terminal-type = <OUTPUT_TERMINAL_SPEAKER>;
assoc-terminal = <&i2s_mic>;
};

/* Capture to Host (ISO IN) */
i2s_mic: i2s_mic {
compatible = "zephyr,uac2-input-terminal";
clock-source = <&uac_aclk>;
terminal-type = <INPUT_TERMINAL_MICROPHONE>;
front-left;
front-right;
};

i2s_in_fu: i2s_in_fu {
compatible = "zephyr,uac2-feature-unit";
data-source = <&i2s_mic>;
mute-control = "host-programmable";
volume-control = "host-programmable";
};

i2s_in_terminal: i2s_in_terminal {
compatible = "zephyr,uac2-output-terminal";
data-source = <&i2s_in_fu>;
clock-source = <&uac_aclk>;
terminal-type = <USB_TERMINAL_STREAMING>;
};

/* Audio Streaming Interfaces */
as_i2s_out: as_i2s_out {
compatible = "zephyr,uac2-audio-streaming";
linked-terminal = <&i2s_out_terminal>;
subslot-size = <2>;
bit-resolution = <16>;
};

as_i2s_in: as_i2s_in {
compatible = "zephyr,uac2-audio-streaming";
linked-terminal = <&i2s_in_terminal>;
subslot-size = <2>;
bit-resolution = <16>;
};
};
};

&flexcan1 {
status = "disabled";
};

&sai1_dai {
status = "okay";
};

&spdif {
status = "okay";
};
34 changes: 34 additions & 0 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
#include <sof/boot_test.h>
#include <zephyr/logging/log.h>

#if defined(CONFIG_PLATFORM_TEENSY41)
#include <zephyr/device.h>
#include <zephyr/usb/usbd.h>
#include <zephyr/usb/class/usbd_uac2.h>
#include <sample_usbd.h>
#include <sof/platform.h>
#include <sof/audio/pipeline/static_pipeline.h>
#endif

LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG);

/* define qemu boot tests if any qemu target is defined, add targets to end */
Expand Down Expand Up @@ -41,6 +50,31 @@ static int sof_app_main(void)

LOG_INF("SOF initialized");

#if defined(CONFIG_PLATFORM_TEENSY41)
ret = sof_static_topology_init(&g_teensy41_static_topology);
if (ret < 0) {
LOG_ERR("Static topology initialization failed: %d", ret);
return ret;
}

const struct device *uac2_dev = DEVICE_DT_GET_ONE(zephyr_uac2);

if (device_is_ready(uac2_dev)) {
usbd_uac2_set_ops(uac2_dev, sof_static_uac2_get_ops(), NULL);
} else {
LOG_ERR("UAC2 device not ready");
}

struct usbd_context *sample_usbd = sample_usbd_init_device(NULL);

if (sample_usbd) {
usbd_enable(sample_usbd);
LOG_INF("SOF USB UAC2 device and static pipelines started");
} else {
LOG_ERR("Failed to initialize USB device context");
}
#endif

#ifdef CONFIG_ARCH_POSIX_LIBFUZZER
/* Workaround for an apparent timing bug in libfuzzer+asan.
* If the initial/main thread is allowed to return, ASAN will
Expand Down
16 changes: 16 additions & 0 deletions app/src/sample_usbd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_SAMPLES_SUBSYS_USB_COMMON_SAMPLE_USBD_H
#define ZEPHYR_SAMPLES_SUBSYS_USB_COMMON_SAMPLE_USBD_H

#include <stdint.h>
#include <zephyr/usb/usbd.h>

struct usbd_context *sample_usbd_init_device(usbd_msg_cb_t msg_cb);
struct usbd_context *sample_usbd_setup_device(usbd_msg_cb_t msg_cb);

#endif /* ZEPHYR_SAMPLES_SUBSYS_USB_COMMON_SAMPLE_USBD_H */
Loading
Loading