Working UART and Console configuration for NRF52840 does not work for NRF5340

Hi,

I've run into a problem where a codebase build for NRF52840dk and NRF5340dk boards successfully but running it on the NRF5340 results in logs not working.

I have included the relevant configuration content below which comes from two configuration files that we are applying in the build: "prj.conf" & "nrf5340dk_nrf5340_cpuapp.conf"

We have a custom library running on UART 1 that handles custom protocol building/parsing, error checking and UART TX & RX, and we have the logs running on the default UART 0.

Can you advise what configuration changes we need to make to allow this to work for both the NRF52840dk and the NRF5340dk?

sdk-nrf version: v2.5.1

nrf5340dk_nrf5340_cpuapp.conf Contents:

CONFIG_UART_1_ASYNC=y
CONFIG_UART_1_INTERRUPT_DRIVEN=n

CONFIG_UART_0_INTERRUPT_DRIVEN=y
CONFIG_UART_0_ASYNC=n

prj.conf Contents:

# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
#
# This file contains selected Kconfig options for the application.
CONFIG_ASSERT=y

CONFIG_LOG=y
CONFIG_BOOT_BANNER=n
CONFIG_APP_LOG_LEVEL_INF=y
CONFIG_APP_BUTTON_LOG_LEVEL_INF=y
CONFIG_APP_LED_LOG_LEVEL_INF=y
CONFIG_APP_UART_LOG_LEVEL_DBG=y

CONFIG_INTER_MCU_COMMS_LOG_LEVEL=4

CONFIG_ZBUS=y
CONFIG_ZBUS_LOG_LEVEL_INF=y
CONFIG_ZBUS_RUNTIME_OBSERVERS=y

CONFIG_ZBUS_CHANNEL_NAME=y
CONFIG_ZBUS_OBSERVER_NAME=y

CONFIG_GPIO=y

CONFIG_SERIAL=y
CONFIG_UART_ASYNC_API=y

CONFIG_SHELL=y
CONFIG_LOG_CMDS=y
CONFIG_DEVICE_SHELL=y
CONFIG_GPIO_SHELL=y

# Task Watchdog
CONFIG_TASK_WDT=y
CONFIG_TASK_WDT_CHANNELS=11
CONFIG_TASK_WDT_MIN_TIMEOUT=10000

# Device power management
CONFIG_PM_DEVICE=y

#Debug
CONFIG_DEBUG=y
CONFIG_DEBUG_OPTIMIZATIONS=y

# BT
CONFIG_BT_LL_SW_SPLIT=n
CONFIG_BT=y
CONFIG_BT_ID_MAX=1
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_BAS=y
CONFIG_BT_HRS=n
CONFIG_BT_DEVICE_NAME="XXXX"
CONFIG_BT_DEVICE_APPEARANCE=31368
# 32 Seconds
CONFIG_BT_LIM_ADV_TIMEOUT=32
# 12.5ms to 15ms COnnection Interval
CONFIG_BT_PERIPHERAL_PREF_MIN_INT=10
CONFIG_BT_PERIPHERAL_PREF_MAX_INT=12

# Enable the NUS service
CONFIG_BT_NUS=y

# BT Pairing
CONFIG_BT_SMP=y
CONFIG_BT_SMP_APP_PAIRING_ACCEPT=y
CONFIG_BT_MAX_CONN=2
CONFIG_BT_MAX_PAIRED=2
CONFIG_BT_FIXED_PASSKEY=y
CONFIG_BT_FILTER_ACCEPT_LIST=y
# The use of RPA is not enabled
CONFIG_BT_PRIVACY=n

# # DIS Items
CONFIG_BT_DIS=y
CONFIG_BT_DIS_PNP=n
CONFIG_BT_DIS_SERIAL_NUMBER=y
CONFIG_BT_DIS_FW_REV=y
CONFIG_BT_DIS_HW_REV=y
CONFIG_BT_DIS_SW_REV=y
CONFIG_BT_DIS_SERIAL_NUMBER_STR="X.X.X.X"
CONFIG_BT_DIS_FW_REV_STR="FW V00.00.00.00"
CONFIG_BT_DIS_HW_REV_STR="Zephyr Hardware"
CONFIG_BT_DIS_SW_REV_STR="Zephyr Software"

# Below is setup to let DIS information be read from settings
CONFIG_BT_SETTINGS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NONE=y

CONFIG_BT_DIS_SETTINGS=y
CONFIG_BT_DIS_STR_MAX=31

# Below is setup to let DIS information be read from settings
CONFIG_SETTINGS_NONE=y

