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.

CCS/CC3220SF-LAUNCHXL: SimpleLink API - Sl_Start(0,0,0) returns -2004 (BAD INTERFACE) when I increase read size from a file

Part Number: CC3220SF-LAUNCHXL

Tool/software: Code Composer Studio

Hi;

I am working on read/write a file with using of SL_Filesystem API. The sl_start(0,0,0) function returns -2004 when I increase read size to 4000 from 3000 bytes.  

I want to get file size then read file in one cycle with using of that size.Is it possible to do this without worrying about a limit on reading size?  So Is there a limit about read size from a file.

I want to share code which I used;

void mainThread(void *pvParameters)
{
        int32_t             status = 0;
        pthread_attr_t      pAttrs_spawn;
        struct sched_param  priParam;

        SPI_init();
        Display_init();
        display = Display_open(Display_Type_UART, NULL);
        if (display == NULL) {
            /* Failed to open display driver */
            while(1);
        }
        pthread_attr_init(&pAttrs_spawn);
        priParam.sched_priority = SPAWN_TASK_PRIORITY;
        status = pthread_attr_setschedparam(&pAttrs_spawn, &priParam);
        status |= pthread_attr_setstacksize(&pAttrs_spawn, TASK_STACK_SIZE);
        status = pthread_create(&spawn_thread, &pAttrs_spawn, sl_Task, NULL);
        if(status)
        {
            printError("Task create failed", status);
        }
        mode = sl_Start(0, 0, 0);
        if (mode < 0)
        {
            Display_printf(display, 0, 0,"\n\r[line:%d, error code:%d] %s\n\r", __LINE__, mode, DEVICE_ERROR);
        }

        char* DeviceFileName = "test.txt";
        _i32 RetVal;
        unsigned long MaxSize = 4000;
        unsigned long Offset = 0;
        unsigned char InputBuffer[4000];

        long DeviceFileHandle = sl_FsOpen((unsigned char *)DeviceFileName,SL_FS_READ,NULL);
        RetVal = sl_FsRead( DeviceFileHandle, Offset, (unsigned char *)InputBuffer, MaxSize);
        RetVal = sl_FsClose(DeviceFileHandle, NULL, NULL , 0);

}

 





  • Hi Abdulkadir Mirik,

    What servicepack version do you have flashed? What SDK version are you using? Are you testing on a LaunchPad?

    Best regards,

    Sarah

  • Hi Sarah;

    Yes I am testing on LaunchPad.

    NWP servicepack Version: 3.0.1.4
    SDK version 4.10.00.07

    I realized that the problem dependent read size from a file and I updated content of question . Please check again.

    Thank you

    Abdulkadir

  • Hi Abdulkadir,

    Based on your updated post, it looks like you are getting the sl_Start error before you call any sl_Fs APIs? -2004 is a bad interface error, which means the host driver interface could not open. Can you try increasing your application task size or check the ROV for any stack overflow in your application?

    Best regards,

    Sarah

  • Hi Sarah;

    Thank for your helpful answer. 

    Yes that's true guess.The problem can solve increasing task size but I don't see any stack overflow on the ROV.

    When I having problem, The ROV is like the picture below;

    StackPeak: 60

    stackSize: 512

    I didn't set 512 size for any stack. Why I don't see my task on the ROV, is it about a parameter set of my task? What does it mean stackPeak:60?

    Best Regards

    Abdulkadir

  • Hi Abdulkadir,

    I can't see the image you attached, but is this the idle thread? The idle thread is created and maintained by the RTOS. The stack peak means the highest stack size for that thread so far.

    The Debugging Features and Tools sections of the TI-RTOS Basics lab may be helpful while you're debugging.

    Best regards,

    Sarah

  • Hi Sarah;

    The resource which you shared is very helpfull, thank you again.

    I have another problem about -2004 (Bad Interface);

    I am using SimpleLink API inside different 2 threads. First manages wifi operations like as communication on TCP, second works about FileSystem. When I start 2 threads, sl_Start(0,0,0) function is returns -2004 (Bad Interface) although It is working successfully when I start only one. I am calling sl_Start in both thread.

    Thread#1 Simplelink API for FileSystem

    void ConfigurationReader::read()
    {
        _i32 retVal;
        unsigned long offset = 0;
        const uint32_t token = 0;
        SlFsFileInfo_t     FsFileInfo;
        SPI_init();
        Display_init();
        retVal = (_i32)createSimplelinkTask();
        if(!retVal)
            return;
        mode = sl_Start(0, 0, 0);
        if (mode < 0){
           return;
        }
        const unsigned char* nDeviceFileName = (const unsigned char*)DeviceFileName;
        retVal = sl_FsGetInfo(nDeviceFileName,token,&FsFileInfo);
        _i32 readSize = FsFileInfo.MaxSize;
        readSize = 100;
        unsigned char inputBuffer[readSize];
        long DeviceFileHandle =  sl_FsOpen((unsigned char *)DeviceFileName,SL_FS_READ,NULL);
        Display_printf(display, 0, 0, "end sl_FsOpen, DeficeFileInfo:%ld \n\r",  DeviceFileHandle);
        retVal = sl_FsRead( DeviceFileHandle, offset, (unsigned char *)inputBuffer, readSize);
        //RetVal = sl_FsWrite( DeviceFileHandle, Offset, (unsigned char *)"HelloWorld", strlen("HelloWorld"));
        Display_printf(display, 0, 0, "end sl_FsRead, RetVal: %d \n\r", retVal );
        retVal = sl_FsClose(DeviceFileHandle, NULL, NULL , 0);
        Display_printf(display, 0, 0, "end sl_FsClose, Retval: %d \n\r", retVal );
    }

    And Thread#2 SimpleLink API for Wifi Operations

     

    void mainThread(void *pvParameters)
    {
        int32_t             status = 0;
        pthread_attr_t      pAttrs_spawn;
        struct sched_param  priParam;
        SPI_init();
        Display_init();
        display = Display_open(Display_Type_UART, NULL);
        if (display == NULL) {
            /* Failed to open display driver */
            while(1);
        }
        /* Start the SimpleLink Host */
        pthread_attr_init(&pAttrs_spawn);
        priParam.sched_priority = SPAWN_TASK_PRIORITY;
        status = pthread_attr_setschedparam(&pAttrs_spawn, &priParam);
        status |= pthread_attr_setstacksize(&pAttrs_spawn, TASK_STACK_SIZE);
        status = pthread_create(&spawn_thread, &pAttrs_spawn, sl_Task, NULL);
        if(status)
        {
            printf("Task create failed %d\n", status);
            //printError("Task create failed", status);
        }
        /* Turn NWP on - initialize the device*/
        mode = sl_Start(0, 0, 0);
        if (mode < 0)
        {
            Display_printf(display, 0, 0,"\n\r[line:%d, error code:%d] %s\n\r", __LINE__, mode, DEVICE_ERROR);
        }
    
        //............. following code
    
    }

    What is your opinion?

    Best Regards

    Abdulkadir

     

  • Hi Abdulkadir,

    You should not try to initialize the NWP twice. The interface is already open, so you are seeing an error that the driver cannot open a second interface.

    You should have one thread handle when the NWP is on (sl_Start, sl_Stop). The Wi-Fi APIs will work in any thread while the NWP is on.

    Best regards,

    Sarah