UART0 RX interrupt stuck in while loop doesn't allow lwm2m function to run?

Hello,

We want to read external sensor data using uart in lwm2m_client project.

I tried below following code :

static char RX_Data;
static char uart_buf[20];
static char *command1 = "This Is A Test of UART0\r\n";
void uart_cb(struct device *x)
{
uart_irq_update(x);
int data_length = 0;

if (uart_irq_rx_ready(x)) {
data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
uart_buf[data_length] = 0;
printk("%s\r\n", uart_buf);
RX_Data= uart_buf[0];
printk("Recived Data %c\r\n", RX_Data);
}


}

==================================================

struct device *uart = device_get_binding("UART_0");
uart_irq_callback_set(uart, uart_cb);
uart_irq_rx_enable(uart);
printk(" UART0 start!\n");

while (true)
{ //uart_send_str(uart1, command1);
lwm2m_rd_client_start(&client, endpoint_name, flags, rd_client_event);

k_sem_take(&lwm2m_restart, K_FOREVER);

LOG_INF("LwM2M restart requested. The sample will try to"
" re-establish network connection.");

/* Stop the LwM2M engine. */
lwm2m_rd_client_stop(&client, rd_client_event);

/* Try to reconnect to the network. */
ret = lte_lc_offline();
if (ret < 0) {
LOG_ERR("Failed to put LTE link in offline state (%d)", ret);
}

modem_connect();

}

==========================================

In terminal it's waiting for next RX value. which doesn't allow to run other function. how we can run both together?

How we can switch UART0 to UART1? i tried to modified above code but it doesn't work.

Best Regards

Deepak  

