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

nRF52 SDK 12.2 UART w/o flow control fails (works on 12.1)

I try to start uart like this:

  uartParams.baud_rate = UART_BAUDRATE_BAUDRATE_Baud115200;
  uartParams.tx_pin_no = tx;
  uartParams.rx_pin_no = rx;
  uartParams.use_parity = false;
  uartParams.flow_control = APP_UART_FLOW_CONTROL_DISABLED;

  uartBuffers.rx_buf = rxBuffer;
  uartBuffers.rx_buf_size = sizeof(rxBuffer);
  uartBuffers.tx_buf = txBuffer;
  uartBuffers.tx_buf_size = sizeof(txBuffer);

  auto error = app_uart_init(&uartParams, &uartBuffers, uart_evt_handler, APP_IRQ_PRIORITY_HIGH);
  if (error != NRF_SUCCESS) {
    DEBUG_ERROR<< "Failed to init uart for esp8266 use: " << error;
    return false;
  }

This has worked perfectly on SDK 12.1, but 12.2 fails with error 8 (bad state). Bad state should not be possible at all when flow control is off if I read the app_uart_init documentation correctly... Have I missed someting? :\

Parents
  • I tried your code and it seems to work. Hower, I spent some time trying to reproduce it and it seems to be related to RTT:

    Here is a small main.c sample that triggers the problem on PCA10040. It requires segger rtt:

    /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
     *
     * The information contained herein is property of Nordic Semiconductor ASA.
     * Terms and conditions of usage are described in detail in NORDIC
     * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
     *
     * Licensees are granted free, non-transferable use of the information. NO
     * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
     * the file.
     *
     */
    
    /** @file
     * @defgroup uart_example_main main.c
     * @{
     * @ingroup uart_example
     * @brief UART Example Application main file.
     *
     * This file contains the source code for a sample application using UART.
     *
     */
    
    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include "app_uart.h"
    #include "app_error.h"
    #include "nrf_delay.h"
    #include "nrf.h"
    #include "SEGGER_RTT.h"
    
    //#define ENABLE_LOOPBACK_TEST  /**< if defined, then this example will be a loopback test, which means that TX should be connected to RX to get data loopback. */
    
    #define MAX_TEST_DATA_BYTES     (15U)                /**< max number of test bytes to be used for tx and rx. */
    #define UART_TX_BUF_SIZE 1                         /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE 1                         /**< UART RX buffer size. */
    
    void uart_evt_handler(app_uart_evt_t * p_event)
    {
    }
    
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
      uint8_t rxBuffer[1];
      uint8_t txBuffer[1];
    
      app_uart_comm_params_t uartParams;
    
      memset(&uartParams, 0, sizeof(uartParams));
    
      uartParams.baud_rate = UART_BAUDRATE_BAUDRATE_Baud115200;
      uartParams.tx_pin_no = 26;
      uartParams.rx_pin_no = 27;
      uartParams.use_parity = false;
      uartParams.flow_control = APP_UART_FLOW_CONTROL_DISABLED;
    
      app_uart_buffers_t uartBuffers;
      uartBuffers.rx_buf = rxBuffer;
      uartBuffers.rx_buf_size = sizeof(rxBuffer);
      uartBuffers.tx_buf = txBuffer;
      uartBuffers.tx_buf_size = sizeof(txBuffer);
    
      // Enable disable this printout to trigger problem!
      SEGGER_RTT_WriteString(0, "Before rtt\n");
    
      uint32_t error = app_uart_init(&uartParams, &uartBuffers, uart_evt_handler, APP_IRQ_PRIORITY_HIGH);
      if (error != NRF_SUCCESS) {
        SEGGER_RTT_WriteString(0, "ERROR!\n");
      } else {
        SEGGER_RTT_WriteString(0, "OK!\n");
      }
    
    
      while (true) {
      }
    }
    
    
    /** @} */
    
  • I'm not able to replicate the error with your code. I'm getting OK! in the RTT viewer with the first SEGGER_RTT_WriteString() call both enabled and disabled. How do you get this error?

Reply Children
No Data
Related