UART Async and Interrupt on different peripherals

I have an nRF5340 and I need to run two different peripherals. One uses the Modbus driver, which requires CONFIG_UART_INTERRUPT_DRIVEN, and another I'm writing but would like to use CONFIG_UART_ASYNC_API.

The Zephyr UART library page has a large warning that these two should not be used at the same time, as they both require hardware interrupts and they would conflict. What's not clear, though, is whether they can't both be used on the same UART peripheral simultaneously, or if they can't be used simultaneously on two different UART peripherals (e.g. uart0 with interrupts, uart1 with async).

Is it safe to disable CONFIG_UART_EXCLUSIVE_API_CALLBACKS in order to enable both the interrupt and async APIs, to be used on different peripherals?

Parents
  • Hi,

    If you're using two different UART instances for each, then it should be ok.

    Are you getting any build time errors when you do that, since you asked about disabling CONFIG_UART_EXCLUSIVE_API_CALLBACKS ?

    regards
    Jared 

  • No, I get runtime errors. When I try to add a UART callback (for async), it returns an error saying that the API is not supported on this system.

  • Hi,

    From our developers: when i greped zephyr code i see that UARTE driver is not using CONFIG_UART_EXCLUSIVE_API_CALLBACKS at all, only UART (legacy peripheral present in nrf51/2). So I am not sure why run time error is seen.

    Do you have a small example that you could share which would reproduce this?

    regards

    Jared 

  • Hi Jared,

    The simplest example is actually the Developer Academy Lesson 5.

    If you add

    CONFIG_UART_INTERRUPT_DRIVEN=y

    to proj.conf, the `uart_callback_set` function (this line) will start returning a -ENOSYS (which, according to the documentation, means it "is not supported by the device".

    After re-reading the Zephyr documentation, it says that you should only not use both for the same hardware peripheral. So, it seems that using both `CONFIG_UART_INTERRUPT_DRIVEN` and `CONFIG_UART_ASYNC_API` should be supported, yet it returns this error.

  • Hi,

    Looking at the dts of the developer academy lesson 5, I see that only 1 instance of the UART peripheral has been enabled, namely UART0. Adding CONFIG_UART_INTERRUPT_DRIVEN=y while CONFIG_UART_ASYNC_API=y already being defined will violate the requirement of never using both for the same hw peripheral. 

    Did you enable another UART instance already?

    regards

    Jared 

  • Yes, I had the second UART enabled.

    I found the issue. It requires using these Kconfig options:

    # Enable both APIs
    CONFIG_UART_ASYNC_API=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    
    # Flag UART0 as not ASYNC, but INTERRUPT
    CONFIG_UART_0_ASYNC=n
    CONFIG_UART_0_INTERRUPT_DRIVEN=y
    
    # Flag UART1 as not INTERRUPT, but ASYNC
    CONFIG_UART_1_INTERRUPT_DRIVEN=n
    CONFIG_UART_1_ASYNC=y

    This tells it which APIs to use on which peripherals.

    These CONFIG_UART_# Kconfigs don't seem to be documented anywhere and I only found them in digging through the source code. They're part of the nRF Connect SDK, not Zephyr, so they should be documented by Nordic.

    Unless I'm missing where they're already documented, in which case a link would be appreciated.

Reply
  • Yes, I had the second UART enabled.

    I found the issue. It requires using these Kconfig options:

    # Enable both APIs
    CONFIG_UART_ASYNC_API=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    
    # Flag UART0 as not ASYNC, but INTERRUPT
    CONFIG_UART_0_ASYNC=n
    CONFIG_UART_0_INTERRUPT_DRIVEN=y
    
    # Flag UART1 as not INTERRUPT, but ASYNC
    CONFIG_UART_1_INTERRUPT_DRIVEN=n
    CONFIG_UART_1_ASYNC=y

    This tells it which APIs to use on which peripherals.

    These CONFIG_UART_# Kconfigs don't seem to be documented anywhere and I only found them in digging through the source code. They're part of the nRF Connect SDK, not Zephyr, so they should be documented by Nordic.

    Unless I'm missing where they're already documented, in which case a link would be appreciated.

Children
Related