Facebook
From Obese Tamarin, 5 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 237
  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) 2019 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. #include "i2c.h"
  44. #include "spi.h"
  45. #include "usart.h"
  46. #include "usb.h"
  47. #include "gpio.h"
  48.  
  49. /* Private includes ----------------------------------------------------------*/
  50. /* USER CODE BEGIN Includes */
  51.  
  52. /* USER CODE END Includes */
  53.  
  54. /* Private typedef -----------------------------------------------------------*/
  55. /* USER CODE BEGIN PTD */
  56.  
  57. /* USER CODE END PTD */
  58.  
  59. /* Private define ------------------------------------------------------------*/
  60. /* USER CODE BEGIN PD */
  61.  
  62. /* USER CODE END PD */
  63.  
  64. /* Private macro -------------------------------------------------------------*/
  65. /* USER CODE BEGIN PM */
  66.  
  67. /* USER CODE END PM */
  68.  
  69. /* Private variables ---------------------------------------------------------*/
  70.  
  71. /* USER CODE BEGIN PV */
  72. /* Private variables ---------------------------------------------------------*/
  73. unsigned char measurementData[6],i;
  74.  signed short rawData[3];
  75.  signed short temp;
  76.   float accData[3];
  77.  float var[3];
  78.  float gyroData[3];
  79. /* USER CODE END PV */
  80.  
  81. /* Private function prototypes -----------------------------------------------*/
  82. void SystemClock_Config(void);
  83. /* USER CODE BEGIN PFP */
  84. /* Private function prototypes -----------------------------------------------*/
  85.  
  86. /* USER CODE END PFP */
  87.  
  88. /* Private user code ---------------------------------------------------------*/
  89. /* USER CODE BEGIN 0 */
  90.  
  91. /* USER CODE END 0 */
  92.  
  93. /**
  94.   * @brief  The application entry point.
  95.   * @retval int
  96.   */
  97. int main(void)
  98. {
  99.   /* USER CODE BEGIN 1 */
  100.  
  101.   /* USER CODE END 1 */
  102.  
  103.   /* MCU Configuration--------------------------------------------------------*/
  104.  
  105.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  106.   HAL_Init();
  107.  
  108.   /* USER CODE BEGIN Init */
  109.  
  110.   /* USER CODE END Init */
  111.  
  112.   /* Configure the system clock */
  113.   SystemClock_Config();
  114.  
  115.   /* USER CODE BEGIN SysInit */
  116.  
  117.   /* USER CODE END SysInit */
  118.  
  119.   /* Initialize all configured peripherals */
  120.   MX_GPIO_Init();
  121.   MX_I2C1_Init();
  122.   MX_SPI1_Init();
  123.   MX_USB_PCD_Init();
  124.   MX_UART4_Init();
  125.   MX_UART5_Init();
  126.   /* USER CODE BEGIN 2 */
  127.         char text[200];
  128. HAL_UART_Transmit(&huart4,(unsigned char*)" Hello World! \n\r",sizeof(" Hello World! "),100);
  129.         i=sprintf(text,"%f %f %f ",var[0],var[1],var[2]);
  130.         HAL_UART_Transmit(&huart4,(unsigned char*)text,i,100);
  131.        
  132.         HAL_UART_Transmit(&huart4,(unsigned char*)"\n\r",sizeof("\n\r"),100);
  133.                 HAL_Delay(100);
  134.  
  135.   /* USER CODE END 2 */
  136.  
  137.   /* Infinite loop */
  138.   /* USER CODE BEGIN WHILE */
  139.   while (1)
  140.   {
  141.  
  142.     /* USER CODE END WHILE */
  143.  
  144.     /* USER CODE BEGIN 3 */
  145.  
  146.   }
  147.   /* USER CODE END 3 */
  148. }
  149.  
  150. /**
  151.   * @brief System Clock Configuration
  152.   * @retval None
  153.   */
  154. void SystemClock_Config(void)
  155. {
  156.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  157.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  158.   RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  159.  
  160.   /**Initializes the CPU, AHB and APB busses clocks
  161.   */
  162.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;
  163.   RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
  164.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  165.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  166.   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  167.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  168.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  169.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  170.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  171.   {
  172.     Error_Handler();
  173.   }
  174.   /**Initializes the CPU, AHB and APB busses clocks
  175.   */
  176.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  177.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  178.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  179.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  180.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  181.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  182.  
  183.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  184.   {
  185.     Error_Handler();
  186.   }
  187.   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB|RCC_PERIPHCLK_UART4
  188.                               |RCC_PERIPHCLK_UART5|RCC_PERIPHCLK_I2C1;
  189.   PeriphClkInit.Uart4ClockSelection = RCC_UART4CLKSOURCE_PCLK1;
  190.   PeriphClkInit.Uart5ClockSelection = RCC_UART5CLKSOURCE_PCLK1;
  191.   PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI;
  192.   PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL;
  193.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  194.   {
  195.     Error_Handler();
  196.   }
  197. }
  198.  
  199. /* USER CODE BEGIN 4 */
  200.  
  201. /* USER CODE END 4 */
  202.  
  203. /**
  204.   * @brief  This function is executed in case of error occurrence.
  205.   * @retval None
  206.   */
  207. void Error_Handler(void)
  208. {
  209.   /* USER CODE BEGIN Error_Handler_Debug */
  210.   /* User can add his own implementation to report the HAL error return state */
  211.   while(1)
  212.   {
  213.   }
  214.   /* USER CODE END Error_Handler_Debug */
  215. }
  216.  
  217. #ifdef  USE_FULL_ASSERT
  218. /**
  219.   * @brief  Reports the name of the source file and the source line number
  220.   *         where the assert_param error has occurred.
  221.   * @param  file: pointer to the source file name
  222.   * @param  line: assert_param error line source number
  223.   * @retval None
  224.   */
  225. void assert_failed(char *file, uint32_t line)
  226. {
  227.   /* USER CODE BEGIN 6 */
  228.   /* User can add his own implementation to report the file name and line number,
  229.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  230.   /* USER CODE END 6 */
  231. }
  232. #endif /* USE_FULL_ASSERT */
  233.  
  234. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  235.