TMS570LS0432: Anyone had example code for Flash W25Q32 with TMSTMS570LS0432 over SPI

Part Number: TMS570LS0432

Tool/software:

Hello,

Looking for example code for Flash W25Q32 with TMSTMS570LS0432 over SPI. Which should had Write and Read example.

Regards,

Nitin

  • Hello also find my example code and its debug output,

    #include "system.h"
    #include "spi.h"
    #include "string.h"

    void W25Q32_WriteEnable(void)
    {
    uint16 tx[1] = { 0x06 };

    spiDAT1_t dataconfig = {
    .CS_HOLD = FALSE,
    .WDEL = FALSE,
    .DFSEL = SPI_FMT_0, // Format 0 (8-bit, CPOL=0, CPHA=0)
    .CSNR = SPI_CS_1 // CSNR = ~(1 << CS1) → 0b11111110
    };

    spiSendData(spiREG2, &dataconfig, 1, tx);
    }

    void W25Q32_WaitWhileBusy(void)
    {
    uint16 tx[2] = { 0x05, 0x00 };
    uint16 rx[2] = { 0 };
    uint32_t timeout = 1000000;

    spiDAT1_t dataconfig = {
    .CS_HOLD = FALSE,
    .WDEL = FALSE,
    .DFSEL = SPI_FMT_0, // Format 0 (8-bit, CPOL=0, CPHA=0)
    .CSNR = SPI_CS_1 // CSNR = ~(1 << CS1) → 0b11111110
    };
    do{
    spiTransmitAndReceiveData(spiREG2, &dataconfig, 2, tx, rx);
    timeout--;
    if(timeout == 0)
    {
    printf("Timeout while waiting for for WIP to clear\n");
    printf("Status Reg: 0x%02X\n", ((uint8_t) (rx[1] & 0xFF)));
    break;
    }
    }while(((uint8_t) (rx[1] & 0xFF)) & 0x01);
    }

    void W25Q32_Write(uint32 address, uint8 *data, uint32 len)
    {
    uint16 txBuf[260];

    W25Q32_WriteEnable();

    // Command + Address
    txBuf[0] = 0x02;
    txBuf[1] = (address >> 16) & 0xFF;
    txBuf[2] = (address >> 8) & 0xFF;
    txBuf[3] = address & 0xFF;

    spiDAT1_t dataconfig = {
    .CS_HOLD = TRUE, // Let CS go high after transfer
    .WDEL = FALSE,
    .DFSEL = SPI_FMT_0, // Format 0 (8-bit, CPOL=0, CPHA=0)
    .CSNR = SPI_CS_1 // CSNR = ~(1 << CS1) → 0b11111110
    };

    // Payload
    for (int i = 0; i < len; i++) {
    txBuf[4 + i] = data[i];
    }

    spiSendData(spiREG2, &dataconfig, len+4, txBuf);
    W25Q32_WaitWhileBusy();
    }

    void W25Q32_Read(uint32 address, uint8 *buffer, uint32 len)
    {
    uint16 txBuf[260] = {0};
    uint16 rxBuf[260] = {0};

    // Command + Address
    txBuf[0] = 0x03;
    txBuf[1] = (address >> 16) & 0xFF;
    txBuf[2] = (address >> 8) & 0xFF;
    txBuf[3] = address & 0xFF;

    spiDAT1_t dataconfig = {
    .CS_HOLD = TRUE, // Let CS go high after transfer
    .WDEL = FALSE,
    .DFSEL = SPI_FMT_0, // Format 0 (8-bit, CPOL=0, CPHA=0)
    .CSNR = SPI_CS_1 // CSNR = ~(1 << CS1) → 0b11111110
    };

    spiTransmitAndReceiveData(spiREG2, &dataconfig, len+4, txBuf, rxBuf);

    // Payload
    for (int i = 0; i < len; i++) {
    buffer[i] = rxBuf[4+i];
    }
    }

    void W25Q32_ReadID(uint8_t *id)
    {
    uint16 txBuf[4] = { 0x9F, 0x00, 0x00, 0x00 };
    uint16 rxBuf[4] = {0};

    spiDAT1_t dataconfig = {
    .CS_HOLD = TRUE, // Let CS go high after transfer
    .WDEL = FALSE,
    .DFSEL = SPI_FMT_0, // Format 0 (8-bit, CPOL=0, CPHA=0)
    .CSNR = SPI_CS_1 // CSNR = ~(1 << CS1) → 0b11111110
    };

    spiTransmitAndReceiveData(spiREG2, &dataconfig, 4, txBuf, rxBuf);

    id[0] = rxBuf[1]; //Manufactur ID
    id[1] = rxBuf[2]; //Memory Type
    id[2] = rxBuf[3]; //Capacity
    }

    int main()
    {
    spiInit();
    uint8_t jdecid[3];
    W25Q32_ReadID(jdecid);
    printf("Manufactur ID: 0x%02X\n", jdecid[0]);
    printf("Memory Type: 0x%02X\n", jdecid[1]);
    printf("Capacity: 0x%02X\n", jdecid[2]);

    const uint32_t targetAddress = 0x000100;
    char writeData[] = "Flash Write OK";
    char readData[32];

    W25Q32_Write(targetAddress, writeData, strlen(writeData));
    printf("Data Written to address: 0x%06X\n", targetAddress);

    W25Q32_Read(targetAddress, readData, strlen(writeData));
    printf("Data Read: %s\n", readData);

    return 0;
    }

    Then i am getting debug output like

    Manufactur ID: 0xEF
    Memory Type: 0x40
    Capacity: 0x16
    Data Written to address: 0x000100l
    Timeout while waiting for for WIP to clear
    Status Reg: 0xFF
    Data Read: yyyyyyyyyyyyyy

    Please guide me, i amusing Data format SP mode 0 and 8 word length with 1MHz baudrate

  • Hi Nitin,

    Looking for example code for Flash W25Q32 with TMSTMS570LS0432 over SPI. Which should had Write and Read example.

    We don't have any direct example on W25Q32.

    We do have only examples for SPI and you can find them in below FAQ:

    (+) [FAQ] TMS570LC4357: Examples and Demos available for Hercules Controllers (E.g. TMS570x, RM57x and RM46x etc) - Arm-based microcontrollers forum - Arm-based microcontrollers - TI E2E support forums

    By taking above examples are reference, just try to implement at your end. If you face any issue let me know the exact issue that you are facing, so that i can guide you.

    --
    Thanks & regards,
    Jagadish.

  • Hello,

    All above mentioned SPI example which one should I try for my application.

    MCU is TMS570LS0432 and FALSH is W25Q32 with SPI2 Port with CS1 

    Regards,

    Nitin

  • Hi Nitin,

    All are general SPI communication examples only, you can refer anyone of the master SPI example and compare the configurations and API's you are using in your example with them. 

    --
    Thanks & regards,
    Jagadish.

  • Hello Jagdish,

    Actually that all examples are without command and W25Q32 is with Command+Address+Data and also Flash is write protected so before write data into flash need to be execute write_enable and then write. 

    As per my above shared code, I am able to read JDEC ID. Means SPI communication is right only when I try to write data then I am unable to write.

    Please refer my above shared code.

    Regards,

    Nitin

  • Hello Jagdish,

    Thanks for support. I got solution and it worked. It was SPI API issue. Instead of spiSendData API I used spiTransmitAndReceiveData API and it worked.

    Regards,

    Nitin