你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

求助,Cube生成的fsmc代码为何没有IO初始化代码?难道不需...

[复制链接]
wofei1314 提问时间:2015-10-23 14:58 /
如题,使用Cube V4.11生成的fsmc代码里,只有FSMC的初始化代码,却没有GPIO初始化代码?难道不需要再对GPIO进行初始化?
生成的SDIO的初始化代码也是一样,也都没有GPIO的初始化代码,记得以前用标准库的时候都是需要对GPIO配置的....求解答!
  1. /**
  2.   ******************************************************************************
  3.   * File Name          : main.c
  4.   * Description        : Main program body
  5.   ******************************************************************************
  6.   *
  7.   * COPYRIGHT(c) 2015 STMicroelectronics
  8.   *
  9.   * Redistribution and use in source and binary forms, with or without modification,
  10.   * are permitted provided that the following conditions are met:
  11.   *   1. Redistributions of source code must retain the above copyright notice,
  12.   *      this list of conditions and the following disclaimer.
  13.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  14.   *      this list of conditions and the following disclaimer in the documentation
  15.   *      and/or other materials provided with the distribution.
  16.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  17.   *      may be used to endorse or promote products derived from this software
  18.   *      without specific prior written permission.
  19.   *
  20.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30.   *
  31.   ******************************************************************************
  32.   */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "stm32f4xx_hal.h"
  35. #include "ili9325.h"
  36. /* USER CODE BEGIN Includes */

  37. /* USER CODE END Includes */

  38. /* Private variables ---------------------------------------------------------*/
  39. I2C_HandleTypeDef hi2c1;

  40. SD_HandleTypeDef hsd;
  41. HAL_SD_CardInfoTypedef SDCardInfo;

  42. SPI_HandleTypeDef hspi1;
  43. SPI_HandleTypeDef hspi2;

  44. UART_HandleTypeDef huart4;
  45. UART_HandleTypeDef huart1;
  46. UART_HandleTypeDef huart2;
  47. UART_HandleTypeDef huart3;

  48. PCD_HandleTypeDef hpcd_USB_OTG_FS;

  49. SRAM_HandleTypeDef hsram1;

  50. /* USER CODE BEGIN PV */
  51. /* Private variables ---------------------------------------------------------*/

  52. /* USER CODE END PV */

  53. /* Private function prototypes -----------------------------------------------*/
  54. void SystemClock_Config(void);
  55. static void MX_GPIO_Init(void);
  56. static void MX_FSMC_Init(void);
  57. static void MX_I2C1_Init(void);
  58. static void MX_SDIO_SD_Init(void);
  59. static void MX_SPI1_Init(void);
  60. static void MX_SPI2_Init(void);
  61. static void MX_UART4_Init(void);
  62. static void MX_USART1_UART_Init(void);
  63. static void MX_USART2_UART_Init(void);
  64. static void MX_USART3_UART_Init(void);
  65. static void MX_USB_OTG_FS_PCD_Init(void);

  66. /* USER CODE BEGIN PFP */
  67. /* Private function prototypes -----------------------------------------------*/

  68. /* USER CODE END PFP */

  69. /* USER CODE BEGIN 0 */

  70. /* USER CODE END 0 */
  71. static void LCD_Rst(void)
  72. {
  73.     long dly;
  74.     HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2,GPIO_PIN_RESET);
  75.     for(dly=0;dly<20000;dly++);                                          
  76.     HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2,GPIO_PIN_SET );                          
  77.     for(dly=0;dly<20000;dly++);        
  78. }
  79. int main(void)
  80. {

  81.   /* USER CODE BEGIN 1 */

  82.   /* USER CODE END 1 */

  83.   /* MCU Configuration----------------------------------------------------------*/

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

  86.   /* Configure the system clock */
  87.   SystemClock_Config();

  88.   /* Initialize all configured peripherals */
  89.   MX_GPIO_Init();
  90.   MX_FSMC_Init();
  91.   MX_I2C1_Init();
  92.   MX_SDIO_SD_Init();
  93.   MX_SPI1_Init();
  94.   MX_SPI2_Init();
  95.   MX_UART4_Init();
  96.   MX_USART1_UART_Init();
  97.   MX_USART2_UART_Init();
  98.   MX_USART3_UART_Init();
  99.   MX_USB_OTG_FS_PCD_Init();

  100.   /* USER CODE BEGIN 2 */
  101.     HAL_GPIO_WritePin(GPIOC,GPIO_PIN_1,GPIO_PIN_SET);//Bl
  102.     HAL_GPIO_WritePin(GPIOC,GPIO_PIN_2,GPIO_PIN_RESET);//LED
  103.   Lcd_Initialize();
  104.   /* USER CODE END 2 */

  105.   /* Infinite loop */
  106.   /* USER CODE BEGIN WHILE */
  107.   while (1)
  108.   {
  109.   /* USER CODE END WHILE */

  110.   /* USER CODE BEGIN 3 */

  111.   }
  112.   /* USER CODE END 3 */

  113. }

  114. /** System Clock Configuration
  115. */
  116. void SystemClock_Config(void)
  117. {

  118.   RCC_OscInitTypeDef RCC_OscInitStruct;
  119.   RCC_ClkInitTypeDef RCC_ClkInitStruct;

  120.   __PWR_CLK_ENABLE();

  121.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  122.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  123.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  124.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  125.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  126.   RCC_OscInitStruct.PLL.PLLM = 8;
  127.   RCC_OscInitStruct.PLL.PLLN = 336;
  128.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  129.   RCC_OscInitStruct.PLL.PLLQ = 7;
  130.   HAL_RCC_OscConfig(&RCC_OscInitStruct);

  131.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
  132.                               |RCC_CLOCKTYPE_PCLK2;
  133.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  134.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  135.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  136.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  137.   HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);

  138.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  139.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  140.   /* SysTick_IRQn interrupt configuration */
  141.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  142. }

  143. /* I2C1 init function */
  144. void MX_I2C1_Init(void)
  145. {

  146.   hi2c1.Instance = I2C1;
  147.   hi2c1.Init.ClockSpeed = 100000;
  148.   hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
  149.   hi2c1.Init.OwnAddress1 = 0;
  150.   hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  151.   hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
  152.   hi2c1.Init.OwnAddress2 = 0;
  153.   hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
  154.   hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
  155.   HAL_I2C_Init(&hi2c1);

  156. }

  157. /* SDIO init function */
  158. void MX_SDIO_SD_Init(void)
  159. {

  160.   hsd.Instance = SDIO;
  161.   hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
  162.   hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
  163.   hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
  164.   hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
  165.   hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
  166.   hsd.Init.ClockDiv = 0;
  167.   HAL_SD_Init(&hsd, &SDCardInfo);

  168.   HAL_SD_WideBusOperation_Config(&hsd, SDIO_BUS_WIDE_4B);

  169. }

  170. /* SPI1 init function */
  171. void MX_SPI1_Init(void)
  172. {

  173.   hspi1.Instance = SPI1;
  174.   hspi1.Init.Mode = SPI_MODE_MASTER;
  175.   hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  176.   hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  177.   hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  178.   hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  179.   hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT;
  180.   hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  181.   hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  182.   hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
  183.   hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
  184.   hspi1.Init.CRCPolynomial = 10;
  185.   HAL_SPI_Init(&hspi1);

  186. }

  187. /* SPI2 init function */
  188. void MX_SPI2_Init(void)
  189. {

  190.   hspi2.Instance = SPI2;
  191.   hspi2.Init.Mode = SPI_MODE_MASTER;
  192.   hspi2.Init.Direction = SPI_DIRECTION_2LINES;
  193.   hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
  194.   hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
  195.   hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
  196.   hspi2.Init.NSS = SPI_NSS_HARD_OUTPUT;
  197.   hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  198.   hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
  199.   hspi2.Init.TIMode = SPI_TIMODE_DISABLED;
  200.   hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
  201.   hspi2.Init.CRCPolynomial = 10;
  202.   HAL_SPI_Init(&hspi2);

  203. }

  204. /* UART4 init function */
  205. void MX_UART4_Init(void)
  206. {

  207.   huart4.Instance = UART4;
  208.   huart4.Init.BaudRate = 115200;
  209.   huart4.Init.WordLength = UART_WORDLENGTH_8B;
  210.   huart4.Init.StopBits = UART_STOPBITS_1;
  211.   huart4.Init.Parity = UART_PARITY_NONE;
  212.   huart4.Init.Mode = UART_MODE_TX_RX;
  213.   huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  214.   huart4.Init.OverSampling = UART_OVERSAMPLING_16;
  215.   HAL_UART_Init(&huart4);

  216. }

  217. /* USART1 init function */
  218. void MX_USART1_UART_Init(void)
  219. {

  220.   huart1.Instance = USART1;
  221.   huart1.Init.BaudRate = 115200;
  222.   huart1.Init.WordLength = UART_WORDLENGTH_8B;
  223.   huart1.Init.StopBits = UART_STOPBITS_1;
  224.   huart1.Init.Parity = UART_PARITY_NONE;
  225.   huart1.Init.Mode = UART_MODE_TX_RX;
  226.   huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  227.   huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  228.   HAL_UART_Init(&huart1);

  229. }

  230. /* USART2 init function */
  231. void MX_USART2_UART_Init(void)
  232. {

  233.   huart2.Instance = USART2;
  234.   huart2.Init.BaudRate = 115200;
  235.   huart2.Init.WordLength = UART_WORDLENGTH_8B;
  236.   huart2.Init.StopBits = UART_STOPBITS_1;
  237.   huart2.Init.Parity = UART_PARITY_NONE;
  238.   huart2.Init.Mode = UART_MODE_TX_RX;
  239.   huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  240.   huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  241.   HAL_UART_Init(&huart2);

  242. }

  243. /* USART3 init function */
  244. void MX_USART3_UART_Init(void)
  245. {

  246.   huart3.Instance = USART3;
  247.   huart3.Init.BaudRate = 115200;
  248.   huart3.Init.WordLength = UART_WORDLENGTH_8B;
  249.   huart3.Init.StopBits = UART_STOPBITS_1;
  250.   huart3.Init.Parity = UART_PARITY_NONE;
  251.   huart3.Init.Mode = UART_MODE_TX_RX;
  252.   huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  253.   huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  254.   HAL_UART_Init(&huart3);

  255. }

  256. /* USB_OTG_FS init function */
  257. void MX_USB_OTG_FS_PCD_Init(void)
  258. {

  259.   hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
  260.   hpcd_USB_OTG_FS.Init.dev_endpoints = 7;
  261.   hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
  262.   hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
  263.   hpcd_USB_OTG_FS.Init.ep0_mps = DEP0CTL_MPS_64;
  264.   hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
  265.   hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
  266.   hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
  267.   hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
  268.   hpcd_USB_OTG_FS.Init.vbus_sensing_enable = ENABLE;
  269.   hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
  270.   HAL_PCD_Init(&hpcd_USB_OTG_FS);

  271. }

  272. /** Configure pins as
  273.         * Analog
  274.         * Input
  275.         * Output
  276.         * EVENT_OUT
  277.         * EXTI
  278. */
  279. void MX_GPIO_Init(void)
  280. {

  281.   GPIO_InitTypeDef GPIO_InitStruct;

  282.   /* GPIO Ports Clock Enable */
  283.   __GPIOE_CLK_ENABLE();
  284.   __GPIOH_CLK_ENABLE();
  285.   __GPIOC_CLK_ENABLE();
  286.   __GPIOA_CLK_ENABLE();
  287.   __GPIOB_CLK_ENABLE();
  288.   __GPIOD_CLK_ENABLE();

  289.   /*Configure GPIO pin : PE2 */
  290.   GPIO_InitStruct.Pin = GPIO_PIN_2;
  291.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  292.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  293.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  294.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  295.   /*Configure GPIO pins : PC1 PC2 PC4 PC5 */
  296.   GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_4|GPIO_PIN_5;
  297.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  298.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  299.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  300.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  301.   /*Configure GPIO pin : PA8 */
  302.   GPIO_InitStruct.Pin = GPIO_PIN_8;
  303.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  304.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  305.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  306.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  307.   /*Configure GPIO pins : PD3 PD6 */
  308.   GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_6;
  309.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  310.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  311.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  312.   HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  313. }

  314. /* FSMC initialization function */
  315. void MX_FSMC_Init(void)
  316. {
  317.   FSMC_NORSRAM_TimingTypeDef Timing;

  318.   /** Perform the SRAM1 memory initialization sequence
  319.   */
  320.   hsram1.Instance = FSMC_NORSRAM_DEVICE;
  321.   hsram1.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
  322.   /* hsram1.Init */
  323.   hsram1.Init.NSBank = FSMC_NORSRAM_BANK1;
  324.   hsram1.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
  325.   hsram1.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
  326.   hsram1.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
  327.   hsram1.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
  328.   hsram1.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
  329.   hsram1.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
  330.   hsram1.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
  331.   hsram1.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
  332.   hsram1.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
  333.   hsram1.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE;
  334.   hsram1.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
  335.   hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
  336.   /* Timing */
  337.   Timing.AddressSetupTime = 15;
  338.   Timing.AddressHoldTime = 15;
  339.   Timing.DataSetupTime = 255;
  340.   Timing.BusTurnAroundDuration = 15;
  341.   Timing.CLKDivision = 16;
  342.   Timing.DataLatency = 17;
  343.   Timing.AccessMode = FSMC_ACCESS_MODE_A;
  344.   /* ExtTiming */

  345.   HAL_SRAM_Init(&hsram1, &Timing, NULL);

  346. }

  347. /* USER CODE BEGIN 4 */

  348. /* USER CODE END 4 */

  349. #ifdef USE_FULL_ASSERT

  350. /**
  351.    * @brief Reports the name of the source file and the source line number
  352.    * where the assert_param error has occurred.
  353.    * @param file: pointer to the source file name
  354.    * @param line: assert_param error line source number
  355.    * @retval None
  356.    */
  357. void assert_failed(uint8_t* file, uint32_t line)
  358. {
  359.   /* USER CODE BEGIN 6 */
  360.   /* User can add his own implementation to report the file name and line number,
  361.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  362.   /* USER CODE END 6 */

  363. }

  364. #endif

  365. /**
  366.   * @}
  367.   */

  368. /**
  369.   * @}
  370. */

  371. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码

