]> begriffs open source - cmsis-driver-validation/blob - Boards/ST/B-L475E-IOT01A1/RTE/Device/STM32L475VGTx/STCubeGenerated/Src/main.c
Deprecated usage of CMSIS-RTOS1
[cmsis-driver-validation] / Boards / ST / B-L475E-IOT01A1 / RTE / Device / STM32L475VGTx / STCubeGenerated / Src / main.c
1 /* USER CODE BEGIN Header */
2 /**
3   ******************************************************************************
4   * @file           : main.c
5   * @brief          : Main program body
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10   * All rights reserved.</center></h2>
11   *
12   * This software component is licensed by ST under BSD 3-Clause license,
13   * the "License"; You may not use this file except in compliance with the
14   * License. You may obtain a copy of the License at:
15   *                        opensource.org/licenses/BSD-3-Clause
16   *
17   ******************************************************************************
18   */
19 /* USER CODE END Header */
20
21 /* Includes ------------------------------------------------------------------*/
22 #include "main.h"
23
24 /* Private includes ----------------------------------------------------------*/
25 /* USER CODE BEGIN Includes */
26 #include "cmsis_dv.h"                   // ARM.API::CMSIS Driver Validation:Framework
27
28 extern void WiFi_ISM43362_Pin_DATARDY_IRQ (void);
29 /* USER CODE END Includes */
30
31 /* Private typedef -----------------------------------------------------------*/
32 /* USER CODE BEGIN PTD */
33
34 /* USER CODE END PTD */
35
36 /* Private define ------------------------------------------------------------*/
37 /* USER CODE BEGIN PD */
38
39 /* USER CODE END PD */
40
41 /* Private macro -------------------------------------------------------------*/
42 /* USER CODE BEGIN PM */
43
44 /* USER CODE END PM */
45
46 /* Private variables ---------------------------------------------------------*/
47 SPI_HandleTypeDef hspi3;
48 DMA_HandleTypeDef hdma_spi3_rx;
49 DMA_HandleTypeDef hdma_spi3_tx;
50
51 /* USER CODE BEGIN PV */
52
53 /* USER CODE END PV */
54
55 /* Private function prototypes -----------------------------------------------*/
56 void SystemClock_Config(void);
57 static void MX_GPIO_Init(void);
58 static void MX_DMA_Init(void);
59 static void MX_SPI3_Init(void);
60 /* USER CODE BEGIN PFP */
61
62 /* USER CODE END PFP */
63
64 /* Private user code ---------------------------------------------------------*/
65 /* USER CODE BEGIN 0 */
66
67 /**
68   * Override default HAL_GetTick function
69   */
70   
71 volatile uint32_t DEBUG_Tick = 0;
72 uint32_t HAL_GetTick (void) {
73   static uint32_t ticks = 0U;
74          uint32_t i;
75
76   if (osKernelGetState () == osKernelRunning) {
77     DEBUG_Tick = osKernelGetTickCount ();
78     return ((uint32_t)osKernelGetTickCount ());
79   }
80
81   /* If Kernel is not running wait approximately 1 ms then increment 
82      and return auxiliary tick counter value */
83   for (i = (SystemCoreClock >> 14U); i > 0U; i--) {
84     __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
85     __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
86   }
87   return ++ticks;
88 }
89
90 /**
91   * @brief  EXTI line detection callback.
92   * @param  GPIO_Pin: Specifies the port pin connected to corresponding EXTI line.
93   * @retval None
94   */
95 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
96 {
97   if (GPIO_Pin == GPIO_PIN_1) {
98     WiFi_ISM43362_Pin_DATARDY_IRQ();
99   }
100 }
101
102 /* USER CODE END 0 */
103
104 /**
105   * @brief  The application entry point.
106   * @retval int
107   */
108 int main(void)
109 {
110   /* USER CODE BEGIN 1 */
111
112   /* USER CODE END 1 */
113
114   /* MCU Configuration--------------------------------------------------------*/
115
116   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
117   HAL_Init();
118
119   /* USER CODE BEGIN Init */
120
121   /* USER CODE END Init */
122
123   /* Configure the system clock */
124   SystemClock_Config();
125
126   /* USER CODE BEGIN SysInit */
127   SystemCoreClockUpdate();
128   /* USER CODE END SysInit */
129
130   /* Initialize all configured peripherals */
131   MX_GPIO_Init();
132   MX_DMA_Init();
133   MX_SPI3_Init();
134   /* USER CODE BEGIN 2 */
135
136   osKernelInitialize ();                /* Initialize CMSIS-RTOS2 */
137   osThreadNew(cmsis_dv, NULL, NULL);    /* Create validation main thread */
138   osKernelStart();                      /* Start thread execution */
139
140   /* USER CODE END 2 */
141
142   /* Infinite loop */
143   /* USER CODE BEGIN WHILE */
144   while (1)
145   {
146     /* USER CODE END WHILE */
147
148     /* USER CODE BEGIN 3 */
149   }
150   /* USER CODE END 3 */
151 }
152
153 /**
154   * @brief System Clock Configuration
155   * @retval None
156   */
157 void SystemClock_Config(void)
158 {
159   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
160   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
161
162   /** Configure LSE Drive Capability 
163   */
164   HAL_PWR_EnableBkUpAccess();
165   __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
166   /** Initializes the CPU, AHB and APB busses clocks 
167   */
168   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
169   RCC_OscInitStruct.LSEState = RCC_LSE_ON;
170   RCC_OscInitStruct.MSIState = RCC_MSI_ON;
171   RCC_OscInitStruct.MSICalibrationValue = 0;
172   RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
173   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
174   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
175   RCC_OscInitStruct.PLL.PLLM = 1;
176   RCC_OscInitStruct.PLL.PLLN = 40;
177   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
178   RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
179   RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
180   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
181   {
182     Error_Handler();
183   }
184   /** Initializes the CPU, AHB and APB busses clocks 
185   */
186   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
187                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
188   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
189   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
190   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
191   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
192
193   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
194   {
195     Error_Handler();
196   }
197   /** Configure the main internal regulator output voltage 
198   */
199   if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
200   {
201     Error_Handler();
202   }
203   /** Enable MSI Auto calibration 
204   */
205   HAL_RCCEx_EnableMSIPLLMode();
206 }
207
208 /**
209   * @brief SPI3 Initialization Function
210   * @param None
211   * @retval None
212   */
213 static void MX_SPI3_Init(void)
214 {
215
216   /* USER CODE BEGIN SPI3_Init 0 */
217
218   /* USER CODE END SPI3_Init 0 */
219
220   /* USER CODE BEGIN SPI3_Init 1 */
221
222   /* USER CODE END SPI3_Init 1 */
223   /* SPI3 parameter configuration*/
224   hspi3.Instance = SPI3;
225   hspi3.Init.Mode = SPI_MODE_MASTER;
226   hspi3.Init.Direction = SPI_DIRECTION_2LINES;
227   hspi3.Init.DataSize = SPI_DATASIZE_4BIT;
228   hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
229   hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
230   hspi3.Init.NSS = SPI_NSS_SOFT;
231   hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
232   hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
233   hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
234   hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
235   hspi3.Init.CRCPolynomial = 7;
236   hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
237   hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
238   if (HAL_SPI_Init(&hspi3) != HAL_OK)
239   {
240     Error_Handler();
241   }
242   /* USER CODE BEGIN SPI3_Init 2 */
243
244   /* USER CODE END SPI3_Init 2 */
245
246 }
247
248 /** 
249   * Enable DMA controller clock
250   */
251 static void MX_DMA_Init(void) 
252 {
253   /* DMA controller clock enable */
254   __HAL_RCC_DMA2_CLK_ENABLE();
255
256   /* DMA interrupt init */
257   /* DMA2_Channel1_IRQn interrupt configuration */
258   HAL_NVIC_SetPriority(DMA2_Channel1_IRQn, 7, 0);
259   HAL_NVIC_EnableIRQ(DMA2_Channel1_IRQn);
260   /* DMA2_Channel2_IRQn interrupt configuration */
261   HAL_NVIC_SetPriority(DMA2_Channel2_IRQn, 7, 0);
262   HAL_NVIC_EnableIRQ(DMA2_Channel2_IRQn);
263
264 }
265
266 /**
267   * @brief GPIO Initialization Function
268   * @param None
269   * @retval None
270   */
271 static void MX_GPIO_Init(void)
272 {
273   GPIO_InitTypeDef GPIO_InitStruct = {0};
274
275   /* GPIO Ports Clock Enable */
276   __HAL_RCC_GPIOC_CLK_ENABLE();
277   __HAL_RCC_GPIOE_CLK_ENABLE();
278   __HAL_RCC_GPIOB_CLK_ENABLE();
279
280   /*Configure GPIO pin Output Level */
281   HAL_GPIO_WritePin(GPIOE, ISM43362_RESET_Pin|ISM43362_SPI_NSS_Pin, GPIO_PIN_RESET);
282
283   /*Configure GPIO pin Output Level */
284   HAL_GPIO_WritePin(ISM43362_WAKEUP_GPIO_Port, ISM43362_WAKEUP_Pin, GPIO_PIN_RESET);
285
286   /*Configure GPIO pin : ISM43362_RESET_Pin */
287   GPIO_InitStruct.Pin = ISM43362_RESET_Pin;
288   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
289   GPIO_InitStruct.Pull = GPIO_NOPULL;
290   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
291   HAL_GPIO_Init(ISM43362_RESET_GPIO_Port, &GPIO_InitStruct);
292
293   /*Configure GPIO pin : ISM43362_WAKEUP_Pin */
294   GPIO_InitStruct.Pin = ISM43362_WAKEUP_Pin;
295   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
296   GPIO_InitStruct.Pull = GPIO_NOPULL;
297   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
298   HAL_GPIO_Init(ISM43362_WAKEUP_GPIO_Port, &GPIO_InitStruct);
299
300   /*Configure GPIO pin : ISM43362_SPI_NSS_Pin */
301   GPIO_InitStruct.Pin = ISM43362_SPI_NSS_Pin;
302   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
303   GPIO_InitStruct.Pull = GPIO_NOPULL;
304   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
305   HAL_GPIO_Init(ISM43362_SPI_NSS_GPIO_Port, &GPIO_InitStruct);
306
307   /*Configure GPIO pin : ISM43362_DATARDY_Pin */
308   GPIO_InitStruct.Pin = ISM43362_DATARDY_Pin;
309   GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
310   GPIO_InitStruct.Pull = GPIO_NOPULL;
311   HAL_GPIO_Init(ISM43362_DATARDY_GPIO_Port, &GPIO_InitStruct);
312
313   /* EXTI interrupt init*/
314   HAL_NVIC_SetPriority(EXTI1_IRQn, 8, 0);
315   HAL_NVIC_EnableIRQ(EXTI1_IRQn);
316
317 }
318
319 /* USER CODE BEGIN 4 */
320
321 /* USER CODE END 4 */
322
323 /**
324   * @brief  This function is executed in case of error occurrence.
325   * @retval None
326   */
327 void Error_Handler(void)
328 {
329   /* USER CODE BEGIN Error_Handler_Debug */
330   /* User can add his own implementation to report the HAL error return state */
331   while(1)
332   {
333   }
334   /* USER CODE END Error_Handler_Debug */
335 }
336
337 #ifdef  USE_FULL_ASSERT
338 /**
339   * @brief  Reports the name of the source file and the source line number
340   *         where the assert_param error has occurred.
341   * @param  file: pointer to the source file name
342   * @param  line: assert_param error line source number
343   * @retval None
344   */
345 void assert_failed(char *file, uint32_t line)
346
347   /* USER CODE BEGIN 6 */
348   /* User can add his own implementation to report the file name and line number,
349      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
350   /* USER CODE END 6 */
351 }
352 #endif /* USE_FULL_ASSERT */
353
354 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/