This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320C6748: C6748 user data logging via USB 2.0 port crashes after logging for a while

Part Number: TMS320C6748
Other Parts Discussed in Thread: OMAPL138

Hi,

We have a TMS320C6748 custom board.

We do a data logging via USB 2.0 port (USB OTG in host mode) to capture live data every 2 secs. The length of each record that captures every 2 secs is approx 155 bytes. But, the overall length of data that is sent to the USB at once is approx 9KB (MAX). But, it's not always MAX bytes.

Here's the main logic of our code that does the logging...

(below codes are NOT the exact code we have in our project, but modified codes for you to understand the main flow in our code.)

#define USB3SS_EN
#define DMA_MODE
#define NANDWIDTH_16
#define OMAPL138_LCDK
#define USB_INSTANCE    0
#define MAX_HEADER_SIZE 110
#define MAX_DATA_SIZE   256
#define MAX_BUF_SIZE    MAX_DATA_SIZE*32

...

...

void logData(void) {

...

.../// new DATA_BUF
    char DATA_BUF[MAX_DATA_SIZE];
    static int LOG_BUF_SIZE = 0;
    static int return_val = 0;
    static BOOL buf_select = TRUE;
    DATA_BUF[0] = '\0';

    /// get modbus data
    printf("get DATA_BUF\n");
    while (1) {
        return_val = sprintf(DATA_BUF,"%02d-%02d-20%02d,%02d:%02d:%02d,%10d,%2.0f,%6.2f,%5.1f,%5.1f,%5.1f,%5.1f,%6.3f,%6.3f,%6.3f,%5.1f,%5.1f,%5.1f,%5.1f,%6.3f,%6.3f,%5.1f,%5.1f,%5.2f,%8.1f,\n",USB_RTC_MON,USB_RTC_DAY,USB_RTC_YR,USB_RTC_HR,USB_RTC_MIN,USB_RTC_SEC,DIAGNOSTICS,REG_STREAM.calc_val,REG_WATERCUT.calc_val,REG_WATERCUT_RAW,REG_TEMP_USER.calc_val,REG_TEMP_AVG.calc_val,REG_TEMP_ADJUST.calc_val,REG_FREQ.calc_val,REG_OIL_INDEX.calc_val,REG_OIL_RP,REG_OIL_PT,REG_OIL_P0.calc_val,REG_OIL_P1.calc_val, REG_OIL_DENSITY.calc_val, REG_OIL_FREQ_LOW.calc_val, REG_OIL_FREQ_HIGH.calc_val, REG_AO_LRV.calc_val, REG_AO_URV.calc_val, REG_AO_MANUAL_VAL,REG_RELAY_SETPOINT.calc_val);
        printf ("return size: %d\n",return_val);
        if (return_val > 0) break;
    }

if (buf_select)
{
    /// fill data upto MAX_DATA_SIZE
    if (MAX_BUF_SIZE >= (LOG_BUF_SIZE + MAX_DATA_SIZE))
    {
            LOG_BUF_SIZE += MAX_DATA_SIZE;
            strcat(LOG_BUF,DATA_BUF);
            return;
    }
    else
    {
        // reset logbuf length
        LOG_BUF_SIZE = 0;

        /// open
        fresult = f_open(&logWriteObject, logFile, FA_WRITE | FA_OPEN_EXISTING);
        if (fresult != FR_OK)
        {
            LOG_BUF[0] = '\0';
            f_close(&logWriteObject);
            stopAccessingUsb(fresult);
            return;
        }
        printf("open\n");
        usb_osalDelayMs(1000);

 if (f_error(&logWriteObject) != 0)
        {
            LOG_BUF[0] = '\0';
            f_close(&logWriteObject);
            PDI_USBBufferFlush(USB_INSTANCE);
            stopAccessingUsb(FR_DISK_ERR);
            printf("error...\n");
            return;
        }

        /// append mode
        fresult = f_lseek(&logWriteObject,f_size(&logWriteObject));
        if (fresult != FR_OK)
        {
            LOG_BUF[0] = '\0';
            f_close(&logWriteObject);
            stopAccessingUsb(fresult);
            return;
        }
        printf("seek\n");
        usb_osalDelayMs(1000);

        if (f_error(&logWriteObject) != 0)
        {
            LOG_BUF[0] = '\0';
            f_close(&logWriteObject);
            PDI_USBBufferFlush(USB_INSTANCE);
            stopAccessingUsb(FR_DISK_ERR);
            printf("error...\n");
            return;
        }

        /// write
        int val = f_puts(LOG_BUF,&logWriteObject);
        if (val != strlen(LOG_BUF))
        {
            LOG_BUF[0] = '\0';
            f_close(&logWriteObject);
            stopAccessingUsb(FR_DISK_ERR);
            return;
        }
        printf("puts %d\n", val);
        usb_osalDelayMs(1000);

        if (f_error(&logWriteObject) != 0)
        {
            LOG_BUF[0] = '\0';
            f_close(&logWriteObject);
PDI_USBBufferFlush(USB_INSTANCE);
            stopAccessingUsb(FR_DISK_ERR);
            printf("error...\n");
            return;
        }

        /// sync
        fresult = f_sync(&logWriteObject);
        if (fresult != FR_OK)
        {
            LOG_BUF[0] = '\0';
            f_close(&logWriteObject);
            stopAccessingUsb(fresult);
            return;
        }
        usb_osalDelayMs(1000);

        if (f_error(&logWriteObject) != 0)
        {
            LOG_BUF[0] = '\0';
            f_close(&logWriteObject);
            PDI_USBBufferFlush(USB_INSTANCE);
            stopAccessingUsb(FR_DISK_ERR);
            printf("error...\n");
            return;
        }

        /// close
        fresult = f_close(&logWriteObject);
        if (fresult != FR_OK)
        {
            LOG_BUF[0] = '\0';
            stopAccessingUsb(fresult);
            return;
        }
        printf("f_close\n");

        /// reset log buf
        LOG_BUF1[0] = '\0';
        buf_select = !buf_select;
        PDI_USBBufferFlush(USB_INSTANCE);
        return;
}

void
PDI_USBBufferFlush(uint32_t ulIndex)
{
    USBHCDTxAbort(ulIndex, 0);  
    USBHCDRxAbort(ulIndex, 0);  
}


*** when it crashes, it crashes at f_lseek() in most cases. As you can see, I've added lots of error checking steps in between f_xxxx() libraries to give enough delay time. But, it crashes eventually in "some" devices.

When I say "some", that means it does NOT always crash but some devices always crash when the other devices run perfect with data logging via USB. My question is what makes this differences between devices. If there's a problem in the software logging logic, then it should always crash no matter which devices are logging.

Based on the experiment so far, there are some factors that help avoid the crash:

1. Increase logging gap from 2 secs to 10 secs. If we increase logging gap from 2 to every 10 secs, most likely crash won't happen.

2. Use certain type of USB thumb drive. Certain type of USB never crashes with data logging but some USB types always crash. Is this due to the write-speed of the USB drive?

How to avoid crash?

Thanks,

Dan