Skip to main content
Associate
Nov 3, 2026 6:46 PM UTC
Solved

OSPI clock signal not being generated

Title pretty much says it all. I am able to toggle the pin, PB2, on the STM32H7, when configured as GPIO output but nothing happens when configured as OSPI_SCK.

 

Here is the MX_OCTOSPI1_Init:
 

void MX_OCTOSPI1_Init(void)
{

/* USER CODE BEGIN OCTOSPI1_Init 0 */

/* USER CODE END OCTOSPI1_Init 0 */

OSPIM_CfgTypeDef sOspiManagerCfg = {0};

/* USER CODE BEGIN OCTOSPI1_Init 1 */

/* USER CODE END OCTOSPI1_Init 1 */
hospi1.Instance = OCTOSPI1;
hospi1.Init.FifoThreshold = 1;
hospi1.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;
hospi1.Init.MemoryType = HAL_OSPI_MEMTYPE_MICRON;
hospi1.Init.DeviceSize = 24;
hospi1.Init.ChipSelectHighTime = 3;
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_HALFCYCLE;
hospi1.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_DISABLE;
hospi1.Init.ChipSelectBoundary = 0;
hospi1.Init.DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_USED;
hospi1.Init.MaxTran = 0;
hospi1.Init.Refresh = 0;
if (HAL_OSPI_Init(&hospi1) != HAL_OK)
{
Error_Handler();
}
sOspiManagerCfg.ClkPort = 1;
sOspiManagerCfg.NCSPort = 1;
sOspiManagerCfg.IOLowPort = HAL_OSPIM_IOPORT_1_LOW;
if (HAL_OSPIM_Config(&hospi1, &sOspiManagerCfg, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN OCTOSPI1_Init 2 */

/* USER CODE END OCTOSPI1_Init 2 */

}

Here is the very first OPSI related function I run after the above init:
 

HAL_StatusTypeDef W25Q_EnableReset(OSPI_HandleTypeDef *hospi)
{
OSPI_RegularCmdTypeDef cmd;
HAL_StatusTypeDef status;

cmd.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG;
cmd.Instruction = W25Q_ENABLE_RESET;
cmd.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE;
cmd.InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS;
cmd.Address = 0;
cmd.AddressMode = HAL_OSPI_ADDRESS_NONE;
cmd.AddressSize = HAL_OSPI_ADDRESS_8_BITS;
cmd.AlternateBytes = 0;
cmd.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
cmd.AlternateBytesSize = HAL_OSPI_ALTERNATE_BYTES_8_BITS;
cmd.DummyCycles = 0;
cmd.NbData = 0;
cmd.DataMode = HAL_OSPI_DATA_NONE;
cmd.DataDtrMode = HAL_OSPI_DATA_DTR_DISABLE;
cmd.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;

//HAL_GPIO_WritePin(QSPI_CLK_GPIO_Port, QSPI_CLK_Pin, RESET); // Not sure yet if needed
status = HAL_OSPI_Command(&hospi1, &cmd, W25Q_TIMEOUT_VALUE);
//HAL_GPIO_WritePin(QSPI_CLK_GPIO_Port, QSPI_CLK_Pin, SET);

return status;
}

The HAL_OSPI_Command hits the timeout and I never see a clock signal for the entire function duration. Any guidance would be wonderful!

RglasgowBest answer
Associate
Nov 4, 2026 3:59 PM UTC

After making sure all three commands were initialized to zero and THEN modified as need be, everything now works!!!

5 replies

KDJEM.1
ST Technical Moderator
Nov 4, 2026 8:24 AM UTC

Hello ​@Rglasgow ;

 

Could you please give more details about the issue: Which STM32CubeMX version are you using? Which STM32H7 and memory reference are you using? Could you please share the memory datasheet?

Please look at:

 

Thank you.

Kaouthar

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.
RglasgowAuthor
Associate
Nov 4, 2026 2:00 PM UTC

CubeMX: 6.18.1

CPU: STM32H735VGTx

Memory datasheet: see attached

 

KDJEM.1
ST Technical Moderator
Nov 4, 2026 3:03 PM UTC

Hello ​@Rglasgow ;

 

Thank you for sharing these details.

Is the issue solved when add a “Reset (99h)” instruction after enable reset ?

I recommend you to check the GPIOs Configuration:

Do you get the same issue when using another command such as “write”, “read”?

Is the DQS enabled?

What is the OCTOSPI frequency? 

 

 

Thank you.

Kaouthar

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.
RglasgowAuthor
Associate
Nov 4, 2026 3:35 PM UTC

I uncommented the following reset and readjedec but still not luck. Here is the code for those functions respectively:
 

HAL_StatusTypeDef W25Q_ResetDevice(OSPI_HandleTypeDef *hospi)
{
OSPI_RegularCmdTypeDef cmd;
HAL_StatusTypeDef status;

cmd.Instruction = W25Q_RESET_DEVICE;
cmd.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE;
cmd.Address = 0;
cmd.AddressMode = HAL_OSPI_ADDRESS_NONE;
cmd.AddressSize = HAL_OSPI_ADDRESS_8_BITS;
cmd.AlternateBytes = 0;
cmd.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
cmd.AlternateBytesSize = HAL_OSPI_ALTERNATE_BYTES_8_BITS;
cmd.DummyCycles = 0;
cmd.NbData = 0;
cmd.DataMode = HAL_OSPI_DATA_NONE;
cmd.DataDtrMode = HAL_OSPI_DATA_DTR_DISABLE;

cmd.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;

status = HAL_OSPI_Command(&hospi1, &cmd, W25Q_TIMEOUT_VALUE);

return status;
}
HAL_StatusTypeDef W25Q_ReadJedecId(OSPI_HandleTypeDef *hospi, uint8_t *pManufacturerId, uint8_t *pMemoryTypeId, uint8_t *pCapacityId)
{
OSPI_RegularCmdTypeDef cmd;
HAL_StatusTypeDef status;
uint8_t response[3];

cmd.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG;
cmd.Instruction = W25Q_READ_JEDEC_ID;
cmd.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE;
cmd.Address = 0;
cmd.AddressMode = HAL_OSPI_ADDRESS_NONE;
cmd.AddressSize = HAL_OSPI_ADDRESS_8_BITS;
cmd.AlternateBytes = 0;
cmd.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
cmd.AlternateBytesSize = HAL_OSPI_ALTERNATE_BYTES_8_BITS;
cmd.DummyCycles = 0;
cmd.NbData = 3;
cmd.DataMode = HAL_OSPI_DATA_1_LINE;
cmd.DataDtrMode = HAL_OSPI_DATA_DTR_DISABLE;

cmd.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;

status = HAL_OSPI_Command(&hospi1, &cmd, W25Q_TIMEOUT_VALUE);
if (status != HAL_OK)
{
return status;
}
status = HAL_OSPI_Receive(hospi, &response[0], W25Q_TIMEOUT_VALUE);
if (status == HAL_OK)
{
*pManufacturerId = response[0];
*pMemoryTypeId = response[1];
*pCapacityId = response[2];
}

return status;
}

I still just get HAL_Error as statuses with no clock signal showing up.

 

Currently clocking OCTOSPI at 100MHz
 


At this point, I forgot about the DQS, i have disabled it as well as initializing the cmd struct to {0} so anything else that should be disabled is disabled automatically. This DOES result in an improvement but now i just see a SINGLE clock pulse but that might be down to my logic analyzer only sampling at 100MS/s. The result of the readjedecid() is all zeros though, which it presumably shouldnt be.

Follow up, i realized i forgot to share the main function where this is all being called from:
 

int main(void)
{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MPU Configuration--------------------------------------------------------*/
MPU_Config();

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* Configure the peripherals common clocks */
PeriphCommonClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_USB_OTG_HS_PCD_Init();
MX_I2C4_Init();
MX_I2S1_Init();
MX_I2S2_Init();
MX_ADC1_Init();
MX_ADC3_Init();
MX_DFSDM1_Init();
MX_I2C1_Init();
MX_OCTOSPI1_Init();
MX_SPI3_Init();
MX_SPI6_Init();
MX_UART4_Init();
MX_UART5_Init();
/* USER CODE BEGIN 2 */
HAL_NVIC_SetPriority(LIGHTING_ENC_A_EXTI_IRQn, 0, 0);
HAL_NVIC_SetPriority(LIGHTING_SW1_EXTI_IRQn, 0, 0);
HAL_NVIC_SetPriority(VOL_ENC_A_EXTI_IRQn, 0, 0);
HAL_NVIC_SetPriority(VOL_SW1_EXTI_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(LIGHTING_ENC_A_EXTI_IRQn);
HAL_NVIC_EnableIRQ(LIGHTING_SW1_EXTI_IRQn);
HAL_NVIC_EnableIRQ(VOL_ENC_A_EXTI_IRQn);
HAL_NVIC_EnableIRQ(VOL_SW1_EXTI_IRQn);
PRINTF("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
PRINTF("System initialization complete, entering ThreadX");
PRINTF("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
uint8_t buf1[1] = {0};
uint8_t buf2[1] = {0};
uint8_t buf3[1] = {0};
//EnterQuadMode();
//EnableMemMappedQuadMode();
// 1. Reset the device to a known state (recover from soft resets)
// Both of these must be done and in this sequence
W25Q_EnableReset(&hospi1);
W25Q_ResetDevice(&hospi1);
W25Q_ReadJedecId(&hospi1, buf1, buf2, buf3);

// 2. Enable Quad bit (QE) in Status Register 2 for Quad I/O operations
// Using Volatile Write Enable to avoid wearing out the flash on every boot
//W25Q_VolatileSrWriteEnable(&hospi1);
//W25Q_WriteStatusRegister(&hospi1, W25Q_SR2, W25Q_SR2_QE);

//W25Q_ReadUniqueId(&hospi1, buf);
/* USER CODE END 2 */

MX_ThreadX_Init();

/* We should never get here as control is now taken by the scheduler */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}

 

RglasgowAuthorBest answer
Associate
Nov 4, 2026 3:59 PM UTC

After making sure all three commands were initialized to zero and THEN modified as need be, everything now works!!!