收藏 评论15 发布时间:2015-10-23 14:58

举报

15个回答
microcomput 回答时间:2015-10-23 15:07:49
HAL_FSMC_MspDeInit()    你搜索这个函数就出来了.
wofei1314 回答时间:2015-10-23 15:02:03
莫非它不在需要配置GPIO?只要初始化FSMC,单片机会自动配置GPIO?亦或者,HAL库在自己的某个角落里已经配置好了GPIO,可是我也没找到...
再或者,需要使用者自己写GPIO的初始化代码,那感脚太不智能了.....

用过的朋友们,给科普一下!谢谢:)
wofei1314 回答时间:2015-10-23 15:10:37
microcomput 发表于 2015-10-23 15:07
HAL_FSMC_MspDeInit()    你搜索这个函数就出来了.

谢谢啊,终于解了我的疑惑,真的是看的不仔细啊,还是很智能的,得好好学习一下HAL  
wofei1314 回答时间:2015-10-23 15:27:07
microcomput 发表于 2015-10-23 15:07
HAL_FSMC_MspDeInit()    你搜索这个函数就出来了.

再请教一下,是不是直接用我面贴的代码就无需初始化GPIO了?
刚才搜了一下你说的那个函数,确实找到了初始化的代码,但逐级“追踪”,却没看出来那个函数调用了它...

