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

Timing Issue with app_uart_put()?

Hello everyone,

I have very pesky bug that is leaving me in fits. I have a feeling it is a timing issue, but I am not sure at this point. Here is my issue, and I would love anyone's debugging help:

I have helper functions to write chars over UART (I am using a FTDI board to make serial connection to my mac). I am using Rev 1 NRF52 chip with UART configured as 115200baud, IRQ low priority, and flow control off.

    void uart_print(char *str)
{   
    uint32_t err_code;
    int i = 0;
    while (str[i] != '\0'){
        err_code = app_uart_put(str[i]);
        APP_ERROR_CHECK(err_code);
        i++;
    }
}

void uart_println(char *str)
{
    uint32_t err_code;

    uart_print(str);
    err_code = app_uart_put('\n');
    APP_ERROR_CHECK(err_code);
}

The above functions works perfectly on initialization methods, Advertising states, and when the device is connected. Once connected I have a timer that starts and grabs samples from my accelerometer and the failure happens in one condition branch in callback method. That method is here:

void accelgyro_timer_timeout_handler(void * p_context)
{
    float sensors[3];
    char test_str[30];
    memset(&sensors[0], 0, sizeof(sensors));
    
    read_accelgyro_data(&sensors[0]);

    fft_in_buffer[0][buffer_idx] = sensors[0];
    fft_in_buffer[1][buffer_idx] = sensors[1];

    if (buffer_idx < FFT_SIZE - 1){
        buffer_idx++;
        sprintf(test_str, "Sample %d", buffer_idx);
        uart_println(test_str);
    } else if (buffer_idx == FFT_SIZE - 1) {
        uart_println("--PSD Start--");
                   .
                   .
                 <algorithm code>
                   .
                   .
    }
}

The failure occurs when trying to write the first char of the "uart_println("--PSD Start--");" statement (the actual failure is at err_code = app_uart_put(str[i]); in the uart_print method above). It immediately fails with this error in my gdb terminal:

Program received signal SIGTRAP, Trace/breakpoint trap. 0x000008e4 in ?? ()

This is baffling me since the first condition uart_println(test_str); works fine, and if I remove the uart_println statement entirely the function behaves normally. Does anybody have any suggestions on how I should debug or try a different approach. For instance, could this be solved with flow control?

Thank you for the time and help. Josh

Below is snapshot of the Serial output image description

Parents
  • I guess one modification you needed in your code was this, not sure if this was your actual problem. It was skipping few character for me.

     void uart_print(char *str){   
        int i = 0;
        while (str[i] != '\0'){
            while(app_uart_put(str[i])!= NRF_SUCCESS);
            i++;
        }
     }
    
    void uart_println(char *str){
        uart_print(str);
        while(app_uart_put('\n')!= NRF_SUCCESS);
    }
    

    The 'app_uart_put' function needs to wait before the previous characters which you have already put are sent, Hence the while loop. Hope this will help others.

Reply
  • I guess one modification you needed in your code was this, not sure if this was your actual problem. It was skipping few character for me.

     void uart_print(char *str){   
        int i = 0;
        while (str[i] != '\0'){
            while(app_uart_put(str[i])!= NRF_SUCCESS);
            i++;
        }
     }
    
    void uart_println(char *str){
        uart_print(str);
        while(app_uart_put('\n')!= NRF_SUCCESS);
    }
    

    The 'app_uart_put' function needs to wait before the previous characters which you have already put are sent, Hence the while loop. Hope this will help others.

Children
No Data
Related