This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52833 peripheral_uart zephyr example only works with "prj_minimal.conf", and not "prj.conf"

Hi,

I have built and flashed the "peripheral_uart" example on the nrf52833dk_nrf52833 from nrfconnect sdk v1.5.0. When I build using the prj_minimal.conf file, everything works as expected; I can send data through the J-Link UART and it appears as a notification in the nrfconnect app on my iOS device (iPhone SE). I can also perform writes to the RX characteristic and then it is sent to the UART.

However, when I build with the prj.conf file, it doesn't appear to work. I can connect to the device, but when I try to subscribe to the notification TX characteristic, the iOS app says "writing is not permitted", and if I try to send UART data, I can see the message "peripheral_uart: Failed to send data over BLE connection" in the RTT logs.

[00:00:02.824,951] [0m<inf> fs_nvs: 6 Sectors of 4096 bytes[0m
[00:00:02.824,981] [0m<inf> fs_nvs: alloc wra: 0, fd8[0m
[00:00:02.824,981] [0m<inf> fs_nvs: data wra: 0, 19[0m
[00:00:02.825,195] [0m<inf> sdc_hci_driver: SoftDevice Controller build revision: 
                                         e5 c7 9c d9 91 00 1d 66  ea fb 6e 7b 98 2f 42 0d |.......f ..n{./B.
                                         f1 60 93 c8                                      |.`..             [0m
[00:00:02.829,284] [0m<inf> bt_hci_core: No ID address. App must call settings_load()[0m
[00:00:02.829,315] [0m<inf> peripheral_uart: Bluetooth initialized[0m
[00:00:07.445,739] [0m<inf> peripheral_uart: Connected 6E:9E:F9:93:3E:97 (random)[0m
[00:00:07.934,997] [1;33m<wrn> bt_l2cap: Ignoring data for unknown CID 0x003a[0m
[00:17:52.777,465] [1;33m<wrn> peripheral_uart: Failed to send data over BLE connection[0m
[00:17:53.791,168] [1;33m<wrn> peripheral_uart: Failed to send data over BLE connection[0m
[00:17:56.850,860] [1;33m<wrn> peripheral_uart: Failed to send data over BLE connection[0m

Looking at the code, I think this has something to do with bonding/pairing, but the iOS app doesn't seem to ask to pair when I connect to the device.

Could you please help me understand what I am doing wrong here?

Thanks.

Parents Reply Children
  • Another interesting update: I just built the code for the nrf52840dk_nrf52840 and it works fine. All I did was:

    rm -fr build/
    BOARD=nrf52840dk_nrf52840 west build
    BOARD=nrf52840dk_nrf52840 west flash

    And now I don't see the error in the nrfconnect iOS app when subscribing to notifications, but I also get a brand new error in the RTT console which implies that the k_malloc is failing:

    [00:00:02.049,835] [1;33m<wrn> peripheral_uart: Not able to allocate UART receive buffer[0m

  • This error was caused by setting the wrong baudrate in the terminal (9600 instead of 115200, my mistake), and presumably some garbage being received means that the uart_work_handler is stuck in an infinite loop as the memory is never being freed, so the malloc will always fail forever:

    static void uart_work_handler(struct k_work *item)
    {
            struct uart_data_t *buf;
    
            buf = k_malloc(sizeof(*buf));
            if (buf) {
                    buf->len = 0;
            } else {
                    LOG_WRN("Not able to allocate UART receive buffer");
                    k_delayed_work_submit(&uart_work, UART_WAIT_FOR_BUF_DELAY);
                    return;
            }
    
            uart_rx_enable(uart, buf->data, sizeof(buf->data), UART_WAIT_FOR_RX);
    }
    

  • I have just confirmed that the example code flashed to a nrf52840dk works fine with the iOS app:

    rm -fr build
    BOARD=nrf52840dk_nrf52840 west build
    BOARD=nrf52840dk_nrf52840 west flash

    But then the exact same code on the nrf52833dk does not work with the iOS app with the error box saying "writing is not permitted":

    rm -fr build
    BOARD=nrf52833dk_nrf52833 west build
    BOARD=nrf52833dk_nrf52833 west flash

    So it appears there is an issue with the nrf52833 BLE stack and/or softdevice.

  • I'll try to get ahold of an nRF52833 DK tomorrow and try to reproduce the error.

    Best regards,

    Simon

  • I'm not able to reproduce this, I did the following:

    • Opened NCS v1.5.0
    • Navigated to the folder nrf/samples/bluetooth/peripheral_uart
    • Connected the nRF52833 DK and ran the following commands:
      • BOARD=nrf52833dk_nrf52833 west build -d build33
      • BOARD=nrf52833dk_nrf52833 west flash -d build33
    • Opened Termite and selected the COM port connected to the DK
      • COM port can be found by running nrfjprog --com

    • Opened nRF Connect For Mobile v2.4.8 on an iPhone 11 Pro (Software version 14.0)
    • Started scanning (with no filters) and saw the device advertising with the name "Nordic_UART_Service", and connected to that device
    • Enabled notifications for the TX Characteristic
    • Wrote "Hello" in Termite and saw that 0x68-6C-6C-6F-0A was received in the App
    • Wrote "Hello" from the RX Characteristic (UTF8 and Request) and saw that it was received in Termite

    Could you try to repeat the same steps, and if you still encounter issues, could you point to what is different between our environments. A sniffer log may be useful as well

    Best regards,

    Simon

Related