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.

cannot erase the spi flash w25x32 in 6747

hello, every one ,i am debugging "spiflash.pjt" which is a example  provided by ti EVMC6747

The example project write, read and  erase the spi flash  w25x32 with SPI_SPIFMT0. Char Len=8bit,i want to modifiedit for read or write the flash for char len=16bit,but it cannot erase the flash ,  but i can  read the flash with char len=16bit,why?what is wrong ???please help me!

thank you!

the following is code:

======================

#include "spiflash.h"

static Uint16 spiflashbuf[spiflash_PAGESIZE/2 + 3];
static Uint32 spidat1;

void spiflash_init( )
{
     /* Reset SPI */
    SPI_SPIGCR0 = 0;
    EVMC6747_wait( 1000 );

    /* Release SPI */
    SPI_SPIGCR0 = 1;

    /* SPI 4-Pin Mode setup */
    SPI_SPIGCR1 = 0
        | ( 0 << 24 )
        | ( 0 << 16 )
        | ( 1 << 1 )
        | ( 1 << 0 );

    SPI_SPIPC0 = 0
        | ( 1 << 11 )   // DI
        | ( 1 << 10 )   // DO
        | ( 1 << 9 )    // CLK
        | ( 1 << 1 )    // EN1
        | ( 1 << 0 );   // EN0

    SPI_SPIFMT0 = 0
        | ( 0 << 20 )   // SHIFTDIR
        | ( 0 << 17 )   // Polarity
        | ( 1 << 16 )   // Phase
        | ( 2 << 8 )    // Prescale to 30MHz
        | ( 16 << 0 );   // Char Len

    spidat1 = 0
        | ( 1 << 28 )   // CSHOLD
        | ( 0 << 24 )   // Format [0]
        | ( 2 << 16 )   // CSNR   [only CS0 enbled]
        | ( 0 << 0 );   //

    SPI_SPIDAT1 = spidat1;

    SPI_SPIDELAY = 0
        | ( 8 << 24 )   // C2TDELAY
        | ( 8 << 16 );  // T2CDELAY

    SPI_SPIDEF = 0
        | ( 1 << 1 )    // EN1 inactive high
        | ( 1 << 0 );   // EN0 inactive high

    SPI_SPIINT = 0
        | ( 0 << 16 )   //
        | ( 0 << 8 )    //
        | ( 0 << 6 )    //
        | ( 1 << 4 );   //

    SPI_SPILVL = 0
        | ( 0 << 8 )    // EN0
        | ( 0 << 6 )    // EN0
        | ( 0 << 4 );   // EN0

    /* Enable SPI */
    SPI_SPIGCR1 |= ( 1 << 24 );
}

void spiflash_cycle(Uint16 *buf, Uint16 len)
{
  Uint16 i;
 SPI_SPIBUF;
 for (i = 0; i <len; i++)
 {
    while( SPI_SPIBUF & 0x10000000 );
  if (i == (len-1))
         SPI_SPIDAT1 = (spidat1 & 0x0ffcffff) |  buf[i] ;
  else
         SPI_SPIDAT1 = spidat1 | buf[i];
    while ( SPI_SPIBUF & ( 0x80000000 ) );
    buf[i] = SPI_SPIBUF;
 }
}


Uint8 spiflash_status( )
{
  spiflashbuf[0] = spiflash_CMD_RDSR<<8 | 0;
 spiflash_cycle(spiflashbuf, 1);
  return spiflashbuf[0];
}

void spiflash_sector_erase(Uint32 sector_num) 
{
 Uint32 eraseaddr=spiflash_SECTORSIZE*sector_num;

  spiflashbuf[0]=(spiflash_CMD_WREN<<8) | 0;
 spiflash_cycle(spiflashbuf, 1);

  spiflashbuf[0] = (Uint16) (spiflash_CMD_ERASESEC<<8)|(eraseaddr>>16);
 spiflashbuf[1] = (Uint16) (eraseaddr & 0xffff);
  spiflash_cycle(spiflashbuf, 2);

  while( ( spiflash_status( ) & 0x01) );
}

void main( void )

{
 Setup_System_Config( );       
 Setup_PLL();
 Setup_Psc_All_On( );          
 Setup_EMIFA();                 
 Setup_EMIFB();
  spiflash_init( );
 spiflash_sector_erase(0);    
}