Stima V4 Slave RAIN  4.2
module_slave_hal.cpp
Go to the documentation of this file.
1 
31 #include "stm32l4xx_ll_system.h"
32 #include "stm32l4xx_ll_cortex.h"
33 
34 #if (ENABLE_I2C2)
35 TwoWire Wire2 = TwoWire(PIN_I2C2_SDA, PIN_I2C2_SCL);
36 #endif
37 
38 /* Private Hardware_Handler istance initialization ---------------------------------------*/
39 #if (ENABLE_CAN)
40 CAN_HandleTypeDef hcan1;
41 #endif
42 #if (ENABLE_QSPI)
43 QSPI_HandleTypeDef hqspi;
44 #endif
45 
46 // ********************************************************************************
47 // LOCAL REDEFINITION Weak PinMap ARDUINO for SETUP PIN Base or Alternate Function
48 // ********************************************************************************
49 
50 #ifdef HAL_ADC_MODULE_ENABLED
51 const PinMap PinMap_ADC[] = {
52  {PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9
53  {PC_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1
54  {PC_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2
55  {PC_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3
56  {PC_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4
57  {NC, NP, 0}
58 };
59 #endif
60 
61 #ifdef HAL_DAC_MODULE_ENABLED
62 const PinMap PinMap_DAC[] = {
63  {NC, NP, 0}
64 };
65 #endif
66 
67 #ifdef HAL_I2C_MODULE_ENABLED
68 const PinMap PinMap_I2C_SDA[] = {
69  {PB_7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
70  {PB_14, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
71  {NC, NP, 0}
72 };
73 const PinMap PinMap_I2C_SCL[] = {
74  {PB_6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
75  {PB_10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
76  {NC, NP, 0}
77 };
78 #endif
79 
80 #ifdef HAL_TIM_MODULE_ENABLED
81 const PinMap PinMap_TIM[] = {
82  {NC, NP, 0}
83 };
84 #endif
85 
86 #ifdef HAL_UART_MODULE_ENABLED
87 const PinMap PinMap_UART_TX[] = {
88  {PA_2_ALT1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
89  {PA_9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
90  {NC, NP, 0}
91 };
92 const PinMap PinMap_UART_RX[] = {
93  {PA_10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
94  {PA_15, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_USART2)},
95  {NC, NP, 0}
96 };
97 const PinMap PinMap_UART_RTS[] = {
98  {PA_1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
99  {NC, NP, 0}
100 };
101 const PinMap PinMap_UART_CTS[] = {
102  {PA_0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
103  {NC, NP, 0}
104 };
105 #endif
106 
107 #ifdef HAL_SPI_MODULE_ENABLED
108 const PinMap PinMap_SPI_MOSI[] = {
109  {PA_12, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
110  {NC, NP, 0}
111 };
112 const PinMap PinMap_SPI_MISO[] = {
113  {PA_11, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
114  {NC, NP, 0}
115 };
116 const PinMap PinMap_SPI_SCLK[] = {
117  {PA_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
118  {NC, NP, 0}
119 };
120 const PinMap PinMap_SPI_SSEL[] = {
121  {NC, NP, 0}
122 };
123 #endif
124 
125 #ifdef HAL_CAN_MODULE_ENABLED
126 const PinMap PinMap_CAN_RD[] = {
127  {PB_12, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_CAN1)},
128  {NC, NP, 0}
129 };
130 const PinMap PinMap_CAN_TD[] = {
131  {PB_13, CAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_CAN1)},
132  {NC, NP, 0}
133 };
134 #endif
135 
136 #ifdef HAL_QSPI_MODULE_ENABLED
137 const PinMap PinMap_QUADSPI_DATA0[] = {
138  {PB_1, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK1_IO0
139  {NC, NP, 0}
140 };
141 const PinMap PinMap_QUADSPI_DATA1[] = {
142  {PB_0, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK1_IO1
143  {NC, NP, 0}
144 };
145 const PinMap PinMap_QUADSPI_DATA2[] = {
146  {PA_7, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK1_IO2
147  {NC, NP, 0}
148 };
149 const PinMap PinMap_QUADSPI_DATA3[] = {
150  {PA_6, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK1_IO3
151  {NC, NP, 0}
152 };
153 const PinMap PinMap_QUADSPI_SCLK[] = {
154  {PA_3, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_CLK
155  {NC, NP, 0}
156 };
157 const PinMap PinMap_QUADSPI_SSEL[] = {
158  {PB_11, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK1_NCS
159  {NC, NP, 0}
160 };
161 #endif
162 
163 #if defined(HAL_PCD_MODULE_ENABLED) || defined(HAL_HCD_MODULE_ENABLED)
164 const PinMap PinMap_USB[] = {
165  {NC, NP, 0}
166 };
167 #endif
168 
169 #ifdef HAL_SD_MODULE_ENABLED
170 const PinMap PinMap_SD[] = {
171  {NC, NP, 0}
172 };
173 #endif
174 
175 /* Private Hardware_Handler istance initialization ---------------------------------------*/
176 
177 /*******************************************************************************************
178 ********************************************************************************************
179  System clock and private setup PIN (VBat/Chg, PLLSynch)
180 ********************************************************************************************
181 *******************************************************************************************/
183 extern "C" void SystemClock_Config(void)
184 {
185  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
186  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
187  RCC_CRSInitTypeDef RCC_CRSInitStruct = {0};
188 
191  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
192  {
193  Error_Handler();
194  }
195 
198  HAL_PWR_EnableBkUpAccess();
199  __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
200 
204  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
205  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
206  RCC_OscInitStruct.MSIState = RCC_MSI_ON;
207  RCC_OscInitStruct.MSICalibrationValue = 0;
208  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
209  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
210  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
211  RCC_OscInitStruct.PLL.PLLM = 1;
212  RCC_OscInitStruct.PLL.PLLN = 40;
213  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
214  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
215  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
216  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
217  {
218  Error_Handler();
219  }
220 
223  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
224  |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
225  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
226  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
227  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
228  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
229 
230  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
231  {
232  Error_Handler();
233  }
234 
237  HAL_RCCEx_EnableMSIPLLMode();
238 
241  __HAL_RCC_CRS_CLK_ENABLE();
242 
245  RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1;
246  RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_LSE;
247  RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING;
248  RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000,32768);
249  RCC_CRSInitStruct.ErrorLimitValue = 34;
250  RCC_CRSInitStruct.HSI48CalibrationValue = 32;
251 
252  HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct);
253 }
254 
257 
258  FLASH_OBProgramInitTypeDef OBInit; // flash option bytes copy
259 
260  /* get flash option bytes */
261  OBInit.WRPArea = OB_WRPAREA_BANK1_AREAA;
262  OBInit.PCROPConfig = FLASH_BANK_1;
263  HAL_FLASHEx_OBGetConfig(&OBInit);
264 
265  /* config flash option bytes */
266  if ((OBInit.USERConfig & OB_IWDG_STOP_RUN) == OB_IWDG_STOP_RUN) {
267  OBInit.OptionType = OPTIONBYTE_USER;
268  OBInit.USERType = OB_USER_IWDG_STOP | OB_USER_IWDG_STDBY;
269  OBInit.USERConfig = OB_IWDG_STOP_FREEZE | OB_IWDG_STDBY_FREEZE;
270 
271  HAL_FLASH_Unlock();
272  HAL_FLASH_OB_Unlock();
273  HAL_FLASHEx_OBProgram(&OBInit);
274  HAL_FLASH_OB_Launch();
275  HAL_FLASH_OB_Lock();
276  HAL_FLASH_Lock();
277  }
278 
280  CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
281  DWT->CYCCNT = 0;
282  DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
283 
284  // Enable Handler Fault Error
285  LL_HANDLER_EnableFault(LL_HANDLER_FAULT_USG);
286  LL_HANDLER_EnableFault(LL_HANDLER_FAULT_BUS);
287  LL_HANDLER_EnableFault(LL_HANDLER_FAULT_MEM);
288 
289  MX_GPIO_Init();
290 
291  #if (ENABLE_CAN)
292  MX_CAN1_Init();
293  #endif
294  #if (ENABLE_QSPI)
295  MX_QUADSPI_Init();
296  #endif
297 
298  /* Abilito la carica del supercap */
299  HAL_PWREx_EnableBatteryCharging(PWR_BATTERY_CHARGING_RESISTOR_5);
300 }
301 
304 void STM32L4GetCPUID(uint8_t *ptrCpuId) {
305  for(uint8_t uid=0; uid<12; uid++) {
306  ptrCpuId[uid++] = (uint8_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + uid))));
307  }
308 }
309 
312 uint64_t StimaV4GetSerialNumber(void) {
313  volatile uint64_t serNumb = 0;
314  uint8_t *ptrData = (uint8_t*)&serNumb;
315  ptrData[0] = MODULE_TYPE;
316  ptrData[1] = (uint8_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS))));
317  ptrData[2] = (uint8_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 10))));
318  ptrData[3] = (uint8_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 9))));
319  ptrData[4] = (uint8_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 7))));
320  ptrData[5] = (uint8_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 6))));
321  ptrData[6] = (uint8_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 5))));
322  ptrData[7] = (uint8_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 4))));
323  return serNumb;
324 }
325 
326 /*******************************************************************************************
327 ********************************************************************************************
328  System base Hardware Istance and private Initialization
329 ********************************************************************************************
330 *******************************************************************************************/
331 #if (ENABLE_CAN)
333 extern "C" void MX_CAN1_Init(void)
334 {
335  CAN_FilterTypeDef CAN_FilterInitStruct;
336 
337  // Default Speed Base CAN Setup module 1Mhz
338  hcan1.Instance = CAN1;
339  hcan1.Init.Prescaler = 8;
340  hcan1.Init.Mode = CAN_MODE_NORMAL;
341  hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
342  hcan1.Init.TimeSeg1 = CAN_BS1_8TQ;
343  hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;
344  hcan1.Init.TimeTriggeredMode = DISABLE;
345  hcan1.Init.AutoBusOff = DISABLE;
346  hcan1.Init.AutoWakeUp = DISABLE;
347  hcan1.Init.AutoRetransmission = DISABLE;
348  hcan1.Init.ReceiveFifoLocked = DISABLE;
349  hcan1.Init.TransmitFifoPriority = DISABLE;
350  if (HAL_CAN_Init(&hcan1) != HAL_OK) {
351  Error_Handler();
352  }
353 
354  // CAN filter basic initialization
355  CAN_FilterInitStruct.FilterIdHigh = 0x0000;
356  CAN_FilterInitStruct.FilterIdLow = 0x0000;
357  CAN_FilterInitStruct.FilterMaskIdHigh = 0x0000;
358  CAN_FilterInitStruct.FilterMaskIdLow = 0x0000;
359  CAN_FilterInitStruct.FilterFIFOAssignment = CAN_RX_FIFO0;
360  CAN_FilterInitStruct.FilterBank = 0;
361  CAN_FilterInitStruct.FilterMode = CAN_FILTERMODE_IDMASK;
362  CAN_FilterInitStruct.FilterScale = CAN_FILTERSCALE_32BIT;
363  CAN_FilterInitStruct.FilterActivation = ENABLE;
364 
365  // Check error initalization CAN filter
366  if (HAL_CAN_ConfigFilter(&hcan1, &CAN_FilterInitStruct) != HAL_OK) {
367  Error_Handler();
368  }
369 }
370 #endif
371 
372 #if (ENABLE_QSPI)
374 extern "C" void MX_QUADSPI_Init(void)
375 {
376  /* USER CODE BEGIN QUADSPI_Init 0 */
377 
378  /* USER CODE END QUADSPI_Init 0 */
379 
380  /* USER CODE BEGIN QUADSPI_Init 1 */
381 
382  /* USER CODE END QUADSPI_Init 1 */
383  /* QUADSPI parameter configuration*/
384  hqspi.Instance = QUADSPI;
385  hqspi.Init.ClockPrescaler = 1;
386  hqspi.Init.FifoThreshold = 4;
387  hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_NONE;
388  hqspi.Init.FlashSize = 20;
389  hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_1_CYCLE;
390  hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
391  hqspi.Init.FlashID = QSPI_FLASH_ID_1;
392  hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
393  if (HAL_QSPI_Init(&hqspi) != HAL_OK)
394  {
395  Error_Handler();
396  }
397  /* USER CODE BEGIN QUADSPI_Init 2 */
398 
399  /* USER CODE END QUADSPI_Init 2 */
400 }
401 #endif
402 
404 extern "C" void MX_GPIO_Init(void)
405 {
406  GPIO_InitTypeDef GPIO_InitStruct = {0};
407 
408  /* GPIO Ports Clock Enable */
409  __HAL_RCC_GPIOC_CLK_ENABLE();
410  __HAL_RCC_GPIOA_CLK_ENABLE();
411  __HAL_RCC_GPIOB_CLK_ENABLE();
412  __HAL_RCC_GPIOD_CLK_ENABLE();
413 #ifdef STIMAV4_SLAVE_HW_VER_01_01
414  __HAL_RCC_GPIOH_CLK_ENABLE();
415 #endif
416 
417  /*Configure GPIO pins : DEN_Pin DSEL0_Pin DSEL1_Pin PW0_Pin
418  PW1_Pin PW2_Pin PW3_Pin I2C2_EN_Pin
419  EN_CAN_Pin */
420  GPIO_InitStruct.Pin = DEN_Pin|DSEL0_Pin|DSEL1_Pin|PW0_Pin
422  |EN_CAN_Pin;
423  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
424  GPIO_InitStruct.Pull = GPIO_NOPULL;
425  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
426  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
427 
428  /*Configure GPIO pins : IN0_Pin FAULT_Pin IN2_Pin */
429  GPIO_InitStruct.Pin = IN0_Pin|FAULT_Pin|IN2_Pin;
430  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
431  GPIO_InitStruct.Pull = GPIO_NOPULL;
432  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
433 
434  /*Configure GPIO pins : STB_CAN_Pin EN_5VS_Pin EN_5VA_Pin */
435  GPIO_InitStruct.Pin = STB_CAN_Pin|EN_5VS_Pin|EN_5VA_Pin;
436  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
437  GPIO_InitStruct.Pull = GPIO_NOPULL;
438  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
439  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
440 
441  /*Configure GPIO pin : IN1_Pin */
442  GPIO_InitStruct.Pin = IN1_Pin;
443  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
444  GPIO_InitStruct.Pull = GPIO_NOPULL;
445  HAL_GPIO_Init(IN1_GPIO_Port, &GPIO_InitStruct);
446 
447  /*Configure GPIO pin : EN_SPLY_Pin */
448  GPIO_InitStruct.Pin = EN_SPLY_Pin;
449  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
450  GPIO_InitStruct.Pull = GPIO_NOPULL;
451  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
452  HAL_GPIO_Init(EN_SPLY_GPIO_Port, &GPIO_InitStruct);
453 
454 #ifdef STIMAV4_SLAVE_HW_VER_01_01
455  /*Configure GPIO pin : IN_BTN_Pin */
456  GPIO_InitStruct.Pin = IN_BTN_Pin;
457  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
458  GPIO_InitStruct.Pull = GPIO_NOPULL;
459  HAL_GPIO_Init(IN_BTN_GPIO_Port, &GPIO_InitStruct);
460 #endif
461 
462  /*Configure GPIO pin Output Level */
463  HAL_GPIO_WritePin(GPIOC, DEN_Pin|DSEL0_Pin|DSEL1_Pin|PW0_Pin
465  |EN_CAN_Pin, GPIO_PIN_RESET);
466 
467  /*Configure GPIO pin Output Level */
468  HAL_GPIO_WritePin(GPIOB, STB_CAN_Pin|EN_5VS_Pin|EN_5VA_Pin, GPIO_PIN_RESET);
469 
470  /*Configure GPIO pin Output Level */
471  HAL_GPIO_WritePin(EN_SPLY_GPIO_Port, EN_SPLY_Pin, GPIO_PIN_RESET);
472 }
473 
474 /*******************************************************************************************
475 ********************************************************************************************
476  PRIVATE HAL_MspInit_XXModule
477 ********************************************************************************************
478 *******************************************************************************************/
479 
481 extern "C" void HAL_MspInit(void)
482 {
483  /* USER CODE BEGIN MspInit 0 */
484 
485  /* USER CODE END MspInit 0 */
486  PWR_PVDTypeDef sConfigPVD = {0};
487 
488  // Control debugger StopMode
489  if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) {
490  LL_DBGMCU_EnableDBGStopMode();
491  } else {
492  LL_DBGMCU_DisableDBGStopMode();
493  }
494 
495  __HAL_RCC_SYSCFG_CLK_ENABLE();
496  __HAL_RCC_PWR_CLK_ENABLE();
497 
500  sConfigPVD.PVDLevel = PWR_PVDLEVEL_0;
501  sConfigPVD.Mode = PWR_PVD_MODE_NORMAL;
502  HAL_PWR_ConfigPVD(&sConfigPVD);
503 
506  HAL_PWR_EnablePVD();
507 
508  /* USER CODE BEGIN MspInit 1 */
509 
510  /* USER CODE END MspInit 1 */
511 }
512 
513 #if (ENABLE_CAN)
516 extern "C" void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
517 {
518  GPIO_InitTypeDef GPIO_InitStruct = {0};
519  if(hcan->Instance==CAN1)
520  {
521  /* USER CODE BEGIN CAN1_MspInit 0 */
522 
523  /* USER CODE END CAN1_MspInit 0 */
524 
525  // GPIO Ports clock enable
526  __HAL_RCC_GPIOB_CLK_ENABLE();
527 
528  // CAN1 clock enable
529  __HAL_RCC_CAN1_CLK_ENABLE();
530 
531  // Mapping GPIO for CAN
532  /* Configure CAN pin: RX */
533  GPIO_InitStruct.Pin = GPIO_PIN_12;
534  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
535  GPIO_InitStruct.Pull = GPIO_NOPULL;
536  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
537  GPIO_InitStruct.Alternate = GPIO_AF10_CAN1;
538  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
539  /* Configure CAN pin: TX */
540  GPIO_InitStruct.Pin = GPIO_PIN_13;
541  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
542  GPIO_InitStruct.Pull = GPIO_PULLUP;
543  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
544  GPIO_InitStruct.Alternate = GPIO_AF10_CAN1;
545  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
546  /* USER CODE BEGIN CAN1_MspInit 1 */
547 
548  /* USER CODE END CAN1_MspInit 1 */
549  }
550 }
551 
554 extern "C" void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)
555 {
556  if(hcan->Instance==CAN1)
557  {
558  /* USER CODE BEGIN CAN1_MspDeInit 0 */
559 
560  /* USER CODE END CAN1_MspDeInit 0 */
561  /* Peripheral clock disable */
562  __HAL_RCC_CAN1_CLK_DISABLE();
563 
568  HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13);
569 
570  /* USER CODE BEGIN CAN1_MspDeInit 1 */
571 
572  /* USER CODE END CAN1_MspDeInit 1 */
573  }
574 
575 }
576 #endif
577 
578 #if (ENABLE_QSPI)
581 extern "C" void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)
582 {
583  GPIO_InitTypeDef GPIO_InitStruct = {0};
584  if(hqspi->Instance==QUADSPI)
585  {
586  /* USER CODE BEGIN QUADSPI_MspInit 0 */
587 
588  /* USER CODE END QUADSPI_MspInit 0 */
589  /* Peripheral clock enable */
590  __HAL_RCC_QSPI_CLK_ENABLE();
591 
592  __HAL_RCC_GPIOA_CLK_ENABLE();
593  __HAL_RCC_GPIOB_CLK_ENABLE();
602  GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7;
603  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
604  GPIO_InitStruct.Pull = GPIO_NOPULL;
605  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
606  GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
607  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
608 
609  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_11;
610  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
611  GPIO_InitStruct.Pull = GPIO_NOPULL;
612  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
613  GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
614  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
615 
616  /* QUADSPI interrupt Init */
617  HAL_NVIC_SetPriority(QUADSPI_IRQn, QSPI_NVIC_INT_PREMPT_PRIORITY, 0);
618  HAL_NVIC_EnableIRQ(QUADSPI_IRQn);
619  /* USER CODE BEGIN QUADSPI_MspInit 1 */
620 
621  /* USER CODE END QUADSPI_MspInit 1 */
622  }
623 
624 }
625 
628 void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi)
629 {
630  if(hqspi->Instance==QUADSPI)
631  {
632  /* USER CODE BEGIN QUADSPI_MspDeInit 0 */
633 
634  /* USER CODE END QUADSPI_MspDeInit 0 */
635  /* Peripheral clock disable */
636  __HAL_RCC_QSPI_CLK_DISABLE();
637 
646  HAL_GPIO_DeInit(GPIOA, GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7);
647 
648  HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_11);
649 
650  /* QUADSPI interrupt DeInit */
651  HAL_NVIC_DisableIRQ(QUADSPI_IRQn);
652  /* USER CODE BEGIN QUADSPI_MspDeInit 1 */
653 
654  /* USER CODE END QUADSPI_MspDeInit 1 */
655  }
656 
657 }
658 #endif
#define MODULE_TYPE
Type of module. It is defined in registers.h.
Definition: config.h:55
void MX_CAN1_Init(void)
CAN1 Initialization Function.
void SetupSystemPeripheral(void)
Startup PeripheralConfig Local Board.
CAN_HandleTypeDef hcan1
void STM32L4GetCPUID(uint8_t *ptrCpuId)
Get Unique ID HW of CPU (SerialNumber Unique ID)
uint64_t StimaV4GetSerialNumber(void)
Get StimaV4 Serial Number from UID Cpu and Module TYPE.
void SystemClock_Config(void)
System Clock Configuration.
void HAL_CAN_MspDeInit(CAN_HandleTypeDef *hcan)
CAN MSP De-Initialization. This function freeze the hardware resources used in this example.
void HAL_CAN_MspInit(CAN_HandleTypeDef *hcan)
CAN MSP Initialization. This function configures the hardware resources used in this example.
void MX_GPIO_Init(void)
GPIO Initialization Function.
void HAL_MspInit(void)
Initializes the Global MSP.
Interface STM32 hardware_hal STIMAV4 Header config.
#define PW3_Pin
#define EN_5VA_Pin
#define PW2_Pin
#define IN2_Pin
#define PIN_I2C2_SDA
#define I2C2_EN_Pin
#define PW1_Pin
#define FAULT_Pin
#define DEN_Pin
#define STB_CAN_Pin
#define EN_SPLY_Pin
#define EN_5VS_Pin
#define UID_BASE_ADDRESS
#define IN1_GPIO_Port
#define DSEL0_Pin
#define EN_SPLY_GPIO_Port
#define IN1_Pin
#define DSEL1_Pin
#define EN_CAN_Pin
#define PIN_I2C2_SCL
#define IN0_Pin
#define PW0_Pin