HAL_FSMC_MspDeInit()上级是HAL_SRAM_MspDeInit(),
HAL_SRAM_MspDeInit()的上级是HAL_SRAM_DeInit()
可是没看到那个函数调用了HAL_SRAM_DeInit()....

难道需要使用者手动调一下HAL_SRAM_DeInit()  ?
microcomput 回答时间:2015-10-23 16:11:56
他是在库里面调用初始化的,你再搜这HAL_FSMC_MspInit    ,一级一级往上搜就知道谁调用了.
wofei1314 回答时间:2015-10-23 16:14:08
microcomput 发表于 2015-10-23 16:11
他是在库里面调用初始化的,你再搜这HAL_FSMC_MspInit    ,一级一级往上搜就知道谁调用了. ...

谢谢你的耐心解答,受教了~
你好我好大家好! 回答时间:2015-10-23 17:45:56
帮顶                                   
peter001 回答时间:2015-10-23 18:15:48
封装的很深呀
jiaswang 回答时间:2015-10-23 18:56:10
学习了,还没用过FSMC
Mr.rong 回答时间:2015-10-23 19:08:10
表示:??/、/、/、、、、/
Mr.rong 回答时间:2015-10-23 19:09:25
free-368046 回答时间:2017-5-29 17:03:47
我生成的有IO初始化啊
void MX_FSMC_Init(void)
{
  FSMC_NORSRAM_TimingTypeDef Timing;

  /** Perform the SRAM1 memory initialization sequence
  */
  hsram1.Instance = FSMC_NORSRAM_DEVICE;
  hsram1.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
  /* hsram1.Init */
  hsram1.Init.NSBank = FSMC_NORSRAM_BANK1;
  hsram1.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_ENABLE;
  hsram1.Init.MemoryType = FSMC_MEMORY_TYPE_PSRAM;
  hsram1.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_8;
  hsram1.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
  hsram1.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
  hsram1.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
  hsram1.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
  hsram1.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
  hsram1.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
  hsram1.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE;
  hsram1.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_ENABLE;
  hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
  /* Timing */
  Timing.AddressSetupTime = 1;
  Timing.AddressHoldTime = 1;
  Timing.DataSetupTime = 5;
  Timing.BusTurnAroundDuration = 0;
  Timing.CLKDivision = 16;
  Timing.DataLatency = 17;
  Timing.AccessMode = FSMC_ACCESS_MODE_A;
  /* ExtTiming */

  if (HAL_SRAM_Init(&hsram1, &Timing, NULL) != HAL_OK)
  {
    Error_Handler();
  }

}

