Soft UART (Uart-bitbang) on nRF52 DK (nrf52832) fails with

Hi all hope you all are fine and doing well.

I am trying to use the Soft UART (uart-bitbang.c driver) on nRF52 DK for a low-speed UART connection. The initialization fails with the following error: <err> uart_bitbang: Couldn't configure tx counter. 

This happens repeatedly and I cannot transmit data using the software UART (bitbang).

Board & SDK:

  • nRF52 DK (nRF52832)

  • nRF Connect SDK Toolchain v3.2.0 (VS code Extension) / Zephyr v4.2.99

  • Baudrate: 2400

Problem:

  • Soft UART (uart-bitbang) fails to initialize.

  • Error seen: <err> uart_bitbang: Couldn't configure tx counter

  • Cannot transmit data using software UART (bitbang).

Setup:

  • Device Tree overlay configured with uart-bitbang on P0.13 (TX) and P0.14 (RX).

  • prj.conf enables GPIO, SERIAL, UART_BITBANG, and logging.

  • main.c uses uart_poll_out() for TX.

Steps to Reproduce:

  1. Build Soft UART project using Zephyr SDK v4.2.99 for nRF52 DK

  2. Use overlay and prj.conf as below

  3. Flash on nRF52 DK

  4. Observe error in logs (Serial monitor of VS Code with default baudrate of 115200)

Questions / Help needed:

  1. Why does the TX counter fail to configure?

  2. Are there limitations of uart-bitbang on nRF52 DK?

  3. Is there an example of Soft UART initialization for nRF52 DK?

nrf52dk_nrf52832.overlay file

/ {
    uart_bb0: uart_bitbang_0 {
        compatible = "zephyr,uart-bitbang";
        status = "okay";

        label = "UART_BB0";

        tx-gpios = <&gpio0 13 GPIO_ACTIVE_HIGH>;
        rx-gpios = <&gpio0 14 GPIO_ACTIVE_HIGH>;

        current-speed = <2400>;      /* numeric, correct property */

        data-bits = <8>;      
        stop-bits = "1";    
        parity = "none";    
    };
};
Prj.conf file
# GPIO and Hardware
CONFIG_GPIO=y

# Counter support (required for uart-bitbang timing)
# The driver uses counter API internally, counter driver will be auto-selected
CONFIG_COUNTER=y

# UART
CONFIG_SERIAL=y

CONFIG_UART_BITBANG=y
CONFIG_UART_INTERRUPT_DRIVEN=n
CONFIG_PRINTK=y

# Logging
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_BACKEND_UART=y
CONFIG_USE_SEGGER_RTT=n

# System Settings
CONFIG_REBOOT=y

CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_LOG_MODE_IMMEDIATE=y


Sample.yaml
sample:
  name: UART Bitbang Test

tests:
  uart.bitbang.basic:
    platform_allow:
      - nrf52dk_nrf52832
    tags:
      - uart
      - bitbang
    harness: console
main.c
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/sys/printk.h>

#define UART_LABEL "UART_BB0"  // Must match the label in your DTS overlay

static uint32_t tx_count = 0;
static uint32_t rx_count = 0;

int main(void)
{
    const struct device *uart = device_get_binding(UART_LABEL);

    if (!uart) {
        printk("ERROR: Could not get UART device binding!\n");
        return 0;
    }

    if (!device_is_ready(uart)) {
        printk("ERROR: Soft UART device not ready!\n");
        return 0;
    }

    printk("Soft UART ready @ %lld ms\n", k_uptime_get());

    const char msg[] = "Hello UART Bitbang\r\n";

    while (1) {
        printk("\nTX loop start @ %lld ms\n", k_uptime_get());

        // Use uart_poll_out for blocking transmission (simpler for bit-bang)
        for (size_t i = 0; i < sizeof(msg) - 1; i++) {
            uart_poll_out(uart, msg[i]);
        }
        tx_count += sizeof(msg) - 1;
        printk("TX done, total TX chars = %u\n", tx_count);

        // Non-blocking RX check
        uint8_t rx;
        int ret = uart_poll_in(uart, &rx);
        if (ret == 0) {
            printk("RX[%u]: '%c' (0x%02X)\n", rx_count, rx, rx);
            rx_count++;
        } else {
            printk("RX: no data available\n");
        }

        k_sleep(K_SECONDS(2));
    }
}
Output Result

Best Regards
Nabeel
Parents Reply Children
No Data
Related