Parents
  • Hello!

    In terminal it's waiting for next RX value. which doesn't allow to run other function.

    I think it's a bad idea to place your uart read code in an ISR, for exactly the reason you mention that other functions get starved while the high priority ISR is waiting for the uart device.

    Instead I would make a lower priority thread that takes care of your uart reading, that you can signal to with a semaphore from your ISR.

    How we can switch UART0 to UART1? 

    When you call device_get_binding("UART_0"), you are using Zephyr's Devicetree API to access your device.

    You can find the devicetree file in your application folder as build/zephyr/zephyr.dts

    If you look up the uart nodes in this file you'll find that uart_1 is disabled by default in the lwm2m_client project (status = "disabled").

    One way to change this is by adding a devicetree overlay file to your project. Please refer to Zephyr's introduction to devicetree to learn how to do this.

    Best regards,

    Einar

  • I didn't understand shared documents. but i found uart1 can't use for _ns board project :

    so i am trying to configure uart2:

    In prj.conf
    CONFIG_UART_2_NRF_UARTE=y
    but it shows this :: CONFIG_UART_2_NRF_UARTE cannot be set (has no prompt) and getting error in compilation.

    Compiled Deice tree output showing this:

    art2: uart@a000 {

                                    compatible = "nordic,nrf-uarte";
                                    reg = <0xa000 0x1000>;
                                    interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>;
                                    status = "disabled";
                                    label = "UART_2";
                                    tx-pin = <24>;
                                    rx-pin = <23>;
    ==========================================================================
    can we enable in device tree: manually?
    uart2: uart@a000 {
        compatible = "nordic,nrf-uarte";
        reg = <0xa000 0x1000>;
        interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>;
        status = "disabled";
        label = "UART_2";
    };
    and
     &uart2 {
        status = "okay";
        current-speed = <115200>;
        tx-pin = <24>;
        rx-pin = <23>;
        rx-pull-up;
       
    };
    Best Regards
    Deepak
  • Yes you can enable it manually, and that's what you're supposed to do.

    But you don't edit the devicetree file itself, you add a devicetree overlay file to your project.

    You would know this if you read through what I sent you.

    Please read the devicetree documentation, and about how to use devicetree overlays here.

    -Einar

  • Is this my "nrf9160dk_uart2_nrf9160_ns.overlay" file correct?

    -------------------------------------------------------------------------------------------------------------------------

    #include <nordic/nrf9160ns_sica.dtsi>
    #include "nrf9160dk_nrf9160_common.dts"

    / {
    chosen {
    zephyr,uart=&uart2;
    };
    };

    &uart2 {
    compatible = "nordic,nrf-uarte";
    current-speed = <115200>;
    status = "okay";
    label = "UART_2";
    tx-pin = <24>;
    rx-pin = <23>;
    /* Set to FFFFFFFF to disconnect/disable */
    rts-pin = <0xFFFFFFFF>;
    cts-pin = <0xFFFFFFFF>;

    };

    ------------------------------------------------------------------------------------

    I am planning to add this file in Board folder of project

    and 

    In prj.conf file includes >> 
    CONFIG_SERIAL=y
    CONFIG_TRUSTED_EXECUTION_NONSECURE=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_UART_2_NRF_UARTE=y
    ---------------------------------------------------------------------------------
    Is this correct way? Could you please help me ...
    Best Regards
    Deepak Aagri
  • if i include this CONFIG_UART_2_NRF_UARTE=y
    I am this error....
    ------------------------------------------------------------------------------------------------------------
    Merged configuration 'c:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client/prj.conf'
    Merged configuration 'c:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client/boards/nrf9160dk_nrf9160_ns.conf'
    Merged configuration 'C:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client/build/zephyr/misc/generated/extra_kconfig_options.conf'

    error: UART_2_NRF_UARTE (defined at c:\Users\kumarde\ncs\v1.9.0\nrf\samples\nrf9160\lwm2m_client\build\drivers\serial\Kconfig.nrfx:198) is assigned in a configuration
    file, but is not directly user-configurable (has no prompt). It gets its value indirectly from other
    symbols. See docs.zephyrproject.org/.../CONFIG_UART_2_NRF_UARTE.html
    and/or look up UART_2_NRF_UARTE in the menuconfig/guiconfig interface. The Application Development
    Primer, Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual
    might be helpful too.

    CMake Error at C:\Users\kumarde\ncs\v1.9.0\zephyr\cmake\kconfig.cmake:272 (message):
    command failed with return code: 1
    Call Stack (most recent call first):
    C:\Users\kumarde\ncs\v1.9.0\zephyr\cmake\app\boilerplate.cmake:544 (include)
    C:\Users\kumarde\ncs\v1.9.0\zephyr\share\zephyr-package\cmake\ZephyrConfig.cmake:24 (include)
    C:\Users\kumarde\ncs\v1.9.0\zephyr\share\zephyr-package\cmake\ZephyrConfig.cmake:35 (include_boilerplate)
    c:\Users\kumarde\ncs\v1.9.0\nrf\samples\nrf9160\lwm2m_client\build\CMakeLists.txt:9 (find_package)


    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: 'c:\Users\kumarde\ncs\v1.9.0\toolchain\opt\bin\cmake.EXE' '-DWEST_PYTHON=c:\Users\kumarde\ncs\v1.9.0\toolchain\opt\bin\python.exe' '-Bc:\Users\kumarde\ncs\v1.9.0\nrf\samples\nrf9160\lwm2m_client\build' '-Sc:\Users\kumarde\ncs\v1.9.0\nrf\samples\nrf9160\lwm2m_client' -GNinja -DBOARD=nrf9160dk_nrf9160_ns -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=On -DNCS_TOOLCHAIN_VERSION:STRING=NONE -DBOARD_ROOT:STRING=c:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client -DCONFIG_DEBUG_OPTIMIZATIONS:STRING=y -DCONFIG_DEBUG_THREAD_INFO:STRING=y -DDTC_OVERLAY_FILE:STRING=c:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client/boards/nrf9160dk_nrf9160_ns.overlay '-DCONF_FILE:STRING=c:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client/prj.conf;c:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client/boards/nrf9160dk_nrf9160_ns.conf'
    The terminal process terminated with exit code
    Best Regards
    Deepak Aagri
Reply
  • if i include this CONFIG_UART_2_NRF_UARTE=y
    I am this error....
    ------------------------------------------------------------------------------------------------------------
    Merged configuration 'c:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client/prj.conf'
    Merged configuration 'c:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client/boards/nrf9160dk_nrf9160_ns.conf'
    Merged configuration 'C:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client/build/zephyr/misc/generated/extra_kconfig_options.conf'

    error: UART_2_NRF_UARTE (defined at c:\Users\kumarde\ncs\v1.9.0\nrf\samples\nrf9160\lwm2m_client\build\drivers\serial\Kconfig.nrfx:198) is assigned in a configuration
    file, but is not directly user-configurable (has no prompt). It gets its value indirectly from other
    symbols. See docs.zephyrproject.org/.../CONFIG_UART_2_NRF_UARTE.html
    and/or look up UART_2_NRF_UARTE in the menuconfig/guiconfig interface. The Application Development
    Primer, Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual
    might be helpful too.

    CMake Error at C:\Users\kumarde\ncs\v1.9.0\zephyr\cmake\kconfig.cmake:272 (message):
    command failed with return code: 1
    Call Stack (most recent call first):
    C:\Users\kumarde\ncs\v1.9.0\zephyr\cmake\app\boilerplate.cmake:544 (include)
    C:\Users\kumarde\ncs\v1.9.0\zephyr\share\zephyr-package\cmake\ZephyrConfig.cmake:24 (include)
    C:\Users\kumarde\ncs\v1.9.0\zephyr\share\zephyr-package\cmake\ZephyrConfig.cmake:35 (include_boilerplate)
    c:\Users\kumarde\ncs\v1.9.0\nrf\samples\nrf9160\lwm2m_client\build\CMakeLists.txt:9 (find_package)


    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: 'c:\Users\kumarde\ncs\v1.9.0\toolchain\opt\bin\cmake.EXE' '-DWEST_PYTHON=c:\Users\kumarde\ncs\v1.9.0\toolchain\opt\bin\python.exe' '-Bc:\Users\kumarde\ncs\v1.9.0\nrf\samples\nrf9160\lwm2m_client\build' '-Sc:\Users\kumarde\ncs\v1.9.0\nrf\samples\nrf9160\lwm2m_client' -GNinja -DBOARD=nrf9160dk_nrf9160_ns -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=On -DNCS_TOOLCHAIN_VERSION:STRING=NONE -DBOARD_ROOT:STRING=c:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client -DCONFIG_DEBUG_OPTIMIZATIONS:STRING=y -DCONFIG_DEBUG_THREAD_INFO:STRING=y -DDTC_OVERLAY_FILE:STRING=c:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client/boards/nrf9160dk_nrf9160_ns.overlay '-DCONF_FILE:STRING=c:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client/prj.conf;c:/Users/kumarde/ncs/v1.9.0/nrf/samples/nrf9160/lwm2m_client/boards/nrf9160dk_nrf9160_ns.conf'
    The terminal process terminated with exit code
    Best Regards
    Deepak Aagri
Children
Related