Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.45 KB | None | 0 0
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   ** This notice applies to any and all portions of this file
  8.   * that are not between comment pairs USER CODE BEGIN and
  9.   * USER CODE END. Other portions of this file, whether
  10.   * inserted by the user or by software development tools
  11.   * are owned by their respective copyright owners.
  12.   *
  13.   * COPYRIGHT(c) 2018 STMicroelectronics
  14.   *
  15.   * Redistribution and use in source and binary forms, with or without modification,
  16.   * are permitted provided that the following conditions are met:
  17.   *   1. Redistributions of source code must retain the above copyright notice,
  18.   *      this list of conditions and the following disclaimer.
  19.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  20.   *      this list of conditions and the following disclaimer in the documentation
  21.   *      and/or other materials provided with the distribution.
  22.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  23.   *      may be used to endorse or promote products derived from this software
  24.   *      without specific prior written permission.
  25.   *
  26.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  30.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  34.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36.   *
  37.   ******************************************************************************
  38.   */
  39. /* USER CODE END Header */
  40.  
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "main.h"
  43.  
  44. /* Private includes ----------------------------------------------------------*/
  45. /* USER CODE BEGIN Includes */
  46.  
  47. /* USER CODE END Includes */
  48.  
  49. /* Private typedef -----------------------------------------------------------*/
  50. /* USER CODE BEGIN PTD */
  51.  
  52. /* USER CODE END PTD */
  53.  
  54. /* Private define ------------------------------------------------------------*/
  55. /* USER CODE BEGIN PD */
  56.  
  57. /* USER CODE END PD */
  58.  
  59. /* Private macro -------------------------------------------------------------*/
  60. /* USER CODE BEGIN PM */
  61.  
  62. /* USER CODE END PM */
  63.  
  64. /* Private variables ---------------------------------------------------------*/
  65. SPI_HandleTypeDef hspi2;
  66.  
  67. /* USER CODE BEGIN PV */
  68.  
  69. /* USER CODE END PV */
  70.  
  71. /* Private function prototypes -----------------------------------------------*/
  72. void SystemClock_Config(void);
  73. static void MX_GPIO_Init(void);
  74. static void MX_SPI2_Init(void);
  75. /* USER CODE BEGIN PFP */
  76.  
  77. /* USER CODE END PFP */
  78.  
  79. /* Private user code ---------------------------------------------------------*/
  80. /* USER CODE BEGIN 0 */
  81.  
  82. /* USER CODE END 0 */
  83.  
  84. /**
  85.   * @brief  The application entry point.
  86.   * @retval int
  87.   */
  88. int main(void)
  89. {
  90.   /* USER CODE BEGIN 1 */
  91.  
  92.   /* USER CODE END 1 */
  93.  
  94.   /* MCU Configuration--------------------------------------------------------*/
  95.  
  96.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  97.   HAL_Init();
  98.  
  99.   /* USER CODE BEGIN Init */
  100.  
  101.   /* USER CODE END Init */
  102.  
  103.   /* Configure the system clock */
  104.   SystemClock_Config();
  105.  
  106.   /* USER CODE BEGIN SysInit */
  107.  
  108.   /* USER CODE END SysInit */
  109.  
  110.   /* Initialize all configured peripherals */
  111.   MX_GPIO_Init();
  112.   MX_SPI2_Init();
  113.   /* USER CODE BEGIN 2 */
  114.   HAL_SPI_Transmit(&hspi2, (uint8_t *)0x12, 1, HAL_TIMEOUT);
  115.   /* USER CODE END 2 */
  116.  
  117.   /* Infinite loop */
  118.   /* USER CODE BEGIN WHILE */
  119.   while (1)
  120.   {
  121.     /* USER CODE END WHILE */
  122.  
  123.     /* USER CODE BEGIN 3 */
  124.   }
  125.   /* USER CODE END 3 */
  126. }
  127.  
  128. /**
  129.   * @brief System Clock Configuration
  130.   * @retval None
  131.   */
  132. void SystemClock_Config(void)
  133. {
  134.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  135.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  136.  
  137.   /**Initializes the CPU, AHB and APB busses clocks
  138.   */
  139.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
  140.   RCC_OscInitStruct.LSEState = RCC_LSE_BYPASS;
  141.   RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  142.   RCC_OscInitStruct.MSICalibrationValue = 0;
  143.   RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
  144.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  145.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  146.   {
  147.     Error_Handler();
  148.   }
  149.   /**Initializes the CPU, AHB and APB busses clocks
  150.   */
  151.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  152.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  153.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
  154.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  155.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  156.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  157.  
  158.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  159.   {
  160.     Error_Handler();
  161.   }
  162.   /**Configure the main internal regulator output voltage
  163.   */
  164.   if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
  165.   {
  166.     Error_Handler();
  167.   }
  168.   /**Enable MSI Auto calibration
  169.   */
  170.   HAL_RCCEx_EnableMSIPLLMode();
  171. }
  172.  
  173. /**
  174.   * @brief SPI2 Initialization Function
  175.   * @param None
  176.   * @retval None
  177.   */
  178. static void MX_SPI2_Init(void)
  179. {
  180.  
  181.   /* USER CODE BEGIN SPI2_Init 0 */
  182.  
  183.   /* USER CODE END SPI2_Init 0 */
  184.  
  185.   /* USER CODE BEGIN SPI2_Init 1 */
  186.  
  187.   /* USER CODE END SPI2_Init 1 */
  188.   /* SPI2 parameter configuration*/
  189.   hspi2.Instance = SPI2;
  190.   hspi2.Init.Mode = SPI_MODE_MASTER;
  191.   hspi2.Init.Direction = SPI_DIRECTION_2LINES;
  192.   hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
  193.   hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
  194.   hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
  195.   hspi2.Init.NSS = SPI_NSS_SOFT;
  196.   hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
  197.   hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
  198.   hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
  199.   hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  200.   hspi2.Init.CRCPolynomial = 7;
  201.   hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  202.   hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  203.   if (HAL_SPI_Init(&hspi2) != HAL_OK)
  204.   {
  205.     Error_Handler();
  206.   }
  207.   /* USER CODE BEGIN SPI2_Init 2 */
  208.  
  209.   /* USER CODE END SPI2_Init 2 */
  210.  
  211. }
  212.  
  213. /**
  214.   * @brief GPIO Initialization Function
  215.   * @param None
  216.   * @retval None
  217.   */
  218. static void MX_GPIO_Init(void)
  219. {
  220.   GPIO_InitTypeDef GPIO_InitStruct = {0};
  221.  
  222.   /* GPIO Ports Clock Enable */
  223.   __HAL_RCC_GPIOC_CLK_ENABLE();
  224.   __HAL_RCC_GPIOH_CLK_ENABLE();
  225.   __HAL_RCC_GPIOF_CLK_ENABLE();
  226.   __HAL_RCC_GPIOB_CLK_ENABLE();
  227.  
  228.   /*Configure GPIO pin Output Level */
  229.   HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_RESET);
  230.  
  231.   /*Configure GPIO pin : PF11 */
  232.   GPIO_InitStruct.Pin = GPIO_PIN_11;
  233.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  234.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  235.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  236.   HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  237.  
  238. }
  239.  
  240. /* USER CODE BEGIN 4 */
  241.  
  242. /* USER CODE END 4 */
  243.  
  244. /**
  245.   * @brief  This function is executed in case of error occurrence.
  246.   * @retval None
  247.   */
  248. void Error_Handler(void)
  249. {
  250.   /* USER CODE BEGIN Error_Handler_Debug */
  251.   /* User can add his own implementation to report the HAL error return state */
  252.  
  253.   /* USER CODE END Error_Handler_Debug */
  254. }
  255.  
  256. #ifdef  USE_FULL_ASSERT
  257. /**
  258.   * @brief  Reports the name of the source file and the source line number
  259.   *         where the assert_param error has occurred.
  260.   * @param  file: pointer to the source file name
  261.   * @param  line: assert_param error line source number
  262.   * @retval None
  263.   */
  264. void assert_failed(char *file, uint32_t line)
  265. {
  266.   /* USER CODE BEGIN 6 */
  267.   /* User can add his own implementation to report the file name and line number,
  268.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  269.   /* USER CODE END 6 */
  270. }
  271. #endif /* USE_FULL_ASSERT */
  272.  
  273. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement