2025-04-27 11:54 PM - last edited on 2025-04-28 3:50 AM by mƎALLEm
Hi Everyone,
I have W25Q256JV and STM32L562CEU6 with 38 Pin Package and have OSPI (Single SPI, Dual SPI and Quad SPI option only). Below is my Clock Settings, OSPI (Quad SPI) with Quad Lines Settings and Error Status during Write Enable and main.c file.
Kindly check and let me what is wrong so it's going into Error Handler every time on Write Enable.
If any basic drivers are available for OSPI in Quad Mode for Read/Write/Erase.
Looking forward to your kind help...
static void WriteEnable(OSPI_HandleTypeDef *hospi) {
OSPI_RegularCmdTypeDef sCommand;
OSPI_AutoPollingTypeDef sConfig;
HAL_StatusTypeDef ret;
/* Enable write operations ------------------------------------------ */
sCommand.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG;
sCommand.FlashId = HAL_OSPI_FLASH_ID_1;
sCommand.Instruction = 0x06; // Use standard Write Enable command for Quad mode
sCommand.InstructionMode = HAL_OSPI_INSTRUCTION_4_LINES; // Use 4-line instruction mode
sCommand.InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS; // 8-bit instruction size
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;
ret = HAL_OSPI_Command(hospi, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE);
if (ret != HAL_OK) {
// Log the error here
Error_Handler();
}
/* Configure automatic polling mode to wait for write enabling ---- */
sCommand.Instruction = 0x05; // Read the status register command for Quad mode
sCommand.Address = 0x0;
sCommand.AddressMode = HAL_OSPI_ADDRESS_4_LINES; // Use 4-line address mode
sCommand.AddressSize = HAL_OSPI_ADDRESS_24_BITS; // Standard 3-byte address size
sCommand.AddressDtrMode = HAL_OSPI_ADDRESS_DTR_DISABLE;
sCommand.DataMode = HAL_OSPI_DATA_4_LINES; // Use 4-line data mode
sCommand.DataDtrMode = HAL_OSPI_DATA_DTR_DISABLE;
sCommand.NbData = 1; // 1 byte to read from status register
sCommand.DummyCycles = 8;
ret = HAL_OSPI_Command(hospi, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE);
if (ret != HAL_OK) {
// Log the error here
Error_Handler();
}
ret = HAL_OSPI_AutoPolling(hospi, &sConfig, HAL_OSPI_TIMEOUT_DEFAULT_VALUE);
if (ret != HAL_OK) {
// Log the error here
Error_Handler(); /* every time goes into error handler here */
}
/* Polling finished successfully */
}
2025-04-28 3:49 AM
Hello @NajeebUllahKhan ,
Please kindly use </> button to share your code. refer to this post. I'm editing your post.
Thank you for your understanding.
2025-04-30 1:45 AM
Hello @NajeebUllahKhan;
What is the OCTOSPI frequency value?
Could you please try to decrease the OCTOSPI clock frequency.
Is the memory configured in memory mapped mode?
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-05-04 3:44 AM
System is running at 110 MHz and Prescaler is 2, so OSPI Freq is 55 MHz.
Yes, tried but still no response from W25Q256.
I am just configuring Quad Mode, then write and read that's it.
You can see my above main.c file I shared, my code goes into error handler when in write enable function.
Do you have any example for OSPI configured in Quad Mode for any flash? Or any working example code or function for it, you can share may be that can help me???
Looking to your response as I need to get it done very soon due to time limitation in project
2025-05-04 4:48 AM
Clear the sCommand structure. Probably sConfig too and whatever configuration parameters it needs.
Part would need to be in quad mode already for 4-bit command operation.
2025-05-04 8:56 PM
Already doing it for sCommand and sConfig using {0} but still not working.
I have a question, does OSPI in Quad Mode really works with W25Q Quad based Flash? If yes, then there should be some example or test code for it to check if its really works?
I can't find any STM example or test code to confirm if its really works because I am doing QSPI with W25Q in Quad Mode and its working fine but when use OSPI in Quad Mode then no response???
2025-05-05 9:39 AM - edited 2025-05-05 9:42 AM
Isn't the code generator supposed to do that? Or the Engineer responsible for the board, and board bring up? Not everything is a cut-n-paste exercise. ST generally provides code showing that THEIR boards work, ie EVAL, DISCO, not what others chose to build.
I'd previously built a Micron MT25Q256 implementation for a STM32L562
For the W25Q256, try this one
https://github.com/cturvey/stm32extldr/blob/main/l5_w25q256/README.md
PA3:AF10 CLK
PA2:AF10 NCS
PB1:AF10 IO0
PB0:AF10 IO1
PA7:AF10 IO2
PA6:AF10 IO3