Hello.
I am using vscode.
I added sdcard to broadcast_sink in the existing samples in applications/nrf5340_audio and checked the list with the serial monitor and wanted to check the playback, but since there is no device with Bluetooth function, pairing is not possible, so I created a new main.c and excluded the Bluetooth function and only added the part that reads the list in sdcard and plays the audio file in sdcard to test it.
Added CONFIG_SD_CARD_PLAYBACK=y, CONFIG_CONSOLE=y, CONFIG_SERIAL=y, CONFIG_SHELL=y to prj.conf. The prj.conf file is located in the applications/nRF5340_audio path.
vscode: V1.102.3
sdk: V3.0.2
Toolchain: V3.0.2

The image shows the build settings in vscode.
*---
The full build is attached as build.txt below.
* 작업 실행 중: nRF Connect: Generate config nrf5340_audio_dk/nrf5340/cpuapp for c:\ncs\v3.0.2\nrf\applications\nrf5340_audio Building nrf5340_audio C:\WINDOWS\system32\cmd.exe /d /s /c "west build --build-dir c:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build c:/ncs/v3.0.2/nrf/applications/nrf5340_audio --pristine --board nrf5340_audio_dk/nrf5340/cpuapp --sysbuild -- -DCONF_FILE=prj.conf -DBOARD_ROOT=c:/ncs/v3.0.2/nrf/applications/nrf5340_audio" -- west build: generating a build system Loading Zephyr module(s) (Zephyr base): sysbuild_default -- Found Python3: C:/ncs/toolchains/0b393f9e1b/opt/bin/python.exe (found suitable version "3.12.4", minimum required is "3.10") found components: Interpreter -- Cache files will be written to: C:/ncs/v3.0.2/zephyr/.cache -- Found west (found suitable version "1.2.0", minimum required is "0.14.0") -- Board: nrf5340_audio_dk, qualifiers: nrf5340/cpuapp Parsing c:/ncs/v3.0.2/nrf/applications/nrf5340_audio/Kconfig.sysbuild Loaded configuration 'C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/_sysbuild/empty.conf' Merged configuration 'C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/_sysbuild/empty.conf' Configuration saved to 'C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/zephyr/.config' Kconfig header saved to 'C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/_sysbuild/autoconf.h' -- *********************************** * Running CMake for nrf5340_audio * *********************************** Loading Zephyr default modules (Zephyr base). -- Application: C:/ncs/v3.0.2/nrf/applications/nrf5340_audio -- CMake version: 3.21.0 -- Found Python3: C:/ncs/toolchains/0b393f9e1b/opt/bin/python.exe (found suitable version "3.12.4", minimum required is "3.10") found components: Interpreter -- Cache files will be written to: C:/ncs/v3.0.2/zephyr/.cache -- Zephyr version: 4.0.99 (C:/ncs/v3.0.2/zephyr) -- Found west (found suitable version "1.2.0", minimum required is "0.14.0") -- Board: nrf5340_audio_dk, qualifiers: nrf5340/cpuapp -- Found host-tools: zephyr 0.17.0 (C:/ncs/toolchains/0b393f9e1b/opt/zephyr-sdk) -- Found toolchain: zephyr 0.17.0 (C:/ncs/toolchains/0b393f9e1b/opt/zephyr-sdk) -- Found Dtc: C:/ncs/toolchains/0b393f9e1b/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6") -- Found BOARD.dts: C:/ncs/v3.0.2/zephyr/boards/nordic/nrf5340_audio_dk/nrf5340_audio_dk_nrf5340_cpuapp.dts -- Generated zephyr.dts: C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/nrf5340_audio/zephyr/zephyr.dts -- Generated pickled edt: C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/nrf5340_audio/zephyr/edt.pickle -- Generated zephyr.dts: C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/nrf5340_audio/zephyr/zephyr.dts -- Generated devicetree_generated.h: C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/nrf5340_audio/zephyr/include/generated/zephyr/devicetree_generated.h -- Including generated dts.cmake file: C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/nrf5340_audio/zephyr/dts.cmake warning: Experimental symbol NRF5340_AUDIO is enabled. warning: Experimental symbol SD_CARD_PLAYBACK is enabled. Parsing C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/Kconfig Loaded configuration 'C:/ncs/v3.0.2/zephyr/boards/nordic/nrf5340_audio_dk/nrf5340_audio_dk_nrf5340_cpuapp_defconfig' Merged configuration 'C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/prj.conf' Merged configuration 'C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/nrf5340_audio/zephyr/.config.sysbuild' Configuration saved to 'C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/nrf5340_audio/zephyr/.config' Kconfig header saved to 'C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/nrf5340_audio/zephyr/include/generated/zephyr/autoconf.h' -- Found GnuLd: c:/ncs/toolchains/0b393f9e1b/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38") -- The C compiler identification is GNU 12.2.0 -- The CXX compiler identification is GNU 12.2.0 -- The ASM compiler identification is GNU -- Found assembler: C:/ncs/toolchains/0b393f9e1b/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe =========== Generating psa_crypto_config =============== Backup: CONFIG_MBEDTLS_PSA_CRYPTO_SPM: False Backup: CONFIG_MBEDTLS_PSA_CRYPTO_C: True Backup: CONFIG_MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER: False Backup: CONFIG_MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT: False Backup: CONFIG_MBEDTLS_THREADING: False Backup: CONFIG_MBEDTLS_THREADING_ALT: True =========== Checkpoint: backup =============== Restore: CONFIG_MBEDTLS_PSA_CRYPTO_SPM: False Restore: CONFIG_MBEDTLS_PSA_CRYPTO_C: True Restore: CONFIG_MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER: False Restore: CONFIG_MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT: False Restore: CONFIG_MBEDTLS_THREADING: False Restore: CONFIG_MBEDTLS_THREADING_ALT: True =========== End psa_crypto_config =============== =========== Generating psa_crypto_library_config =============== Backup: CONFIG_MBEDTLS_PSA_CRYPTO_C: True Backup: CONFIG_MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER: False Backup: CONFIG_MBEDTLS_PSA_CRYPTO_SPM: False Backup: CONFIG_MBEDTLS_USE_PSA_CRYPTO: True Backup: CONFIG_MBEDTLS_PLATFORM_PRINTF_ALT: False Backup: CONFIG_MBEDTLS_THREADING: False Backup: CONFIG_MBEDTLS_THREADING_ALT: True =========== Checkpoint: backup =============== Restore: CONFIG_MBEDTLS_PSA_CRYPTO_C: True Restore: CONFIG_MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER: False Restore: CONFIG_MBEDTLS_PSA_CRYPTO_SPM: False Restore: CONFIG_MBEDTLS_USE_PSA_CRYPTO: True Restore: CONFIG_MBEDTLS_PLATFORM_PRINTF_ALT: False Restore: CONFIG_MBEDTLS_THREADING: False Restore: CONFIG_MBEDTLS_THREADING_ALT: True =========== End psa_crypto_library_config =============== -- libmetal version: 1.7.0 (C:/ncs/v3.0.2/nrf/applications/nrf5340_audio) -- Build type: -- Host: Windows/AMD64 -- Target: Generic/arm -- Machine: arm -- Vendor: none -- Looking for include file stdatomic.h -- Looking for include file stdatomic.h - found -- open-amp version: 1.7.0 (C:/ncs/v3.0.2/modules/lib/open-amp/open-amp) -- Host: Windows/AMD64 -- Target: Generic/arm -- Machine: arm -- C_FLAGS : -Wall -Wextra -- Looking for include file fcntl.h -- Looking for include file fcntl.h - found CMake Warning at C:/ncs/v3.0.2/zephyr/CMakeLists.txt:2180 (message): __ASSERT() statements are globally ENABLED CMake Error at CMakeLists.txt:17 (message): No configuration file specified, set -- -DEXTRA_CONF_FILE=<configuration file> -- Configuring incomplete, errors occurred! See also "C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/nrf5340_audio/CMakeFiles/CMakeOutput.log". See also "C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/nrf5340_audio/CMakeFiles/CMakeError.log". CMake Error at cmake/modules/sysbuild_extensions.cmake:514 (message): CMake configure failed for Zephyr project: nrf5340_audio Location: C:/ncs/v3.0.2/nrf/applications/nrf5340_audio Call Stack (most recent call first): cmake/modules/sysbuild_images.cmake:43 (ExternalZephyrProject_Cmake) cmake/modules/sysbuild_default.cmake:21 (include) C:/ncs/v3.0.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:75 (include) C:/ncs/v3.0.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate) C:/ncs/v3.0.2/zephyr/share/sysbuild-package/cmake/SysbuildConfig.cmake:8 (include) template/CMakeLists.txt:10 (find_package) -- Configuring incomplete, errors occurred! See also "C:/ncs/v3.0.2/nrf/applications/nrf5340_audio/build/CMakeFiles/CMakeOutput.log". FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\0b393f9e1b\opt\bin\cmake.EXE' -DWEST_PYTHON=C:/ncs/toolchains/0b393f9e1b/opt/bin/python.exe '-Bc:\ncs\v3.0.2\nrf\applications\nrf5340_audio\build' -GNinja -DBOARD=nrf5340_audio_dk/nrf5340/cpuapp -DCONF_FILE=prj.conf -DBOARD_ROOT=c:/ncs/v3.0.2/nrf/applications/nrf5340_audio '-SC:\ncs\v3.0.2\zephyr\share\sysbuild' '-DAPP_DIR:PATH=c:\ncs\v3.0.2\nrf\applications\nrf5340_audio' * 터미널 프로세스가 종료되었습니다(종료 코드: 1). * 터미널이 작업에서 다시 사용됩니다. 닫으려면 아무 키나 누르세요.
--*
I saved main.c in the src folder. I'll attach the main.c I'm using.
/* * Copyright (c) 2023 Nordic Semiconductor ASA * * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ #include <zephyr/kernel.h> #include <zephyr/logging/log.h> #include <zephyr/zbus/zbus.h> #include <zephyr/sys/byteorder.h> #include <zephyr/console/console.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include "nrf5340_audio_dk.h" #include "led.h" #include "button_assignments.h" #include "macros_common.h" #include "audio_system.h" #include "bt_mgmt.h" #include "fw_info_app.h" #include "sd_card.h" #include "sd_card_playback.h" #include "button_handler.h" #include "zbus_common.h" LOG_MODULE_REGISTER(main, CONFIG_MAIN_LOG_LEVEL); /* ZBus subscribers */ ZBUS_SUBSCRIBER_DEFINE(button_evt_sub, CONFIG_BUTTON_MSG_SUB_QUEUE_SIZE); /* ZBus channels */ ZBUS_CHAN_DECLARE(button_chan); /* Thread definitions */ static struct k_thread button_msg_sub_thread_data; static struct k_thread console_thread_data; static k_tid_t button_msg_sub_thread_id; static k_tid_t console_thread_id; K_THREAD_STACK_DEFINE(button_msg_sub_thread_stack, CONFIG_BUTTON_MSG_SUB_STACK_SIZE); K_THREAD_STACK_DEFINE(console_thread_stack, 1024); /* SD Card file list buffer */ #define MAX_FILES 50 #define MAX_FILENAME_LENGTH 64 static char file_list[MAX_FILES][MAX_FILENAME_LENGTH]; static int file_count = 0; /* Console command buffer */ #define CONSOLE_CMD_MAX_LEN 128 static char console_cmd_buffer[CONSOLE_CMD_MAX_LEN]; /* Function prototypes */ static void button_msg_sub_thread(void); static void console_thread(void); static int zbus_subscribers_create(void); static int zbus_link_producers_observers(void); static void list_sd_card_files(void); static void play_audio_file(const char *filename); static void show_help(void); static void process_console_command(char *cmd); /** * @brief Button message subscriber thread */ static void button_msg_sub_thread(void) { const struct zbus_channel *chan; while (1) { if (zbus_sub_wait(&button_evt_sub, &chan, K_FOREVER)) { LOG_ERR("Failed to wait for zbus message"); continue; } const struct button_msg *msg = zbus_chan_const_msg(chan); if (msg == NULL) { LOG_ERR("Failed to get message from channel"); continue; } LOG_DBG("Button event: pin=%d, action=%d", msg->button_pin, msg->button_action); switch (msg->button_pin) { case BUTTON_VOLUME_DOWN: if (msg->button_action == BUTTON_PRESS) { LOG_INF("Volume Down button pressed"); } break; case BUTTON_VOLUME_UP: if (msg->button_action == BUTTON_PRESS) { LOG_INF("Volume Up button pressed"); } break; case BUTTON_PLAY_PAUSE: if (msg->button_action == BUTTON_PRESS) { LOG_INF("Play/Pause button pressed"); } break; case BUTTON_4: if (msg->button_action == BUTTON_PRESS) { LOG_INF("Button 4 pressed - List SD card files"); list_sd_card_files(); } break; case BUTTON_5: if (msg->button_action == BUTTON_PRESS) { LOG_INF("Button 5 pressed"); } break; default: LOG_DBG("Unhandled button: %d", msg->button_pin); break; } } } /** * @brief Console thread for handling serial commands */ static void console_thread(void) { console_getline_init(); while (1) { printf("\nSD Card Audio Player> "); fflush(stdout); if (console_getline(console_cmd_buffer, CONSOLE_CMD_MAX_LEN) > 0) { process_console_command(console_cmd_buffer); } k_sleep(K_MSEC(100)); } } /** * @brief Process console commands */ static void process_console_command(char *cmd) { char *token; char *saveptr; // Remove newline cmd[strcspn(cmd, "\n")] = 0; token = strtok_r(cmd, " ", &saveptr); if (token == NULL) { return; } if (strcmp(token, "help") == 0 || strcmp(token, "h") == 0) { show_help(); } else if (strcmp(token, "list") == 0 || strcmp(token, "ls") == 0) { list_sd_card_files(); } else if (strcmp(token, "playback") == 0 || strcmp(token, "p") == 0) { token = strtok_r(NULL, " ", &saveptr); if (token == NULL) { printf("Usage: playback <filename>\n"); printf("Example: playback audio.wav\n"); } else { play_audio_file(token); } } else if (strcmp(token, "status") == 0 || strcmp(token, "s") == 0) { if (sd_card_playback_is_active()) { printf("Playback is active\n"); } else { printf("No playback active\n"); } } else if (strcmp(token, "clear") == 0 || strcmp(token, "cls") == 0) { printf("\033[2J\033[H"); // Clear screen } else { printf("Unknown command: %s\n", token); printf("Type 'help' for available commands\n"); } } /** * @brief Show help information */ static void show_help(void) { printf("\n=== SD Card Audio Player Commands ===\n"); printf("help, h - Show this help\n"); printf("list, ls - List all audio files on SD card\n"); printf("playback <filename>, p - Play audio file\n"); printf("status, s - Show current playback status\n"); printf("clear, cls - Clear screen\n"); printf("=====================================\n\n"); } /** * @brief List all audio files on SD card */ static void list_sd_card_files(void) { printf("Scanning SD card for audio files...\n"); // Clear previous file list memset(file_list, 0, sizeof(file_list)); file_count = 0; // Search for WAV files int wav_count = sd_card_list_files_match(MAX_FILES, MAX_FILENAME_LENGTH, file_list, NULL, "*.wav"); if (wav_count > 0) { file_count = wav_count; printf("Found %d WAV files:\n", wav_count); for (int i = 0; i < wav_count; i++) { printf(" %d: %s\n", i + 1, file_list[i]); } } // Search for LC3 files int lc3_count = sd_card_list_files_match(MAX_FILES - file_count, MAX_FILENAME_LENGTH, &file_list[file_count], NULL, "*.lc3"); if (lc3_count > 0) { printf("Found %d LC3 files:\n", lc3_count); for (int i = 0; i < lc3_count; i++) { printf(" %d: %s\n", file_count + i + 1, file_list[file_count + i]); } file_count += lc3_count; } if (file_count == 0) { printf("No audio files found on SD card\n"); } else { printf("Total audio files found: %d\n", file_count); } } /** * @brief Play audio file */ static void play_audio_file(const char *filename) { if (filename == NULL || strlen(filename) == 0) { printf("Error: Invalid filename\n"); return; } printf("Playing file: %s\n", filename); // Check if it's a WAV file if (strstr(filename, ".wav") != NULL) { int ret = sd_card_playback_wav((char *)filename); if (ret == 0) { printf("Started playing WAV file: %s\n", filename); } else { printf("Failed to play WAV file %s: %d\n", filename, ret); } } // Check if it's an LC3 file else if (strstr(filename, ".lc3") != NULL) { int ret = sd_card_playback_lc3((char *)filename); if (ret == 0) { printf("Started playing LC3 file: %s\n", filename); } else { printf("Failed to play LC3 file %s: %d\n", filename, ret); } } else { printf("Unsupported file format: %s\n", filename); printf("Supported formats: .wav, .lc3\n"); } } /** * @brief Create ZBus subscribers */ static int zbus_subscribers_create(void) { int ret; button_msg_sub_thread_id = k_thread_create(&button_msg_sub_thread_data, button_msg_sub_thread_stack, K_THREAD_STACK_SIZEOF(button_msg_sub_thread_stack), button_msg_sub_thread, NULL, NULL, NULL, K_PRIO_PREEMPT(CONFIG_BUTTON_MSG_SUB_PRIO), 0, K_NO_WAIT); if (!button_msg_sub_thread_id) { LOG_ERR("Failed to create button message subscriber thread"); return -ENOMEM; } ret = k_thread_name_set(button_msg_sub_thread_id, "BUTTON_MSG_SUB"); if (ret) { LOG_ERR("Failed to set thread name"); return ret; } // Create console thread console_thread_id = k_thread_create(&console_thread_data, console_thread_stack, K_THREAD_STACK_SIZEOF(console_thread_stack), console_thread, NULL, NULL, NULL, K_PRIO_PREEMPT(CONFIG_BUTTON_MSG_SUB_PRIO), 0, K_NO_WAIT); if (!console_thread_id) { LOG_ERR("Failed to create console thread"); return -ENOMEM; } ret = k_thread_name_set(console_thread_id, "CONSOLE_THREAD"); if (ret) { LOG_ERR("Failed to set console thread name"); return ret; } ret = zbus_chan_add_obs(&button_chan, &button_evt_sub, K_NO_WAIT); if (ret) { LOG_ERR("Failed to add button subscriber to channel"); return ret; } return 0; } /** * @brief Link ZBus producers and observers */ static int zbus_link_producers_observers(void) { int ret; ret = zbus_chan_add_obs(&button_chan, &button_evt_sub, K_NO_WAIT); if (ret) { LOG_ERR("Failed to add button subscriber to channel"); return ret; } return 0; } /** * @brief Main function */ int main(void) { int ret; printf("\n=== nRF5340 Audio DK SD Card Playback Application ===\n"); printf("Serial Monitor Commands:\n"); printf(" list, ls - List SD card files\n"); printf(" playback <filename> - Play audio file\n"); printf(" status, s - Show playback status\n"); printf(" help, h - Show help\n"); printf(" clear, cls - Clear screen\n"); printf("====================================================\n\n"); /* Initialize board */ ret = nrf5340_audio_dk_init(); if (ret) { LOG_ERR("Failed to initialize nRF5340 Audio DK: %d", ret); return ret; } /* Initialize button handler */ ret = button_handler_init(); if (ret) { LOG_ERR("Failed to initialize button handler: %d", ret); return ret; } /* Initialize SD card */ ret = sd_card_init(); if (ret) { LOG_ERR("Failed to initialize SD card: %d", ret); printf("SD card may not be inserted or properly connected\n"); } else { printf("SD card initialized successfully\n"); } /* Initialize SD card playback */ ret = sd_card_playback_init(); if (ret) { LOG_ERR("Failed to initialize SD card playback: %d", ret); return ret; } printf("SD card playback initialized successfully\n"); /* Initialize audio system */ ret = audio_system_init(); if (ret) { LOG_ERR("Failed to initialize audio system: %d", ret); return ret; } /* Initialize Bluetooth management */ ret = bt_mgmt_init(); if (ret) { LOG_ERR("Failed to initialize Bluetooth management: %d", ret); return ret; } /* Create ZBus subscribers */ ret = zbus_subscribers_create(); if (ret) { LOG_ERR("Failed to create ZBus subscribers: %d", ret); return ret; } /* Link ZBus producers and observers */ ret = zbus_link_producers_observers(); if (ret) { LOG_ERR("Failed to link ZBus producers and observers: %d", ret); return ret; } /* Start threads */ k_thread_start(button_msg_sub_thread_id); k_thread_start(console_thread_id); printf("Application started successfully\n"); printf("Type 'help' for available commands\n"); /* Main loop */ while (1) { k_sleep(K_SECONDS(1)); } return 0; }