spi communication issue on nrf5340 custom board

Hello.
I'm trying to do spi communication on a custom board with nrf5340 used.
I'm using three threads,
I build it, but if I put it on the board, the board will have a problem.
How can I solve this?

///////////////////////////////////////////////////////////////////////////////////////////////////

cpuapp_defconfig

#enable SPI
CONFIG_SPI=y
CONFIG_SPI_NRFX=y

///////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////

.dts

&spi1 {
    compatible = "nordic,nrf-spim";
    status = "okay";

    pinctrl-0 = <&spi1_default>;
    pinctrl-1 = <&spi1_sleep>;
    pinctrl-names = "default", "sleep";
   
    cs-gpios = <&gpio0 8 GPIO_ACTIVE_LOW>,  /* CS1 핀 */
               <&gpio0 9 GPIO_ACTIVE_LOW>,  /* CS2 핀 */
               <&gpio0 10 GPIO_ACTIVE_LOW>;  /* CS3 핀 */
               
    slave1: spi-dev1@0 {
        compatible = "spi-device";
        reg = <0>;       /* 슬레이브 1의 ID */
        spi-max-frequency = <8000000>;
    };

    slave2: spi-dev2@1 {
        compatible = "spi-device";
        reg = <1>;       /* 슬레이브 2의 ID */
        spi-max-frequency = <8000000>;
    };

    slave3: spi-dev3@2 {
        compatible = "spi-device";
        reg = <2>;       /* 슬레이브 3의 ID */
        spi-max-frequency = <8000000>;
    };
};
&pinctrl {
    // uart0_default: uart0_default {
    //  group1 {
    //      psels = <NRF_PSEL(UART_TX, 0, 20)>,
    //          <NRF_PSEL(UART_RTS, 0, 19)>;
    //  };
    //  group2 {
    //      psels = <NRF_PSEL(UART_RX, 0, 22)>,
    //          <NRF_PSEL(UART_CTS, 0, 21)>;
    //      bias-pull-up;
    //  };
    // };
   
    spi1_default: spi1_default {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 0, 20)>,        /* SPI SCK 핀 */
                    <NRF_PSEL(SPIM_MOSI, 0, 21)>,       /* SPI MOSI 핀 */
                    <NRF_PSEL(SPIM_MISO, 0, 22)>;       /* SPI MISO 핀 */
        };
    };

    spi1_sleep: spi1_sleep {
        group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 20)>,        /* SPI SCK 핀 */
                        <NRF_PSEL(SPIM_MOSI, 0, 21)>,       /* SPI MOSI 핀 */
                        <NRF_PSEL(SPIM_MISO, 0, 22)>;       /* SPI MISO 핀 */
                low-power-enable;
        };
    };

///////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////

struct k_mutex tx_mutex;

#define SPI_DEV_NODE DT_NODELABEL(spi1) /* SPI1 노드 */

static const struct device *spi_dev;

/* CS 핀 정의 */
static const struct gpio_dt_spec cs_pins[] = {
    GPIO_DT_SPEC_GET_BY_IDX(SPI_DEV_NODE, cs_gpios, 0),
    GPIO_DT_SPEC_GET_BY_IDX(SPI_DEV_NODE, cs_gpios, 1),
    GPIO_DT_SPEC_GET_BY_IDX(SPI_DEV_NODE, cs_gpios, 2),
};

/* SPI 설정 */
struct spi_cs_control cs_controls[3] = {
    { .gpio = &cs_pins[0], .delay = 0 },
    { .gpio = &cs_pins[1], .delay = 0 },
    { .gpio = &cs_pins[2], .delay = 0 },
};

void spi_init(void) {
    spi_dev = DEVICE_DT_GET(SPI_DEV_NODE);
    if (!device_is_ready(spi_dev)) {
        printk("SPI device is not ready\n");
        return;
    }

    for (int i = 0; i < ARRAY_SIZE(cs_pins); i++) {
        if (!device_is_ready(cs_pins[i].port)) {
            printk("GPIO device %d is not ready\n", i);
            return;
        }

        int ret = gpio_pin_configure_dt(&cs_pins[i], GPIO_OUTPUT_INACTIVE);
        if (ret < 0) {
            printk("Failed to configure GPIO pin %d: %d\n", cs_pins[i].pin, ret);
            return;
        }
    }

    printk("SPI and CS pins initialized\n");
}

/* 전역 변수로 동적 데이터 정의 */
uint8_t tx_data[2];
uint8_t rx_data[2];

const struct spi_buf tx_buf = {
    .buf = tx_data,
    .len = sizeof(tx_data),
};

const struct spi_buf rx_buf = {
    .buf = rx_data,
    .len = sizeof(rx_data),
};

