261 #include "stm32h7xx_hal.h"
263 #if defined(OCTOSPI) || defined(OCTOSPI1) || defined(OCTOSPI2)
274 #ifdef HAL_OSPI_MODULE_ENABLED
282 #define OSPI_FUNCTIONAL_MODE_INDIRECT_WRITE ((uint32_t)0x00000000)
283 #define OSPI_FUNCTIONAL_MODE_INDIRECT_READ ((uint32_t)OCTOSPI_CR_FMODE_0)
284 #define OSPI_FUNCTIONAL_MODE_AUTO_POLLING ((uint32_t)OCTOSPI_CR_FMODE_1)
285 #define OSPI_FUNCTIONAL_MODE_MEMORY_MAPPED ((uint32_t)OCTOSPI_CR_FMODE)
287 #define OSPI_CFG_STATE_MASK 0x00000004U
288 #define OSPI_BUSY_STATE_MASK 0x00000008U
290 #define OSPI_NB_INSTANCE 2U
291 #define OSPI_IOM_NB_PORTS 2U
292 #define OSPI_IOM_PORT_MASK 0x1U
295 #define IS_OSPI_FUNCTIONAL_MODE(MODE) (((MODE) == OSPI_FUNCTIONAL_MODE_INDIRECT_WRITE) || \
296 ((MODE) == OSPI_FUNCTIONAL_MODE_INDIRECT_READ) || \
297 ((MODE) == OSPI_FUNCTIONAL_MODE_AUTO_POLLING) || \
298 ((MODE) == OSPI_FUNCTIONAL_MODE_MEMORY_MAPPED))
307 uint32_t Tickstart, uint32_t Timeout);
308 static HAL_StatusTypeDef OSPI_ConfigCmd (OSPI_HandleTypeDef *hospi, OSPI_RegularCmdTypeDef *cmd);
309 static HAL_StatusTypeDef OSPIM_GetConfig (uint8_t instance_nb, OSPIM_CfgTypeDef *cfg);
356 assert_param(IS_OSPI_FIFO_THRESHOLD (hospi->Init.FifoThreshold));
357 assert_param(IS_OSPI_DUALQUAD_MODE (hospi->Init.DualQuad));
358 assert_param(IS_OSPI_MEMORY_TYPE (hospi->Init.MemoryType));
359 assert_param(IS_OSPI_DEVICE_SIZE (hospi->Init.DeviceSize));
360 assert_param(IS_OSPI_CS_HIGH_TIME (hospi->Init.ChipSelectHighTime));
361 assert_param(IS_OSPI_FREE_RUN_CLK (hospi->Init.FreeRunningClock));
362 assert_param(IS_OSPI_CLOCK_MODE (hospi->Init.ClockMode));
364 assert_param(IS_OSPI_CLK_PRESCALER (hospi->Init.ClockPrescaler));
365 assert_param(IS_OSPI_SAMPLE_SHIFTING(hospi->Init.SampleShifting));
366 assert_param(IS_OSPI_DHQC (hospi->Init.DelayHoldQuarterCycle));
367 assert_param(IS_OSPI_CS_BOUNDARY (hospi->Init.ChipSelectBoundary));
368 assert_param(IS_OSPI_CKCSHT (hospi->Init.ClkChipSelectHighTime));
369 assert_param(IS_OSPI_DLYBYP (hospi->Init.DelayBlockBypass));
373 hospi->ErrorCode = HAL_OSPI_ERROR_NONE;
376 if (hospi->State == HAL_OSPI_STATE_RESET)
378 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
380 hospi->ErrorCallback = HAL_OSPI_ErrorCallback;
381 hospi->AbortCpltCallback = HAL_OSPI_AbortCpltCallback;
382 hospi->FifoThresholdCallback = HAL_OSPI_FifoThresholdCallback;
383 hospi->CmdCpltCallback = HAL_OSPI_CmdCpltCallback;
384 hospi->RxCpltCallback = HAL_OSPI_RxCpltCallback;
385 hospi->TxCpltCallback = HAL_OSPI_TxCpltCallback;
386 hospi->RxHalfCpltCallback = HAL_OSPI_RxHalfCpltCallback;
387 hospi->TxHalfCpltCallback = HAL_OSPI_TxHalfCpltCallback;
388 hospi->StatusMatchCallback = HAL_OSPI_StatusMatchCallback;
389 hospi->TimeOutCallback = HAL_OSPI_TimeOutCallback;
391 if(hospi->MspInitCallback ==
NULL)
393 hospi->MspInitCallback = HAL_OSPI_MspInit;
397 hospi->MspInitCallback(hospi);
400 HAL_OSPI_MspInit(hospi);
404 (void)HAL_OSPI_SetTimeout(hospi, HAL_OSPI_TIMEOUT_DEFAULT_VALUE);
413 hospi->Init.DelayBlockBypass | hospi->Init.ClockMode));
423 hospi->Instance->DCR4 = hospi->Init.Refresh;
429 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_BUSY,
RESET, tickstart, hospi->Timeout);
442 (hospi->Init.SampleShifting | hospi->Init.DelayHoldQuarterCycle));
445 __HAL_OSPI_ENABLE(hospi);
448 if (hospi->Init.FreeRunningClock == HAL_OSPI_FREERUNCLK_ENABLE)
454 if (hospi->Init.MemoryType == HAL_OSPI_MEMTYPE_HYPERBUS)
456 hospi->State = HAL_OSPI_STATE_HYPERBUS_INIT;
460 hospi->State = HAL_OSPI_STATE_READY;
475 __weak
void HAL_OSPI_MspInit(OSPI_HandleTypeDef *hospi)
503 __HAL_OSPI_DISABLE(hospi);
508 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
509 if(hospi->MspDeInitCallback ==
NULL)
511 hospi->MspDeInitCallback = HAL_OSPI_MspDeInit;
515 hospi->MspDeInitCallback(hospi);
518 HAL_OSPI_MspDeInit(hospi);
522 hospi->State = HAL_OSPI_STATE_RESET;
533 __weak
void HAL_OSPI_MspDeInit(OSPI_HandleTypeDef *hospi)
573 void HAL_OSPI_IRQHandler(OSPI_HandleTypeDef *hospi)
575 __IO uint32_t *data_reg = &hospi->Instance->DR;
576 uint32_t flag = hospi->Instance->SR;
577 uint32_t itsource = hospi->Instance->CR;
578 uint32_t currentstate = hospi->State;
581 if (((flag & HAL_OSPI_FLAG_FT) != 0U) && ((itsource & HAL_OSPI_IT_FT) != 0U))
583 if (currentstate == HAL_OSPI_STATE_BUSY_TX)
586 *((
__IO uint8_t *)data_reg) = *hospi->pBuffPtr;
590 else if (currentstate == HAL_OSPI_STATE_BUSY_RX)
593 *hospi->pBuffPtr = *((
__IO uint8_t *)data_reg);
602 if (hospi->XferCount == 0U)
606 __HAL_OSPI_DISABLE_IT(hospi, HAL_OSPI_IT_FT);
610 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
611 hospi->FifoThresholdCallback(hospi);
613 HAL_OSPI_FifoThresholdCallback(hospi);
617 else if (((flag & HAL_OSPI_FLAG_TC) != 0U) && ((itsource & HAL_OSPI_IT_TC) != 0U))
619 if (currentstate == HAL_OSPI_STATE_BUSY_RX)
624 *hospi->pBuffPtr = *((
__IO uint8_t *)data_reg);
628 else if(hospi->XferCount == 0U)
631 hospi->Instance->FCR = HAL_OSPI_FLAG_TC;
634 __HAL_OSPI_DISABLE_IT(hospi, HAL_OSPI_IT_TC | HAL_OSPI_IT_FT | HAL_OSPI_IT_TE);
637 hospi->State = HAL_OSPI_STATE_READY;
640 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
641 hospi->RxCpltCallback(hospi);
643 HAL_OSPI_RxCpltCallback(hospi);
654 hospi->Instance->FCR = HAL_OSPI_FLAG_TC;
657 __HAL_OSPI_DISABLE_IT(hospi, HAL_OSPI_IT_TC | HAL_OSPI_IT_FT | HAL_OSPI_IT_TE);
660 hospi->State = HAL_OSPI_STATE_READY;
662 if (currentstate == HAL_OSPI_STATE_BUSY_TX)
665 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
666 hospi->TxCpltCallback(hospi);
668 HAL_OSPI_TxCpltCallback(hospi);
671 else if (currentstate == HAL_OSPI_STATE_BUSY_CMD)
674 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
675 hospi->CmdCpltCallback(hospi);
677 HAL_OSPI_CmdCpltCallback(hospi);
680 else if (currentstate == HAL_OSPI_STATE_ABORT)
682 if (hospi->ErrorCode == HAL_OSPI_ERROR_NONE)
686 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
687 hospi->AbortCpltCallback(hospi);
689 HAL_OSPI_AbortCpltCallback(hospi);
696 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
697 hospi->ErrorCallback(hospi);
699 HAL_OSPI_ErrorCallback(hospi);
710 else if (((flag & HAL_OSPI_FLAG_SM) != 0U) && ((itsource & HAL_OSPI_IT_SM) != 0U))
713 hospi->Instance->FCR = HAL_OSPI_FLAG_SM;
719 __HAL_OSPI_DISABLE_IT(hospi, HAL_OSPI_IT_SM | HAL_OSPI_IT_TE);
722 hospi->State = HAL_OSPI_STATE_READY;
726 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
727 hospi->StatusMatchCallback(hospi);
729 HAL_OSPI_StatusMatchCallback(hospi);
733 else if (((flag & HAL_OSPI_FLAG_TE) != 0U) && ((itsource & HAL_OSPI_IT_TE) != 0U))
736 hospi->Instance->FCR = HAL_OSPI_FLAG_TE;
739 __HAL_OSPI_DISABLE_IT(hospi, (HAL_OSPI_IT_TO | HAL_OSPI_IT_SM | HAL_OSPI_IT_FT | HAL_OSPI_IT_TC | HAL_OSPI_IT_TE));
742 hospi->ErrorCode = HAL_OSPI_ERROR_TRANSFER;
751 hospi->hmdma->XferAbortCallback = OSPI_DMAAbortCplt;
755 hospi->State = HAL_OSPI_STATE_READY;
758 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
759 hospi->ErrorCallback(hospi);
761 HAL_OSPI_ErrorCallback(hospi);
768 hospi->State = HAL_OSPI_STATE_READY;
771 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
772 hospi->ErrorCallback(hospi);
774 HAL_OSPI_ErrorCallback(hospi);
779 else if (((flag & HAL_OSPI_FLAG_TO) != 0U) && ((itsource & HAL_OSPI_IT_TO) != 0U))
782 hospi->Instance->FCR = HAL_OSPI_FLAG_TO;
785 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
786 hospi->TimeOutCallback(hospi);
788 HAL_OSPI_TimeOutCallback(hospi);
804 HAL_StatusTypeDef HAL_OSPI_Command(OSPI_HandleTypeDef *hospi, OSPI_RegularCmdTypeDef *cmd, uint32_t Timeout)
813 if (hospi->Init.DualQuad == HAL_OSPI_DUALQUAD_DISABLE)
819 if (
cmd->InstructionMode != HAL_OSPI_INSTRUCTION_NONE)
826 if (
cmd->AddressMode != HAL_OSPI_ADDRESS_NONE)
833 if (
cmd->AlternateBytesMode != HAL_OSPI_ALTERNATE_BYTES_NONE)
840 if (
cmd->DataMode != HAL_OSPI_DATA_NONE)
842 if (
cmd->OperationType == HAL_OSPI_OPTYPE_COMMON_CFG)
854 state = hospi->State;
855 if (((state == HAL_OSPI_STATE_READY) && (hospi->Init.MemoryType != HAL_OSPI_MEMTYPE_HYPERBUS)) ||
856 ((state == HAL_OSPI_STATE_READ_CMD_CFG) && ((
cmd->OperationType == HAL_OSPI_OPTYPE_WRITE_CFG)
857 || (
cmd->OperationType == HAL_OSPI_OPTYPE_WRAP_CFG))) ||
858 ((state == HAL_OSPI_STATE_WRITE_CMD_CFG) && ((
cmd->OperationType == HAL_OSPI_OPTYPE_READ_CFG) ||
859 (
cmd->OperationType == HAL_OSPI_OPTYPE_WRAP_CFG))))
862 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_BUSY,
RESET, tickstart, Timeout);
867 hospi->ErrorCode = HAL_OSPI_ERROR_NONE;
870 status = OSPI_ConfigCmd(hospi, cmd);
874 if (
cmd->DataMode == HAL_OSPI_DATA_NONE)
878 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_TC,
SET, tickstart, Timeout);
880 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TC);
885 if (
cmd->OperationType == HAL_OSPI_OPTYPE_COMMON_CFG)
887 hospi->State = HAL_OSPI_STATE_CMD_CFG;
889 else if (
cmd->OperationType == HAL_OSPI_OPTYPE_READ_CFG)
891 if (hospi->State == HAL_OSPI_STATE_WRITE_CMD_CFG)
893 hospi->State = HAL_OSPI_STATE_CMD_CFG;
897 hospi->State = HAL_OSPI_STATE_READ_CMD_CFG;
900 else if (
cmd->OperationType == HAL_OSPI_OPTYPE_WRITE_CFG)
902 if (hospi->State == HAL_OSPI_STATE_READ_CMD_CFG)
904 hospi->State = HAL_OSPI_STATE_CMD_CFG;
908 hospi->State = HAL_OSPI_STATE_WRITE_CMD_CFG;
922 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
936 HAL_StatusTypeDef HAL_OSPI_Command_IT(OSPI_HandleTypeDef *hospi, OSPI_RegularCmdTypeDef *cmd)
944 if (hospi->Init.DualQuad == HAL_OSPI_DUALQUAD_DISABLE)
950 if (
cmd->InstructionMode != HAL_OSPI_INSTRUCTION_NONE)
957 if (
cmd->AddressMode != HAL_OSPI_ADDRESS_NONE)
964 if (
cmd->AlternateBytesMode != HAL_OSPI_ALTERNATE_BYTES_NONE)
971 if (
cmd->DataMode != HAL_OSPI_DATA_NONE)
982 if ((hospi->State == HAL_OSPI_STATE_READY) && (
cmd->OperationType == HAL_OSPI_OPTYPE_COMMON_CFG) &&
983 (
cmd->DataMode == HAL_OSPI_DATA_NONE) && (hospi->Init.MemoryType != HAL_OSPI_MEMTYPE_HYPERBUS))
986 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_BUSY,
RESET, tickstart, hospi->Timeout);
991 hospi->ErrorCode = HAL_OSPI_ERROR_NONE;
994 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TE | HAL_OSPI_FLAG_TC);
997 status = OSPI_ConfigCmd(hospi, cmd);
1002 hospi->State = HAL_OSPI_STATE_BUSY_CMD;
1005 __HAL_OSPI_ENABLE_IT(hospi, HAL_OSPI_IT_TC | HAL_OSPI_IT_TE);
1012 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
1026 HAL_StatusTypeDef HAL_OSPI_HyperbusCfg(OSPI_HandleTypeDef *hospi, OSPI_HyperbusCfgTypeDef *cfg, uint32_t Timeout)
1033 assert_param(IS_OSPI_RW_RECOVERY_TIME (cfg->RWRecoveryTime));
1035 assert_param(IS_OSPI_WRITE_ZERO_LATENCY(cfg->WriteZeroLatency));
1039 state = hospi->State;
1040 if ((state == HAL_OSPI_STATE_HYPERBUS_INIT) || (state == HAL_OSPI_STATE_READY))
1043 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_BUSY,
RESET, tickstart, Timeout);
1050 cfg->WriteZeroLatency | cfg->LatencyMode));
1053 hospi->State = HAL_OSPI_STATE_READY;
1059 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
1073 HAL_StatusTypeDef HAL_OSPI_HyperbusCmd(OSPI_HandleTypeDef *hospi, OSPI_HyperbusCmdTypeDef *cmd, uint32_t Timeout)
1085 if ((hospi->State == HAL_OSPI_STATE_READY) && (hospi->Init.MemoryType == HAL_OSPI_MEMTYPE_HYPERBUS))
1088 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_BUSY,
RESET, tickstart, Timeout);
1114 hospi->State = HAL_OSPI_STATE_CMD_CFG;
1120 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
1135 HAL_StatusTypeDef HAL_OSPI_Transmit(OSPI_HandleTypeDef *hospi, uint8_t *pData, uint32_t Timeout)
1139 __IO uint32_t *data_reg = &hospi->Instance->DR;
1145 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_PARAM;
1150 if (hospi->State == HAL_OSPI_STATE_CMD_CFG)
1153 hospi->XferCount =
READ_REG(hospi->Instance->DLR) + 1U;
1154 hospi->XferSize = hospi->XferCount;
1155 hospi->pBuffPtr = pData;
1163 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_FT,
SET, tickstart, Timeout);
1170 *((
__IO uint8_t *)data_reg) = *hospi->pBuffPtr;
1173 }
while (hospi->XferCount > 0U);
1178 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_TC,
SET, tickstart, Timeout);
1183 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TC);
1186 hospi->State = HAL_OSPI_STATE_READY;
1193 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
1209 HAL_StatusTypeDef HAL_OSPI_Receive(OSPI_HandleTypeDef *hospi, uint8_t *pData, uint32_t Timeout)
1213 __IO uint32_t *data_reg = &hospi->Instance->DR;
1214 uint32_t addr_reg = hospi->Instance->AR;
1215 uint32_t ir_reg = hospi->Instance->IR;
1221 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_PARAM;
1226 if (hospi->State == HAL_OSPI_STATE_CMD_CFG)
1229 hospi->XferCount =
READ_REG(hospi->Instance->DLR) + 1U;
1230 hospi->XferSize = hospi->XferCount;
1231 hospi->pBuffPtr = pData;
1237 if (hospi->Init.MemoryType == HAL_OSPI_MEMTYPE_HYPERBUS)
1239 WRITE_REG(hospi->Instance->AR, addr_reg);
1245 WRITE_REG(hospi->Instance->AR, addr_reg);
1256 status = OSPI_WaitFlagStateUntilTimeout(hospi, (HAL_OSPI_FLAG_FT | HAL_OSPI_FLAG_TC),
SET, tickstart, Timeout);
1263 *hospi->pBuffPtr = *((
__IO uint8_t *)data_reg);
1266 }
while(hospi->XferCount > 0U);
1271 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_TC,
SET, tickstart, Timeout);
1276 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TC);
1279 hospi->State = HAL_OSPI_STATE_READY;
1286 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
1301 HAL_StatusTypeDef HAL_OSPI_Transmit_IT(OSPI_HandleTypeDef *hospi, uint8_t *pData)
1309 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_PARAM;
1314 if (hospi->State == HAL_OSPI_STATE_CMD_CFG)
1317 hospi->XferCount =
READ_REG(hospi->Instance->DLR) + 1U;
1318 hospi->XferSize = hospi->XferCount;
1319 hospi->pBuffPtr = pData;
1325 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TE | HAL_OSPI_FLAG_TC);
1328 hospi->State = HAL_OSPI_STATE_BUSY_TX;
1331 __HAL_OSPI_ENABLE_IT(hospi, HAL_OSPI_IT_TC | HAL_OSPI_IT_FT | HAL_OSPI_IT_TE);
1336 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
1351 HAL_StatusTypeDef HAL_OSPI_Receive_IT(OSPI_HandleTypeDef *hospi, uint8_t *pData)
1354 uint32_t addr_reg = hospi->Instance->AR;
1355 uint32_t ir_reg = hospi->Instance->IR;
1361 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_PARAM;
1366 if (hospi->State == HAL_OSPI_STATE_CMD_CFG)
1369 hospi->XferCount =
READ_REG(hospi->Instance->DLR) + 1U;
1370 hospi->XferSize = hospi->XferCount;
1371 hospi->pBuffPtr = pData;
1377 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TE | HAL_OSPI_FLAG_TC);
1380 hospi->State = HAL_OSPI_STATE_BUSY_RX;
1383 __HAL_OSPI_ENABLE_IT(hospi, HAL_OSPI_IT_TC | HAL_OSPI_IT_FT | HAL_OSPI_IT_TE);
1386 if (hospi->Init.MemoryType == HAL_OSPI_MEMTYPE_HYPERBUS)
1388 WRITE_REG(hospi->Instance->AR, addr_reg);
1394 WRITE_REG(hospi->Instance->AR, addr_reg);
1405 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
1424 HAL_StatusTypeDef HAL_OSPI_Transmit_DMA(OSPI_HandleTypeDef *hospi, uint8_t *pData)
1427 uint32_t data_size = hospi->Instance->DLR + 1U;
1433 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_PARAM;
1438 if (hospi->State == HAL_OSPI_STATE_CMD_CFG)
1440 hospi->XferCount = data_size;
1443 hospi->XferSize = hospi->XferCount;
1444 hospi->pBuffPtr = pData;
1450 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TE | HAL_OSPI_FLAG_TC);
1453 hospi->State = HAL_OSPI_STATE_BUSY_TX;
1456 hospi->hmdma->XferCpltCallback = OSPI_DMACplt;
1459 hospi->hmdma->XferErrorCallback = OSPI_DMAError;
1462 hospi->hmdma->XferAbortCallback =
NULL;
1483 hospi->ErrorCode |= HAL_OSPI_ERROR_DMA;
1488 if (
HAL_MDMA_Start_IT(hospi->hmdma, (uint32_t)pData, (uint32_t)&hospi->Instance->DR, hospi->XferSize,1) ==
HAL_OK)
1491 __HAL_OSPI_ENABLE_IT(hospi, HAL_OSPI_IT_TE);
1498 hospi->ErrorCode = HAL_OSPI_ERROR_DMA;
1499 hospi->State = HAL_OSPI_STATE_READY;
1506 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
1525 HAL_StatusTypeDef HAL_OSPI_Receive_DMA(OSPI_HandleTypeDef *hospi, uint8_t *pData)
1528 uint32_t data_size = hospi->Instance->DLR + 1U;
1529 uint32_t addr_reg = hospi->Instance->AR;
1530 uint32_t ir_reg = hospi->Instance->IR;
1536 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_PARAM;
1541 if (hospi->State == HAL_OSPI_STATE_CMD_CFG)
1543 hospi->XferCount = data_size;
1546 hospi->XferSize = hospi->XferCount;
1547 hospi->pBuffPtr = pData;
1553 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TE | HAL_OSPI_FLAG_TC);
1556 hospi->State = HAL_OSPI_STATE_BUSY_RX;
1559 hospi->hmdma->XferCpltCallback = OSPI_DMACplt;
1562 hospi->hmdma->XferErrorCallback = OSPI_DMAError;
1565 hospi->hmdma->XferAbortCallback =
NULL;
1586 hospi->ErrorCode |= HAL_OSPI_ERROR_DMA;
1591 if (
HAL_MDMA_Start_IT(hospi->hmdma, (uint32_t)&hospi->Instance->DR, (uint32_t)pData, hospi->XferSize, 1) ==
HAL_OK)
1594 __HAL_OSPI_ENABLE_IT(hospi, HAL_OSPI_IT_TE);
1597 if (hospi->Init.MemoryType == HAL_OSPI_MEMTYPE_HYPERBUS)
1599 WRITE_REG(hospi->Instance->AR, addr_reg);
1605 WRITE_REG(hospi->Instance->AR, addr_reg);
1618 hospi->ErrorCode = HAL_OSPI_ERROR_DMA;
1619 hospi->State = HAL_OSPI_STATE_READY;
1626 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
1642 HAL_StatusTypeDef HAL_OSPI_AutoPolling(OSPI_HandleTypeDef *hospi, OSPI_AutoPollingTypeDef *cfg, uint32_t Timeout)
1646 uint32_t addr_reg = hospi->Instance->AR;
1647 uint32_t ir_reg = hospi->Instance->IR;
1648 #ifdef USE_FULL_ASSERT
1649 uint32_t dlr_reg = hospi->Instance->DLR;
1654 assert_param(IS_OSPI_AUTOMATIC_STOP (cfg->AutomaticStop));
1659 if ((hospi->State == HAL_OSPI_STATE_CMD_CFG) && (cfg->AutomaticStop == HAL_OSPI_AUTOMATIC_STOP_ENABLE))
1662 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_BUSY,
RESET, tickstart, Timeout);
1667 WRITE_REG (hospi->Instance->PSMAR, cfg->Match);
1668 WRITE_REG (hospi->Instance->PSMKR, cfg->Mask);
1669 WRITE_REG (hospi->Instance->PIR, cfg->Interval);
1671 (cfg->MatchMode | cfg->AutomaticStop | OSPI_FUNCTIONAL_MODE_AUTO_POLLING));
1674 if (hospi->Init.MemoryType == HAL_OSPI_MEMTYPE_HYPERBUS)
1676 WRITE_REG(hospi->Instance->AR, addr_reg);
1682 WRITE_REG(hospi->Instance->AR, addr_reg);
1691 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_SM,
SET, tickstart, Timeout);
1696 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_SM);
1699 hospi->State = HAL_OSPI_STATE_READY;
1706 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
1720 HAL_StatusTypeDef HAL_OSPI_AutoPolling_IT(OSPI_HandleTypeDef *hospi, OSPI_AutoPollingTypeDef *cfg)
1724 uint32_t addr_reg = hospi->Instance->AR;
1725 uint32_t ir_reg = hospi->Instance->IR;
1726 #ifdef USE_FULL_ASSERT
1727 uint32_t dlr_reg = hospi->Instance->DLR;
1732 assert_param(IS_OSPI_AUTOMATIC_STOP (cfg->AutomaticStop));
1737 if (hospi->State == HAL_OSPI_STATE_CMD_CFG)
1740 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_BUSY,
RESET, tickstart, hospi->Timeout);
1745 WRITE_REG (hospi->Instance->PSMAR, cfg->Match);
1746 WRITE_REG (hospi->Instance->PSMKR, cfg->Mask);
1747 WRITE_REG (hospi->Instance->PIR, cfg->Interval);
1749 (cfg->MatchMode | cfg->AutomaticStop | OSPI_FUNCTIONAL_MODE_AUTO_POLLING));
1752 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TE | HAL_OSPI_FLAG_SM);
1755 hospi->State = HAL_OSPI_STATE_BUSY_AUTO_POLLING;
1758 __HAL_OSPI_ENABLE_IT(hospi, HAL_OSPI_IT_SM | HAL_OSPI_IT_TE);
1761 if (hospi->Init.MemoryType == HAL_OSPI_MEMTYPE_HYPERBUS)
1763 WRITE_REG(hospi->Instance->AR, addr_reg);
1769 WRITE_REG(hospi->Instance->AR, addr_reg);
1781 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
1795 HAL_StatusTypeDef HAL_OSPI_MemoryMapped(OSPI_HandleTypeDef *hospi, OSPI_MemoryMappedTypeDef *cfg)
1801 assert_param(IS_OSPI_TIMEOUT_ACTIVATION(cfg->TimeOutActivation));
1804 if (hospi->State == HAL_OSPI_STATE_CMD_CFG)
1807 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_BUSY,
RESET, tickstart, hospi->Timeout);
1812 hospi->State = HAL_OSPI_STATE_BUSY_MEM_MAPPED;
1814 if (cfg->TimeOutActivation == HAL_OSPI_TIMEOUT_COUNTER_ENABLE)
1816 assert_param(IS_OSPI_TIMEOUT_PERIOD(cfg->TimeOutPeriod));
1819 WRITE_REG(hospi->Instance->LPTR, cfg->TimeOutPeriod);
1822 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TO);
1825 __HAL_OSPI_ENABLE_IT(hospi, HAL_OSPI_IT_TO);
1830 (cfg->TimeOutActivation | OSPI_FUNCTIONAL_MODE_MEMORY_MAPPED));
1836 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
1848 __weak
void HAL_OSPI_ErrorCallback(OSPI_HandleTypeDef *hospi)
1863 __weak
void HAL_OSPI_AbortCpltCallback(OSPI_HandleTypeDef *hospi)
1878 __weak
void HAL_OSPI_FifoThresholdCallback(OSPI_HandleTypeDef *hospi)
1893 __weak
void HAL_OSPI_CmdCpltCallback(OSPI_HandleTypeDef *hospi)
1908 __weak
void HAL_OSPI_RxCpltCallback(OSPI_HandleTypeDef *hospi)
1923 __weak
void HAL_OSPI_TxCpltCallback(OSPI_HandleTypeDef *hospi)
1938 __weak
void HAL_OSPI_RxHalfCpltCallback(OSPI_HandleTypeDef *hospi)
1953 __weak
void HAL_OSPI_TxHalfCpltCallback(OSPI_HandleTypeDef *hospi)
1968 __weak
void HAL_OSPI_StatusMatchCallback(OSPI_HandleTypeDef *hospi)
1983 __weak
void HAL_OSPI_TimeOutCallback(OSPI_HandleTypeDef *hospi)
1993 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
2015 HAL_StatusTypeDef HAL_OSPI_RegisterCallback(OSPI_HandleTypeDef *hospi, HAL_OSPI_CallbackIDTypeDef CallbackID,
2016 pOSPI_CallbackTypeDef pCallback)
2020 if(pCallback ==
NULL)
2023 hospi->ErrorCode |= HAL_OSPI_ERROR_INVALID_CALLBACK;
2027 if(hospi->State == HAL_OSPI_STATE_READY)
2031 case HAL_OSPI_ERROR_CB_ID :
2032 hospi->ErrorCallback = pCallback;
2034 case HAL_OSPI_ABORT_CB_ID :
2035 hospi->AbortCpltCallback = pCallback;
2037 case HAL_OSPI_FIFO_THRESHOLD_CB_ID :
2038 hospi->FifoThresholdCallback = pCallback;
2040 case HAL_OSPI_CMD_CPLT_CB_ID :
2041 hospi->CmdCpltCallback = pCallback;
2043 case HAL_OSPI_RX_CPLT_CB_ID :
2044 hospi->RxCpltCallback = pCallback;
2046 case HAL_OSPI_TX_CPLT_CB_ID :
2047 hospi->TxCpltCallback = pCallback;
2049 case HAL_OSPI_RX_HALF_CPLT_CB_ID :
2050 hospi->RxHalfCpltCallback = pCallback;
2052 case HAL_OSPI_TX_HALF_CPLT_CB_ID :
2053 hospi->TxHalfCpltCallback = pCallback;
2055 case HAL_OSPI_STATUS_MATCH_CB_ID :
2056 hospi->StatusMatchCallback = pCallback;
2058 case HAL_OSPI_TIMEOUT_CB_ID :
2059 hospi->TimeOutCallback = pCallback;
2061 case HAL_OSPI_MSP_INIT_CB_ID :
2062 hospi->MspInitCallback = pCallback;
2064 case HAL_OSPI_MSP_DEINIT_CB_ID :
2065 hospi->MspDeInitCallback = pCallback;
2069 hospi->ErrorCode |= HAL_OSPI_ERROR_INVALID_CALLBACK;
2075 else if (hospi->State == HAL_OSPI_STATE_RESET)
2079 case HAL_OSPI_MSP_INIT_CB_ID :
2080 hospi->MspInitCallback = pCallback;
2082 case HAL_OSPI_MSP_DEINIT_CB_ID :
2083 hospi->MspDeInitCallback = pCallback;
2087 hospi->ErrorCode |= HAL_OSPI_ERROR_INVALID_CALLBACK;
2096 hospi->ErrorCode |= HAL_OSPI_ERROR_INVALID_CALLBACK;
2124 HAL_StatusTypeDef HAL_OSPI_UnRegisterCallback (OSPI_HandleTypeDef *hospi, HAL_OSPI_CallbackIDTypeDef CallbackID)
2128 if(hospi->State == HAL_OSPI_STATE_READY)
2132 case HAL_OSPI_ERROR_CB_ID :
2133 hospi->ErrorCallback = HAL_OSPI_ErrorCallback;
2135 case HAL_OSPI_ABORT_CB_ID :
2136 hospi->AbortCpltCallback = HAL_OSPI_AbortCpltCallback;
2138 case HAL_OSPI_FIFO_THRESHOLD_CB_ID :
2139 hospi->FifoThresholdCallback = HAL_OSPI_FifoThresholdCallback;
2141 case HAL_OSPI_CMD_CPLT_CB_ID :
2142 hospi->CmdCpltCallback = HAL_OSPI_CmdCpltCallback;
2144 case HAL_OSPI_RX_CPLT_CB_ID :
2145 hospi->RxCpltCallback = HAL_OSPI_RxCpltCallback;
2147 case HAL_OSPI_TX_CPLT_CB_ID :
2148 hospi->TxCpltCallback = HAL_OSPI_TxCpltCallback;
2150 case HAL_OSPI_RX_HALF_CPLT_CB_ID :
2151 hospi->RxHalfCpltCallback = HAL_OSPI_RxHalfCpltCallback;
2153 case HAL_OSPI_TX_HALF_CPLT_CB_ID :
2154 hospi->TxHalfCpltCallback = HAL_OSPI_TxHalfCpltCallback;
2156 case HAL_OSPI_STATUS_MATCH_CB_ID :
2157 hospi->StatusMatchCallback = HAL_OSPI_StatusMatchCallback;
2159 case HAL_OSPI_TIMEOUT_CB_ID :
2160 hospi->TimeOutCallback = HAL_OSPI_TimeOutCallback;
2162 case HAL_OSPI_MSP_INIT_CB_ID :
2163 hospi->MspInitCallback = HAL_OSPI_MspInit;
2165 case HAL_OSPI_MSP_DEINIT_CB_ID :
2166 hospi->MspDeInitCallback = HAL_OSPI_MspDeInit;
2170 hospi->ErrorCode |= HAL_OSPI_ERROR_INVALID_CALLBACK;
2176 else if (hospi->State == HAL_OSPI_STATE_RESET)
2180 case HAL_OSPI_MSP_INIT_CB_ID :
2181 hospi->MspInitCallback = HAL_OSPI_MspInit;
2183 case HAL_OSPI_MSP_DEINIT_CB_ID :
2184 hospi->MspDeInitCallback = HAL_OSPI_MspDeInit;
2188 hospi->ErrorCode |= HAL_OSPI_ERROR_INVALID_CALLBACK;
2197 hospi->ErrorCode |= HAL_OSPI_ERROR_INVALID_CALLBACK;
2241 state = hospi->State;
2242 if (((state & OSPI_BUSY_STATE_MASK) != 0U) || ((state & OSPI_CFG_STATE_MASK) != 0U))
2254 hospi->ErrorCode = HAL_OSPI_ERROR_DMA;
2258 if (__HAL_OSPI_GET_FLAG(hospi, HAL_OSPI_FLAG_BUSY) !=
RESET)
2264 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_TC,
SET, tickstart, hospi->Timeout);
2269 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TC);
2272 status = OSPI_WaitFlagStateUntilTimeout(hospi, HAL_OSPI_FLAG_BUSY,
RESET, tickstart, hospi->Timeout);
2277 hospi->State = HAL_OSPI_STATE_READY;
2284 hospi->State = HAL_OSPI_STATE_READY;
2290 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
2308 state = hospi->State;
2309 if (((state & OSPI_BUSY_STATE_MASK) != 0U) || ((state & OSPI_CFG_STATE_MASK) != 0U))
2312 __HAL_OSPI_DISABLE_IT(hospi, (HAL_OSPI_IT_TO | HAL_OSPI_IT_SM | HAL_OSPI_IT_FT | HAL_OSPI_IT_TC | HAL_OSPI_IT_TE));
2315 hospi->State = HAL_OSPI_STATE_ABORT;
2324 hospi->hmdma->XferAbortCallback = OSPI_DMAAbortCplt;
2328 hospi->State = HAL_OSPI_STATE_READY;
2331 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
2332 hospi->AbortCpltCallback(hospi);
2334 HAL_OSPI_AbortCpltCallback(hospi);
2340 if (__HAL_OSPI_GET_FLAG(hospi, HAL_OSPI_FLAG_BUSY) !=
RESET)
2343 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TC);
2346 __HAL_OSPI_ENABLE_IT(hospi, HAL_OSPI_IT_TC);
2354 hospi->State = HAL_OSPI_STATE_READY;
2357 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
2358 hospi->AbortCpltCallback(hospi);
2360 HAL_OSPI_AbortCpltCallback(hospi);
2368 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
2380 HAL_StatusTypeDef HAL_OSPI_SetFifoThreshold(OSPI_HandleTypeDef *hospi, uint32_t Threshold)
2385 if ((hospi->State & OSPI_BUSY_STATE_MASK) == 0U)
2388 hospi->Init.FifoThreshold = Threshold;
2397 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_SEQUENCE;
2408 uint32_t HAL_OSPI_GetFifoThreshold(OSPI_HandleTypeDef *hospi)
2418 HAL_StatusTypeDef HAL_OSPI_SetTimeout(OSPI_HandleTypeDef *hospi, uint32_t Timeout)
2420 hospi->Timeout = Timeout;
2429 uint32_t HAL_OSPI_GetError(OSPI_HandleTypeDef *hospi)
2431 return hospi->ErrorCode;
2439 uint32_t HAL_OSPI_GetState(OSPI_HandleTypeDef *hospi)
2442 return hospi->State;
2471 HAL_StatusTypeDef HAL_OSPIM_Config(OSPI_HandleTypeDef *hospi, OSPIM_CfgTypeDef *cfg, uint32_t Timeout)
2476 uint8_t ospi_enabled = 0U;
2477 uint8_t other_instance;
2478 OSPIM_CfgTypeDef IOM_cfg[OSPI_NB_INSTANCE];
2494 other_instance = 1U;
2499 other_instance = 0U;
2503 for (index = 0U; index < OSPI_NB_INSTANCE; index++)
2505 if (OSPIM_GetConfig(index+1U, &(IOM_cfg[index])) !=
HAL_OK)
2508 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_PARAM;
2518 ospi_enabled |= 0x1U;
2523 ospi_enabled |= 0x2U;
2533 if (other_instance == 1U)
2536 if (IOM_cfg[other_instance].DQSPort != 0U)
2540 if (IOM_cfg[other_instance].IOLowPort != HAL_OSPIM_IOPORT_NONE)
2544 if (IOM_cfg[other_instance].IOHighPort != HAL_OSPIM_IOPORT_NONE)
2552 if (IOM_cfg[instance].ClkPort != 0U)
2555 if (IOM_cfg[instance].DQSPort != 0U)
2559 if (IOM_cfg[instance].IOLowPort != HAL_OSPIM_IOPORT_NONE)
2563 if (IOM_cfg[instance].IOHighPort != HAL_OSPIM_IOPORT_NONE)
2571 if ((cfg->ClkPort == IOM_cfg[other_instance].ClkPort) || (cfg->DQSPort == IOM_cfg[other_instance].DQSPort) ||
2572 (cfg->NCSPort == IOM_cfg[other_instance].NCSPort) || (cfg->IOLowPort == IOM_cfg[other_instance].IOLowPort) ||
2573 (cfg->IOHighPort == IOM_cfg[other_instance].IOHighPort))
2575 if ((cfg->ClkPort == IOM_cfg[other_instance].ClkPort) &&
2576 (cfg->DQSPort == IOM_cfg[other_instance].DQSPort) &&
2577 (cfg->IOLowPort == IOM_cfg[other_instance].IOLowPort) &&
2578 (cfg->IOHighPort == IOM_cfg[other_instance].IOHighPort))
2586 if (IOM_cfg[other_instance].DQSPort != 0U)
2591 if (IOM_cfg[other_instance].IOLowPort != HAL_OSPIM_IOPORT_NONE)
2593 CLEAR_BIT(
OCTOSPIM->PCR[((IOM_cfg[other_instance].IOLowPort-1U)& OSPI_IOM_PORT_MASK)],
2596 if (IOM_cfg[other_instance].IOHighPort != HAL_OSPIM_IOPORT_NONE)
2598 CLEAR_BIT(
OCTOSPIM->PCR[((IOM_cfg[other_instance].IOHighPort-1U)& OSPI_IOM_PORT_MASK)],
2616 if (cfg->DQSPort != 0U)
2626 else if (cfg->IOLowPort != HAL_OSPIM_IOPORT_NONE)
2641 else if (cfg->IOHighPort != HAL_OSPIM_IOPORT_NONE)
2655 if (cfg->DQSPort != 0U)
2667 else if (cfg->IOLowPort != HAL_OSPIM_IOPORT_NONE)
2684 else if (cfg->IOHighPort != HAL_OSPIM_IOPORT_NONE)
2697 if ((ospi_enabled & 0x1U) != 0U)
2701 if ((ospi_enabled & 0x2U) != 0U)
2725 OSPI_HandleTypeDef* hospi = ( OSPI_HandleTypeDef* )(hmdma->
Parent);
2726 hospi->XferCount = 0;
2735 __HAL_OSPI_ENABLE_IT(hospi, HAL_OSPI_IT_TC);
2745 OSPI_HandleTypeDef* hospi = ( OSPI_HandleTypeDef* )(hmdma->
Parent);
2746 hospi->XferCount = 0;
2747 hospi->ErrorCode = HAL_OSPI_ERROR_DMA;
2753 if (HAL_OSPI_Abort_IT(hospi) !=
HAL_OK)
2756 __HAL_OSPI_DISABLE_IT(hospi, HAL_OSPI_IT_TC | HAL_OSPI_IT_FT | HAL_OSPI_IT_TE);
2759 hospi->State = HAL_OSPI_STATE_READY;
2762 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
2763 hospi->ErrorCallback(hospi);
2765 HAL_OSPI_ErrorCallback(hospi);
2777 OSPI_HandleTypeDef* hospi = ( OSPI_HandleTypeDef* )(hmdma->
Parent);
2778 hospi->XferCount = 0;
2781 if (hospi->State == HAL_OSPI_STATE_ABORT)
2784 if (__HAL_OSPI_GET_FLAG(hospi, HAL_OSPI_FLAG_BUSY) !=
RESET)
2787 __HAL_OSPI_CLEAR_FLAG(hospi, HAL_OSPI_FLAG_TC);
2790 __HAL_OSPI_ENABLE_IT(hospi, HAL_OSPI_IT_TC);
2798 hospi->State = HAL_OSPI_STATE_READY;
2801 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
2802 hospi->AbortCpltCallback(hospi);
2804 HAL_OSPI_AbortCpltCallback(hospi);
2812 hospi->State = HAL_OSPI_STATE_READY;
2815 #if defined (USE_HAL_OSPI_REGISTER_CALLBACKS) && (USE_HAL_OSPI_REGISTER_CALLBACKS == 1U)
2816 hospi->ErrorCallback(hospi);
2818 HAL_OSPI_ErrorCallback(hospi);
2832 static HAL_StatusTypeDef OSPI_WaitFlagStateUntilTimeout(OSPI_HandleTypeDef *hospi, uint32_t Flag,
2833 FlagStatus State, uint32_t Tickstart, uint32_t Timeout)
2836 while((__HAL_OSPI_GET_FLAG(hospi, Flag)) != State)
2841 if(((
HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
2843 hospi->State = HAL_OSPI_STATE_ERROR;
2844 hospi->ErrorCode |= HAL_OSPI_ERROR_TIMEOUT;
2859 static HAL_StatusTypeDef OSPI_ConfigCmd(OSPI_HandleTypeDef *hospi, OSPI_RegularCmdTypeDef *cmd)
2862 __IO uint32_t *ccr_reg;
2863 __IO uint32_t *tcr_reg;
2864 __IO uint32_t *ir_reg;
2865 __IO uint32_t *abr_reg;
2871 if (hospi->Init.DualQuad == HAL_OSPI_DUALQUAD_DISABLE)
2876 if (
cmd->OperationType == HAL_OSPI_OPTYPE_WRITE_CFG)
2878 ccr_reg = &(hospi->Instance->WCCR);
2879 tcr_reg = &(hospi->Instance->WTCR);
2880 ir_reg = &(hospi->Instance->WIR);
2881 abr_reg = &(hospi->Instance->WABR);
2883 else if (
cmd->OperationType == HAL_OSPI_OPTYPE_WRAP_CFG)
2885 ccr_reg = &(hospi->Instance->WPCCR);
2886 tcr_reg = &(hospi->Instance->WPTCR);
2887 ir_reg = &(hospi->Instance->WPIR);
2888 abr_reg = &(hospi->Instance->WPABR);
2892 ccr_reg = &(hospi->Instance->CCR);
2893 tcr_reg = &(hospi->Instance->TCR);
2894 ir_reg = &(hospi->Instance->IR);
2895 abr_reg = &(hospi->Instance->ABR);
2899 *ccr_reg = (
cmd->DQSMode |
cmd->SIOOMode);
2901 if (
cmd->AlternateBytesMode != HAL_OSPI_ALTERNATE_BYTES_NONE)
2904 *abr_reg =
cmd->AlternateBytes;
2908 (
cmd->AlternateBytesMode |
cmd->AlternateBytesDtrMode |
cmd->AlternateBytesSize));
2914 if (
cmd->DataMode != HAL_OSPI_DATA_NONE)
2916 if (
cmd->OperationType == HAL_OSPI_OPTYPE_COMMON_CFG)
2919 hospi->Instance->DLR = (
cmd->NbData - 1U);
2923 if (
cmd->InstructionMode != HAL_OSPI_INSTRUCTION_NONE)
2925 if (
cmd->AddressMode != HAL_OSPI_ADDRESS_NONE)
2927 if (
cmd->DataMode != HAL_OSPI_DATA_NONE)
2935 (
cmd->InstructionMode |
cmd->InstructionDtrMode |
cmd->InstructionSize |
2936 cmd->AddressMode |
cmd->AddressDtrMode |
cmd->AddressSize |
2937 cmd->DataMode |
cmd->DataDtrMode));
2946 (
cmd->InstructionMode |
cmd->InstructionDtrMode |
cmd->InstructionSize |
2947 cmd->AddressMode |
cmd->AddressDtrMode |
cmd->AddressSize));
2950 if ((hospi->Init.DelayHoldQuarterCycle == HAL_OSPI_DHQC_ENABLE) &&
2951 (
cmd->InstructionDtrMode == HAL_OSPI_INSTRUCTION_DTR_ENABLE))
2958 *ir_reg =
cmd->Instruction;
2961 hospi->Instance->AR =
cmd->Address;
2965 if (
cmd->DataMode != HAL_OSPI_DATA_NONE)
2972 (
cmd->InstructionMode |
cmd->InstructionDtrMode |
cmd->InstructionSize |
2973 cmd->DataMode |
cmd->DataDtrMode));
2981 (
cmd->InstructionMode |
cmd->InstructionDtrMode |
cmd->InstructionSize));
2984 if ((hospi->Init.DelayHoldQuarterCycle == HAL_OSPI_DHQC_ENABLE) &&
2985 (
cmd->InstructionDtrMode == HAL_OSPI_INSTRUCTION_DTR_ENABLE))
2992 *ir_reg =
cmd->Instruction;
2998 if (
cmd->AddressMode != HAL_OSPI_ADDRESS_NONE)
3000 if (
cmd->DataMode != HAL_OSPI_DATA_NONE)
3007 (
cmd->AddressMode |
cmd->AddressDtrMode |
cmd->AddressSize |
3008 cmd->DataMode |
cmd->DataDtrMode));
3016 (
cmd->AddressMode |
cmd->AddressDtrMode |
cmd->AddressSize));
3020 hospi->Instance->AR =
cmd->Address;
3026 hospi->ErrorCode = HAL_OSPI_ERROR_INVALID_PARAM;
3040 static HAL_StatusTypeDef OSPIM_GetConfig(uint8_t instance_nb, OSPIM_CfgTypeDef *cfg)
3044 uint32_t value = 0U;
3047 if ((instance_nb == 0U) || (instance_nb > OSPI_NB_INSTANCE) || (cfg ==
NULL))
3058 cfg->IOLowPort = 0U;
3059 cfg->IOHighPort = 0U;
3061 if (instance_nb == 2U)
3075 for (index = 0U; index < OSPI_IOM_NB_PORTS; index ++)
3085 cfg->ClkPort = index+1U;
3095 cfg->DQSPort = index+1U;
3105 cfg->NCSPort = index+1U;