# Enable BT Bonding and DIS info read from settings
CONFIG_BT_SETTINGS=y
CONFIG_SETTINGS=y
CONFIG_NVS=y
CONFIG_SETTINGS_NVS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_BT_BONDABLE=y
CONFIG_BT_ID_UNPAIR_MATCHING_BONDS=y

# Stacks & threads
CONFIG_MPU_STACK_GUARD=y
CONFIG_BT_RX_STACK_SIZE=2048
# Note: This stack must be 2K or higher to avoid stack overflow when pairing to Android Devices
CONFIG_MPSL_WORK_STACK_SIZE=2048
CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y
CONFIG_BT_HCI_TX_STACK_SIZE=1024
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4608
CONFIG_IDLE_STACK_SIZE=1024
CONFIG_MAIN_STACK_SIZE=4096

# Priority
# We set the main thread priority low to ensure all other threads have a chance to run first and block on their
# semaphores. Doing this is better since we do not have to wait for the other threads to run first
CONFIG_MAIN_THREAD_PRIORITY=10

# Helps make breakpoint debugging more reliable - otherwise will often not break at main
CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=n
CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH=n

# Logging & Console
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_LOG_TIMESTAMP_64BIT=y

CONFIG_USE_SEGGER_RTT=n
CONFIG_RTT_CONSOLE=y
CONFIG_PRINTK=y
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_SENSOR=y
# Inter-MCU Comms Module
CONFIG_INTER_MCU_COMMS_MODULE=y
CONFIG_RING_BUFFER=y
CONFIG_CRC=y
CONFIG_INTER_MCU_COMMS_MAX_PAYLOAD_SIZE=1024
CONFIG_MW_COBS=y
CONFIG_HEAP_MEM_POOL_SIZE=4096
  • Have you looked into the device tree stuff? The NRF5340 has different GPIOs set up by default IIRC.

    You also have to share some of those BT configs with the network core.

  • Further update on a number of things I've tried with some help from Johnny:

    1. Temporarily changed log backend to use RTT so I can view logs.

    • Added the following to prj.conf:
    CONFIG_SHELL_LOG_BACKEND=n
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    • This allowed me to view logs via RTT
    • With logs now accessible via RTT I can see the other issue that we are encountering with our current configuration:
    • UART1 is getting constant "UART_RX_STOPPED" errors with reason "0x04" [UART_ERROR_FRAMING] , even though we have nothing connected to that UART and we are not sending it any data.

    2. Disable I2C1 in case it was clashing with UART1 and causing the framing errors:

    • We aren't using I2C1 in out application code but it was being enabled in the device tree due to its inclusion in the NRF5340dk base device tree files.
    • The following was added to the overlay file to disable it:
    &i2c1 {
    status = "disabled";
    };
    • This change had no effect on the UART1 issue


    So after these steps we have two problems to resolve:
    1. UART1 is encountering constant framing errors even though it is received no data
    2. We cannot get logs on UART0 with our current configuration

  • Further update:

    1. UART1 is encountering constant framing errors even though it is received no data [SOLVED]

    2. We cannot get logs on UART0 with our current configuration

    Solution for Problem #1:

    The UART1 issue was due to the UART1 pins being made available for the network core to use as a UART out via the GPIO forwarder node in the nrf5340dk_nrf5340_cpuapp device tree.

    To resolve the issue I implementing a combination of solutions from the following tickets (Ticket1 and Ticket2).

    I added an overlay file for both the cpuapp and cpunet.

    The cpunet opverlay file must be placed in the following folder for the build system to detect it: 

    "<application root folder>/child_image/hci_rpmsg/boards"  

    The gpio forwarder was disabled in the cpuapp overlay:

    / {
    gpio_fwd: nrf-gpio-forwarder {
    status = "disabled";
    };
    };

    uart0 was disabled in the cpunet overlay:

    &uart0 {
    status = "disabled";
    };

    Note: I tired to disable serial by adding "CONFIG_SERIAL=n" to a .conf file for the cpunet child image build but this resulted in a build error so I disabled uart0 via the overlay instead.

    Solution for Problem #2:

    Hopefully you can help shed some light on how to resolve issue number 2 and then it will be fully resolved

  • MarkMcAllisterMW said:

    Solution for Problem #2:

    Hopefully you can help shed some light on how to resolve issue number 2 and then it will be fully resolved

    So your current issue is that you do not get logs on the nRF5340DK on UART0, right?

    How do you try to read from UART0?

    I can suggest that you try to run a simple sample (like hello_world) and only add UART0 configurations to this sample, then see if that works. This will help us rule out if any other parts of the project impacts this issue.

Related