static uint32_t FSMC_Initialized = 0;

static void HAL_FSMC_MspInit(void){
  /* USER CODE BEGIN FSMC_MspInit 0 */

  /* USER CODE END FSMC_MspInit 0 */
  GPIO_InitTypeDef GPIO_InitStruct;
  if (FSMC_Initialized) {
    return;
  }
  FSMC_Initialized = 1;
  /* Peripheral clock enable */
  __HAL_RCC_FSMC_CLK_ENABLE();
  
  /** FSMC GPIO Configuration  
  PE7   ------> FSMC_DA4
  PE8   ------> FSMC_DA5
  PE9   ------> FSMC_DA6
  PE10   ------> FSMC_DA7
  PD14   ------> FSMC_DA0
  PD15   ------> FSMC_DA1
  PD0   ------> FSMC_DA2
  PD1   ------> FSMC_DA3
  PD4   ------> FSMC_NOE
  PD5   ------> FSMC_NWE
  PD6   ------> FSMC_NWAIT
  PD7   ------> FSMC_NE1
  PB7   ------> FSMC_NL
  */
  /* GPIO_InitStruct */
  GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  /* GPIO_InitStruct */
  GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1
                          |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /* GPIO_InitStruct */
  GPIO_InitStruct.Pin = GPIO_PIN_6;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;

  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /* GPIO_InitStruct */
  GPIO_InitStruct.Pin = GPIO_PIN_7;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /* USER CODE BEGIN FSMC_MspInit 1 */

  /* USER CODE END FSMC_MspInit 1 */
}

