nRF5340, switch UART code to use another peripheral (uart1 instead of uart0)

I would like to setup a project that uses multiple UART peripherals, based off separate projects I have that each use 1 UART peripheral:

  • Separate project #1 (based off NCS 2.5.0 at nrf/samples/bluetooth/peripheral_uart) uses UART (based off DT_NODELABEL(uart0)) for outputting raw data
  • Separate project #2 (based off NCS 2.5.0 at zephyr/samples/drivers/uart/echo_bot) uses UART (based off DT_CHOSEN(zephyr_shell_uart)) through the COM port so that a user can interact with it like a serial terminal (user types in some commands, terminal replies with info).

Since both of the projects utilize UART0, and the one outputting raw data does so every couple milliseconds, the 'combined project' needs the 2 features to be on their own UART peripherals. I've been trying to play around with changing #1 to use UART1, but I would never see the data output over the UART1 pins. I was doing the following:

  • NOTE - I didn't make changes to the pinout of UART1, so it should be using the default P1.00 for RX and P1.01 for TX.
  • main.c, change argument for DEVICE_DT_GET() to 'DT_NODELABEL(arduino_serial)'
  • prj.conf, add: CONFIG_UART_ASYNC_API=y, CONFIG_NRFX_UARTE1=y and CONFIG_UART_1_INTERRUPT_DRIVEN=n
    • To get #1 to work, I added: CONFIG_UART_ASYNC_API=y, CONFIG_NRFX_UARTE0=y, and CONFIG_UART_0_INTERRUPT_DRIVEN=n
  • nrf.overlay, add &uart1 { status = "okay"; }

I am relatively new to Zephyr, using overlays, etc. so making changes like this haven't been easy, and I've been struggling to find resources/websites showing how it should be done. If anyone has any thoughts about what else I can try, please let me know. Thanks in advance!

Here are some other details that might be relevant:

  • My build configuration file is selected to be prj.conf
  • My combined project is also utilizing both cores for the nRF5340 for other features. When playing around, I did somehow see printk() calls from my network core being 'duplicated'/also-shown on UART1 default pins (connected FTDI to P1.00 and P1.01). So far I haven't seen any code for the network core that specifies using UART1 for printk(), so I'm a little confused how that can be the case.

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

Development Setup:

  • Board: nRF5340-DK
  • Development Environment: VS Code
  • SDK: nRF Connect 2.5.0
  • OS: Windows 10
Parents Reply Children
  • Yes that seemed to be it; the net core was indeed 'getting in the way' (thanks Hieu). If I made my changes to #1 (see original post), but in another project that didn't utilize the network core, they worked. In hindsight, I probably should have tried this first. But glad to know my changes to #1 are at least one way to change from uart0 to uart1.

  • I also did get it working for my dual-core project as well; I ended using UART1 (with different pins) for the #1 code and UART0 (default i.e., no pins were changed) for the #2 code. In my case, I didn't need UART1 to output to the VCOM and chose P0.25 and P0.26. In short, these were the additional code changes I needed to make:

    • nrf.overlay, add '&pinctrl' block with my own default/sleep configurations (but w/ P0.25 and P0.26)
      • My default & sleep configurations had label 'uart1_alt_default' and 'uart1_alt_sleep' respectively
      • Configurations had same format as ones like 'uart0_default' and 'uart0_sleep' (see NCS 2.5.0 at zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common-pinctrl.dtsi)
    • nrf.overlay, edit '&uart1' block to additionally have:
      • pinctrl-0=< &uart1_alt_default >
      • pinctrl-1=< &uart1_alt_sleep >
Related