S25FL128L writing sequence

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
vishc_4020611
Level 1
Level 1
First like given

hello,

i am trying to read and write data to S25FL128 NOR Flash(defaults mode is QUAD) with STM32L4R5ZI controller.

i am able to read device id, but when i trying to send write enable command and after that reading command for the status register 1 ,and then waiting for the WEL bit to be set in status  register 1, code returns "HAL_Error" status.

basically i am not able to run two commands back to back like ( HAL_OSPI_Command  followed by HAL_OSPI_Receive ), it gives me wrong status which result in HAL_Error return status.

can any-body help me with the exact sequencing of NOR Flash for read/write operation with QSPI along with STM32 Controller.

please find below code,

static void MX_OCTOSPI1_Init(void)

{

  OSPIM_CfgTypeDef OSPIM_Cfg_Struct;

  OSPI_MemoryMappedTypeDef sMemMappedCfg;

  /* OCTOSPI1 parameter configuration*/

  hospi1.Instance = OCTOSPI1;

  hospi1.Init.FifoThreshold = 4;

  hospi1.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;

  hospi1.Init.MemoryType = HAL_OSPI_MEMTYPE_MICRON;

  hospi1.Init.DeviceSize = 23;

  hospi1.Init.ChipSelectHighTime = 1;

  hospi1.Init.FreeRunningClock = HAL_OSPI_FREERUNCLK_DISABLE;

  hospi1.Init.ClockMode = HAL_OSPI_CLOCK_MODE_0;

  hospi1.Init.WrapSize = HAL_OSPI_WRAP_NOT_SUPPORTED;

  hospi1.Init.ClockPrescaler = 1;

  hospi1.Init.SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE;

  hospi1.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_DISABLE;

  hospi1.Init.ChipSelectBoundary = 1;

  if (HAL_OSPI_Init(&hospi1) != HAL_OK)

  {

    _Error_Handler(__FILE__, __LINE__);

  }

}

void WriteEnable (void)

{

  OSPI_RegularCmdTypeDef        sCommand;

  OSPI_AutoPollingTypeDef            sConfig;

 

 

  sCommand.OperationType        = HAL_OSPI_OPTYPE_COMMON_CFG;

  sCommand.FlashId              = HAL_OSPI_FLASH_ID_1;

  sCommand.InstructionMode      = HAL_OSPI_INSTRUCTION_1_LINE;

  sCommand.Instruction          = WRITE_CMD;                                                            //0x06

  sCommand.InstructionSize      = HAL_OSPI_INSTRUCTION_8_BITS;

//  sCommand.DataDtrMode          = HAL_OSPI_DATA_DTR_DISABLE;

  sCommand.InstructionDtrMode   = HAL_OSPI_INSTRUCTION_DTR_DISABLE;

  sCommand.AddressMode          = HAL_OSPI_ADDRESS_NONE;

  sCommand.AlternateBytesMode   = HAL_OSPI_ALTERNATE_BYTES_NONE;

  sCommand.DataMode             = HAL_OSPI_DATA_NONE;

  sCommand.DummyCycles          = 0;

  sCommand.DQSMode              = HAL_OSPI_DQS_DISABLE;

  sCommand.SIOOMode             = HAL_OSPI_SIOO_INST_EVERY_CMD;

 

    if (HAL_OSPI_Command ( &hospi1 , &sCommand , 1000 ) != HAL_OK )

  {

      _Error_Handler(__FILE__, __LINE__);

  }

 

  sCommand.Instruction          = READ_STATUS_REG_CMD;

  sCommand.DataMode             = HAL_OSPI_DATA_1_LINE;

  sCommand.DataDtrMode          = HAL_OSPI_DATA_DTR_DISABLE;

  sCommand.NbData               = 1;

 

if ( HAL_OSPI_Receive ( &hospi1 , Id_Reg , 1000 ) != HAL_OK )               //it is not returning the HAL_OK

  {

    _Error_Handler(__FILE__, __LINE__);

  }

   

  sConfig.Match                 = WRITE_ENABLE_MATCH_VALUE;

  sConfig.Mask                  = WRITE_ENABLE_MASK_VALUE;

  sConfig.MatchMode             = HAL_OSPI_MATCH_MODE_AND;

  sConfig.Interval              = AUTO_POLLING_INTERVAL;

  sConfig.AutomaticStop         = HAL_OSPI_AUTOMATIC_STOP_ENABLE;

 

  if ( HAL_OSPI_AutoPolling(&hospi1, &sConfig,HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)

  {

     _Error_Handler(__FILE__, __LINE__);

  }

 

  asm("NOP");

}

kindly reply as soon as possible.

thanks in advance!!!

0 Likes
1 Solution

Hello,

We recommend to attach a logic analyzer and see what is going on at the SPI bus level. Also please contact STM since you are using STM controller and driver.

Thank you

Regards,

Bushra




View solution in original post

0 Likes
4 Replies
BushraH_91
Moderator
Moderator
Moderator
750 replies posted 50 likes received 250 solutions authored

Hello Viren,

Thank you for contacting Cypress Community Forum. Currently we are reviewing the issue and will get back to you as soon as we find the resolution.

Have a wonderful day

Regards,

Bushra

Hello,

We recommend to attach a logic analyzer and see what is going on at the SPI bus level. Also please contact STM since you are using STM controller and driver.

Thank you

Regards,

Bushra




0 Likes

Screenshot_2019-02-27_1_120229.pngHi,

With reference to previous post, now i am able to perform write enable command,

followed by sector erase command , page program command and read command.

but not able to get expected results.

With help of logic analyzer i have captured few things, for below command sequence,

1) write enable command

