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.

外部flash读写

Other Parts Discussed in Thread: CC3200

我想在外部flash写入一个数,然后读出来,请问怎么写,谢谢

  • 你按照你外部Flash的操作时序写和读就行了。

  • 参考TI的SDK中的例子file_download

    //-------------------------------------------------从网页下载数据写入SPI_Flash中---------------------------------------------------
    // Open file to save the downloaded file
    lRetVal = sl_FsOpen((_u8 *)FILE_NAME, FS_MODE_OPEN_WRITE, &Token, &fileHandle);
    if(lRetVal < 0)
    {
    // File Doesn't exit create a new of 40 KB file
    lRetVal = sl_FsOpen((unsigned char *)FILE_NAME, FS_MODE_OPEN_CREATE(SIZE_40K, _FS_FILE_OPEN_FLAG_COMMIT|_FS_FILE_PUBLIC_WRITE), &Token, &fileHandle);
    ASSERT_ON_ERROR(lRetVal);
    }
    while(1)
    {
    len = HTTPCli_readResponseBody(cli, (char *)g_buff, sizeof(g_buff) - 1, &moreFlag);
    if(len < 0)
    {
    // Close file without saving
    lRetVal = sl_FsClose(fileHandle, 0, (unsigned char*) "A", 1);
    return lRetVal;
    }

    lRetVal = sl_FsWrite(fileHandle, bytesReceived,(unsigned char *)g_buff, len);

    if(lRetVal < len)
    {
    UART_PRINT("Failed during writing the file, Error-code: %d\r\n", \
    FILE_WRITE_ERROR);
    // Close file without saving
    lRetVal = sl_FsClose(fileHandle, 0, (unsigned char*) "A", 1);
    return lRetVal;
    }
    bytesReceived +=len; //偏移地址增加

    if ((len - 2) >= 0 && g_buff[len - 2] == '\r' && g_buff [len - 1] == '\n')
    {
    break;
    }

    if(!moreFlag)
    {
    break;
    }
    }
    //
    // If user file has checksum which can be used to verify the temporary
    // file then file should be verified
    // In case of invalid file (FILE_NAME) should be closed without saving to
    // recover the previous version of file
    //

    // Save and close file
    UART_PRINT("Total bytes received: %d\n\r", bytesReceived);
    lRetVal = sl_FsClose(fileHandle, 0, 0, 0);
    ASSERT_ON_ERROR(lRetVal);
    //--------------------------------------------------------------------------------------------------------------------------------------------

  • 谢谢。

    这个外部flash是通过spi读写数据的吗?

    我的程序里有用到spi干别的事,会影响吗?为什么一到写的时候就运行不下去了

  •     lRetVal = sl_FsOpen((unsigned char *)USER_FILE_NAME,
                    FS_MODE_OPEN_CREATE(SIZE_40K, \
                              _FS_FILE_OPEN_FLAG_COMMIT|_FS_FILE_PUBLIC_WRITE),
                            ulToken,
                            lFileHandle);

    到这一句就死了

  • 你在操作fsopen之前,需要调用sl_Start的,请问你调用了吗?也就是说你要把WIFI先enable起来才可以。

  • 谢谢回复。我用的是多个task,加上了sl_start()就成功了。

  • 这个外部flash是通过spi读写数据的,你的程序里有用到spi干别的事只要不要调用 SPI Flash的SPI就不会有影响,CC3200有3个SPI模块,一个内部总线使用,一个给外部的SPI Flash芯片,另一个给用户使用。你调用用户使用的SPI 就可以了。