This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reconfig UART RX PIN as GPIO and use it to wake-up 52840. And how to do it using Zephyr UART?

Hi All,

I am new to Zephyr/NCS, so I am a little confused about which UART driver (Zephyr's uart/nrf_libuarte/nrfx_uart/nrfx_uarte) to use to approach this feature with the lowest power consumption:

My custom 52840 board have 2-wire rx/tx connected to a sensor's UART and there is no RTS/CTS.

After received UART data from the sensor, 52840 will wake up and then process the data send by the sensor and then back to sleep again.

The sensor will resend uart data until hear UART response from 52840, so I don't need to worry about data lost.

To do this, my plan is as same as mentioned in Case ID:231801

1. Configuring the rx as GPIO input and configuring the GPIO as wakeup pin with sense low

2. Read the GPIO status, if it is low then deinit the gpio and reinit it as UART

3. After done with the recved UART data, deinit the UART and reinit the rx pin as GPIO

My questions are:

1. Can I use Zephyr's UART/GPIO driver to do this or I must disable Zephyr's driver and use nrfx drivers directly?

2. Doing some search on devzone and it seems I should choose nrfx_uart over nrfx_uarte as enable easyDMA will have higher current consumption, am I correct?

3. Accourding to 1 and 2, which driver should I use? Zephyr's uart or nrf_libuarte or nrfx_uart or nrfx_uarte?

3. Is there any code snippet of init/deinit UART/GPIO in Zephyr/NCS? All I can find on github are using nrf APIs and seems deprecated in NCS 1.6.1.

Regards,

Anthony

Parents
  • Hi The lpuart source code can be found in \NCS_FOLDER\v1.x.0\nrf\samples\peripheral\lpuart.

    Best regards,

    Simon

  • Thanks for the update Simon.

    I read lpuart sample code and it looks like a sample shows how to use 4-wire lpuart but I can not find how it handles rdy-pin.

    I came across this repo NordicPlayground/nrf51-UART-examples and it use below code to set UART off when CTS pin toggled.

    uint32_t app_uart_close(uint16_t app_uart_uid)
    {
        uint16_t gpiote_uid;
    
        if (app_uart_uid < UART_INSTANCE_GPIOTE_BASE)
        {
            on_uart_event(ON_UART_CLOSE);
            return NRF_SUCCESS;
        }
    
        gpiote_uid = (app_uart_uid >> 8) & UART_INSTANCE_GPIOTE_BASE;
    
        if (gpiote_uid != m_gpiote_uid)
        {
            return NRF_ERROR_INVALID_PARAM;
        }
    
        on_uart_event(ON_UART_CLOSE);
    
        return app_gpiote_user_disable(m_gpiote_uid);
    }

    /**@brief Function for disabling the UART when entering the UART_OFF state.
     */
    static void action_uart_deactivate(void)
    {
        m_current_state         = UART_OFF;
        NRF_UART0->TASKS_STOPTX = 1;
        NRF_UART0->TASKS_STOPRX = 1;
        NRF_UART0->ENABLE       = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos);
    }

    But I can not find code handle NRF_UART0 register in NCS1.6.1, seems deprecated?

    Could you let me know which function is the counterpart of app_uart_close() in NCS?

    Regards,

    Anthony

Reply
  • Thanks for the update Simon.

    I read lpuart sample code and it looks like a sample shows how to use 4-wire lpuart but I can not find how it handles rdy-pin.

    I came across this repo NordicPlayground/nrf51-UART-examples and it use below code to set UART off when CTS pin toggled.

    uint32_t app_uart_close(uint16_t app_uart_uid)
    {
        uint16_t gpiote_uid;
    
        if (app_uart_uid < UART_INSTANCE_GPIOTE_BASE)
        {
            on_uart_event(ON_UART_CLOSE);
            return NRF_SUCCESS;
        }
    
        gpiote_uid = (app_uart_uid >> 8) & UART_INSTANCE_GPIOTE_BASE;
    
        if (gpiote_uid != m_gpiote_uid)
        {
            return NRF_ERROR_INVALID_PARAM;
        }
    
        on_uart_event(ON_UART_CLOSE);
    
        return app_gpiote_user_disable(m_gpiote_uid);
    }

    /**@brief Function for disabling the UART when entering the UART_OFF state.
     */
    static void action_uart_deactivate(void)
    {
        m_current_state         = UART_OFF;
        NRF_UART0->TASKS_STOPTX = 1;
        NRF_UART0->TASKS_STOPRX = 1;
        NRF_UART0->ENABLE       = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos);
    }

    But I can not find code handle NRF_UART0 register in NCS1.6.1, seems deprecated?

    Could you let me know which function is the counterpart of app_uart_close() in NCS?

    Regards,

    Anthony

Children
No Data
Related