const struct spi_buf_set tx_set = { .buffers = &tx_buf, .count = 1 };
const struct spi_buf_set rx_set = { .buffers = &rx_buf, .count = 1 };

void spi_transceive_slave(int slave_index) {
    if (slave_index < 0 || slave_index >= ARRAY_SIZE(cs_controls)) {
        printk("Invalid slave index\n");
        return;
    }

    /* 전역 변수 보호 시작 */
    if (k_mutex_lock(&tx_mutex, K_FOREVER) == 0) {
    struct spi_config spi_cfg = {
        .frequency = 8000000,
        .operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB,
        .cs = &cs_controls[slave_index],
    };

    int ret = spi_transceive(spi_dev, &spi_cfg, &tx_set, &rx_set);
    if (ret < 0) {
        printk("SPI transfer failed for slave %d: %d\n", slave_index, ret);
    } else {
        printk("Received from slave %d: %x %x\n",
               slave_index, rx_data[0], rx_data[1]);
    }/* 전역 변수 보호 종료 */
        k_mutex_unlock(&tx_mutex);
    } else {
        printk("Failed to acquire mutex\n");
    }
}
void ADC( void )
{ ...
k_mutex_init(&tx_mutex);
    spi_init();

    tx_data[0] = 0xAA;
    tx_data[1] = 0xBB;
    spi_transceive_slave(0);
    k_sleep(K_SECONDS(100));
...
while(1) {
...}
void Task_ADC_Init( void ){
   
    k_thread_create (                                                      
                    &ADCThread,                                    
                    ADC_STACK,                                      
                    ADC_STACK_SIZE,                                
                    (k_thread_entry_t)ADC,                          
                    NULL,                                                  
                    NULL,                                                  
                    NULL,                                                  
                    ADC_PRIORITY,                                  
                    0,                                                      
                    K_NO_WAIT);

     k_thread_name_set(&ADCThread, "ADC");
     k_thread_start(&ADCThread);
};

///////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////

rtt viewer log message
00> [00:00:00.487,701] <inf> sta: ADC Test
00> SPI and CS pins initialized
00> [00:00:00.487,854] <err> os: ***** Reserved Exception ( -16) *****
00> [00:00:00.487,884] <err> os: r0/a1: 0x20017248 r1/a2: 0x00007025 r2/a3: 0x0004efbf
00> [00:00:00.487,884] <err> os: r3/a4: 0x00007011 r12/ip: 0x00007011 r14/lr: 0x00007011
00> [00:00:00.487,884] <err> os: xpsr: 0x00007000
00> [00:00:00.487,915] <err> os: Faulting instruction address (r15/pc): 0x00007011
00> [00:00:00.487,915] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
00> [00:00:00.487,945] <err> os: Current thread: 0x200018c8 (unknown)
00> [00:00:00.491,668] <err> coredump: #CD:BEGIN#
00> [00:00:00.511,749] <err> coredump: #CD:5a4501000300050000000000
00> [00:00:00.536,773] <err> coredump: #CD:4102004400
00> [00:00:00.556,854] <err> coredump: #CD:4872012025700000bfef04001170000011700000117000001170000000700000
00> [00:00:00.596,862] <err> coredump: #CD:0000000000000000000000000000000000000000000000000000000000000000
00> [00:00:00.636,810] <err> coredump: #CD:00000000
00> [00:00:00.656,890] <err> coredump: #CD:4d0100c818002060190020
00> [00:00:00.681,945] <err> coredump: #CD:482b0020cc540020000000000080070000000000000000000000000000000000
00> [00:00:00.721,954] <err> coredump: #CD:0000000000000000000000000000000000000000000000000000000000000000
00> [00:00:00.761,932] <err> coredump: #CD:0000000000000000000000000000000008760020000000002019002020190020
00> [00:00:00.801,940] <err> coredump: #CD:0000000000000000286e00200008000000000000301500200000000000000000
00> [00:00:00.841,949] <err> coredump: #CD:000000000000000000000000000000000000000000000000
00> [00:00:00.876,953] <err> coredump: #CD:4d0100286e002028760020
00> [00:00:00.902,008] <err> coredump: #CD:f0f0f0f0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:00.941,986] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:00.981,994] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[0m
00> [00:00:01.021,972] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.061,981] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.101,959] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.141,937] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.181,945] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[0m
00> [00:00:01.221,954] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.261,962] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.301,971] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.341,979] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.381,958] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.421,936] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.461,883] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.501,861] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.541,839] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.581,817] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.621,795] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.661,773] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.701,751] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.741,729] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.781,707] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.821,685] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.861,633] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:01.901,611] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[0m
00> [00:00:01.941,589] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[0m
00> [00:00:01.981,567] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:02.021,514] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:02.061,492] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:02.101,470] <err> coredump: #CD:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
00> [00:00:02.141,448] <err> coredump: #CD:aaaaaaaaaaaaaaaa00000000040000000100000010000000fa5f0020fc5f0020
00> [00:00:02.181,427] <err> coredump: #CD:fb5f0020a0870700ffffffff7b6800000000000010000000fc5f002035680000
00> [00:00:02.221,405] <err> coredump: #CD:00000000a087070062bc0700d3ee040000000000a08707003000000066bc0700
00> [00:00:02.261,383] <err> coredump: #CD:01ef0400f9ee0400a087070017ef040066bc070066bc070062bc0700b9e60400
00> [00:00:02.301,330] <err> coredump: #CD:447300200000000001ef0400407300200100000007540000741d002004000000[0m
00> [00:00:02.341,308] <err> coredump: #CD:151e002001ef040061bc070000000000000000003000000000000000000d0800
00> [00:00:02.381,286] <err> coredump: #CD:e6c2070000000000000000000000000000000033e5c2070062bc070000000000
00> [00:00:02.421,234] <err> coredump: #CD:80000373000000000000000000000000951e002000000000230000000f000000
00> [00:00:02.461,212] <err> coredump: #CD:1300000000000000e803000012c3070001000000e3ee040000000000a0870700
00> [00:00:02.501,190] <err> coredump: #CD:00000000040000000100000004000000fa5f0020fc5f0020fb5f00200a000000[0m
00> [00:00:02.541,168] <err> coredump: #CD:040000007b6800000000000004000000fc5f0020356800000000000027400100
00> [00:00:02.581,115] <err> coredump: #CD:00000000d3ee040000000000a0870700a0870700010000000f000000f9ee0400
00> [00:00:02.621,093] <err> coredump: #CD:b6200020abef0400000000000100000068200020b62000209814002031e70400
00> [00:00:02.661,041] <err> coredump: #CD:20000000c0140020c0140020a1bc030034330020486b0600b820002021600000[0m
00> [00:00:02.701,019] <err> coredump: #CD:20000000409c000000000000a561000098140020c80100001821002047630000
00> [00:00:02.740,966] <err> coredump: #CD:0a0000000c74002004000000147400204e00000000000000906906000e000000
00> [00:00:02.780,944] <err> coredump: #CD:906906004100000004000000081a00204e0000004e0000001600000008740020
00> [00:00:02.820,892] <err> coredump: #CD:68740020000200006874002051600020e0c20700277400202c8a0700e17e0000
00> [00:00:02.860,870] <err> coredump: #CD:2c8a0700e17e0000887400205160002003000001e0c207005160002000020700[0m
00> [00:00:02.900,848] <err> coredump: #CD:286e00200008000000000000c874002000000000c874002005000000bb7d0000
00> [00:00:02.940,826] <err> coredump: #CD:050000004d0100286e00202876002000c0000000c818002010750020177e0000
00> [00:00:02.980,804] <err> coredump: #CD:000000005a45010003000500000000000000000010750020c8180020f3b50300
00> [00:00:03.020,751] <err> coredump: #CD:6019002010750020c074002000000000e8740020d0740020e8740020756b0000[0m
00> [00:00:03.060,729] <err> coredump: #CD:200000003075002000000000087500200875002010100020108a0700476f0000
00> [00:00:03.100,708] <err> coredump: #CD:00000000010000004872012025700000bfef0400117000001170000011700000
00> [00:00:03.140,686] <err> coredump: #CD:117000000070000010100020000000000867060058750020b475002021700000
00> [00:00:03.180,664] <err> coredump: #CD:08610120894f0500101000203553010000127a00108a0700f0860700f8860700
00> [00:00:03.220,611] <err> coredump: #CD:000000000000000000000000ffffffff0000ff0000127a000000000101000000
00> [00:00:03.260,589] <err> coredump: #CD:981b002000000000a550010001000000e0750020000000000000000000000000
00> [00:00:03.300,567] <err> coredump: #CD:00000000b94400000000000000127a0000010000700700200000000000000000
00> [00:00:03.340,545] <err> coredump: #CD:59ba0700000000000000000049470000aaaaaaaaaaaaaaaaaaaaaaaa00000000
00> [00:00:03.380,523] <err> coredump: #CD:00000000e27500200200000000000000aaaaaaaa6d4600000000000000000000
00> [00:00:03.420,471] <err> coredump: #CD:000000000000000000000000000000000000000049e6040000000000aaaaaaaa[0m
00> [00:00:03.460,418] <err> coredump: #CD:END#
00> [00:00:03.480,438] <err> os: Halting system

///////////////////////////////////////////////////////////////////////////////////////////////////

Related