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.

EVMK2GX: SPI norflash blocking mode issue.

Part Number: EVMK2GX
Other Parts Discussed in Thread: SYSBIOS

Hello,

I am setting up the SPI to communicate with the NorFlash on the K2G Evm and I am not able to get reproducible correct reading when using BLOCKING mode ( with interrupt enable).

What I am doing is reading the NorFlash ID once a sec to verify the proper configuration of the SPI driver and I am basically getting the first response with good data (as per datasheet) but next are not (full of 0x0).

On the positive side, I am able to get constant proper read when using POLLING mode ...so I am confident the flash is not to blame.

But I really need to release the CPU when transferring data, other code needs to run. Any idea what I am missing ?

thank you,

Vincent

More info:

I am relying on #include <ti/drv/spi/soc/SPI_soc.h> to point to me to the correct driver (V0) for SOC_K2G.

I am following example main_spi_flash_read_example.c

I am using ti/board/src/flash/nor/spi/nor_spi.c directly because I am wrapping the SPI driver for other need as well. But I rely a lot on this code.

  • Hi Vincent, 

    Which exact SDK version are you using?

    And could you include a code snippet of your code for enabling BLOCKING mode?

    Best regards,

    Dillon

  • Hi Frank,

    I am using TI SDK 06_03_00.  I m running 3 functions:

    // Setting SPI config

          SPI_HWAttrs cfg;
         SPI_socGetInitCfg( info->id, &cfg);
         cfg.enableIntr = true;
         SPI_socSetInitCfg( info->id, &cfg);

    // Opening

          SPI_Params     param;
          SPI_Params_init( &param );
          param.transferMode = SPI_MODE_BLOCKING;
          info->handler = SPI_open( info->id, &param);

           uint32_t spi_cmd = 0;
           SPI_control( info->handler, SPI_V0_CMD_XFER_ACTIVATE, (void *)&spi_cmd);

    // Calling this part to retrieve the Norflash ID. I am testing a call 1 sec. Half of the time if returns 0x0

          uint32_t spi_cmd = 1;
          SPI_control( info->handler, SPI_V0_CMD_XFER_ACTIVATE, (void *)&spi_cmd);

           uint32_t terminateXfer = 1;
           info->xchange.arg = (void *)&terminateXfer;
           info->xchange.status = SPI_TRANSFER_STARTED;

           info->xchange.txBu f= tx; info->xchange.rxBu f= rx;
           info->xchange.count = exchange_size;
           status = SPI_transfer( info->handler, &info->xchange);

    thank you,

    Cheers,

    Vincent

  • Thank you for the SDK version and code snippets. Everything there looks generally ok to me. Although what steps do you take after the first transaction is complete? Since you said that the first one is always successful. 

    Something to try would be to connect to CCS, enter debug mode, record all of the SPI values for the first transaction, and then compare them to the SPI values of a failed transaction. Could you try this and then report back the values or include screenshots to compare?

    I have a suspicion that some value isn't being reset after the first transaction completes.

    Best regards,

    Dillon

  • Hey Frank,

    I am actually in the process of buying a debugger. I can't manage to connect to the one on the evm. Just not recognized by Windows in the device manager ...

    Also, I tried using the DMA but it just blocks everything after the first reading (which is good).

    To give you more details on the interrupts mode (code described). First try is good, and them I am getting everything 0x0 on every try.

    Anything I could check without the debugger ?

    Regards,

    Vincent

  • Could it be something in the configuration ?

  • If you're running into issues with connecting your debugger, I'd recommend searching e2e to see if there's a similar thread for the exact issue that you're seeing, or opening up a new e2e thread to get that figured out.

    Using a debugger makes things easier, but in the meantime, try inserting a bunch of print statements all throughout your code to get the values of certain variables at different times in your code. Mostly to print out SPI values and settings for the first transaction, and then compare them to the values printed out for the second transaction.

    It could be something in the configuration, but considering the first transaction happens correctly, the initial configuration may be set up properly. Although, there may be some configuration from clearing the read data after the first transaction that may be missing.

    Best regards,

    Dillon

  • Hey Frank,

    Actually I am now able to get the SPI transactions to go through, data are actually exchanged on every transaction..

    But 50% of the time I am missing some data. It looks like the SPI interrupt was not processed fast enough and the driver did not removed the data from the SPI peripheral.

    So for example on success I would get 0xA 0xB 0xC 0xD.  On failure that would be 0xA 0xC 0xD 0xE ... ( I do not think it is the FLASH as I am able to get 100% success in pooling mode (SPI_MODE_BLOCKING interrupts disabled). Funny thing is I am always getting the proper number of  byte exchanged. The last one are filled with 0x0.

    Any idea were this is coming from?

    Note: I am running in a task. And there is nothing else running.

    thank you,

    Vincent

  • When configuring your SPI parameters, could you try increasing the bitRate parameter and testing again? That may allow all of the data to be process in enough time.

    /*!
     *  @brief  Function to initialize the SPI_Params struct to its defaults
     *
     *  @param  params      An pointer to SPI_Params structure for
     *                      initialization
     *
     *  Defaults values are:
     *      transferMode        = SPI_MODE_BLOCKING
     *      transferTimeout     = SPI_WAIT_FOREVER
     *      transferCallbackFxn = NULL
     *      mode                = SPI_MASTER
     *      bitRate             = 1000000 (Hz)
     *      dataSize            = 8 (bits)
     *      frameFormat         = SPI_POL0_PHA0
     */

    Best regards,

    Dillon

  • Thank you for this idea.

    I had to reduce the speed down to 80Khz to get good results. FLASH is supposed to be able to run at 5Mhz .... It would seem I still have a problem with my SYSBIOS configuration. I will keep looking there.

    thank you for your help,

    Cheers,

    Vincent

  • Glad to hear that you're able to get good results now. If you continue having issues with your SYSBIOS configuration, please feel free to open up a new thread and someone on the E2E team will provide some assistance. 

    Best regards,

    Dillon