1 /* USER CODE BEGIN Header */
3 ******************************************************************************
5 * @brief : Main program body
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2019 STMicroelectronics.
10 * All rights reserved.</center></h2>
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
17 ******************************************************************************
19 /* USER CODE END Header */
21 /* Includes ------------------------------------------------------------------*/
24 /* Private includes ----------------------------------------------------------*/
25 /* USER CODE BEGIN Includes */
26 #include "cmsis_dv.h" // ARM.API::CMSIS Driver Validation:Framework
28 extern void WiFi_ISM43362_Pin_DATARDY_IRQ (void);
29 /* USER CODE END Includes */
31 /* Private typedef -----------------------------------------------------------*/
32 /* USER CODE BEGIN PTD */
34 /* USER CODE END PTD */
36 /* Private define ------------------------------------------------------------*/
37 /* USER CODE BEGIN PD */
39 /* USER CODE END PD */
41 /* Private macro -------------------------------------------------------------*/
42 /* USER CODE BEGIN PM */
44 /* USER CODE END PM */
46 /* Private variables ---------------------------------------------------------*/
47 SPI_HandleTypeDef hspi3;
48 DMA_HandleTypeDef hdma_spi3_rx;
49 DMA_HandleTypeDef hdma_spi3_tx;
51 /* USER CODE BEGIN PV */
53 /* USER CODE END PV */
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 */
62 /* USER CODE END PFP */
64 /* Private user code ---------------------------------------------------------*/
65 /* USER CODE BEGIN 0 */
68 * Override default HAL_GetTick function
71 volatile uint32_t DEBUG_Tick = 0;
72 uint32_t HAL_GetTick (void) {
73 static uint32_t ticks = 0U;
76 if (osKernelGetState () == osKernelRunning) {
77 DEBUG_Tick = osKernelGetTickCount ();
78 return ((uint32_t)osKernelGetTickCount ());
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();
91 * @brief EXTI line detection callback.
92 * @param GPIO_Pin: Specifies the port pin connected to corresponding EXTI line.
95 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
97 if (GPIO_Pin == GPIO_PIN_1) {
98 WiFi_ISM43362_Pin_DATARDY_IRQ();
102 /* USER CODE END 0 */
105 * @brief The application entry point.
110 /* USER CODE BEGIN 1 */
112 /* USER CODE END 1 */
114 /* MCU Configuration--------------------------------------------------------*/
116 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
119 /* USER CODE BEGIN Init */
121 /* USER CODE END Init */
123 /* Configure the system clock */
124 SystemClock_Config();
126 /* USER CODE BEGIN SysInit */
127 SystemCoreClockUpdate();
128 /* USER CODE END SysInit */
130 /* Initialize all configured peripherals */
134 /* USER CODE BEGIN 2 */
136 osKernelInitialize (); /* Initialize CMSIS-RTOS2 */
137 osThreadNew(cmsis_dv, NULL, NULL); /* Create validation main thread */
138 osKernelStart(); /* Start thread execution */
140 /* USER CODE END 2 */
143 /* USER CODE BEGIN WHILE */
146 /* USER CODE END WHILE */
148 /* USER CODE BEGIN 3 */
150 /* USER CODE END 3 */
154 * @brief System Clock Configuration
157 void SystemClock_Config(void)
159 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
160 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
162 /** Configure LSE Drive Capability
164 HAL_PWR_EnableBkUpAccess();
165 __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
166 /** Initializes the CPU, AHB and APB busses clocks
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)
184 /** Initializes the CPU, AHB and APB busses clocks
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;
193 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
197 /** Configure the main internal regulator output voltage
199 if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
203 /** Enable MSI Auto calibration
205 HAL_RCCEx_EnableMSIPLLMode();
209 * @brief SPI3 Initialization Function
213 static void MX_SPI3_Init(void)
216 /* USER CODE BEGIN SPI3_Init 0 */
218 /* USER CODE END SPI3_Init 0 */
220 /* USER CODE BEGIN SPI3_Init 1 */
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)
242 /* USER CODE BEGIN SPI3_Init 2 */
244 /* USER CODE END SPI3_Init 2 */
249 * Enable DMA controller clock
251 static void MX_DMA_Init(void)
253 /* DMA controller clock enable */
254 __HAL_RCC_DMA2_CLK_ENABLE();
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);
267 * @brief GPIO Initialization Function
271 static void MX_GPIO_Init(void)
273 GPIO_InitTypeDef GPIO_InitStruct = {0};
275 /* GPIO Ports Clock Enable */
276 __HAL_RCC_GPIOC_CLK_ENABLE();
277 __HAL_RCC_GPIOE_CLK_ENABLE();
278 __HAL_RCC_GPIOB_CLK_ENABLE();
280 /*Configure GPIO pin Output Level */
281 HAL_GPIO_WritePin(GPIOE, ISM43362_RESET_Pin|ISM43362_SPI_NSS_Pin, GPIO_PIN_RESET);
283 /*Configure GPIO pin Output Level */
284 HAL_GPIO_WritePin(ISM43362_WAKEUP_GPIO_Port, ISM43362_WAKEUP_Pin, GPIO_PIN_RESET);
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);
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);
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);
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);
313 /* EXTI interrupt init*/
314 HAL_NVIC_SetPriority(EXTI1_IRQn, 8, 0);
315 HAL_NVIC_EnableIRQ(EXTI1_IRQn);
319 /* USER CODE BEGIN 4 */
321 /* USER CODE END 4 */
324 * @brief This function is executed in case of error occurrence.
327 void Error_Handler(void)
329 /* USER CODE BEGIN Error_Handler_Debug */
330 /* User can add his own implementation to report the HAL error return state */
334 /* USER CODE END Error_Handler_Debug */
337 #ifdef USE_FULL_ASSERT
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
345 void assert_failed(char *file, uint32_t line)
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 */
352 #endif /* USE_FULL_ASSERT */
354 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/