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

Working / sample programs crashing on Custom Board?

Hi, I have made my custom board using nrf51422 sample chips (Which came nrf 51422DK ), but my working / sample program which works on DK gets crashed on custom Board.

Blinking works fine, but uart and other soft device programs crashes.

Marking on my chip is: NRF51422 QFAC A1 1503AD

  • The program runs fine on NRF DK 51, but not on our chip

    /* 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 "bsp.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 256                         /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE 256                           /**< UART RX buffer size. */
    
    void uart_error_handle(app_uart_evt_t * p_event)
    {
        if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
        {
            APP_ERROR_HANDLER(p_event->data.error_communication);
        }
        else if (p_event->evt_type == APP_UART_FIFO_ERROR)
        {
            APP_ERROR_HANDLER(p_event->data.error_code);
        }
    }
    
    
    
    #ifdef ENABLE_LOOPBACK_TEST
    /** @brief Function for setting the @ref ERROR_PIN high, and then enter an infinite loop.
     */
    static void show_error(void)
    {
        
        LEDS_ON(LEDS_MASK);
        while(true)
        {
            // Do nothing.
        }
    }
    
    
    /** @brief Function for testing UART loop back. 
     *  @details Transmitts one character at a time to check if the data received from the loopback is same as the transmitted data.
     *  @note  @ref TX_PIN_NUMBER must be connected to @ref RX_PIN_NUMBER)
     */
    static void uart_loopback_test()
    {
        uint8_t * tx_data = (uint8_t *)("\n\rLOOPBACK_TEST\n\r");
        uint8_t   rx_data;
    
        // Start sending one byte and see if you get the same
        for (uint32_t i = 0; i < MAX_TEST_DATA_BYTES; i++)
        {
            uint32_t err_code;
            while(app_uart_put(tx_data[i]) != NRF_SUCCESS);
    
            nrf_delay_ms(10);
            err_code = app_uart_get(&rx_data);
    
            if ((rx_data != tx_data[i]) || (err_code != NRF_SUCCESS))
            {
                show_error();
            }
        }
        return;
    }
    
    
    #endif
    
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
        LEDS_CONFIGURE(LEDS_MASK);
        LEDS_OFF(LEDS_MASK);
        uint32_t err_code;
        const app_uart_comm_params_t comm_params =
          {
              RX_PIN_NUMBER,
              TX_PIN_NUMBER,
              RTS_PIN_NUMBER,
              CTS_PIN_NUMBER,
              APP_UART_FLOW_CONTROL_ENABLED,
              false,
              UART_BAUDRATE_BAUDRATE_Baud38400
          };
    
        APP_UART_FIFO_INIT(&comm_params,
                             UART_RX_BUF_SIZE,
                             UART_TX_BUF_SIZE,
                             uart_error_handle,
                             APP_IRQ_PRIORITY_LOW,
                             err_code);
    
        APP_ERROR_CHECK(err_code);
    
    #ifndef ENABLE_LOOPBACK_TEST
        printf("\n\rStart: \n\r");
    
        while (true)
        {
            uint8_t cr;
            while(app_uart_get(&cr) != NRF_SUCCESS);
            while(app_uart_put(cr) != NRF_SUCCESS);
    
            if (cr == 'q' || cr == 'Q')
            {
                printf(" \n\rExit!\n\r");
    
                while (true)
                {
                    // Do nothing.
                }
            }
        }
    #else
    
        // This part of the example is just for testing the loopback .
        while (true)
        {
            uart_loopback_test();
        }
    #endif
    }
    
  • I have not been able to reproduce this. What is the other differences between your board and the DK? I assume you have the correct pin numbers for RX, TX, RTS and CTS (in case they are different on your board and DK)? Could you you try to disable flow control?

  • Hi I forgot to mention we are not using any external crystals. As external crystal is required for Radio (16MHZ). Any way we are not using any radio functionality or softdevices. Do i need to make any changes in the code to run the code on internal Oscillator

  • The UART module normally use the internal oscillator, not the external crystal, so you should not need to do anything. You can see this from the Block resource requirements section in the Product specification. Just in case there is a clock issue, can you try to set constant latency mode in order to force the clock always on? Put this line in the beginning of your main function:

    NRF_POWER->TASKS_CONSTLAT = 1;
    

    From your debugging, it seems that an error is found in the call to APP_ERROR_HANDLER() on line 42 in your main.c. This is due to a APP_UART_COMMUNICATION_ERROR, which indicate that a communication error has occurred during reception. The error is stored in app_uart_evt_t.data.error_communication field. Can you check that field in the debugger?

  • This is what i get when i try to print app_uart_Evt.data.error_communication (12)

    #1  0x0000030e in uart_error_handle (p_event=0x20007f70) at /home/qwe/Downloads/ClubTag/nRF_SDK_9.0/examples/peripheral/uart/main.c:42
    (gdb) p p_event->
    data      evt_type
    (gdb) p p_event->
    data      evt_type
    (gdb) p p_event->data.
    error_code           error_communication  value
    (gdb) p p_event->data.error_communication 
    $1 = 12
    (gdb) up
    #2  0x00000aea in UART0_IRQHandler () at /home/qwe/Downloads/ClubTag/nRF_SDK_9.0/components/drivers_nrf/uart/app_uart_fifo.c:327
    (gdb) up
    #3  <signal handler called>
    (gdb)
    
Related