void HAL_SRAM_MspInit(SRAM_HandleTypeDef* sramHandle){
  /* USER CODE BEGIN SRAM_MspInit 0 */

  /* USER CODE END SRAM_MspInit 0 */
  HAL_FSMC_MspInit();
  /* USER CODE BEGIN SRAM_MspInit 1 */

  /* USER CODE END SRAM_MspInit 1 */
}

static uint32_t FSMC_DeInitialized = 0;

static void HAL_FSMC_MspDeInit(void){
  /* USER CODE BEGIN FSMC_MspDeInit 0 */

  /* USER CODE END FSMC_MspDeInit 0 */
  if (FSMC_DeInitialized) {
    return;
  }
  FSMC_DeInitialized = 1;
  /* Peripheral clock enable */
  __HAL_RCC_FSMC_CLK_DISABLE();
  
  /** FSMC GPIO Configuration  
  PE7   ------> FSMC_DA4
  PE8   ------> FSMC_DA5
  PE9   ------> FSMC_DA6
  PE10   ------> FSMC_DA7
  PD14   ------> FSMC_DA0
  PD15   ------> FSMC_DA1
  PD0   ------> FSMC_DA2
  PD1   ------> FSMC_DA3
  PD4   ------> FSMC_NOE
  PD5   ------> FSMC_NWE
  PD6   ------> FSMC_NWAIT
  PD7   ------> FSMC_NE1
  PB7   ------> FSMC_NL
  */

  HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);

  HAL_GPIO_DeInit(GPIOD, GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1
                          |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);

  HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);

  /* USER CODE BEGIN FSMC_MspDeInit 1 */

  /* USER CODE END FSMC_MspDeInit 1 */
}

void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef* sramHandle){
  /* USER CODE BEGIN SRAM_MspDeInit 0 */

  /* USER CODE END SRAM_MspDeInit 0 */
  HAL_FSMC_MspDeInit();
  /* USER CODE BEGIN SRAM_MspDeInit 1 */

  /* USER CODE END SRAM_MspDeInit 1 */
}
/**
  * @}
  */

/**
  * @}
  */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
zhao.zhao 回答时间:2017-5-30 10:16:57
总结一下,CUBE中,底层和引脚有关的初始化都是在 HAL_XXX_MspInit() 中完成的
枫天123 回答时间:2017-12-22 19:41:07
越看越迷糊。。。。谁有cub的fsmc的例程
12下一页

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版