MCU was reset from time to time

HI,

I have a product which scan for RFID card through NFC and Mobile Device through BLE after nRF52840 MCU was wakeup.

If I scan NFC and BLE scanning separately, everything was OK.

But, If I start BLE scanning first, do connect-discovery-exchange data in the event handle, then in a loop, I scan NFC for RFID card and check BLE state, nRF52840 will be reset from time to time.

May I scan NFC and BLE at same time, if yes, how to do it ?

Thanks,

Mark,

Parents
  • Hi Mark,

    I have following suggests to help you debug this issue: 

    1) Try to enable log and check the debug output from terminal, set "CONFIG_RESET_ON_FATAL_ERROR=n" to see the error cause when failure happens.

    2) Try to set up a seperate Thread for NFC opetation since you have verifed they can work seperately. I feel not confident about the bloking logic in your while loop.  

    Best regards,

    Charlie 

  • HI, Charlie: 

    My project is a bare-metal firmware, should I convert the project to RTOS before I can use separate thread for BLE scanning ?  If yes, is that hard to convert from bare-metal to RTOS ? I'm a beginner on RTOS.

    Thanks,

    mark,

  • Hi Mark,

    This is not hard since your porject is based on NCS/Zephyr.

    Just learn about Thread usage and refer to the Zephyr sample. We also have DevAcademy course cover Zephyr RTOS basics.

    https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-7-multithreaded-applications/topic/scheduler/

    https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/kernel/services/threads/index.html

    Best regards,

    Charlie

  • HI, Charlie:

      I have read the document from the link you post. Now, I start to make a simple project on my custom board.

    There is a PIC24 MCU and nRF52832 from MS50SFA on the board. They communicate through UART.

    PIC_BMD1: Master RQ

    PIC_BMD2: BMD RX

    PIC_BMD3: BMD TX

    PIC_BMD4: Slaver RQ

    PIC will send a command packet to BMD every seconds. That will trigger BMD UART RX interrupt, BMD read the the data on RX, BMD will send a response packet to PIC after it receives a valid packet.

    For RTOS project on nRF52832:

      Main tread will initialize system and hardware.

      After UART on BMD receive a valid packet, it will create a response packet and send to uart_tx_queue.

      A UART TX thread is created to send the response packet if it could be read from uart_tx_queue.

      Prj.conf:

    CONFIG_CONSOLE=n

    CONFIG_GPIO=y
    CONFIG_SERIAL=y
    CONFIG_UART_INTERRUPT_DRIVEN=y

    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
     
      overlay:
    / {
        master_rq {
            compatible = "gpio-keys";
            status = "okay";

            master_rq_int: master_rq_int {
                gpios = <&gpio0 28 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
                label = "Master RQ Interrupt";
            };
        };

        slaver_rq {
            compatible = "gpio-keys";
            status = "okay";

            slaver_rq: slaver_rq {
                gpios = <&gpio0 17 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
                label = "Slaver RQ";
            };
        };

        pic_uart {
            compatible = "gpio-keys";
            status = "okay";

            picuart_rx: picuart_rx {
                gpios = <&gpio0 4 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
                label = "PIC_UART RX";
            };

            picuart_tx: picuart_tx {
                gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
                label = "PIC_UART TX";
            };
        };



        aliases {
            masterrqint = &master_rq_int;
            slaverrq = &slaver_rq;
            picuartrx = &picuart_rx;
            picuarttx = &picuart_tx;
        };  
    };


    &pinctrl {
        uart0_default: uart0_default {
            group1 {
                psels = <NRF_PSEL(UART_TX, 0, 11)>,
                        <NRF_PSEL(UART_RX, 0, 4)>;
            };
        };
             
        /* required if CONFIG_PM_DEVICE=y */
        uart0_sleep: uart0_sleep {
            group1 {
                psels = <NRF_PSEL(UART_TX, 0, 11)>,
                        <NRF_PSEL(UART_RX, 0, 4)>;
                   low-power-enable;
            };
        };
    };
       

       
    &uart0 {
        compatible = "nordic,nrf-uarte";    
        reg = < 0x40002000 0x1000 >;        
        current-speed = <921600>;
        status = "okay";
           
        pinctrl-0 = <&uart0_sleep>;
        pinctrl-1 = <&uart0_default>;
        pinctrl-names = "sleep", "default";  
    };    
     
    main.c
    #include <errno.h>
    #include <stddef.h>
    #include <stdio.h>
    #include <string.h>

    #include <zephyr/kernel.h>
    #include <zephyr/arch/cpu.h>
    #include <zephyr/sys/byteorder.h>
    #include <zephyr/logging/log.h>
    #include <zephyr/sys/util.h>

    #include <zephyr/device.h>
    #include <zephyr/init.h>
    #include <zephyr/drivers/uart.h>

    #include <zephyr/net/buf.h>


    /* size of stack area used by each thread */
    #define STACKSIZE 1024

    #define LOG_MODULE_NAME pivot_bmd
    LOG_MODULE_REGISTER(LOG_MODULE_NAME);



    typedef enum {
        CMD_GET_VERSION = 0x05,
        CMD_CHECK_MOBILE = 0x0C,
        CMD_BLE_REQUEST_RESET = 0x10,       // BLE device request PIC reset        
    } _tBMD_CMD_CODE;

    typedef enum {
        MOBILE_CHECK_NOTHING = 0,           // Catch all unknown cases                
        MOBILE_CHECK_FOUND = 1,             // Found a mobile access credential
        MOBILE_CHECK_NOT_FOUND = 2,         // Could not find a mobile access credential
        MOBILE_CHECK_PENDING = 3,           // Still looking for mobile access credential
        MOBILE_CHECK_COMPLETE = 5,          // Status reported to phone
                   
        MOBILE_CHECK_SCANNING = 6,
        MOBILE_CHECK_CONNECTING = 4,        // UUID match and in range
        MOBILE_CHECK_CONNECTED = 7,
        MOBILE_CHECK_DISCOVERIED = 8,       // Service found
        MOBILE_CHECK_DISCONNECTED = 9                
    } _tMOBILE_CHECK_STATE;

    #define RESP_CODE_PASS  0x00
    #define RESP_CODE_FAIL  0x01

    static const struct device *const pic_uart_dev = DEVICE_DT_GET(DT_NODELABEL(uart0));

    static K_THREAD_STACK_DEFINE(tx_thread_stack, STACKSIZE);
    static struct k_thread tx_thread_data;

    static K_FIFO_DEFINE(uart_tx_queue);

    #define MAX_PAYLOAD_SIZE 32-3           // 0x7E, len, CMD
    #define PKT_HEADER 0x7E

    /* Receiver states. */
    #define ST_IDLE 0   /* Waiting for packet type. */
    #define ST_HDR 1    /* Receiving packet header. */
    #define ST_PAYLOAD 2    /* Receiving packet payload. */
    #define ST_DISCARD 3    /* Dropping packet. */

    #define DISCARD_LEN 33


    struct uart_pkt_hdr {
        uint8_t length;         // 2 + payload size
        uint8_t cmd;
    } __packed;

    static uint8_t CalcXOR(uint8_t *XorData, uint16_t Size) {
        uint8_t xorVal;
        uint8_t i;

        xorVal = XorData[0];
        for (i = 1; i < Size; i++) {
            xorVal ^= XorData[i];
        }

        return xorVal;
    }


    static int uart_read(const struct device *uart, uint8_t *buf, size_t len)
    {
        int rx = uart_fifo_read(uart, buf, len);

        LOG_DBG("read %d req %d", rx, len);

        return rx;
    }

    static void ReadUartPacket(void)
    {
        static int remaining;
        static uint8_t state;
        static uint8_t data;
        static uint8_t cmd;
        static uint8_t packet_buf[32];
        static uint8_t data_buf[32];
        int read;

        do {
            switch (state) {
            case ST_IDLE:
                /* Get packet type */
                read = uart_read(pic_uart_dev, &data, sizeof(data));
                /* since we read in loop until no data is in the fifo,
                 * it is possible that read = 0.
                 */
                if (read) {
                    if (data == PKT_HEADER) {
                        /* Get expected header size and switch
                         * to receiving header.
                         */
                        remaining = sizeof(struct uart_pkt_hdr);
                        state = ST_HDR;
                    } else {
                        LOG_WRN("Unknown header %d", data);
                    }
                }
                break;
            case ST_HDR:
                read = uart_read(pic_uart_dev, &packet_buf[sizeof(struct uart_pkt_hdr) - remaining], remaining);
                remaining -= read;
                if (remaining == 0) {
                    /* Header received. Allocate buffer and get
                     * payload length. If allocation fails leave
                     * interrupt. On failed allocation state machine
                     * is reset.
                     */
                    remaining = packet_buf[0] - sizeof(struct uart_pkt_hdr);

                    if (remaining > MAX_PAYLOAD_SIZE) {
                        LOG_ERR("Not enough space in packet buffer");
                        state = ST_DISCARD;
                    } else {
                        state = ST_PAYLOAD;
                    }

                }
                break;

            case ST_PAYLOAD:
                read = uart_read(pic_uart_dev, &packet_buf[packet_buf[0] - remaining], remaining);
                remaining -= read;
                if (remaining == 0) {
                    /* Packet received */
                    LOG_DBG("putting RX packet in queue.");

                    if(packet_buf[packet_buf[0]] == CalcXOR(packet_buf, packet_buf[0])) {
                        cmd = packet_buf[1];
                        switch(cmd) {
                            case CMD_CHECK_MOBILE:
                                // Send response to PIC
                                data_buf[0] = 6;
                                data_buf[1] = PKT_HEADER;
                                data_buf[2] = 4;
                                data_buf[3] = CMD_CHECK_MOBILE;
                                data_buf[4] = RESP_CODE_PASS;  
                                data_buf[5] = MOBILE_CHECK_PENDING;
                                data_buf[6] = CalcXOR(&data_buf[2], 4);

                                char *mem_ptr = k_malloc(7);
                                __ASSERT_NO_MSG(mem_ptr != 0);
                                memcpy(mem_ptr, data_buf, 7);
                                k_fifo_put(&uart_tx_queue, mem_ptr);

                                state = ST_IDLE;
                                break;
                            default:
                                break;        
                        }
                    } else {
                        state = ST_DISCARD;
                    }              
                }
                break;
            case ST_DISCARD:
            {
                uint8_t discard[32];
                size_t to_read = MIN(remaining, sizeof(discard));

                read = uart_read(pic_uart_dev, discard, to_read);
                remaining -= read;
                if (remaining == 0) {
                    state = ST_IDLE;
                }

                break;

            }
            default:
                read = 0;
                __ASSERT_NO_MSG(0);
                break;

            }
        } while (read);
    }

    void uart_tx_thread(void)
    {
        uint8_t *data_buf;

        while(1) {
            data_buf = k_fifo_get(&uart_tx_queue, K_FOREVER);
            uart_fifo_fill(pic_uart_dev, &data_buf[1], data_buf[0]);
            k_free(data_buf);

            k_yield();
        }
    }

    static void uart_rx_isr(const struct device *unused, void *user_data)
    {
        ARG_UNUSED(unused);
        ARG_UNUSED(user_data);

        if (!uart_irq_rx_ready(pic_uart_dev)) {
            LOG_DBG("spurious interrupt");
        }

        if (uart_irq_rx_ready(pic_uart_dev)) {
            ReadUartPacket();
        }
    }

    static int pivot_bmd_init(const struct device *unused)
    {
        LOG_DBG("");

        if (!device_is_ready(pic_uart_dev)) {
            LOG_ERR("HCI UART %s is not ready", pic_uart_dev->name);
            return -EINVAL;
        }

        uart_irq_rx_disable(pic_uart_dev);
        uart_irq_tx_disable(pic_uart_dev);

        uart_irq_callback_set(pic_uart_dev, uart_rx_isr);
        uart_irq_rx_enable(pic_uart_dev);

        return 0;
    }


    SYS_INIT(pivot_bmd_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);

    void main(void)
    {
        /* incoming events and data from the PIC */
        static K_FIFO_DEFINE(uart_rx_queue);
        int err;

        LOG_DBG("Start");
        __ASSERT(pic_uart_dev, "UART device is NULL");

        /* Spawn the TX thread and start feeding commands and data to the
         * PIC
         */
        k_thread_create(&tx_thread_data, tx_thread_stack,
                K_THREAD_STACK_SIZEOF(tx_thread_stack), uart_tx_thread,
                NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT);
        k_thread_name_set(&tx_thread_data, "Pivot-BMD uart TX");

        while (1) {

        }
    }
    I got error when I compile the project:
    Building pivot_bmd_03-RTOS
    C:\WINDOWS\system32\cmd.exe /d /s /c "west build --build-dir c:/WorkFolder/FW/Nordic/WorkSpace/MS50SFA/pivot_bmd_03-RTOS/build c:/WorkFolder/FW/Nordic/WorkSpace/MS50SFA/pivot_bmd_03-RTOS"

    [1/44] Building C object zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj
    FAILED: zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj
    C:\ncs\toolchains\c57af46cb7\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF52832_XXAA -DUSE_PARTITION_MANAGER=0 -D__PROGRAM_START -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -IC:/ncs/v2.3.0/zephyr/include -Izephyr/include/generated -IC:/ncs/v2.3.0/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/ncs/v2.3.0/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.3.0/nrf/include -IC:/ncs/v2.3.0/nrf/tests/include -IC:/ncs/v2.3.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.3.0/modules/hal/nordic/nrfx -IC:/ncs/v2.3.0/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.3.0/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.3.0/zephyr/modules/hal_nordic/nrfx/. -isystem C:/ncs/v2.3.0/zephyr/lib/libc/minimal/include -isystem c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include -isystem c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed -fno-strict-aliasing -Os -imacros C:/WorkFolder/FW/Nordic/WorkSpace/MS50SFA/pivot_bmd_03-RTOS/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=C:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.3.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=C:/WorkFolder/FW/Nordic/WorkSpace/MS50SFA/pivot_bmd_03-RTOS=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.3.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.3.0=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj -MF zephyr\drivers\serial\CMakeFiles\drivers__serial.dir\uart_nrfx_uarte.c.obj.d -o zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj -c C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c
    In file included from C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_macro.h:34,
    from C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util.h:17,
    from C:/ncs/v2.3.0/zephyr/include/zephyr/devicetree.h:21,
    from C:/ncs/v2.3.0/zephyr/include/zephyr/device.h:12,
    from C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/uart.h:26,
    from C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:11:
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:173:53: error: expected expression before ',' token
    173 | Z_PINCTRL_STATE_INIT, (,), node_id) \
    | ^
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:72:26: note: in definition of macro '__DEBRACKET'
    72 | #define __DEBRACKET(...) __VA_ARGS__
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
    64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
    | ^~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
    59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_macro.h:157:9: note: in expansion of macro 'Z_COND_CODE_1'
    157 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_macro.h:201:9: note: in expansion of macro 'COND_CODE_1'
    201 | COND_CODE_1(_flag, _code, ())
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:2080:9: note: in expansion of macro 'IF_ENABLED'
    2080 | IF_ENABLED(CONFIG_PINCTRL, (PINCTRL_DT_DEFINE(UARTE(idx));)) \
    | ^~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_loops.h:1089:47: note: in expansion of macro '__DEBRACKET'
    1089 | Z_UTIL_LISTIFY_1(F, sep, __VA_ARGS__) __DEBRACKET sep \
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:105:36: note: in expansion of macro 'Z_UTIL_LISTIFY_2'
    105 | #define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__
    | ^
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:172:17: note: in expansion of macro 'LISTIFY'
    172 | LISTIFY(DT_NUM_PINCTRL_STATES(node_id), \
    | ^~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:242:9: note: in expansion of macro 'Z_PINCTRL_STATES_DEFINE'
    242 | Z_PINCTRL_STATES_DEFINE(node_id) \
    | ^~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:2080:37: note: in expansion of macro 'PINCTRL_DT_DEFINE'
    2080 | IF_ENABLED(CONFIG_PINCTRL, (PINCTRL_DT_DEFINE(UARTE(idx));)) \
    | ^~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:2181:1: note: in expansion of macro 'UART_NRF_UARTE_DEVICE'
    2181 | UART_NRF_UARTE_DEVICE(0);
    | ^~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:120:17: warning: '__pinctrl_state_pins_1__device_dts_ord_87' defined but not used [-Wunused-const-variable=]
    120 | _CONCAT(__pinctrl_state_pins_ ## state_idx, DEVICE_DT_NAME_GET(node_id))
    | ^~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:72:26: note: in definition of macro '__DEBRACKET'
    72 | #define __DEBRACKET(...) __VA_ARGS__
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
    64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
    | ^~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
    59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_macro.h:157:9: note: in expansion of macro 'Z_COND_CODE_1'
    157 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_macro.h:201:9: note: in expansion of macro 'COND_CODE_1'
    201 | COND_CODE_1(_flag, _code, ())
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:2080:9: note: in expansion of macro 'IF_ENABLED'
    2080 | IF_ENABLED(CONFIG_PINCTRL, (PINCTRL_DT_DEFINE(UARTE(idx));)) \
    | ^~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:69:53: note: in expansion of macro '__DEBRACKET'
    69 | #define __GET_ARG2_DEBRACKET(ignore_this, val, ...) __DEBRACKET val
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
    64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
    | ^~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
    59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_macro.h:157:9: note: in expansion of macro 'Z_COND_CODE_1'
    157 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:144:9: note: in expansion of macro 'COND_CODE_1'
    144 | COND_CODE_1(Z_PINCTRL_SKIP_STATE(state_idx, node_id), (), \
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:146:9: note: in expansion of macro 'Z_PINCTRL_STATE_PINS_NAME'
    146 | Z_PINCTRL_STATE_PINS_NAME(state_idx, node_id)[] = \
    | ^~~~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_loops.h:1090:9: note: in expansion of macro 'Z_PINCTRL_STATE_PINS_DEFINE'
    1090 | F(1, __VA_ARGS__)
    | ^
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:105:36: note: in expansion of macro 'Z_UTIL_LISTIFY_2'
    105 | #define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__
    | ^
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:240:9: note: in expansion of macro 'LISTIFY'
    240 | LISTIFY(DT_NUM_PINCTRL_STATES(node_id), \
    | ^~~~~~~
    C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:2080:37: note: in expansion of macro 'PINCTRL_DT_DEFINE'
    2080 | IF_ENABLED(CONFIG_PINCTRL, (PINCTRL_DT_DEFINE(UARTE(idx));)) \
    | ^~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:2181:1: note: in expansion of macro 'UART_NRF_UARTE_DEVICE'
    2181 | UART_NRF_UARTE_DEVICE(0);
    | ^~~~~~~~~~~~~~~~~~~~~
    [7/44] Building C object CMakeFiles/app.dir/src/main.c.obj
    ../src/main.c: In function 'main':
    ../src/main.c:266:65: warning: passing argument 4 of 'k_thread_create' from incompatible pointer type [-Wincompatible-pointer-types]
    266 | K_THREAD_STACK_SIZEOF(tx_thread_stack), uart_tx_thread,
    | ^~~~~~~~~~~~~~
    | |
    | void (*)(void)
    In file included from C:/ncs/v2.3.0/zephyr/include/zephyr/kernel.h:5890,
    from ../src/main.c:6:
    If I delete the Uart0 definition from Overlay, compiling is fine. That overlay works fine on bare metal project.
    Please help to take a look and tell me how to overlay with RTOS project.
    Thanks, Mark,

Reply
  • HI, Charlie:

      I have read the document from the link you post. Now, I start to make a simple project on my custom board.

    There is a PIC24 MCU and nRF52832 from MS50SFA on the board. They communicate through UART.

    PIC_BMD1: Master RQ

    PIC_BMD2: BMD RX

    PIC_BMD3: BMD TX

    PIC_BMD4: Slaver RQ

    PIC will send a command packet to BMD every seconds. That will trigger BMD UART RX interrupt, BMD read the the data on RX, BMD will send a response packet to PIC after it receives a valid packet.

    For RTOS project on nRF52832:

      Main tread will initialize system and hardware.

      After UART on BMD receive a valid packet, it will create a response packet and send to uart_tx_queue.

      A UART TX thread is created to send the response packet if it could be read from uart_tx_queue.

      Prj.conf:

    CONFIG_CONSOLE=n

    CONFIG_GPIO=y
    CONFIG_SERIAL=y
    CONFIG_UART_INTERRUPT_DRIVEN=y

    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
     
      overlay:
    / {
        master_rq {
            compatible = "gpio-keys";
            status = "okay";

            master_rq_int: master_rq_int {
                gpios = <&gpio0 28 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
                label = "Master RQ Interrupt";
            };
        };

        slaver_rq {
            compatible = "gpio-keys";
            status = "okay";

            slaver_rq: slaver_rq {
                gpios = <&gpio0 17 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
                label = "Slaver RQ";
            };
        };

        pic_uart {
            compatible = "gpio-keys";
            status = "okay";

            picuart_rx: picuart_rx {
                gpios = <&gpio0 4 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
                label = "PIC_UART RX";
            };

            picuart_tx: picuart_tx {
                gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
                label = "PIC_UART TX";
            };
        };



        aliases {
            masterrqint = &master_rq_int;
            slaverrq = &slaver_rq;
            picuartrx = &picuart_rx;
            picuarttx = &picuart_tx;
        };  
    };


    &pinctrl {
        uart0_default: uart0_default {
            group1 {
                psels = <NRF_PSEL(UART_TX, 0, 11)>,
                        <NRF_PSEL(UART_RX, 0, 4)>;
            };
        };
             
        /* required if CONFIG_PM_DEVICE=y */
        uart0_sleep: uart0_sleep {
            group1 {
                psels = <NRF_PSEL(UART_TX, 0, 11)>,
                        <NRF_PSEL(UART_RX, 0, 4)>;
                   low-power-enable;
            };
        };
    };
       

       
    &uart0 {
        compatible = "nordic,nrf-uarte";    
        reg = < 0x40002000 0x1000 >;        
        current-speed = <921600>;
        status = "okay";
           
        pinctrl-0 = <&uart0_sleep>;
        pinctrl-1 = <&uart0_default>;
        pinctrl-names = "sleep", "default";  
    };    
     
    main.c
    #include <errno.h>
    #include <stddef.h>
    #include <stdio.h>
    #include <string.h>

    #include <zephyr/kernel.h>
    #include <zephyr/arch/cpu.h>
    #include <zephyr/sys/byteorder.h>
    #include <zephyr/logging/log.h>
    #include <zephyr/sys/util.h>

    #include <zephyr/device.h>
    #include <zephyr/init.h>
    #include <zephyr/drivers/uart.h>

    #include <zephyr/net/buf.h>


    /* size of stack area used by each thread */
    #define STACKSIZE 1024

    #define LOG_MODULE_NAME pivot_bmd
    LOG_MODULE_REGISTER(LOG_MODULE_NAME);



    typedef enum {
        CMD_GET_VERSION = 0x05,
        CMD_CHECK_MOBILE = 0x0C,
        CMD_BLE_REQUEST_RESET = 0x10,       // BLE device request PIC reset        
    } _tBMD_CMD_CODE;

    typedef enum {
        MOBILE_CHECK_NOTHING = 0,           // Catch all unknown cases                
        MOBILE_CHECK_FOUND = 1,             // Found a mobile access credential
        MOBILE_CHECK_NOT_FOUND = 2,         // Could not find a mobile access credential
        MOBILE_CHECK_PENDING = 3,           // Still looking for mobile access credential
        MOBILE_CHECK_COMPLETE = 5,          // Status reported to phone
                   
        MOBILE_CHECK_SCANNING = 6,
        MOBILE_CHECK_CONNECTING = 4,        // UUID match and in range
        MOBILE_CHECK_CONNECTED = 7,
        MOBILE_CHECK_DISCOVERIED = 8,       // Service found
        MOBILE_CHECK_DISCONNECTED = 9                
    } _tMOBILE_CHECK_STATE;

    #define RESP_CODE_PASS  0x00
    #define RESP_CODE_FAIL  0x01

    static const struct device *const pic_uart_dev = DEVICE_DT_GET(DT_NODELABEL(uart0));

    static K_THREAD_STACK_DEFINE(tx_thread_stack, STACKSIZE);
    static struct k_thread tx_thread_data;

    static K_FIFO_DEFINE(uart_tx_queue);

    #define MAX_PAYLOAD_SIZE 32-3           // 0x7E, len, CMD
    #define PKT_HEADER 0x7E

    /* Receiver states. */
    #define ST_IDLE 0   /* Waiting for packet type. */
    #define ST_HDR 1    /* Receiving packet header. */
    #define ST_PAYLOAD 2    /* Receiving packet payload. */
    #define ST_DISCARD 3    /* Dropping packet. */

    #define DISCARD_LEN 33


    struct uart_pkt_hdr {
        uint8_t length;         // 2 + payload size
        uint8_t cmd;
    } __packed;

    static uint8_t CalcXOR(uint8_t *XorData, uint16_t Size) {
        uint8_t xorVal;
        uint8_t i;

        xorVal = XorData[0];
        for (i = 1; i < Size; i++) {
            xorVal ^= XorData[i];
        }

        return xorVal;
    }


    static int uart_read(const struct device *uart, uint8_t *buf, size_t len)
    {
        int rx = uart_fifo_read(uart, buf, len);

        LOG_DBG("read %d req %d", rx, len);

        return rx;
    }

    static void ReadUartPacket(void)
    {
        static int remaining;
        static uint8_t state;
        static uint8_t data;
        static uint8_t cmd;
        static uint8_t packet_buf[32];
        static uint8_t data_buf[32];
        int read;

        do {
            switch (state) {
            case ST_IDLE:
                /* Get packet type */
                read = uart_read(pic_uart_dev, &data, sizeof(data));
                /* since we read in loop until no data is in the fifo,
                 * it is possible that read = 0.
                 */
                if (read) {
                    if (data == PKT_HEADER) {
                        /* Get expected header size and switch
                         * to receiving header.
                         */
                        remaining = sizeof(struct uart_pkt_hdr);
                        state = ST_HDR;
                    } else {
                        LOG_WRN("Unknown header %d", data);
                    }
                }
                break;
            case ST_HDR:
                read = uart_read(pic_uart_dev, &packet_buf[sizeof(struct uart_pkt_hdr) - remaining], remaining);
                remaining -= read;
                if (remaining == 0) {
                    /* Header received. Allocate buffer and get
                     * payload length. If allocation fails leave
                     * interrupt. On failed allocation state machine
                     * is reset.
                     */
                    remaining = packet_buf[0] - sizeof(struct uart_pkt_hdr);

                    if (remaining > MAX_PAYLOAD_SIZE) {
                        LOG_ERR("Not enough space in packet buffer");
                        state = ST_DISCARD;
                    } else {
                        state = ST_PAYLOAD;
                    }

                }
                break;

            case ST_PAYLOAD:
                read = uart_read(pic_uart_dev, &packet_buf[packet_buf[0] - remaining], remaining);
                remaining -= read;
                if (remaining == 0) {
                    /* Packet received */
                    LOG_DBG("putting RX packet in queue.");

                    if(packet_buf[packet_buf[0]] == CalcXOR(packet_buf, packet_buf[0])) {
                        cmd = packet_buf[1];
                        switch(cmd) {
                            case CMD_CHECK_MOBILE:
                                // Send response to PIC
                                data_buf[0] = 6;
                                data_buf[1] = PKT_HEADER;
                                data_buf[2] = 4;
                                data_buf[3] = CMD_CHECK_MOBILE;
                                data_buf[4] = RESP_CODE_PASS;  
                                data_buf[5] = MOBILE_CHECK_PENDING;
                                data_buf[6] = CalcXOR(&data_buf[2], 4);

                                char *mem_ptr = k_malloc(7);
                                __ASSERT_NO_MSG(mem_ptr != 0);
                                memcpy(mem_ptr, data_buf, 7);
                                k_fifo_put(&uart_tx_queue, mem_ptr);

                                state = ST_IDLE;
                                break;
                            default:
                                break;        
                        }
                    } else {
                        state = ST_DISCARD;
                    }              
                }
                break;
            case ST_DISCARD:
            {
                uint8_t discard[32];
                size_t to_read = MIN(remaining, sizeof(discard));

                read = uart_read(pic_uart_dev, discard, to_read);
                remaining -= read;
                if (remaining == 0) {
                    state = ST_IDLE;
                }

                break;

            }
            default:
                read = 0;
                __ASSERT_NO_MSG(0);
                break;

            }
        } while (read);
    }

    void uart_tx_thread(void)
    {
        uint8_t *data_buf;

        while(1) {
            data_buf = k_fifo_get(&uart_tx_queue, K_FOREVER);
            uart_fifo_fill(pic_uart_dev, &data_buf[1], data_buf[0]);
            k_free(data_buf);

            k_yield();
        }
    }

    static void uart_rx_isr(const struct device *unused, void *user_data)
    {
        ARG_UNUSED(unused);
        ARG_UNUSED(user_data);

        if (!uart_irq_rx_ready(pic_uart_dev)) {
            LOG_DBG("spurious interrupt");
        }

        if (uart_irq_rx_ready(pic_uart_dev)) {
            ReadUartPacket();
        }
    }

    static int pivot_bmd_init(const struct device *unused)
    {
        LOG_DBG("");

        if (!device_is_ready(pic_uart_dev)) {
            LOG_ERR("HCI UART %s is not ready", pic_uart_dev->name);
            return -EINVAL;
        }

        uart_irq_rx_disable(pic_uart_dev);
        uart_irq_tx_disable(pic_uart_dev);

        uart_irq_callback_set(pic_uart_dev, uart_rx_isr);
        uart_irq_rx_enable(pic_uart_dev);

        return 0;
    }


    SYS_INIT(pivot_bmd_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);

    void main(void)
    {
        /* incoming events and data from the PIC */
        static K_FIFO_DEFINE(uart_rx_queue);
        int err;

        LOG_DBG("Start");
        __ASSERT(pic_uart_dev, "UART device is NULL");

        /* Spawn the TX thread and start feeding commands and data to the
         * PIC
         */
        k_thread_create(&tx_thread_data, tx_thread_stack,
                K_THREAD_STACK_SIZEOF(tx_thread_stack), uart_tx_thread,
                NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT);
        k_thread_name_set(&tx_thread_data, "Pivot-BMD uart TX");

        while (1) {

        }
    }
    I got error when I compile the project:
    Building pivot_bmd_03-RTOS
    C:\WINDOWS\system32\cmd.exe /d /s /c "west build --build-dir c:/WorkFolder/FW/Nordic/WorkSpace/MS50SFA/pivot_bmd_03-RTOS/build c:/WorkFolder/FW/Nordic/WorkSpace/MS50SFA/pivot_bmd_03-RTOS"

    [1/44] Building C object zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj
    FAILED: zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj
    C:\ncs\toolchains\c57af46cb7\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF52832_XXAA -DUSE_PARTITION_MANAGER=0 -D__PROGRAM_START -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -IC:/ncs/v2.3.0/zephyr/include -Izephyr/include/generated -IC:/ncs/v2.3.0/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/ncs/v2.3.0/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.3.0/nrf/include -IC:/ncs/v2.3.0/nrf/tests/include -IC:/ncs/v2.3.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.3.0/modules/hal/nordic/nrfx -IC:/ncs/v2.3.0/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.3.0/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.3.0/zephyr/modules/hal_nordic/nrfx/. -isystem C:/ncs/v2.3.0/zephyr/lib/libc/minimal/include -isystem c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include -isystem c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed -fno-strict-aliasing -Os -imacros C:/WorkFolder/FW/Nordic/WorkSpace/MS50SFA/pivot_bmd_03-RTOS/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=C:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.3.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=C:/WorkFolder/FW/Nordic/WorkSpace/MS50SFA/pivot_bmd_03-RTOS=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.3.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.3.0=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj -MF zephyr\drivers\serial\CMakeFiles\drivers__serial.dir\uart_nrfx_uarte.c.obj.d -o zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj -c C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c
    In file included from C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_macro.h:34,
    from C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util.h:17,
    from C:/ncs/v2.3.0/zephyr/include/zephyr/devicetree.h:21,
    from C:/ncs/v2.3.0/zephyr/include/zephyr/device.h:12,
    from C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/uart.h:26,
    from C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:11:
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:173:53: error: expected expression before ',' token
    173 | Z_PINCTRL_STATE_INIT, (,), node_id) \
    | ^
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:72:26: note: in definition of macro '__DEBRACKET'
    72 | #define __DEBRACKET(...) __VA_ARGS__
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
    64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
    | ^~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
    59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_macro.h:157:9: note: in expansion of macro 'Z_COND_CODE_1'
    157 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_macro.h:201:9: note: in expansion of macro 'COND_CODE_1'
    201 | COND_CODE_1(_flag, _code, ())
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:2080:9: note: in expansion of macro 'IF_ENABLED'
    2080 | IF_ENABLED(CONFIG_PINCTRL, (PINCTRL_DT_DEFINE(UARTE(idx));)) \
    | ^~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_loops.h:1089:47: note: in expansion of macro '__DEBRACKET'
    1089 | Z_UTIL_LISTIFY_1(F, sep, __VA_ARGS__) __DEBRACKET sep \
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:105:36: note: in expansion of macro 'Z_UTIL_LISTIFY_2'
    105 | #define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__
    | ^
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:172:17: note: in expansion of macro 'LISTIFY'
    172 | LISTIFY(DT_NUM_PINCTRL_STATES(node_id), \
    | ^~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:242:9: note: in expansion of macro 'Z_PINCTRL_STATES_DEFINE'
    242 | Z_PINCTRL_STATES_DEFINE(node_id) \
    | ^~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:2080:37: note: in expansion of macro 'PINCTRL_DT_DEFINE'
    2080 | IF_ENABLED(CONFIG_PINCTRL, (PINCTRL_DT_DEFINE(UARTE(idx));)) \
    | ^~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:2181:1: note: in expansion of macro 'UART_NRF_UARTE_DEVICE'
    2181 | UART_NRF_UARTE_DEVICE(0);
    | ^~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:120:17: warning: '__pinctrl_state_pins_1__device_dts_ord_87' defined but not used [-Wunused-const-variable=]
    120 | _CONCAT(__pinctrl_state_pins_ ## state_idx, DEVICE_DT_NAME_GET(node_id))
    | ^~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:72:26: note: in definition of macro '__DEBRACKET'
    72 | #define __DEBRACKET(...) __VA_ARGS__
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
    64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
    | ^~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
    59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_macro.h:157:9: note: in expansion of macro 'Z_COND_CODE_1'
    157 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_macro.h:201:9: note: in expansion of macro 'COND_CODE_1'
    201 | COND_CODE_1(_flag, _code, ())
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:2080:9: note: in expansion of macro 'IF_ENABLED'
    2080 | IF_ENABLED(CONFIG_PINCTRL, (PINCTRL_DT_DEFINE(UARTE(idx));)) \
    | ^~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:69:53: note: in expansion of macro '__DEBRACKET'
    69 | #define __GET_ARG2_DEBRACKET(ignore_this, val, ...) __DEBRACKET val
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
    64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
    | ^~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
    59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_macro.h:157:9: note: in expansion of macro 'Z_COND_CODE_1'
    157 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:144:9: note: in expansion of macro 'COND_CODE_1'
    144 | COND_CODE_1(Z_PINCTRL_SKIP_STATE(state_idx, node_id), (), \
    | ^~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:146:9: note: in expansion of macro 'Z_PINCTRL_STATE_PINS_NAME'
    146 | Z_PINCTRL_STATE_PINS_NAME(state_idx, node_id)[] = \
    | ^~~~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_loops.h:1090:9: note: in expansion of macro 'Z_PINCTRL_STATE_PINS_DEFINE'
    1090 | F(1, __VA_ARGS__)
    | ^
    C:/ncs/v2.3.0/zephyr/include/zephyr/sys/util_internal.h:105:36: note: in expansion of macro 'Z_UTIL_LISTIFY_2'
    105 | #define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__
    | ^
    C:/ncs/v2.3.0/zephyr/include/zephyr/drivers/pinctrl.h:240:9: note: in expansion of macro 'LISTIFY'
    240 | LISTIFY(DT_NUM_PINCTRL_STATES(node_id), \
    | ^~~~~~~
    C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:2080:37: note: in expansion of macro 'PINCTRL_DT_DEFINE'
    2080 | IF_ENABLED(CONFIG_PINCTRL, (PINCTRL_DT_DEFINE(UARTE(idx));)) \
    | ^~~~~~~~~~~~~~~~~
    C:/ncs/v2.3.0/zephyr/drivers/serial/uart_nrfx_uarte.c:2181:1: note: in expansion of macro 'UART_NRF_UARTE_DEVICE'
    2181 | UART_NRF_UARTE_DEVICE(0);
    | ^~~~~~~~~~~~~~~~~~~~~
    [7/44] Building C object CMakeFiles/app.dir/src/main.c.obj
    ../src/main.c: In function 'main':
    ../src/main.c:266:65: warning: passing argument 4 of 'k_thread_create' from incompatible pointer type [-Wincompatible-pointer-types]
    266 | K_THREAD_STACK_SIZEOF(tx_thread_stack), uart_tx_thread,
    | ^~~~~~~~~~~~~~
    | |
    | void (*)(void)
    In file included from C:/ncs/v2.3.0/zephyr/include/zephyr/kernel.h:5890,
    from ../src/main.c:6:
    If I delete the Uart0 definition from Overlay, compiling is fine. That overlay works fine on bare metal project.
    Please help to take a look and tell me how to overlay with RTOS project.
    Thanks, Mark,

Children
Related