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

NRF52840 USB_CDC_ACM + UART

Hi,

I'm trying to combine serial UART functionality into the USBD_BLE_UART example. The goal is to send data in/out to the hardware UART as well.

I started off by loading the USBD_BLE_UART example, then added the UART functions from the UART peripheral example. Build was successful, but when executing, I get a NRF_INVALID_STATE error. I can only get the firmware to run without errors by commenting out the uart_init() function, but then the UART will not function if I do so.

It seems that the error is caused in APP_UART_FIFO, under nrfx_drv_init.

I'm using SES 3.34b, with SDKv15. 

Any help appreciated. 

Parents
  • Hi,

    Is it maybe nrf_drv_uart_init() that returns NRF_INVALID_STATE ? That indicates that the uart driver is already initialized.

    Then this is maybe happening because nrf_log is using uart as backend, and then you try to initialize uart again after log_init()? If so, I would then recommend that you use RTT as logging backend instead.

    In sdk_config.h, set NRF_LOG_BACKEND_UART_ENABLED to 0 and NRF_LOG_BACKEND_RTT_ENABLED to 1

  • Hi Sigurd,

    Sorry for not describing the issue in enough detail. 

    You are absolutely right, the function that returns NRF_INVALID_STATE is actually nrfx_uart_init(), which resides in nrf_drv_uart_init(). It returns this error if the drv is already in initialized state.

    I have set NRF_LOG_BACKEND_UART_ENABLED to 0. Now I am getting a different error below. I couldn't manage to trace down which function triggered this error at the moment.

    <info> app: USBD BLE UART example started.
    <error> app: Communication error occurred while handling UART.
    <error> app: ERROR 12 [NRF_ERROR_DATA_SIZE] at :0
    PC at: 0x00000000
    <error> app: End of error report

    This error occurred right on start up, and I'm not transmitting anything on the UART lines.

  • Hi,

    I assume that you are printing "Communication error occurred while handling UART." when you get the APP_UART_COMMUNICATION_ERROR event.

    For APP_UART_COMMUNICATION_ERROR, the error-field contains the value in the ERRORSRC register for the UART peripheral.

    12 in binary is 1100, so looking at the ERRORSRC register you are getting a Break condition and Framing error.

    Are you receiving anything over UART? Could you check with a signal analyzer or oscilloscope ?

    Is this a nRF52840-DK or a custom board?

    How does your uart_init() function looks like ?

  • Hi Sigurd,

    I have found the cause of this issue. When you asked about my uart_init() function , I went through it again and sure enough, the RX & TX pins are initialized wrongly. Sorry for such a newbie mistake.

    I'd like to express my appreciation for your in-depth explanation on the UART SDK and hardware register.

    Thank you for your outstanding support.

  • Hi Julian, how did you configure the TX and RX pins to correct this issue?

Reply Children
No Data
Related