bsp_fsmc_nandflash.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include "bsp_fsmc_nandflash.h"
  2. /* USER CODE BEGIN 0 */
  3. /* USER CODE END 0 */
  4. NAND_HandleTypeDef hnand1;
  5. static uint32_t FSMC_Initialized = 0;
  6. /* FSMC initialization function */
  7. /* FSMC initialization function */
  8. void MX_FSMC_NANDFLASH_Init(void)
  9. {
  10. /* USER CODE BEGIN FSMC_Init 0 */
  11. /* USER CODE END FSMC_Init 0 */
  12. FSMC_NAND_PCC_TimingTypeDef ComSpaceTiming = {0};
  13. FSMC_NAND_PCC_TimingTypeDef AttSpaceTiming = {0};
  14. /* USER CODE BEGIN FSMC_Init 1 */
  15. /* USER CODE END FSMC_Init 1 */
  16. /** Perform the NAND1 memory initialization sequence
  17. */
  18. hnand1.Instance = FSMC_NAND_DEVICE;
  19. /* hnand1.Init */
  20. hnand1.Init.NandBank = FSMC_NAND_BANK2;
  21. hnand1.Init.Waitfeature = FSMC_NAND_PCC_WAIT_FEATURE_DISABLE;
  22. hnand1.Init.MemoryDataWidth = FSMC_NAND_PCC_MEM_BUS_WIDTH_8;
  23. hnand1.Init.EccComputation = FSMC_NAND_ECC_ENABLE;
  24. hnand1.Init.ECCPageSize = FSMC_NAND_ECC_PAGE_SIZE_1024BYTE;
  25. hnand1.Init.TCLRSetupTime = 0;
  26. hnand1.Init.TARSetupTime = 0;
  27. /* hnand1.Config */
  28. hnand1.Config.PageSize = 2048;
  29. hnand1.Config.SpareAreaSize = 64;
  30. hnand1.Config.BlockSize = 64;
  31. hnand1.Config.BlockNbr = 1024;
  32. hnand1.Config.PlaneNbr =2;
  33. hnand1.Config.PlaneSize = 2048;
  34. hnand1.Config.ExtraCommandEnable = DISABLE;
  35. /* ComSpaceTiming */
  36. ComSpaceTiming.SetupTime = 0x1;
  37. ComSpaceTiming.WaitSetupTime = 0x2;
  38. ComSpaceTiming.HoldSetupTime = 0x2;
  39. ComSpaceTiming.HiZSetupTime = 0x2;
  40. /* AttSpaceTiming */
  41. AttSpaceTiming.SetupTime = 0x1;
  42. AttSpaceTiming.WaitSetupTime = 0x2;
  43. AttSpaceTiming.HoldSetupTime = 0x2;
  44. AttSpaceTiming.HiZSetupTime = 0x2;
  45. if (HAL_NAND_Init(&hnand1, &ComSpaceTiming, &AttSpaceTiming) != HAL_OK)
  46. {
  47. return ;
  48. }
  49. }
  50. static void HAL_FSMC_NANDFLASH_MspInit()
  51. {
  52. /* USER CODE BEGIN FSMC_MspInit 0 */
  53. /* USER CODE END FSMC_MspInit 0 */
  54. GPIO_InitTypeDef GPIO_InitStruct = {0};
  55. if (FSMC_Initialized) {
  56. return;
  57. }
  58. FSMC_Initialized = 1;
  59. /* Peripheral clock enable */
  60. __HAL_RCC_FSMC_CLK_ENABLE();
  61. __HAL_RCC_GPIOD_CLK_ENABLE();
  62. __HAL_RCC_GPIOE_CLK_ENABLE();
  63. /** FSMC GPIO Configuration
  64. PE7 ------> FSMC_D4
  65. PE8 ------> FSMC_D5
  66. PE9 ------> FSMC_D6
  67. PE10 ------> FSMC_D7
  68. PD11 ------> FSMC_CLE
  69. PD12 ------> FSMC_ALE
  70. PD14 ------> FSMC_D0
  71. PD15 ------> FSMC_D1
  72. PD0 ------> FSMC_D2
  73. PD1 ------> FSMC_D3
  74. PD4 ------> FSMC_NOE
  75. PD5 ------> FSMC_NWE
  76. PD6 ------> FSMC_NWAIT
  77. PD7 ------> FSMC_NCE2
  78. */
  79. /* GPIO_InitStruct */
  80. GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
  81. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  82. GPIO_InitStruct.Pull = GPIO_NOPULL;
  83. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  84. GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
  85. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  86. /* GPIO_InitStruct */
  87. GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_14|GPIO_PIN_15
  88. |GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5
  89. |GPIO_PIN_7;
  90. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  91. GPIO_InitStruct.Pull = GPIO_NOPULL;
  92. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  93. GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
  94. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  95. /* USER CODE BEGIN FSMC_MspInit 1 */
  96. GPIO_InitStruct.Pin = GPIO_PIN_6;
  97. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  98. GPIO_InitStruct.Pull = GPIO_PULLUP;
  99. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  100. GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
  101. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  102. /* USER CODE END FSMC_MspInit 1 */
  103. }
  104. void HAL_NAND_MspInit(NAND_HandleTypeDef *hnand)
  105. {
  106. HAL_FSMC_NANDFLASH_MspInit();
  107. }