File indexing completed on 2025-05-11 08:23:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 #include "stm32h747i_eval_qspi.h"
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 QSPI_HandleTypeDef hqspi;
0120 BSP_QSPI_Ctx_t QSPI_Ctx[QSPI_INSTANCES_NUMBER];
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130 static void QSPI_MspInit(QSPI_HandleTypeDef *hQspi);
0131 static void QSPI_MspDeInit(QSPI_HandleTypeDef *hSspi);
0132 static int32_t QSPI_ResetMemory(uint32_t Instance);
0133 static int32_t QSPI_DummyCyclesCfg(uint32_t Instance);
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 int32_t BSP_QSPI_Init(uint32_t Instance, BSP_QSPI_Init_t *Init)
0150 {
0151 int32_t ret = BSP_ERROR_NONE;
0152 BSP_QSPI_Info_t pInfo;
0153 MX_QSPI_Init_t qspi_init;
0154
0155
0156
0157
0158 static const uint32_t PrescalerTab[2] = {1, 3};
0159
0160
0161 if(Instance >= QSPI_INSTANCES_NUMBER)
0162 {
0163 ret = BSP_ERROR_WRONG_PARAM;
0164 }
0165 else
0166 {
0167
0168 if(QSPI_Ctx[Instance].IsInitialized == QSPI_ACCESS_NONE)
0169 {
0170 #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
0171
0172 if(QSPI_Ctx[Instance].IsMspCallbacksValid == 0UL)
0173 {
0174 if(BSP_QSPI_RegisterDefaultMspCallbacks(Instance) != BSP_ERROR_NONE)
0175 {
0176 ret = BSP_ERROR_PERIPH_FAILURE;
0177 }
0178 }
0179 #else
0180
0181 QSPI_MspInit(&hqspi);
0182 #endif
0183
0184 if(ret == BSP_ERROR_NONE)
0185 {
0186
0187 (void)MT25TL01G_GetFlashInfo(&pInfo);
0188 qspi_init.ClockPrescaler = PrescalerTab[Init->TransferRate];
0189 qspi_init.DualFlashMode = QSPI_DUALFLASH_ENABLE;
0190 qspi_init.FlashSize = (uint32_t)POSITION_VAL((uint32_t)pInfo.FlashSize) - 1U;
0191 qspi_init.SampleShifting = (Init->TransferRate == BSP_QSPI_STR_TRANSFER) ? QSPI_SAMPLE_SHIFTING_HALFCYCLE : QSPI_SAMPLE_SHIFTING_NONE;
0192
0193 if(MX_QSPI_Init(&hqspi, &qspi_init) != HAL_OK)
0194 {
0195 ret = BSP_ERROR_PERIPH_FAILURE;
0196 }
0197 else if(QSPI_ResetMemory(Instance) != BSP_ERROR_NONE)
0198 {
0199 ret = BSP_ERROR_COMPONENT_FAILURE;
0200 }
0201 else if(MT25TL01G_AutoPollingMemReady(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0202 {
0203 ret = BSP_ERROR_COMPONENT_FAILURE;
0204 }
0205 else if(MT25TL01G_Enter4BytesAddressMode(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0206 {
0207 ret = BSP_ERROR_COMPONENT_FAILURE;
0208 }
0209 else if(QSPI_DummyCyclesCfg(Instance) != BSP_ERROR_NONE)
0210 {
0211 ret = BSP_ERROR_COMPONENT_FAILURE;
0212 }
0213 else
0214 {
0215
0216 if(BSP_QSPI_ConfigFlash(Instance, Init->InterfaceMode, Init->TransferRate) != BSP_ERROR_NONE)
0217 {
0218 ret = BSP_ERROR_COMPONENT_FAILURE;
0219 }
0220 }
0221 }
0222 }
0223 }
0224
0225
0226 return ret;
0227 }
0228
0229
0230
0231
0232
0233
0234 int32_t BSP_QSPI_DeInit(uint32_t Instance)
0235 {
0236 int32_t ret = BSP_ERROR_NONE;
0237
0238
0239 if(Instance >= QSPI_INSTANCES_NUMBER)
0240 {
0241 ret = BSP_ERROR_WRONG_PARAM;
0242 }
0243 else
0244 {
0245 if(QSPI_Ctx[Instance].IsInitialized == QSPI_ACCESS_MMP)
0246 {
0247 if(BSP_QSPI_DisableMemoryMappedMode(Instance) != BSP_ERROR_NONE)
0248 {
0249 ret = BSP_ERROR_COMPONENT_FAILURE;
0250 }
0251 }
0252
0253 if(ret == BSP_ERROR_NONE)
0254 {
0255
0256 QSPI_Ctx[Instance].IsInitialized = QSPI_ACCESS_NONE;
0257 QSPI_Ctx[Instance].InterfaceMode = BSP_QSPI_SPI_MODE;
0258 QSPI_Ctx[Instance].TransferRate = BSP_QSPI_STR_TRANSFER;
0259 QSPI_Ctx[Instance].DualFlashMode = QSPI_DUALFLASH_ENABLE;
0260
0261 #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 0)
0262 QSPI_MspDeInit(&hqspi);
0263 #endif
0264
0265
0266 if (HAL_QSPI_DeInit(&hqspi) != HAL_OK)
0267 {
0268 ret = BSP_ERROR_PERIPH_FAILURE;
0269 }
0270 }
0271 }
0272
0273
0274 return ret;
0275 }
0276
0277
0278
0279
0280
0281
0282
0283 __weak HAL_StatusTypeDef MX_QSPI_Init(QSPI_HandleTypeDef *hQspi, MX_QSPI_Init_t *Config)
0284 {
0285
0286
0287 hQspi->Instance = QUADSPI;
0288 hQspi->Init.ClockPrescaler = Config->ClockPrescaler;
0289 hQspi->Init.FifoThreshold = 1;
0290 hQspi->Init.SampleShifting = Config->SampleShifting;
0291 hQspi->Init.FlashSize = Config->FlashSize;
0292 hQspi->Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_4_CYCLE;
0293 hQspi->Init.ClockMode = QSPI_CLOCK_MODE_0;
0294 hQspi->Init.FlashID = QSPI_FLASH_ID_1;
0295 hQspi->Init.DualFlash = Config->DualFlashMode;
0296
0297 return HAL_QSPI_Init(hQspi);
0298 }
0299
0300 #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
0301
0302
0303
0304
0305
0306 int32_t BSP_QSPI_RegisterDefaultMspCallbacks (uint32_t Instance)
0307 {
0308 int32_t ret = BSP_ERROR_NONE;
0309
0310
0311 if(Instance >= QSPI_INSTANCES_NUMBER)
0312 {
0313 ret = BSP_ERROR_WRONG_PARAM;
0314 }
0315 else
0316 {
0317
0318 if(HAL_QSPI_RegisterCallback(&hqspi, HAL_QSPI_MSPINIT_CB_ID, QSPI_MspInit) != HAL_OK)
0319 {
0320 ret = BSP_ERROR_PERIPH_FAILURE;
0321 }
0322 else if(HAL_QSPI_RegisterCallback(&hqspi, HAL_QSPI_MSPDEINIT_CB_ID, QSPI_MspDeInit) != HAL_OK)
0323 {
0324 ret = BSP_ERROR_PERIPH_FAILURE;
0325 }
0326 else
0327 {
0328 QSPI_Ctx[Instance].IsMspCallbacksValid = 1U;
0329 }
0330 }
0331
0332
0333 return ret;
0334 }
0335
0336
0337
0338
0339
0340
0341
0342 int32_t BSP_QSPI_RegisterMspCallbacks (uint32_t Instance, BSP_QSPI_Cb_t *CallBacks)
0343 {
0344 int32_t ret = BSP_ERROR_NONE;
0345
0346
0347 if(Instance >= QSPI_INSTANCES_NUMBER)
0348 {
0349 ret = BSP_ERROR_WRONG_PARAM;
0350 }
0351 else
0352 {
0353
0354 if(HAL_QSPI_RegisterCallback(&hqspi, HAL_QSPI_MSPINIT_CB_ID, CallBacks->pMspInitCb) != HAL_OK)
0355 {
0356 ret = BSP_ERROR_PERIPH_FAILURE;
0357 }
0358 else if(HAL_QSPI_RegisterCallback(&hqspi, HAL_QSPI_MSPDEINIT_CB_ID, CallBacks->pMspDeInitCb) != HAL_OK)
0359 {
0360 ret = BSP_ERROR_PERIPH_FAILURE;
0361 }
0362 else
0363 {
0364 QSPI_Ctx[Instance].IsMspCallbacksValid = 1U;
0365 }
0366 }
0367
0368
0369 return ret;
0370 }
0371 #endif
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381 int32_t BSP_QSPI_Read(uint32_t Instance, uint8_t *pData, uint32_t ReadAddr, uint32_t Size)
0382 {
0383 int32_t ret = BSP_ERROR_NONE;
0384
0385
0386 if(Instance >= QSPI_INSTANCES_NUMBER)
0387 {
0388 ret = BSP_ERROR_WRONG_PARAM;
0389 }
0390 else
0391 {
0392 if(QSPI_Ctx[Instance].TransferRate == BSP_QSPI_STR_TRANSFER)
0393 {
0394 if(MT25TL01G_ReadSTR(&hqspi, QSPI_Ctx[Instance].InterfaceMode, pData, ReadAddr, Size) != MT25TL01G_OK)
0395 {
0396 ret = BSP_ERROR_COMPONENT_FAILURE;
0397 }
0398 }
0399 else
0400 {
0401 if(MT25TL01G_ReadDTR(&hqspi, QSPI_Ctx[Instance].InterfaceMode, pData, ReadAddr, Size) != MT25TL01G_OK)
0402 {
0403 ret = BSP_ERROR_COMPONENT_FAILURE;
0404 }
0405 }
0406 }
0407
0408
0409 return ret;
0410 }
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420 int32_t BSP_QSPI_Write(uint32_t Instance, uint8_t *pData, uint32_t WriteAddr, uint32_t Size)
0421 {
0422 int32_t ret = BSP_ERROR_NONE;
0423 uint32_t end_addr, current_size, current_addr;
0424 uint8_t *write_data;
0425
0426
0427 if(Instance >= QSPI_INSTANCES_NUMBER)
0428 {
0429 ret = BSP_ERROR_WRONG_PARAM;
0430 }
0431 else
0432 {
0433
0434 current_size = MT25TL01G_PAGE_SIZE - (WriteAddr % MT25TL01G_PAGE_SIZE);
0435
0436
0437 if (current_size > Size)
0438 {
0439 current_size = Size;
0440 }
0441
0442
0443 current_addr = WriteAddr;
0444 end_addr = WriteAddr + Size;
0445 write_data = pData;
0446
0447
0448 do
0449 {
0450
0451 if(MT25TL01G_AutoPollingMemReady(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0452 {
0453 ret = BSP_ERROR_COMPONENT_FAILURE;
0454 }
0455 else if(MT25TL01G_WriteEnable(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0456 {
0457 ret = BSP_ERROR_COMPONENT_FAILURE;
0458 }
0459 else if(MT25TL01G_PageProgram(&hqspi, QSPI_Ctx[Instance].InterfaceMode, write_data, current_addr, current_size) != MT25TL01G_OK)
0460 {
0461 ret = BSP_ERROR_COMPONENT_FAILURE;
0462 }
0463 else if (MT25TL01G_AutoPollingMemReady(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0464 {
0465 ret = BSP_ERROR_COMPONENT_FAILURE;
0466 }
0467 else
0468 {
0469
0470 current_addr += current_size;
0471 write_data += current_size;
0472 current_size = ((current_addr + MT25TL01G_PAGE_SIZE) > end_addr) ? (end_addr - current_addr) : MT25TL01G_PAGE_SIZE;
0473 }
0474 } while ((current_addr < end_addr) && (ret == BSP_ERROR_NONE));
0475 }
0476
0477
0478 return ret;
0479 }
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490 int32_t BSP_QSPI_EraseBlock(uint32_t Instance, uint32_t BlockAddress, BSP_QSPI_Erase_t BlockSize)
0491 {
0492 int32_t ret = BSP_ERROR_NONE;
0493
0494
0495 if(Instance >= QSPI_INSTANCES_NUMBER)
0496 {
0497 ret = BSP_ERROR_WRONG_PARAM;
0498 }
0499 else
0500 {
0501
0502 if(MT25TL01G_AutoPollingMemReady(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0503 {
0504 ret = BSP_ERROR_COMPONENT_FAILURE;
0505 }
0506 else if(MT25TL01G_WriteEnable(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0507 {
0508 ret = BSP_ERROR_COMPONENT_FAILURE;
0509 }
0510 else
0511 {
0512
0513 if(MT25TL01G_BlockErase(&hqspi, QSPI_Ctx[Instance].InterfaceMode, BlockAddress, (MT25TL01G_Erase_t)BlockSize) != MT25TL01G_OK)
0514 {
0515 ret = BSP_ERROR_COMPONENT_FAILURE;
0516 }
0517 }
0518 }
0519
0520
0521 return ret;
0522 }
0523
0524
0525
0526
0527
0528
0529 int32_t BSP_QSPI_EraseChip(uint32_t Instance)
0530 {
0531 int32_t ret = BSP_ERROR_NONE;
0532
0533
0534 if(Instance >= QSPI_INSTANCES_NUMBER)
0535 {
0536 ret = BSP_ERROR_WRONG_PARAM;
0537 }
0538 else
0539 {
0540
0541 if(MT25TL01G_AutoPollingMemReady(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0542 {
0543 ret = BSP_ERROR_COMPONENT_FAILURE;
0544 }
0545 else if (MT25TL01G_WriteEnable(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0546 {
0547 ret = BSP_ERROR_COMPONENT_FAILURE;
0548 }
0549 else
0550 {
0551
0552 if(MT25TL01G_ChipErase(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0553 {
0554 ret = BSP_ERROR_COMPONENT_FAILURE;
0555 }
0556 }
0557 }
0558
0559
0560 return ret;
0561 }
0562
0563
0564
0565
0566
0567
0568
0569 int32_t BSP_QSPI_GetStatus(uint32_t Instance)
0570 {
0571 int32_t ret = BSP_ERROR_NONE;
0572 uint8_t reg;
0573
0574
0575 if(Instance >= QSPI_INSTANCES_NUMBER)
0576 {
0577 ret = BSP_ERROR_WRONG_PARAM;
0578 }
0579 else
0580 {
0581 if(MT25TL01G_ReadStatusRegister(&hqspi, QSPI_Ctx[Instance].InterfaceMode, ®) != MT25TL01G_OK)
0582 {
0583 ret = BSP_ERROR_COMPONENT_FAILURE;
0584 }
0585 else
0586 {
0587
0588 if ((reg & MT25TL01G_SR_WIP) != 0U)
0589 {
0590 ret = BSP_ERROR_BUSY;
0591 }
0592 }
0593 }
0594
0595
0596 return ret;
0597 }
0598
0599
0600
0601
0602
0603
0604
0605 int32_t BSP_QSPI_GetInfo(uint32_t Instance, BSP_QSPI_Info_t *pInfo)
0606 {
0607 int32_t ret = BSP_ERROR_NONE;
0608
0609
0610 if(Instance >= QSPI_INSTANCES_NUMBER)
0611 {
0612 ret = BSP_ERROR_WRONG_PARAM;
0613 }
0614 else
0615 {
0616 (void)MT25TL01G_GetFlashInfo(pInfo);
0617 }
0618
0619
0620 return ret;
0621 }
0622
0623
0624
0625
0626
0627
0628
0629 int32_t BSP_QSPI_EnableMemoryMappedMode(uint32_t Instance)
0630 {
0631 int32_t ret = BSP_ERROR_NONE;
0632
0633
0634 if(Instance >= QSPI_INSTANCES_NUMBER)
0635 {
0636 ret = BSP_ERROR_WRONG_PARAM;
0637 }
0638 else
0639 {
0640 if(QSPI_Ctx[Instance].TransferRate == BSP_QSPI_STR_TRANSFER)
0641 {
0642 if(MT25TL01G_EnableMemoryMappedModeSTR(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0643 {
0644 ret = BSP_ERROR_COMPONENT_FAILURE;
0645 }
0646 else
0647 {
0648 QSPI_Ctx[Instance].IsInitialized = QSPI_ACCESS_MMP;
0649 }
0650 }
0651 else
0652 {
0653 if(MT25TL01G_EnableMemoryMappedModeDTR(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0654 {
0655 ret = BSP_ERROR_COMPONENT_FAILURE;
0656 }
0657 else
0658 {
0659 QSPI_Ctx[Instance].IsInitialized = QSPI_ACCESS_MMP;
0660 }
0661 }
0662 }
0663
0664
0665 return ret;
0666 }
0667
0668
0669
0670
0671
0672
0673
0674 int32_t BSP_QSPI_DisableMemoryMappedMode(uint32_t Instance)
0675 {
0676 uint8_t Dummy;
0677 int32_t ret = BSP_ERROR_NONE;
0678
0679
0680 if(Instance >= QSPI_INSTANCES_NUMBER)
0681 {
0682 ret = BSP_ERROR_WRONG_PARAM;
0683 }
0684 else
0685 {
0686 if(QSPI_Ctx[Instance].IsInitialized != QSPI_ACCESS_MMP)
0687 {
0688 ret = BSP_ERROR_QSPI_MMP_UNLOCK_FAILURE;
0689 }
0690 else if(HAL_QSPI_Abort(&hqspi) != HAL_OK)
0691 {
0692 ret = BSP_ERROR_PERIPH_FAILURE;
0693 }
0694 else
0695 {
0696
0697 hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
0698
0699 if(HAL_QSPI_Init(&hqspi)!= HAL_OK)
0700 {
0701 ret = BSP_ERROR_PERIPH_FAILURE;
0702 }
0703
0704 else if(MT25TL01G_ReadSTR(&hqspi, QSPI_Ctx[Instance].InterfaceMode, &Dummy, 0, 1) != MT25TL01G_OK)
0705 {
0706 ret = BSP_ERROR_COMPONENT_FAILURE;
0707 }
0708 else
0709 {
0710 QSPI_Ctx[Instance].IsInitialized = QSPI_ACCESS_INDIRECT;
0711 }
0712 }
0713 }
0714
0715 return ret;
0716 }
0717
0718
0719
0720
0721
0722
0723
0724
0725 int32_t BSP_QSPI_ReadID(uint32_t Instance, uint8_t *Id)
0726 {
0727 int32_t ret = BSP_ERROR_NONE;
0728
0729
0730 if(Instance >= QSPI_INSTANCES_NUMBER)
0731 {
0732 ret = BSP_ERROR_WRONG_PARAM;
0733 }
0734 else
0735 {
0736 if(MT25TL01G_ReadID(&hqspi, QSPI_Ctx[Instance].InterfaceMode, Id) != MT25TL01G_OK)
0737 {
0738 ret = BSP_ERROR_COMPONENT_FAILURE;
0739 }
0740 }
0741
0742
0743 return ret;
0744 }
0745
0746
0747
0748
0749
0750
0751
0752
0753
0754
0755 int32_t BSP_QSPI_ConfigFlash(uint32_t Instance, BSP_QSPI_Interface_t Mode, BSP_QSPI_Transfer_t Rate)
0756 {
0757 int32_t ret = BSP_ERROR_NONE;
0758
0759
0760 if(Instance >= QSPI_INSTANCES_NUMBER)
0761 {
0762 ret = BSP_ERROR_WRONG_PARAM;
0763 }
0764 else
0765 {
0766
0767 if(QSPI_Ctx[Instance].IsInitialized == QSPI_ACCESS_MMP)
0768 {
0769 ret = BSP_ERROR_QSPI_MMP_LOCK_FAILURE;
0770 }
0771 else
0772 {
0773
0774 hqspi.Init.SampleShifting = (Rate == BSP_QSPI_STR_TRANSFER) ? QSPI_SAMPLE_SHIFTING_HALFCYCLE : QSPI_SAMPLE_SHIFTING_NONE;
0775
0776 if(HAL_QSPI_Init(&hqspi)!= HAL_OK)
0777 {
0778 ret = BSP_ERROR_PERIPH_FAILURE;
0779 }
0780 else
0781 {
0782
0783 switch(QSPI_Ctx[Instance].InterfaceMode)
0784 {
0785 case MT25TL01G_QPI_MODE :
0786 if(Mode != MT25TL01G_QPI_MODE)
0787 {
0788 if(MT25TL01G_ExitQPIMode(&hqspi) != MT25TL01G_OK)
0789 {
0790 ret = BSP_ERROR_COMPONENT_FAILURE;
0791 }
0792 }
0793 break;
0794
0795 case BSP_QSPI_SPI_MODE :
0796 case BSP_QSPI_SPI_2IO_MODE :
0797 case BSP_QSPI_SPI_4IO_MODE :
0798 default :
0799 if(Mode == MT25TL01G_QPI_MODE)
0800 {
0801 if(MT25TL01G_EnterQPIMode(&hqspi) != MT25TL01G_OK)
0802 {
0803 ret = BSP_ERROR_COMPONENT_FAILURE;
0804 }
0805 }
0806 break;
0807 }
0808
0809
0810 if(ret == BSP_ERROR_NONE)
0811 {
0812
0813 QSPI_Ctx[Instance].IsInitialized = QSPI_ACCESS_INDIRECT;
0814 QSPI_Ctx[Instance].InterfaceMode = Mode;
0815 QSPI_Ctx[Instance].TransferRate = Rate;
0816 }
0817 }
0818 }
0819 }
0820
0821
0822 return ret;
0823 }
0824
0825
0826
0827
0828
0829
0830
0831
0832
0833
0834
0835
0836
0837
0838
0839
0840
0841
0842 static void QSPI_MspInit(QSPI_HandleTypeDef *hQspi)
0843 {
0844 GPIO_InitTypeDef gpio_init_structure;
0845
0846
0847 UNUSED(hQspi);
0848
0849
0850
0851 QSPI_CLK_ENABLE();
0852
0853 QSPI_FORCE_RESET();
0854 QSPI_RELEASE_RESET();
0855
0856 QSPI_CLK_GPIO_CLK_ENABLE();
0857 QSPI_BK1_CS_GPIO_CLK_ENABLE();
0858 QSPI_BK1_D0_GPIO_CLK_ENABLE();
0859 QSPI_BK1_D1_GPIO_CLK_ENABLE();
0860 QSPI_BK1_D2_GPIO_CLK_ENABLE();
0861 QSPI_BK1_D3_GPIO_CLK_ENABLE();
0862
0863 QSPI_BK2_CS_GPIO_CLK_ENABLE();
0864 QSPI_BK2_D0_GPIO_CLK_ENABLE();
0865 QSPI_BK2_D1_GPIO_CLK_ENABLE();
0866 QSPI_BK2_D2_GPIO_CLK_ENABLE();
0867 QSPI_BK2_D3_GPIO_CLK_ENABLE();
0868
0869
0870
0871 gpio_init_structure.Pin = QSPI_CLK_PIN;
0872 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
0873 gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
0874 gpio_init_structure.Pull = GPIO_NOPULL;
0875 gpio_init_structure.Alternate = GPIO_AF9_QUADSPI;
0876 HAL_GPIO_Init(QSPI_CLK_GPIO_PORT, &gpio_init_structure);
0877
0878
0879 gpio_init_structure.Pin = QSPI_BK1_CS_PIN;
0880 gpio_init_structure.Pull = GPIO_PULLUP;
0881 gpio_init_structure.Alternate = GPIO_AF10_QUADSPI;
0882 HAL_GPIO_Init(QSPI_BK1_CS_GPIO_PORT, &gpio_init_structure);
0883
0884 gpio_init_structure.Pin = QSPI_BK2_CS_PIN;
0885 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
0886 gpio_init_structure.Pull = GPIO_PULLUP;
0887 gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
0888 gpio_init_structure.Alternate = GPIO_AF9_QUADSPI;
0889 HAL_GPIO_Init(QSPI_BK2_CS_GPIO_PORT, &gpio_init_structure);
0890
0891
0892 gpio_init_structure.Pin = QSPI_BK1_D0_PIN;
0893 gpio_init_structure.Pull = GPIO_NOPULL;
0894 gpio_init_structure.Alternate = GPIO_AF10_QUADSPI;
0895 HAL_GPIO_Init(QSPI_BK1_D0_GPIO_PORT, &gpio_init_structure);
0896
0897 gpio_init_structure.Pin = QSPI_BK2_D0_PIN;
0898 gpio_init_structure.Alternate = GPIO_AF9_QUADSPI;
0899 HAL_GPIO_Init(QSPI_BK2_D0_GPIO_PORT, &gpio_init_structure);
0900
0901
0902 gpio_init_structure.Pin = QSPI_BK1_D1_PIN;
0903 gpio_init_structure.Alternate = GPIO_AF10_QUADSPI;
0904 HAL_GPIO_Init(QSPI_BK1_D1_GPIO_PORT, &gpio_init_structure);
0905
0906 gpio_init_structure.Pin = QSPI_BK2_D1_PIN;
0907 gpio_init_structure.Alternate = GPIO_AF9_QUADSPI;
0908 HAL_GPIO_Init(QSPI_BK2_D1_GPIO_PORT, &gpio_init_structure);
0909
0910
0911 gpio_init_structure.Pin = QSPI_BK1_D2_PIN;
0912 gpio_init_structure.Alternate = GPIO_AF9_QUADSPI;
0913 HAL_GPIO_Init(QSPI_BK1_D2_GPIO_PORT, &gpio_init_structure);
0914
0915 gpio_init_structure.Pin = QSPI_BK2_D2_PIN;
0916 HAL_GPIO_Init(QSPI_BK2_D2_GPIO_PORT, &gpio_init_structure);
0917
0918
0919 gpio_init_structure.Pin = QSPI_BK1_D3_PIN;
0920 HAL_GPIO_Init(QSPI_BK1_D3_GPIO_PORT, &gpio_init_structure);
0921
0922 gpio_init_structure.Pin = QSPI_BK2_D3_PIN;
0923 HAL_GPIO_Init(QSPI_BK2_D3_GPIO_PORT, &gpio_init_structure);
0924
0925
0926
0927 HAL_NVIC_SetPriority(QUADSPI_IRQn, 0x0F, 0);
0928 HAL_NVIC_EnableIRQ(QUADSPI_IRQn);
0929 }
0930
0931
0932
0933
0934
0935
0936
0937
0938
0939 static void QSPI_MspDeInit(QSPI_HandleTypeDef *hQspi)
0940 {
0941
0942 UNUSED(hQspi);
0943
0944
0945
0946 HAL_GPIO_DeInit(QSPI_CLK_GPIO_PORT, QSPI_CLK_PIN);
0947 HAL_GPIO_DeInit(QSPI_BK1_CS_GPIO_PORT, QSPI_BK1_CS_PIN);
0948 HAL_GPIO_DeInit(QSPI_BK1_D0_GPIO_PORT, QSPI_BK1_D0_PIN);
0949 HAL_GPIO_DeInit(QSPI_BK1_D1_GPIO_PORT, QSPI_BK1_D1_PIN);
0950 HAL_GPIO_DeInit(QSPI_BK1_D2_GPIO_PORT, QSPI_BK1_D2_PIN);
0951 HAL_GPIO_DeInit(QSPI_BK1_D3_GPIO_PORT, QSPI_BK1_D3_PIN);
0952
0953 HAL_GPIO_DeInit(QSPI_BK2_CS_GPIO_PORT, QSPI_BK2_CS_PIN);
0954 HAL_GPIO_DeInit(QSPI_BK2_D0_GPIO_PORT, QSPI_BK2_D0_PIN);
0955 HAL_GPIO_DeInit(QSPI_BK2_D1_GPIO_PORT, QSPI_BK2_D1_PIN);
0956 HAL_GPIO_DeInit(QSPI_BK2_D2_GPIO_PORT, QSPI_BK2_D2_PIN);
0957 HAL_GPIO_DeInit(QSPI_BK2_D3_GPIO_PORT, QSPI_BK2_D3_PIN);
0958
0959
0960
0961 QSPI_FORCE_RESET();
0962 QSPI_RELEASE_RESET();
0963
0964
0965 QSPI_CLK_DISABLE();
0966 }
0967
0968
0969
0970
0971
0972
0973
0974
0975 static int32_t QSPI_ResetMemory(uint32_t Instance)
0976 {
0977 int32_t ret = BSP_ERROR_NONE;
0978
0979
0980 if(MT25TL01G_ResetEnable(&hqspi, MT25TL01G_QPI_MODE) != MT25TL01G_OK)
0981 {
0982 ret =BSP_ERROR_COMPONENT_FAILURE;
0983 }
0984 else if(MT25TL01G_ResetMemory(&hqspi, MT25TL01G_QPI_MODE) != MT25TL01G_OK)
0985 {
0986 ret = BSP_ERROR_COMPONENT_FAILURE;
0987 }
0988 else if(MT25TL01G_AutoPollingMemReady(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
0989 {
0990 ret = BSP_ERROR_COMPONENT_FAILURE;
0991 }
0992 else if(MT25TL01G_ResetEnable(&hqspi, BSP_QSPI_SPI_MODE) != MT25TL01G_OK)
0993 {
0994 ret = BSP_ERROR_COMPONENT_FAILURE;
0995 }
0996 else if(MT25TL01G_ResetMemory(&hqspi, BSP_QSPI_SPI_MODE) != MT25TL01G_OK)
0997 {
0998 ret = BSP_ERROR_COMPONENT_FAILURE;
0999 }
1000 else
1001 {
1002 QSPI_Ctx[Instance].IsInitialized = QSPI_ACCESS_INDIRECT;
1003 QSPI_Ctx[Instance].InterfaceMode = BSP_QSPI_SPI_MODE;
1004 QSPI_Ctx[Instance].TransferRate = BSP_QSPI_STR_TRANSFER;
1005
1006 }
1007
1008
1009 return ret;
1010 }
1011
1012
1013
1014
1015
1016
1017
1018 static int32_t QSPI_DummyCyclesCfg(uint32_t Instance)
1019 {
1020 int32_t ret= BSP_ERROR_NONE;
1021 QSPI_CommandTypeDef s_command;
1022 uint16_t reg=0;
1023
1024
1025 s_command.InstructionMode = QSPI_INSTRUCTION_4_LINES;
1026 s_command.Instruction = MT25TL01G_READ_VOL_CFG_REG_CMD;
1027 s_command.AddressMode = QSPI_ADDRESS_NONE;
1028 s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
1029 s_command.DataMode = QSPI_DATA_4_LINES;
1030 s_command.DummyCycles = 0;
1031 s_command.NbData = 2;
1032 s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
1033 s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
1034 s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
1035
1036
1037 if (HAL_QSPI_Command(&hqspi, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
1038 {
1039 return BSP_ERROR_COMPONENT_FAILURE;
1040 }
1041
1042
1043 if (HAL_QSPI_Receive(&hqspi, (uint8_t *)(®), HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
1044 {
1045 return BSP_ERROR_COMPONENT_FAILURE;
1046 }
1047
1048
1049 if (MT25TL01G_WriteEnable(&hqspi, QSPI_Ctx[Instance].InterfaceMode) != MT25TL01G_OK)
1050 {
1051 return BSP_ERROR_COMPONENT_FAILURE;
1052 }
1053
1054
1055 s_command.Instruction = MT25TL01G_WRITE_VOL_CFG_REG_CMD;
1056 MODIFY_REG(reg, 0xF0F0, ((MT25TL01G_DUMMY_CYCLES_READ_QUAD << 4) |
1057 (MT25TL01G_DUMMY_CYCLES_READ_QUAD << 12)));
1058
1059
1060 if (HAL_QSPI_Command(&hqspi, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
1061 {
1062 return BSP_ERROR_COMPONENT_FAILURE;
1063 }
1064
1065
1066 if (HAL_QSPI_Transmit(&hqspi, (uint8_t *)(®), HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
1067 {
1068 return BSP_ERROR_COMPONENT_FAILURE;
1069 }
1070
1071
1072 return ret;
1073 }
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088