2) sector erase command

3) write enable command

4) page program command

5) fast read command

i have attached the each above function body along with logic analyzer snap shot.

void WriteEnableCMD (void)

{

  OSPI_RegularCmdTypeDef        sCommand;

  OSPI_AutoPollingTypeDef       sConfig;

 

 

  sCommand.OperationType        = HAL_OSPI_OPTYPE_COMMON_CFG;

  sCommand.FlashId              = HAL_OSPI_FLASH_ID_1;

  sCommand.Instruction          = WRITE_CMD;

  sCommand.InstructionMode      = HAL_OSPI_INSTRUCTION_1_LINE;

  sCommand.InstructionSize      = HAL_OSPI_INSTRUCTION_8_BITS;

  sCommand.DataDtrMode          = HAL_OSPI_DATA_DTR_DISABLE;

  sCommand.AddressMode          = HAL_OSPI_ADDRESS_NONE;

  sCommand.AlternateBytesMode   = HAL_OSPI_ALTERNATE_BYTES_NONE;

  sCommand.DataMode             = HAL_OSPI_DATA_NONE;

  sCommand.DummyCycles          = 0;

  sCommand.DQSMode              = HAL_OSPI_DQS_DISABLE;

  sCommand.SIOOMode             = HAL_OSPI_SIOO_INST_EVERY_CMD; 

  sCommand.InstructionDtrMode   = HAL_OSPI_INSTRUCTION_DTR_DISABLE;

  sCommand.NbData               = 1;

 

 

  if (HAL_OSPI_Command ( &hospi1 , &sCommand , 1000 ) != HAL_OK )

  {

    HAL_GPIO_WritePin ( GPIOB , GPIO_PIN_14 , GPIO_PIN_SET );

    while(1);

  }

   

  sCommand.Instruction          = READ_STATUS_REG_CMD;

  sCommand.DataMode             = HAL_OSPI_DATA_1_LINE;

  sCommand.NbData               = 1;

 

  if ( HAL_OSPI_Command ( &hospi1 , &sCommand , 1000 ) != HAL_OK )

  {

    HAL_GPIO_WritePin ( GPIOB , GPIO_PIN_14 , GPIO_PIN_SET );

    while(1);

  }

 

  sConfig.Match                 = WRITE_ENABLE_MATCH_VALUE;

  sConfig.Mask                  = WRITE_ENABLE_MASK_VALUE;

  sConfig.MatchMode             = HAL_OSPI_MATCH_MODE_AND;

  sConfig.Interval              = AUTO_POLLING_INTERVAL;

  sConfig.AutomaticStop         = HAL_OSPI_AUTOMATIC_STOP_ENABLE;

 

  if ( HAL_OSPI_AutoPolling(&hospi1, &sConfig,HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)

  {

    HAL_GPIO_WritePin ( GPIOB , GPIO_PIN_7 , GPIO_PIN_SET );

    while(1);

  }

 

  asm("NOP");

}

void SectorErase(void)

{

  Id_Reg[0] = Id_Reg[1] = 0x00;

  sCommand.Instruction          = SECTOR_ERASE_CMD;

  sCommand.Address              = 0x000000;

  sCommand.AddressMode          = HAL_OSPI_ADDRESS_1_LINE;

  sCommand.AlternateBytesMode   = HAL_OSPI_ALTERNATE_BYTES_NONE;

  sCommand.DataMode             = HAL_OSPI_DATA_NONE;

  sCommand.NbData               = 0;

  sCommand.DummyCycles          = 0;

  sCommand.DQSMode              = HAL_OSPI_DQS_DISABLE;

  sCommand.SIOOMode             = HAL_OSPI_SIOO_INST_EVERY_CMD;

  sCommand.InstructionMode      = HAL_OSPI_INSTRUCTION_1_LINE; 

  sCommand.InstructionSize      = HAL_OSPI_INSTRUCTION_8_BITS;

  sCommand.AddressSize          = HAL_OSPI_ADDRESS_24_BITS;

  sCommand.InstructionDtrMode   = HAL_OSPI_INSTRUCTION_DTR_DISABLE;

  sCommand.AddressDtrMode       = HAL_OSPI_ADDRESS_DTR_DISABLE;

  sCommand.DataDtrMode          = HAL_OSPI_DATA_DTR_DISABLE;

 

  if ( HAL_OSPI_Command ( &hospi1 , &sCommand , 1000 ) != HAL_OK )

  {

    while(1);

  }

  asm("NOP");  

}

void PageProgram (void)

{

  Id_Reg[0] = 'V';Id_Reg[1] = 'S';

  sCommand.Instruction          = PAGE_PROGRAM_CMD;

  sCommand.Address              = 0x000000;

  sCommand.AddressMode          = HAL_OSPI_ADDRESS_1_LINE;

  sCommand.AlternateBytesMode   = HAL_OSPI_ALTERNATE_BYTES_NONE;

  sCommand.DataMode             = HAL_OSPI_DATA_1_LINE;

  sCommand.NbData               = 2;

  sCommand.DummyCycles          = 0;

  sCommand.DQSMode              = HAL_OSPI_DQS_DISABLE;

  sCommand.SIOOMode             = HAL_OSPI_SIOO_INST_EVERY_CMD;

  if ( HAL_OSPI_Command ( &hospi1 , &sCommand , 1000 ) != HAL_OK )

  {

    while(1);

  }

  if ( HAL_OSPI_Transmit( &hospi1 , &Id_Reg[0] ,  1000 ) != HAL_OK )

  {

    while (1);

  }

  asm("NOP");  

}

void FastRead (void)

{

  Id_Reg[0] = Id_Reg[1] = 0x00;

  sCommand.Instruction          = FAST_READ_CMD;

  sCommand.Address              = 0x000000;

  sCommand.AddressMode          = HAL_OSPI_ADDRESS_1_LINE;

  sCommand.AlternateBytesMode   = HAL_OSPI_ALTERNATE_BYTES_NONE;

  sCommand.DataMode             = HAL_OSPI_DATA_1_LINE;

  sCommand.NbData               = 2;

  sCommand.DummyCycles          = 1;

  sCommand.DQSMode              = HAL_OSPI_DQS_DISABLE;

  sCommand.SIOOMode             = HAL_OSPI_SIOO_INST_EVERY_CMD;

 

  if ( HAL_OSPI_Command ( &hospi1 , &sCommand , 1000 ) != HAL_OK )

  {

    while(1);

  }

  if ( HAL_OSPI_Receive( &hospi1 , &Id_Reg[0] ,  1000 ) != HAL_OK )

  {

    while (1);

  }

  asm("NOP");   

}

kindly guide me with writing sequence.

Thanks in advance

0 Likes

Hello

Are you waiting for the completion of erase/program by polling status register bit 0 (Write In Progress)?

Thank you

Regards,

Bushra

0 Likes