[FL-1587] RFID: Clock for emulation timer from antenna (#622)
* RFID: pull antenna down when emulating * Rfid: fixed HID emulation by adding zero pulse every 4 bits * Rfid: HID emulation fixed with DSP based FSK oscillator. * Rfid: receive 125KHz clock for emulation timer from antenna and comparator * Rfid: commented unused variable * Firmware: rollback changes in f6. * Add F7 target based on F6. * F7/F6: update cube projects, apply changes to the targets, update linker scripts with correct RAM start values. * FuriHal: RFID init routine. * Scripts: update OTP tool for v11 board Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
		
							
								
								
									
										139
									
								
								firmware/targets/f7/cube/Src/adc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										139
									
								
								firmware/targets/f7/cube/Src/adc.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,139 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    adc.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of the ADC instances. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "adc.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| ADC_HandleTypeDef hadc1; | ||||
|  | ||||
| /* ADC1 init function */ | ||||
| void MX_ADC1_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN ADC1_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END ADC1_Init 0 */ | ||||
|  | ||||
|   ADC_ChannelConfTypeDef sConfig = {0}; | ||||
|  | ||||
|   /* USER CODE BEGIN ADC1_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END ADC1_Init 1 */ | ||||
|   /** Common config | ||||
|   */ | ||||
|   hadc1.Instance = ADC1; | ||||
|   hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; | ||||
|   hadc1.Init.Resolution = ADC_RESOLUTION_12B; | ||||
|   hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; | ||||
|   hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; | ||||
|   hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; | ||||
|   hadc1.Init.LowPowerAutoWait = DISABLE; | ||||
|   hadc1.Init.ContinuousConvMode = DISABLE; | ||||
|   hadc1.Init.NbrOfConversion = 1; | ||||
|   hadc1.Init.DiscontinuousConvMode = DISABLE; | ||||
|   hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; | ||||
|   hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; | ||||
|   hadc1.Init.DMAContinuousRequests = DISABLE; | ||||
|   hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; | ||||
|   hadc1.Init.OversamplingMode = DISABLE; | ||||
|   if (HAL_ADC_Init(&hadc1) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /** Configure Regular Channel | ||||
|   */ | ||||
|   sConfig.Channel = ADC_CHANNEL_14; | ||||
|   sConfig.Rank = ADC_REGULAR_RANK_1; | ||||
|   sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5; | ||||
|   sConfig.SingleDiff = ADC_SINGLE_ENDED; | ||||
|   sConfig.OffsetNumber = ADC_OFFSET_NONE; | ||||
|   sConfig.Offset = 0; | ||||
|   if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN ADC1_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END ADC1_Init 2 */ | ||||
|  | ||||
| } | ||||
|  | ||||
| void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) | ||||
| { | ||||
|  | ||||
|   GPIO_InitTypeDef GPIO_InitStruct = {0}; | ||||
|   if(adcHandle->Instance==ADC1) | ||||
|   { | ||||
|   /* USER CODE BEGIN ADC1_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END ADC1_MspInit 0 */ | ||||
|     /* ADC1 clock enable */ | ||||
|     __HAL_RCC_ADC_CLK_ENABLE(); | ||||
|  | ||||
|     __HAL_RCC_GPIOC_CLK_ENABLE(); | ||||
|     /**ADC1 GPIO Configuration | ||||
|     PC5     ------> ADC1_IN14 | ||||
|     */ | ||||
|     GPIO_InitStruct.Pin = RFID_RF_IN_Pin; | ||||
|     GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | ||||
|     GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|     HAL_GPIO_Init(RFID_RF_IN_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|     /* ADC1 interrupt Init */ | ||||
|     HAL_NVIC_SetPriority(ADC1_IRQn, 5, 0); | ||||
|     HAL_NVIC_EnableIRQ(ADC1_IRQn); | ||||
|   /* USER CODE BEGIN ADC1_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END ADC1_MspInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) | ||||
| { | ||||
|  | ||||
|   if(adcHandle->Instance==ADC1) | ||||
|   { | ||||
|   /* USER CODE BEGIN ADC1_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END ADC1_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_ADC_CLK_DISABLE(); | ||||
|  | ||||
|     /**ADC1 GPIO Configuration | ||||
|     PC5     ------> ADC1_IN14 | ||||
|     */ | ||||
|     HAL_GPIO_DeInit(RFID_RF_IN_GPIO_Port, RFID_RF_IN_Pin); | ||||
|  | ||||
|     /* ADC1 interrupt Deinit */ | ||||
|     HAL_NVIC_DisableIRQ(ADC1_IRQn); | ||||
|   /* USER CODE BEGIN ADC1_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END ADC1_MspDeInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										147
									
								
								firmware/targets/f7/cube/Src/aes.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										147
									
								
								firmware/targets/f7/cube/Src/aes.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,147 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    aes.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of the AES instances. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "aes.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| CRYP_HandleTypeDef hcryp1; | ||||
| __ALIGN_BEGIN static const uint32_t pKeyAES1[4] __ALIGN_END = { | ||||
|                             0x00000000,0x00000000,0x00000000,0x00000000}; | ||||
| CRYP_HandleTypeDef hcryp2; | ||||
| __ALIGN_BEGIN static const uint32_t pKeyAES2[4] __ALIGN_END = { | ||||
|                             0x00000000,0x00000000,0x00000000,0x00000000}; | ||||
|  | ||||
| /* AES1 init function */ | ||||
| void MX_AES1_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN AES1_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END AES1_Init 0 */ | ||||
|  | ||||
|   /* USER CODE BEGIN AES1_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END AES1_Init 1 */ | ||||
|   hcryp1.Instance = AES1; | ||||
|   hcryp1.Init.DataType = CRYP_DATATYPE_32B; | ||||
|   hcryp1.Init.KeySize = CRYP_KEYSIZE_128B; | ||||
|   hcryp1.Init.pKey = (uint32_t *)pKeyAES1; | ||||
|   hcryp1.Init.Algorithm = CRYP_AES_ECB; | ||||
|   hcryp1.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD; | ||||
|   hcryp1.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS; | ||||
|   if (HAL_CRYP_Init(&hcryp1) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN AES1_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END AES1_Init 2 */ | ||||
|  | ||||
| } | ||||
| /* AES2 init function */ | ||||
| void MX_AES2_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN AES2_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END AES2_Init 0 */ | ||||
|  | ||||
|   /* USER CODE BEGIN AES2_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END AES2_Init 1 */ | ||||
|   hcryp2.Instance = AES2; | ||||
|   hcryp2.Init.DataType = CRYP_DATATYPE_32B; | ||||
|   hcryp2.Init.KeySize = CRYP_KEYSIZE_128B; | ||||
|   hcryp2.Init.pKey = (uint32_t *)pKeyAES2; | ||||
|   hcryp2.Init.Algorithm = CRYP_AES_ECB; | ||||
|   hcryp2.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD; | ||||
|   hcryp2.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS; | ||||
|   if (HAL_CRYP_Init(&hcryp2) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN AES2_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END AES2_Init 2 */ | ||||
|  | ||||
| } | ||||
|  | ||||
| void HAL_CRYP_MspInit(CRYP_HandleTypeDef* crypHandle) | ||||
| { | ||||
|  | ||||
|   if(crypHandle->Instance==AES1) | ||||
|   { | ||||
|   /* USER CODE BEGIN AES1_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END AES1_MspInit 0 */ | ||||
|     /* AES1 clock enable */ | ||||
|     __HAL_RCC_AES1_CLK_ENABLE(); | ||||
|   /* USER CODE BEGIN AES1_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END AES1_MspInit 1 */ | ||||
|   } | ||||
|   else if(crypHandle->Instance==AES2) | ||||
|   { | ||||
|   /* USER CODE BEGIN AES2_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END AES2_MspInit 0 */ | ||||
|     /* AES2 clock enable */ | ||||
|     __HAL_RCC_AES2_CLK_ENABLE(); | ||||
|   /* USER CODE BEGIN AES2_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END AES2_MspInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef* crypHandle) | ||||
| { | ||||
|  | ||||
|   if(crypHandle->Instance==AES1) | ||||
|   { | ||||
|   /* USER CODE BEGIN AES1_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END AES1_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_AES1_CLK_DISABLE(); | ||||
|   /* USER CODE BEGIN AES1_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END AES1_MspDeInit 1 */ | ||||
|   } | ||||
|   else if(crypHandle->Instance==AES2) | ||||
|   { | ||||
|   /* USER CODE BEGIN AES2_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END AES2_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_AES2_CLK_DISABLE(); | ||||
|   /* USER CODE BEGIN AES2_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END AES2_MspDeInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										183
									
								
								firmware/targets/f7/cube/Src/app_freertos.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										183
									
								
								firmware/targets/f7/cube/Src/app_freertos.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,183 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * File Name          : app_freertos.c | ||||
|   * Description        : Code for freertos applications | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "FreeRTOS.h" | ||||
| #include "task.h" | ||||
| #include "main.h" | ||||
| #include "cmsis_os.h" | ||||
|  | ||||
| /* Private includes ----------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN Includes */ | ||||
|  | ||||
| /* USER CODE END Includes */ | ||||
|  | ||||
| /* Private typedef -----------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PTD */ | ||||
|  | ||||
| /* USER CODE END PTD */ | ||||
|  | ||||
| /* Private define ------------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PD */ | ||||
|  | ||||
| /* USER CODE END PD */ | ||||
|  | ||||
| /* Private macro -------------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PM */ | ||||
|  | ||||
| /* USER CODE END PM */ | ||||
|  | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN Variables */ | ||||
|  | ||||
| /* USER CODE END Variables */ | ||||
| /* Definitions for app_main */ | ||||
| osThreadId_t app_mainHandle; | ||||
| const osThreadAttr_t app_main_attributes = { | ||||
|   .name = "app_main", | ||||
|   .priority = (osPriority_t) osPriorityNormal, | ||||
|   .stack_size = 1024 * 4 | ||||
| }; | ||||
|  | ||||
| /* Private function prototypes -----------------------------------------------*/ | ||||
| /* USER CODE BEGIN FunctionPrototypes */ | ||||
|  | ||||
| /* USER CODE END FunctionPrototypes */ | ||||
|  | ||||
| void app(void *argument); | ||||
|  | ||||
| void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ | ||||
|  | ||||
| /* Hook prototypes */ | ||||
| void configureTimerForRunTimeStats(void); | ||||
| unsigned long getRunTimeCounterValue(void); | ||||
| void vApplicationIdleHook(void); | ||||
| void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName); | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
| /* Functions needed when configGENERATE_RUN_TIME_STATS is on */ | ||||
| __weak void configureTimerForRunTimeStats(void) | ||||
| { | ||||
|  | ||||
| } | ||||
|  | ||||
| __weak unsigned long getRunTimeCounterValue(void) | ||||
| { | ||||
| return 0; | ||||
| } | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /* USER CODE BEGIN 2 */ | ||||
| void vApplicationIdleHook( void ) | ||||
| { | ||||
|    /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set | ||||
|    to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle | ||||
|    task. It is essential that code added to this hook function never attempts | ||||
|    to block in any way (for example, call xQueueReceive() with a block time | ||||
|    specified, or call vTaskDelay()). If the application makes use of the | ||||
|    vTaskDelete() API function (as this demo application does) then it is also | ||||
|    important that vApplicationIdleHook() is permitted to return to its calling | ||||
|    function, because it is the responsibility of the idle task to clean up | ||||
|    memory allocated by the kernel to any task that has since been deleted. */ | ||||
| } | ||||
| /* USER CODE END 2 */ | ||||
|  | ||||
| /* USER CODE BEGIN 4 */ | ||||
| void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName) | ||||
| { | ||||
|    /* Run time stack overflow checking is performed if | ||||
|    configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is | ||||
|    called if a stack overflow is detected. */ | ||||
| } | ||||
| /* USER CODE END 4 */ | ||||
|  | ||||
| /* USER CODE BEGIN VPORT_SUPPORT_TICKS_AND_SLEEP */ | ||||
| __weak void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) | ||||
| { | ||||
|   // Generated when configUSE_TICKLESS_IDLE == 2. | ||||
|   // Function called in tasks.c (in portTASK_FUNCTION). | ||||
|   // TO BE COMPLETED or TO BE REPLACED by a user one, overriding that weak one. | ||||
| } | ||||
| /* USER CODE END VPORT_SUPPORT_TICKS_AND_SLEEP */ | ||||
|  | ||||
| /** | ||||
|   * @brief  FreeRTOS initialization | ||||
|   * @param  None | ||||
|   * @retval None | ||||
|   */ | ||||
| void MX_FREERTOS_Init(void) { | ||||
|   /* USER CODE BEGIN Init */ | ||||
|  | ||||
|   /* USER CODE END Init */ | ||||
|  | ||||
|   /* USER CODE BEGIN RTOS_MUTEX */ | ||||
|   /* add mutexes, ... */ | ||||
|   /* USER CODE END RTOS_MUTEX */ | ||||
|  | ||||
|   /* USER CODE BEGIN RTOS_SEMAPHORES */ | ||||
|   /* add semaphores, ... */ | ||||
|   /* USER CODE END RTOS_SEMAPHORES */ | ||||
|  | ||||
|   /* USER CODE BEGIN RTOS_TIMERS */ | ||||
|   /* start timers, add new ones, ... */ | ||||
|   /* USER CODE END RTOS_TIMERS */ | ||||
|  | ||||
|   /* USER CODE BEGIN RTOS_QUEUES */ | ||||
|   /* add queues, ... */ | ||||
|   /* USER CODE END RTOS_QUEUES */ | ||||
|  | ||||
|   /* Create the thread(s) */ | ||||
|   /* creation of app_main */ | ||||
|   app_mainHandle = osThreadNew(app, NULL, &app_main_attributes); | ||||
|  | ||||
|   /* USER CODE BEGIN RTOS_THREADS */ | ||||
|   /* add threads, ... */ | ||||
|   /* USER CODE END RTOS_THREADS */ | ||||
|  | ||||
|   /* USER CODE BEGIN RTOS_EVENTS */ | ||||
|   /* add events, ... */ | ||||
|   /* USER CODE END RTOS_EVENTS */ | ||||
|  | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN Header_app */ | ||||
| /** | ||||
|   * @brief  Function implementing the app_main thread. | ||||
|   * @param  argument: Not used | ||||
|   * @retval None | ||||
|   */ | ||||
| /* USER CODE END Header_app */ | ||||
| __weak void app(void *argument) | ||||
| { | ||||
|   /* USER CODE BEGIN app */ | ||||
|   /* Infinite loop */ | ||||
|   for(;;) | ||||
|   { | ||||
|     osDelay(1); | ||||
|   } | ||||
|   /* USER CODE END app */ | ||||
| } | ||||
|  | ||||
| /* Private application code --------------------------------------------------*/ | ||||
| /* USER CODE BEGIN Application */ | ||||
|  | ||||
| /* USER CODE END Application */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										113
									
								
								firmware/targets/f7/cube/Src/comp.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								firmware/targets/f7/cube/Src/comp.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,113 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    comp.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of the COMP instances. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "comp.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| COMP_HandleTypeDef hcomp1; | ||||
|  | ||||
| /* COMP1 init function */ | ||||
| void MX_COMP1_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN COMP1_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END COMP1_Init 0 */ | ||||
|  | ||||
|   /* USER CODE BEGIN COMP1_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END COMP1_Init 1 */ | ||||
|   hcomp1.Instance = COMP1; | ||||
|   hcomp1.Init.InputMinus = COMP_INPUT_MINUS_1_4VREFINT; | ||||
|   hcomp1.Init.InputPlus = COMP_INPUT_PLUS_IO1; | ||||
|   hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED; | ||||
|   hcomp1.Init.Hysteresis = COMP_HYSTERESIS_HIGH; | ||||
|   hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE; | ||||
|   hcomp1.Init.Mode = COMP_POWERMODE_MEDIUMSPEED; | ||||
|   hcomp1.Init.WindowMode = COMP_WINDOWMODE_DISABLE; | ||||
|   hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING_FALLING; | ||||
|   if (HAL_COMP_Init(&hcomp1) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN COMP1_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END COMP1_Init 2 */ | ||||
|  | ||||
| } | ||||
|  | ||||
| void HAL_COMP_MspInit(COMP_HandleTypeDef* compHandle) | ||||
| { | ||||
|  | ||||
|   GPIO_InitTypeDef GPIO_InitStruct = {0}; | ||||
|   if(compHandle->Instance==COMP1) | ||||
|   { | ||||
|   /* USER CODE BEGIN COMP1_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END COMP1_MspInit 0 */ | ||||
|  | ||||
|     __HAL_RCC_GPIOC_CLK_ENABLE(); | ||||
|     /**COMP1 GPIO Configuration | ||||
|     PC5     ------> COMP1_INP | ||||
|     */ | ||||
|     GPIO_InitStruct.Pin = RFID_RF_IN_Pin; | ||||
|     GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | ||||
|     GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|     HAL_GPIO_Init(RFID_RF_IN_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|     /* COMP1 interrupt Init */ | ||||
|     HAL_NVIC_SetPriority(COMP_IRQn, 5, 0); | ||||
|     HAL_NVIC_EnableIRQ(COMP_IRQn); | ||||
|   /* USER CODE BEGIN COMP1_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END COMP1_MspInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| void HAL_COMP_MspDeInit(COMP_HandleTypeDef* compHandle) | ||||
| { | ||||
|  | ||||
|   if(compHandle->Instance==COMP1) | ||||
|   { | ||||
|   /* USER CODE BEGIN COMP1_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END COMP1_MspDeInit 0 */ | ||||
|  | ||||
|     /**COMP1 GPIO Configuration | ||||
|     PC5     ------> COMP1_INP | ||||
|     */ | ||||
|     HAL_GPIO_DeInit(RFID_RF_IN_GPIO_Port, RFID_RF_IN_Pin); | ||||
|  | ||||
|     /* COMP1 interrupt Deinit */ | ||||
|     HAL_NVIC_DisableIRQ(COMP_IRQn); | ||||
|   /* USER CODE BEGIN COMP1_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END COMP1_MspDeInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										92
									
								
								firmware/targets/f7/cube/Src/crc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								firmware/targets/f7/cube/Src/crc.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,92 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    crc.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of the CRC instances. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "crc.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| CRC_HandleTypeDef hcrc; | ||||
|  | ||||
| /* CRC init function */ | ||||
| void MX_CRC_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN CRC_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END CRC_Init 0 */ | ||||
|  | ||||
|   /* USER CODE BEGIN CRC_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END CRC_Init 1 */ | ||||
|   hcrc.Instance = CRC; | ||||
|   hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; | ||||
|   hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE; | ||||
|   hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE; | ||||
|   hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE; | ||||
|   hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES; | ||||
|   if (HAL_CRC_Init(&hcrc) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN CRC_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END CRC_Init 2 */ | ||||
|  | ||||
| } | ||||
|  | ||||
| void HAL_CRC_MspInit(CRC_HandleTypeDef* crcHandle) | ||||
| { | ||||
|  | ||||
|   if(crcHandle->Instance==CRC) | ||||
|   { | ||||
|   /* USER CODE BEGIN CRC_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END CRC_MspInit 0 */ | ||||
|     /* CRC clock enable */ | ||||
|     __HAL_RCC_CRC_CLK_ENABLE(); | ||||
|   /* USER CODE BEGIN CRC_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END CRC_MspInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| void HAL_CRC_MspDeInit(CRC_HandleTypeDef* crcHandle) | ||||
| { | ||||
|  | ||||
|   if(crcHandle->Instance==CRC) | ||||
|   { | ||||
|   /* USER CODE BEGIN CRC_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END CRC_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_CRC_CLK_DISABLE(); | ||||
|   /* USER CODE BEGIN CRC_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END CRC_MspDeInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										181
									
								
								firmware/targets/f7/cube/Src/gpio.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										181
									
								
								firmware/targets/f7/cube/Src/gpio.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,181 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    gpio.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of all used GPIO pins. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "gpio.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| /*----------------------------------------------------------------------------*/ | ||||
| /* Configure GPIO                                                             */ | ||||
| /*----------------------------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /** Configure pins as | ||||
|         * Analog | ||||
|         * Input | ||||
|         * Output | ||||
|         * EVENT_OUT | ||||
|         * EXTI | ||||
| */ | ||||
| void MX_GPIO_Init(void) | ||||
| { | ||||
|  | ||||
|   GPIO_InitTypeDef GPIO_InitStruct = {0}; | ||||
|  | ||||
|   /* GPIO Ports Clock Enable */ | ||||
|   __HAL_RCC_GPIOC_CLK_ENABLE(); | ||||
|   __HAL_RCC_GPIOH_CLK_ENABLE(); | ||||
|   __HAL_RCC_GPIOB_CLK_ENABLE(); | ||||
|   __HAL_RCC_GPIOA_CLK_ENABLE(); | ||||
|   __HAL_RCC_GPIOE_CLK_ENABLE(); | ||||
|   __HAL_RCC_GPIOD_CLK_ENABLE(); | ||||
|  | ||||
|   /*Configure GPIO pin Output Level */ | ||||
|   HAL_GPIO_WritePin(GPIOA, RFID_PULL_Pin|VIBRO_Pin, GPIO_PIN_RESET); | ||||
|  | ||||
|   /*Configure GPIO pin Output Level */ | ||||
|   HAL_GPIO_WritePin(PERIPH_POWER_GPIO_Port, PERIPH_POWER_Pin, GPIO_PIN_SET); | ||||
|  | ||||
|   /*Configure GPIO pin Output Level */ | ||||
|   HAL_GPIO_WritePin(RF_SW_0_GPIO_Port, RF_SW_0_Pin, GPIO_PIN_RESET); | ||||
|  | ||||
|   /*Configure GPIO pin Output Level */ | ||||
|   HAL_GPIO_WritePin(GPIOB, DISPLAY_RST_Pin|DISPLAY_DI_Pin, GPIO_PIN_RESET); | ||||
|  | ||||
|   /*Configure GPIO pin Output Level */ | ||||
|   HAL_GPIO_WritePin(NFC_CS_GPIO_Port, NFC_CS_Pin, GPIO_PIN_SET); | ||||
|  | ||||
|   /*Configure GPIO pin Output Level */ | ||||
|   HAL_GPIO_WritePin(GPIOC, DISPLAY_CS_Pin|SD_CS_Pin, GPIO_PIN_SET); | ||||
|  | ||||
|   /*Configure GPIO pin Output Level */ | ||||
|   HAL_GPIO_WritePin(CC1101_CS_GPIO_Port, CC1101_CS_Pin, GPIO_PIN_SET); | ||||
|  | ||||
|   /*Configure GPIO pin : PtPin */ | ||||
|   GPIO_InitStruct.Pin = BUTTON_BACK_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; | ||||
|   GPIO_InitStruct.Pull = GPIO_PULLUP; | ||||
|   HAL_GPIO_Init(BUTTON_BACK_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pin : PtPin */ | ||||
|   GPIO_InitStruct.Pin = BUTTON_OK_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; | ||||
|   GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|   HAL_GPIO_Init(BUTTON_OK_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pins : PCPin PCPin PCPin */ | ||||
|   GPIO_InitStruct.Pin = PC0_Pin|PC1_Pin|PC3_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | ||||
|   GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pins : PAPin PAPin PAPin PAPin | ||||
|                            PAPin */ | ||||
|   GPIO_InitStruct.Pin = CC1101_G0_Pin|PA4_Pin|PA6_Pin|PA7_Pin | ||||
|                           |RFID_CARRIER_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | ||||
|   GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pins : PAPin PAPin */ | ||||
|   GPIO_InitStruct.Pin = RFID_PULL_Pin|VIBRO_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | ||||
|   GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||||
|   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pin : PtPin */ | ||||
|   GPIO_InitStruct.Pin = PERIPH_POWER_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; | ||||
|   GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||||
|   HAL_GPIO_Init(PERIPH_POWER_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pins : PCPin PCPin */ | ||||
|   GPIO_InitStruct.Pin = RF_SW_0_Pin|DISPLAY_CS_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | ||||
|   GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||||
|   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pins : PBPin PBPin PBPin */ | ||||
|   GPIO_InitStruct.Pin = PB2_Pin|iBTN_Pin|PB3_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | ||||
|   GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pins : PBPin PBPin PBPin */ | ||||
|   GPIO_InitStruct.Pin = BUTTON_UP_Pin|BUTTON_LEFT_Pin|BUTTON_RIGHT_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; | ||||
|   GPIO_InitStruct.Pull = GPIO_PULLUP; | ||||
|   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pins : PBPin PBPin */ | ||||
|   GPIO_InitStruct.Pin = DISPLAY_RST_Pin|DISPLAY_DI_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | ||||
|   GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||||
|   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pin : PtPin */ | ||||
|   GPIO_InitStruct.Pin = NFC_CS_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | ||||
|   GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; | ||||
|   HAL_GPIO_Init(NFC_CS_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pins : PCPin PCPin */ | ||||
|   GPIO_InitStruct.Pin = BUTTON_DOWN_Pin|SD_CD_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | ||||
|   GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pin : PtPin */ | ||||
|   GPIO_InitStruct.Pin = SD_CS_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | ||||
|   GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; | ||||
|   HAL_GPIO_Init(SD_CS_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|   /*Configure GPIO pin : PtPin */ | ||||
|   GPIO_InitStruct.Pin = CC1101_CS_Pin; | ||||
|   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | ||||
|   GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; | ||||
|   HAL_GPIO_Init(CC1101_CS_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|   /* EXTI interrupt init*/ | ||||
|   HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0); | ||||
|   HAL_NVIC_EnableIRQ(EXTI3_IRQn); | ||||
|  | ||||
|   HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0); | ||||
|   HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); | ||||
|  | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 2 */ | ||||
|  | ||||
| /* USER CODE END 2 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										83
									
								
								firmware/targets/f7/cube/Src/i2c.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								firmware/targets/f7/cube/Src/i2c.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,83 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    i2c.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of the I2C instances. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "i2c.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| /* I2C1 init function */ | ||||
| void MX_I2C1_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN I2C1_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END I2C1_Init 0 */ | ||||
|  | ||||
|   LL_I2C_InitTypeDef I2C_InitStruct = {0}; | ||||
|  | ||||
|   LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; | ||||
|  | ||||
|   LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); | ||||
|   /**I2C1 GPIO Configuration | ||||
|   PA9   ------> I2C1_SCL | ||||
|   PA10   ------> I2C1_SDA | ||||
|   */ | ||||
|   GPIO_InitStruct.Pin = LL_GPIO_PIN_9|LL_GPIO_PIN_10; | ||||
|   GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; | ||||
|   GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; | ||||
|   GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; | ||||
|   GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; | ||||
|   GPIO_InitStruct.Alternate = LL_GPIO_AF_4; | ||||
|   LL_GPIO_Init(GPIOA, &GPIO_InitStruct); | ||||
|  | ||||
|   /* Peripheral clock enable */ | ||||
|   LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); | ||||
|  | ||||
|   /* USER CODE BEGIN I2C1_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END I2C1_Init 1 */ | ||||
|   /** I2C Initialization | ||||
|   */ | ||||
|   I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; | ||||
|   I2C_InitStruct.Timing = 0x10707DBC; | ||||
|   I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; | ||||
|   I2C_InitStruct.DigitalFilter = 0; | ||||
|   I2C_InitStruct.OwnAddress1 = 0; | ||||
|   I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; | ||||
|   I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; | ||||
|   LL_I2C_Init(I2C1, &I2C_InitStruct); | ||||
|   LL_I2C_EnableAutoEndMode(I2C1); | ||||
|   LL_I2C_SetOwnAddress2(I2C1, 0, LL_I2C_OWNADDRESS2_NOMASK); | ||||
|   LL_I2C_DisableOwnAddress2(I2C1); | ||||
|   LL_I2C_DisableGeneralCall(I2C1); | ||||
|   LL_I2C_EnableClockStretching(I2C1); | ||||
|   /* USER CODE BEGIN I2C1_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END I2C1_Init 2 */ | ||||
|  | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										290
									
								
								firmware/targets/f7/cube/Src/main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										290
									
								
								firmware/targets/f7/cube/Src/main.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,290 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file           : main.c | ||||
|   * @brief          : Main program body | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "main.h" | ||||
| #include "cmsis_os.h" | ||||
| #include "adc.h" | ||||
| #include "aes.h" | ||||
| #include "comp.h" | ||||
| #include "crc.h" | ||||
| #include "i2c.h" | ||||
| #include "pka.h" | ||||
| #include "rf.h" | ||||
| #include "rng.h" | ||||
| #include "rtc.h" | ||||
| #include "spi.h" | ||||
| #include "tim.h" | ||||
| #include "usart.h" | ||||
| #include "usb_device.h" | ||||
| #include "gpio.h" | ||||
|  | ||||
| /* Private includes ----------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN Includes */ | ||||
|  | ||||
| /* USER CODE END Includes */ | ||||
|  | ||||
| /* Private typedef -----------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PTD */ | ||||
|  | ||||
| /* USER CODE END PTD */ | ||||
|  | ||||
| /* Private define ------------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PD */ | ||||
| /* USER CODE END PD */ | ||||
|  | ||||
| /* Private macro -------------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PM */ | ||||
|  | ||||
| /* USER CODE END PM */ | ||||
|  | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
|  | ||||
| /* USER CODE BEGIN PV */ | ||||
|  | ||||
| /* USER CODE END PV */ | ||||
|  | ||||
| /* Private function prototypes -----------------------------------------------*/ | ||||
| void SystemClock_Config(void); | ||||
| void MX_FREERTOS_Init(void); | ||||
| /* USER CODE BEGIN PFP */ | ||||
|  | ||||
| /* USER CODE END PFP */ | ||||
|  | ||||
| /* Private user code ---------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| /** | ||||
|   * @brief  The application entry point. | ||||
|   * @retval int | ||||
|   */ | ||||
| int main(void) | ||||
| { | ||||
|   /* USER CODE BEGIN 1 */ | ||||
|  | ||||
|   /* USER CODE END 1 */ | ||||
|  | ||||
|   /* MCU Configuration--------------------------------------------------------*/ | ||||
|  | ||||
|   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ | ||||
|   HAL_Init(); | ||||
|  | ||||
|   /* USER CODE BEGIN Init */ | ||||
|  | ||||
|   /* USER CODE END Init */ | ||||
|  | ||||
|   /* Configure the system clock */ | ||||
|   SystemClock_Config(); | ||||
|  | ||||
|   /* USER CODE BEGIN SysInit */ | ||||
|  | ||||
|   /* USER CODE END SysInit */ | ||||
|  | ||||
|   /* Initialize all configured peripherals */ | ||||
|   MX_GPIO_Init(); | ||||
|   MX_ADC1_Init(); | ||||
|   MX_I2C1_Init(); | ||||
|   MX_RTC_Init(); | ||||
|   MX_SPI1_Init(); | ||||
|   MX_SPI2_Init(); | ||||
|   MX_USB_Device_Init(); | ||||
|   MX_TIM1_Init(); | ||||
|   MX_TIM2_Init(); | ||||
|   MX_TIM16_Init(); | ||||
|   MX_COMP1_Init(); | ||||
|   MX_RF_Init(); | ||||
|   MX_PKA_Init(); | ||||
|   MX_RNG_Init(); | ||||
|   MX_AES1_Init(); | ||||
|   MX_AES2_Init(); | ||||
|   MX_CRC_Init(); | ||||
|   MX_USART1_UART_Init(); | ||||
|   /* USER CODE BEGIN 2 */ | ||||
|  | ||||
|   /* USER CODE END 2 */ | ||||
|  | ||||
|   /* Init scheduler */ | ||||
|   osKernelInitialize();  /* Call init function for freertos objects (in freertos.c) */ | ||||
|   MX_FREERTOS_Init(); | ||||
|   /* Start scheduler */ | ||||
|   osKernelStart(); | ||||
|  | ||||
|   /* We should never get here as control is now taken by the scheduler */ | ||||
|   /* Infinite loop */ | ||||
|   /* USER CODE BEGIN WHILE */ | ||||
|   while (1) | ||||
|   { | ||||
|     /* USER CODE END WHILE */ | ||||
|  | ||||
|     /* USER CODE BEGIN 3 */ | ||||
|   } | ||||
|   /* USER CODE END 3 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief System Clock Configuration | ||||
|   * @retval None | ||||
|   */ | ||||
| void SystemClock_Config(void) | ||||
| { | ||||
|   LL_FLASH_SetLatency(LL_FLASH_LATENCY_3); | ||||
|   while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_3) | ||||
|   { | ||||
|   } | ||||
|  | ||||
|   /* HSE configuration and activation */ | ||||
|   LL_RCC_HSE_Enable(); | ||||
|   while(LL_RCC_HSE_IsReady() != 1) | ||||
|   { | ||||
|   } | ||||
|  | ||||
|   /* HSI configuration and activation */ | ||||
|   LL_RCC_HSI_Enable(); | ||||
|   while(LL_RCC_HSI_IsReady() != 1) | ||||
|   { | ||||
|   } | ||||
|  | ||||
|   LL_PWR_EnableBkUpAccess(); | ||||
|   if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) | ||||
|   { | ||||
|     LL_RCC_ForceBackupDomainReset(); | ||||
|     LL_RCC_ReleaseBackupDomainReset(); | ||||
|   } | ||||
|   LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_MEDIUMLOW); | ||||
|   LL_RCC_LSE_Enable(); | ||||
|  | ||||
|   /* Wait till LSE is ready */ | ||||
|   while(LL_RCC_LSE_IsReady() != 1) | ||||
|   { | ||||
|   } | ||||
|  | ||||
|   LL_RCC_HSE_EnableCSS(); | ||||
|   LL_RCC_LSE_EnableCSS(); | ||||
|   /* Main PLL configuration and activation */ | ||||
|   LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_2, 8, LL_RCC_PLLR_DIV_2); | ||||
|   LL_RCC_PLL_Enable(); | ||||
|   LL_RCC_PLL_EnableDomain_SYS(); | ||||
|   while(LL_RCC_PLL_IsReady() != 1) | ||||
|   { | ||||
|   } | ||||
|  | ||||
|   LL_RCC_PLLSAI1_ConfigDomain_48M(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_2, 6, LL_RCC_PLLSAI1Q_DIV_2); | ||||
|   LL_RCC_PLLSAI1_ConfigDomain_ADC(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_2, 6, LL_RCC_PLLSAI1R_DIV_2); | ||||
|   LL_RCC_PLLSAI1_Enable(); | ||||
|   LL_RCC_PLLSAI1_EnableDomain_48M(); | ||||
|   LL_RCC_PLLSAI1_EnableDomain_ADC(); | ||||
|  | ||||
|   /* Wait till PLLSAI1 is ready */ | ||||
|   while(LL_RCC_PLLSAI1_IsReady() != 1) | ||||
|   { | ||||
|   } | ||||
|  | ||||
|   /* Sysclk activation on the main PLL */ | ||||
|   /* Set CPU1 prescaler*/ | ||||
|   LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); | ||||
|  | ||||
|   /* Set CPU2 prescaler*/ | ||||
|   LL_C2_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); | ||||
|  | ||||
|   LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); | ||||
|   while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) | ||||
|   { | ||||
|   } | ||||
|  | ||||
|   /* Set AHB SHARED prescaler*/ | ||||
|   LL_RCC_SetAHB4Prescaler(LL_RCC_SYSCLK_DIV_1); | ||||
|  | ||||
|   /* Set APB1 prescaler*/ | ||||
|   LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); | ||||
|  | ||||
|   /* Set APB2 prescaler*/ | ||||
|   LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); | ||||
|  | ||||
|   /* Disable MSI */ | ||||
|   LL_RCC_MSI_Disable(); | ||||
|   while(LL_RCC_MSI_IsReady() != 0) | ||||
|   { | ||||
|   } | ||||
|  | ||||
|   /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ | ||||
|   LL_SetSystemCoreClock(64000000); | ||||
|  | ||||
|    /* Update the time base */ | ||||
|   if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) | ||||
|   { | ||||
|     LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE); | ||||
|   } | ||||
|   LL_RCC_EnableRTC(); | ||||
|   LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2); | ||||
|   LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSOURCE_PLLSAI1); | ||||
|   LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_PCLK1); | ||||
|   LL_RCC_SetRNGClockSource(LL_RCC_RNG_CLKSOURCE_CLK48); | ||||
|   LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_PLLSAI1); | ||||
|   LL_RCC_SetCLK48ClockSource(LL_RCC_CLK48_CLKSOURCE_PLLSAI1); | ||||
|   LL_RCC_SetSMPSClockSource(LL_RCC_SMPS_CLKSOURCE_HSE); | ||||
|   LL_RCC_SetSMPSPrescaler(LL_RCC_SMPS_DIV_1); | ||||
|   LL_RCC_SetRFWKPClockSource(LL_RCC_RFWKP_CLKSOURCE_LSE); | ||||
|   /* USER CODE BEGIN Smps */ | ||||
|  | ||||
|   /* USER CODE END Smps */ | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 4 */ | ||||
|  | ||||
| /* USER CODE END 4 */ | ||||
|  | ||||
| /** | ||||
|   * @brief  This function is executed in case of error occurrence. | ||||
|   * @retval None | ||||
|   */ | ||||
| void Error_Handler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN Error_Handler_Debug */ | ||||
|   /* User can add his own implementation to report the HAL error return state */ | ||||
|   __disable_irq(); | ||||
|   while (1) | ||||
|   { | ||||
|   } | ||||
|   /* USER CODE END Error_Handler_Debug */ | ||||
| } | ||||
|  | ||||
| #ifdef  USE_FULL_ASSERT | ||||
| /** | ||||
|   * @brief  Reports the name of the source file and the source line number | ||||
|   *         where the assert_param error has occurred. | ||||
|   * @param  file: pointer to the source file name | ||||
|   * @param  line: assert_param error line source number | ||||
|   * @retval None | ||||
|   */ | ||||
| void assert_failed(uint8_t *file, uint32_t line) | ||||
| { | ||||
|   /* USER CODE BEGIN 6 */ | ||||
|   /* User can add his own implementation to report the file name and line number, | ||||
|      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | ||||
|   /* USER CODE END 6 */ | ||||
| } | ||||
| #endif /* USE_FULL_ASSERT */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										87
									
								
								firmware/targets/f7/cube/Src/pka.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								firmware/targets/f7/cube/Src/pka.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,87 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    pka.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of the PKA instances. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "pka.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| PKA_HandleTypeDef hpka; | ||||
|  | ||||
| /* PKA init function */ | ||||
| void MX_PKA_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN PKA_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END PKA_Init 0 */ | ||||
|  | ||||
|   /* USER CODE BEGIN PKA_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END PKA_Init 1 */ | ||||
|   hpka.Instance = PKA; | ||||
|   if (HAL_PKA_Init(&hpka) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN PKA_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END PKA_Init 2 */ | ||||
|  | ||||
| } | ||||
|  | ||||
| void HAL_PKA_MspInit(PKA_HandleTypeDef* pkaHandle) | ||||
| { | ||||
|  | ||||
|   if(pkaHandle->Instance==PKA) | ||||
|   { | ||||
|   /* USER CODE BEGIN PKA_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END PKA_MspInit 0 */ | ||||
|     /* PKA clock enable */ | ||||
|     __HAL_RCC_PKA_CLK_ENABLE(); | ||||
|   /* USER CODE BEGIN PKA_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END PKA_MspInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| void HAL_PKA_MspDeInit(PKA_HandleTypeDef* pkaHandle) | ||||
| { | ||||
|  | ||||
|   if(pkaHandle->Instance==PKA) | ||||
|   { | ||||
|   /* USER CODE BEGIN PKA_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END PKA_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_PKA_CLK_DISABLE(); | ||||
|   /* USER CODE BEGIN PKA_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END PKA_MspDeInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										48
									
								
								firmware/targets/f7/cube/Src/rf.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								firmware/targets/f7/cube/Src/rf.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    rf.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of the RF instances. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "rf.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| /* RF init function */ | ||||
| void MX_RF_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN RF_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END RF_Init 0 */ | ||||
|  | ||||
|   /* USER CODE BEGIN RF_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END RF_Init 1 */ | ||||
|   /* USER CODE BEGIN RF_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END RF_Init 2 */ | ||||
|  | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										88
									
								
								firmware/targets/f7/cube/Src/rng.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								firmware/targets/f7/cube/Src/rng.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    rng.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of the RNG instances. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "rng.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| RNG_HandleTypeDef hrng; | ||||
|  | ||||
| /* RNG init function */ | ||||
| void MX_RNG_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN RNG_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END RNG_Init 0 */ | ||||
|  | ||||
|   /* USER CODE BEGIN RNG_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END RNG_Init 1 */ | ||||
|   hrng.Instance = RNG; | ||||
|   hrng.Init.ClockErrorDetection = RNG_CED_ENABLE; | ||||
|   if (HAL_RNG_Init(&hrng) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN RNG_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END RNG_Init 2 */ | ||||
|  | ||||
| } | ||||
|  | ||||
| void HAL_RNG_MspInit(RNG_HandleTypeDef* rngHandle) | ||||
| { | ||||
|  | ||||
|   if(rngHandle->Instance==RNG) | ||||
|   { | ||||
|   /* USER CODE BEGIN RNG_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END RNG_MspInit 0 */ | ||||
|     /* RNG clock enable */ | ||||
|     __HAL_RCC_RNG_CLK_ENABLE(); | ||||
|   /* USER CODE BEGIN RNG_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END RNG_MspInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| void HAL_RNG_MspDeInit(RNG_HandleTypeDef* rngHandle) | ||||
| { | ||||
|  | ||||
|   if(rngHandle->Instance==RNG) | ||||
|   { | ||||
|   /* USER CODE BEGIN RNG_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END RNG_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_RNG_CLK_DISABLE(); | ||||
|   /* USER CODE BEGIN RNG_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END RNG_MspDeInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										134
									
								
								firmware/targets/f7/cube/Src/rtc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										134
									
								
								firmware/targets/f7/cube/Src/rtc.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,134 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    rtc.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of the RTC instances. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "rtc.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| RTC_HandleTypeDef hrtc; | ||||
|  | ||||
| /* RTC init function */ | ||||
| void MX_RTC_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN RTC_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END RTC_Init 0 */ | ||||
|  | ||||
|   RTC_TimeTypeDef sTime = {0}; | ||||
|   RTC_DateTypeDef sDate = {0}; | ||||
|  | ||||
|   /* USER CODE BEGIN RTC_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END RTC_Init 1 */ | ||||
|   /** Initialize RTC Only | ||||
|   */ | ||||
|   hrtc.Instance = RTC; | ||||
|   hrtc.Init.HourFormat = RTC_HOURFORMAT_24; | ||||
|   hrtc.Init.AsynchPrediv = 127; | ||||
|   hrtc.Init.SynchPrediv = 255; | ||||
|   hrtc.Init.OutPut = RTC_OUTPUT_DISABLE; | ||||
|   hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | ||||
|   hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | ||||
|   hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE; | ||||
|   if (HAL_RTC_Init(&hrtc) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|  | ||||
|   /* USER CODE BEGIN Check_RTC_BKUP */ | ||||
|  | ||||
|   /* USER CODE END Check_RTC_BKUP */ | ||||
|  | ||||
|   /** Initialize RTC and set the Time and Date | ||||
|   */ | ||||
|   sTime.Hours = 0x0; | ||||
|   sTime.Minutes = 0x0; | ||||
|   sTime.Seconds = 0x0; | ||||
|   sTime.SubSeconds = 0x0; | ||||
|   sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; | ||||
|   sTime.StoreOperation = RTC_STOREOPERATION_RESET; | ||||
|   if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   sDate.WeekDay = RTC_WEEKDAY_MONDAY; | ||||
|   sDate.Month = RTC_MONTH_JANUARY; | ||||
|   sDate.Date = 0x1; | ||||
|   sDate.Year = 0x0; | ||||
|  | ||||
|   if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN RTC_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END RTC_Init 2 */ | ||||
|  | ||||
| } | ||||
|  | ||||
| void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle) | ||||
| { | ||||
|  | ||||
|   if(rtcHandle->Instance==RTC) | ||||
|   { | ||||
|   /* USER CODE BEGIN RTC_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END RTC_MspInit 0 */ | ||||
|     /* RTC clock enable */ | ||||
|     __HAL_RCC_RTC_ENABLE(); | ||||
|     __HAL_RCC_RTCAPB_CLK_ENABLE(); | ||||
|  | ||||
|     /* RTC interrupt Init */ | ||||
|     HAL_NVIC_SetPriority(TAMP_STAMP_LSECSS_IRQn, 5, 0); | ||||
|     HAL_NVIC_EnableIRQ(TAMP_STAMP_LSECSS_IRQn); | ||||
|   /* USER CODE BEGIN RTC_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END RTC_MspInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle) | ||||
| { | ||||
|  | ||||
|   if(rtcHandle->Instance==RTC) | ||||
|   { | ||||
|   /* USER CODE BEGIN RTC_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END RTC_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_RTC_DISABLE(); | ||||
|     __HAL_RCC_RTCAPB_CLK_DISABLE(); | ||||
|  | ||||
|     /* RTC interrupt Deinit */ | ||||
|     HAL_NVIC_DisableIRQ(TAMP_STAMP_LSECSS_IRQn); | ||||
|   /* USER CODE BEGIN RTC_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END RTC_MspDeInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										232
									
								
								firmware/targets/f7/cube/Src/spi.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										232
									
								
								firmware/targets/f7/cube/Src/spi.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,232 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    spi.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of the SPI instances. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "spi.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| SPI_HandleTypeDef hspi1; | ||||
| SPI_HandleTypeDef hspi2; | ||||
|  | ||||
| /* SPI1 init function */ | ||||
| void MX_SPI1_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN SPI1_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END SPI1_Init 0 */ | ||||
|  | ||||
|   /* USER CODE BEGIN SPI1_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END SPI1_Init 1 */ | ||||
|   hspi1.Instance = SPI1; | ||||
|   hspi1.Init.Mode = SPI_MODE_MASTER; | ||||
|   hspi1.Init.Direction = SPI_DIRECTION_2LINES; | ||||
|   hspi1.Init.DataSize = SPI_DATASIZE_8BIT; | ||||
|   hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; | ||||
|   hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; | ||||
|   hspi1.Init.NSS = SPI_NSS_SOFT; | ||||
|   hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; | ||||
|   hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; | ||||
|   hspi1.Init.TIMode = SPI_TIMODE_DISABLE; | ||||
|   hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; | ||||
|   hspi1.Init.CRCPolynomial = 7; | ||||
|   hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; | ||||
|   hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; | ||||
|   if (HAL_SPI_Init(&hspi1) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN SPI1_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END SPI1_Init 2 */ | ||||
|  | ||||
| } | ||||
| /* SPI2 init function */ | ||||
| void MX_SPI2_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN SPI2_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END SPI2_Init 0 */ | ||||
|  | ||||
|   /* USER CODE BEGIN SPI2_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END SPI2_Init 1 */ | ||||
|   hspi2.Instance = SPI2; | ||||
|   hspi2.Init.Mode = SPI_MODE_MASTER; | ||||
|   hspi2.Init.Direction = SPI_DIRECTION_2LINES; | ||||
|   hspi2.Init.DataSize = SPI_DATASIZE_8BIT; | ||||
|   hspi2.Init.CLKPolarity = SPI_POLARITY_LOW; | ||||
|   hspi2.Init.CLKPhase = SPI_PHASE_1EDGE; | ||||
|   hspi2.Init.NSS = SPI_NSS_SOFT; | ||||
|   hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; | ||||
|   hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB; | ||||
|   hspi2.Init.TIMode = SPI_TIMODE_DISABLE; | ||||
|   hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; | ||||
|   hspi2.Init.CRCPolynomial = 7; | ||||
|   hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; | ||||
|   hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; | ||||
|   if (HAL_SPI_Init(&hspi2) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN SPI2_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END SPI2_Init 2 */ | ||||
|  | ||||
| } | ||||
|  | ||||
| void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) | ||||
| { | ||||
|  | ||||
|   GPIO_InitTypeDef GPIO_InitStruct = {0}; | ||||
|   if(spiHandle->Instance==SPI1) | ||||
|   { | ||||
|   /* USER CODE BEGIN SPI1_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END SPI1_MspInit 0 */ | ||||
|     /* SPI1 clock enable */ | ||||
|     __HAL_RCC_SPI1_CLK_ENABLE(); | ||||
|  | ||||
|     __HAL_RCC_GPIOA_CLK_ENABLE(); | ||||
|     __HAL_RCC_GPIOB_CLK_ENABLE(); | ||||
|     /**SPI1 GPIO Configuration | ||||
|     PA5     ------> SPI1_SCK | ||||
|     PB4     ------> SPI1_MISO | ||||
|     PB5     ------> SPI1_MOSI | ||||
|     */ | ||||
|     GPIO_InitStruct.Pin = SPI_R_SCK_Pin; | ||||
|     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||||
|     GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||||
|     GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; | ||||
|     HAL_GPIO_Init(SPI_R_SCK_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|     GPIO_InitStruct.Pin = SPI_R_MISO_Pin|SPI_R_MOSI_Pin; | ||||
|     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||||
|     GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||||
|     GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; | ||||
|     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | ||||
|  | ||||
|   /* USER CODE BEGIN SPI1_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END SPI1_MspInit 1 */ | ||||
|   } | ||||
|   else if(spiHandle->Instance==SPI2) | ||||
|   { | ||||
|   /* USER CODE BEGIN SPI2_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END SPI2_MspInit 0 */ | ||||
|     /* SPI2 clock enable */ | ||||
|     __HAL_RCC_SPI2_CLK_ENABLE(); | ||||
|  | ||||
|     __HAL_RCC_GPIOC_CLK_ENABLE(); | ||||
|     __HAL_RCC_GPIOB_CLK_ENABLE(); | ||||
|     __HAL_RCC_GPIOD_CLK_ENABLE(); | ||||
|     /**SPI2 GPIO Configuration | ||||
|     PC2     ------> SPI2_MISO | ||||
|     PB15     ------> SPI2_MOSI | ||||
|     PD1     ------> SPI2_SCK | ||||
|     */ | ||||
|     GPIO_InitStruct.Pin = SPI_D_MISO_Pin; | ||||
|     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||||
|     GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||||
|     GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; | ||||
|     HAL_GPIO_Init(SPI_D_MISO_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|     GPIO_InitStruct.Pin = SPI_D_MOSI_Pin; | ||||
|     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||||
|     GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||||
|     GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; | ||||
|     HAL_GPIO_Init(SPI_D_MOSI_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|     GPIO_InitStruct.Pin = SPI_D_SCK_Pin; | ||||
|     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||||
|     GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||||
|     GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; | ||||
|     HAL_GPIO_Init(SPI_D_SCK_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|   /* USER CODE BEGIN SPI2_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END SPI2_MspInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) | ||||
| { | ||||
|  | ||||
|   if(spiHandle->Instance==SPI1) | ||||
|   { | ||||
|   /* USER CODE BEGIN SPI1_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END SPI1_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_SPI1_CLK_DISABLE(); | ||||
|  | ||||
|     /**SPI1 GPIO Configuration | ||||
|     PA5     ------> SPI1_SCK | ||||
|     PB4     ------> SPI1_MISO | ||||
|     PB5     ------> SPI1_MOSI | ||||
|     */ | ||||
|     HAL_GPIO_DeInit(SPI_R_SCK_GPIO_Port, SPI_R_SCK_Pin); | ||||
|  | ||||
|     HAL_GPIO_DeInit(GPIOB, SPI_R_MISO_Pin|SPI_R_MOSI_Pin); | ||||
|  | ||||
|   /* USER CODE BEGIN SPI1_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END SPI1_MspDeInit 1 */ | ||||
|   } | ||||
|   else if(spiHandle->Instance==SPI2) | ||||
|   { | ||||
|   /* USER CODE BEGIN SPI2_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END SPI2_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_SPI2_CLK_DISABLE(); | ||||
|  | ||||
|     /**SPI2 GPIO Configuration | ||||
|     PC2     ------> SPI2_MISO | ||||
|     PB15     ------> SPI2_MOSI | ||||
|     PD1     ------> SPI2_SCK | ||||
|     */ | ||||
|     HAL_GPIO_DeInit(SPI_D_MISO_GPIO_Port, SPI_D_MISO_Pin); | ||||
|  | ||||
|     HAL_GPIO_DeInit(SPI_D_MOSI_GPIO_Port, SPI_D_MOSI_Pin); | ||||
|  | ||||
|     HAL_GPIO_DeInit(SPI_D_SCK_GPIO_Port, SPI_D_SCK_Pin); | ||||
|  | ||||
|   /* USER CODE BEGIN SPI2_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END SPI2_MspDeInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										93
									
								
								firmware/targets/f7/cube/Src/stm32wbxx_hal_msp.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								firmware/targets/f7/cube/Src/stm32wbxx_hal_msp.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,93 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file         stm32wbxx_hal_msp.c | ||||
|   * @brief        This file provides code for the MSP Initialization | ||||
|   *               and de-Initialization codes. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "main.h" | ||||
| /* USER CODE BEGIN Includes */ | ||||
|  | ||||
| /* USER CODE END Includes */ | ||||
|  | ||||
| /* Private typedef -----------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN TD */ | ||||
|  | ||||
| /* USER CODE END TD */ | ||||
|  | ||||
| /* Private define ------------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN Define */ | ||||
|  | ||||
| /* USER CODE END Define */ | ||||
|  | ||||
| /* Private macro -------------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN Macro */ | ||||
|  | ||||
| /* USER CODE END Macro */ | ||||
|  | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PV */ | ||||
|  | ||||
| /* USER CODE END PV */ | ||||
|  | ||||
| /* Private function prototypes -----------------------------------------------*/ | ||||
| /* USER CODE BEGIN PFP */ | ||||
|  | ||||
| /* USER CODE END PFP */ | ||||
|  | ||||
| /* External functions --------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN ExternalFunctions */ | ||||
|  | ||||
| /* USER CODE END ExternalFunctions */ | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
| /** | ||||
|   * Initializes the Global MSP. | ||||
|   */ | ||||
| void HAL_MspInit(void) | ||||
| { | ||||
|   /* USER CODE BEGIN MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END MspInit 0 */ | ||||
|  | ||||
|   __HAL_RCC_HSEM_CLK_ENABLE(); | ||||
|  | ||||
|   /* System interrupt init*/ | ||||
|   /* PendSV_IRQn interrupt configuration */ | ||||
|   HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); | ||||
|  | ||||
|   /* Peripheral interrupt init */ | ||||
|   /* RCC_IRQn interrupt configuration */ | ||||
|   HAL_NVIC_SetPriority(RCC_IRQn, 5, 0); | ||||
|   HAL_NVIC_EnableIRQ(RCC_IRQn); | ||||
|   /* HSEM_IRQn interrupt configuration */ | ||||
|   HAL_NVIC_SetPriority(HSEM_IRQn, 5, 0); | ||||
|   HAL_NVIC_EnableIRQ(HSEM_IRQn); | ||||
|  | ||||
|   /* USER CODE BEGIN MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END MspInit 1 */ | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										326
									
								
								firmware/targets/f7/cube/Src/stm32wbxx_it.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										326
									
								
								firmware/targets/f7/cube/Src/stm32wbxx_it.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,326 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    stm32wbxx_it.c | ||||
|   * @brief   Interrupt Service Routines. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "main.h" | ||||
| #include "stm32wbxx_it.h" | ||||
| #include "FreeRTOS.h" | ||||
| #include "task.h" | ||||
| /* Private includes ----------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN Includes */ | ||||
| /* USER CODE END Includes */ | ||||
|  | ||||
| /* Private typedef -----------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN TD */ | ||||
|  | ||||
| /* USER CODE END TD */ | ||||
|  | ||||
| /* Private define ------------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PD */ | ||||
|  | ||||
| /* USER CODE END PD */ | ||||
|  | ||||
| /* Private macro -------------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PM */ | ||||
|  | ||||
| /* USER CODE END PM */ | ||||
|  | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PV */ | ||||
|  | ||||
| /* USER CODE END PV */ | ||||
|  | ||||
| /* Private function prototypes -----------------------------------------------*/ | ||||
| /* USER CODE BEGIN PFP */ | ||||
|  | ||||
| /* USER CODE END PFP */ | ||||
|  | ||||
| /* Private user code ---------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| /* External variables --------------------------------------------------------*/ | ||||
| extern PCD_HandleTypeDef hpcd_USB_FS; | ||||
| extern ADC_HandleTypeDef hadc1; | ||||
| extern COMP_HandleTypeDef hcomp1; | ||||
| extern RTC_HandleTypeDef hrtc; | ||||
| extern TIM_HandleTypeDef htim1; | ||||
| extern TIM_HandleTypeDef htim2; | ||||
| /* USER CODE BEGIN EV */ | ||||
|  | ||||
| /* USER CODE END EV */ | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /*           Cortex Processor Interruption and Exception Handlers          */ | ||||
| /******************************************************************************/ | ||||
| /** | ||||
|   * @brief This function handles Non maskable interrupt. | ||||
|   */ | ||||
| void NMI_Handler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END NonMaskableInt_IRQn 0 */ | ||||
|   /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ | ||||
|   while (1) | ||||
|   { | ||||
|   } | ||||
|   /* USER CODE END NonMaskableInt_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles Hard fault interrupt. | ||||
|   */ | ||||
| void HardFault_Handler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN HardFault_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END HardFault_IRQn 0 */ | ||||
|   while (1) | ||||
|   { | ||||
|     /* USER CODE BEGIN W1_HardFault_IRQn 0 */ | ||||
|     /* USER CODE END W1_HardFault_IRQn 0 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles Memory management fault. | ||||
|   */ | ||||
| void MemManage_Handler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN MemoryManagement_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END MemoryManagement_IRQn 0 */ | ||||
|   while (1) | ||||
|   { | ||||
|     /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ | ||||
|     /* USER CODE END W1_MemoryManagement_IRQn 0 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles Prefetch fault, memory access fault. | ||||
|   */ | ||||
| void BusFault_Handler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN BusFault_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END BusFault_IRQn 0 */ | ||||
|   while (1) | ||||
|   { | ||||
|     /* USER CODE BEGIN W1_BusFault_IRQn 0 */ | ||||
|     /* USER CODE END W1_BusFault_IRQn 0 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles Undefined instruction or illegal state. | ||||
|   */ | ||||
| void UsageFault_Handler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN UsageFault_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END UsageFault_IRQn 0 */ | ||||
|   while (1) | ||||
|   { | ||||
|     /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ | ||||
|     /* USER CODE END W1_UsageFault_IRQn 0 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles Debug monitor. | ||||
|   */ | ||||
| void DebugMon_Handler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN DebugMonitor_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END DebugMonitor_IRQn 0 */ | ||||
|   /* USER CODE BEGIN DebugMonitor_IRQn 1 */ | ||||
|  | ||||
|   /* USER CODE END DebugMonitor_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles System tick timer. | ||||
|   */ | ||||
| void SysTick_Handler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN SysTick_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END SysTick_IRQn 0 */ | ||||
|   /* USER CODE BEGIN SysTick_IRQn 1 */ | ||||
|  | ||||
|   /* USER CODE END SysTick_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /******************************************************************************/ | ||||
| /* STM32WBxx Peripheral Interrupt Handlers                                    */ | ||||
| /* Add here the Interrupt Handlers for the used peripherals.                  */ | ||||
| /* For the available peripheral interrupt handler names,                      */ | ||||
| /* please refer to the startup file (startup_stm32wbxx.s).                    */ | ||||
| /******************************************************************************/ | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles RTC tamper and time stamp, CSS on LSE interrupts through EXTI line 18. | ||||
|   */ | ||||
| void TAMP_STAMP_LSECSS_IRQHandler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN TAMP_STAMP_LSECSS_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END TAMP_STAMP_LSECSS_IRQn 0 */ | ||||
|   /* USER CODE BEGIN TAMP_STAMP_LSECSS_IRQn 1 */ | ||||
|  | ||||
|   /* USER CODE END TAMP_STAMP_LSECSS_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles RCC global interrupt. | ||||
|   */ | ||||
| void RCC_IRQHandler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN RCC_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END RCC_IRQn 0 */ | ||||
|   /* USER CODE BEGIN RCC_IRQn 1 */ | ||||
|  | ||||
|   /* USER CODE END RCC_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles EXTI line3 interrupt. | ||||
|   */ | ||||
| void EXTI3_IRQHandler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN EXTI3_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END EXTI3_IRQn 0 */ | ||||
|   HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3); | ||||
|   /* USER CODE BEGIN EXTI3_IRQn 1 */ | ||||
|  | ||||
|   /* USER CODE END EXTI3_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles ADC1 global interrupt. | ||||
|   */ | ||||
| void ADC1_IRQHandler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN ADC1_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END ADC1_IRQn 0 */ | ||||
|   HAL_ADC_IRQHandler(&hadc1); | ||||
|   /* USER CODE BEGIN ADC1_IRQn 1 */ | ||||
|  | ||||
|   /* USER CODE END ADC1_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles USB low priority interrupt, USB wake-up interrupt through EXTI line 28. | ||||
|   */ | ||||
| void USB_LP_IRQHandler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN USB_LP_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END USB_LP_IRQn 0 */ | ||||
|   HAL_PCD_IRQHandler(&hpcd_USB_FS); | ||||
|   /* USER CODE BEGIN USB_LP_IRQn 1 */ | ||||
|  | ||||
|   /* USER CODE END USB_LP_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles COMP1 and COMP2 interrupts through EXTI lines 20 and 21. | ||||
|   */ | ||||
| void COMP_IRQHandler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN COMP_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END COMP_IRQn 0 */ | ||||
|   HAL_COMP_IRQHandler(&hcomp1); | ||||
|   /* USER CODE BEGIN COMP_IRQn 1 */ | ||||
|  | ||||
|   /* USER CODE END COMP_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles TIM1 trigger and commutation interrupts and TIM17 global interrupt. | ||||
|   */ | ||||
| void TIM1_TRG_COM_TIM17_IRQHandler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN TIM1_TRG_COM_TIM17_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM1_TRG_COM_TIM17_IRQn 0 */ | ||||
|   HAL_TIM_IRQHandler(&htim1); | ||||
|   /* USER CODE BEGIN TIM1_TRG_COM_TIM17_IRQn 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM1_TRG_COM_TIM17_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles TIM2 global interrupt. | ||||
|   */ | ||||
| void TIM2_IRQHandler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN TIM2_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM2_IRQn 0 */ | ||||
|   HAL_TIM_IRQHandler(&htim2); | ||||
|   /* USER CODE BEGIN TIM2_IRQn 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM2_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles EXTI line[15:10] interrupts. | ||||
|   */ | ||||
| void EXTI15_10_IRQHandler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN EXTI15_10_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END EXTI15_10_IRQn 0 */ | ||||
|   HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10); | ||||
|   HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11); | ||||
|   HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12); | ||||
|   HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13); | ||||
|   /* USER CODE BEGIN EXTI15_10_IRQn 1 */ | ||||
|  | ||||
|   /* USER CODE END EXTI15_10_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief This function handles HSEM global interrupt. | ||||
|   */ | ||||
| void HSEM_IRQHandler(void) | ||||
| { | ||||
|   /* USER CODE BEGIN HSEM_IRQn 0 */ | ||||
|  | ||||
|   /* USER CODE END HSEM_IRQn 0 */ | ||||
|   HAL_HSEM_IRQHandler(); | ||||
|   /* USER CODE BEGIN HSEM_IRQn 1 */ | ||||
|  | ||||
|   /* USER CODE END HSEM_IRQn 1 */ | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										368
									
								
								firmware/targets/f7/cube/Src/system_stm32wbxx.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										368
									
								
								firmware/targets/f7/cube/Src/system_stm32wbxx.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,368 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    system_stm32wbxx.c | ||||
|   * @author  MCD Application Team | ||||
|   * @brief   CMSIS Cortex Device Peripheral Access Layer System Source File | ||||
|   * | ||||
|   *   This file provides two functions and one global variable to be called from | ||||
|   *   user application: | ||||
|   *      - SystemInit(): This function is called at startup just after reset and | ||||
|   *                      before branch to main program. This call is made inside | ||||
|   *                      the "startup_stm32wbxx.s" file. | ||||
|   * | ||||
|   *      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used | ||||
|   *                                  by the user application to setup the SysTick | ||||
|   *                                  timer or configure other parameters. | ||||
|   * | ||||
|   *      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must | ||||
|   *                                 be called whenever the core clock is changed | ||||
|   *                                 during program execution. | ||||
|   * | ||||
|   *   After each device reset the MSI (4 MHz) is used as system clock source. | ||||
|   *   Then SystemInit() function is called, in "startup_stm32wbxx.s" file, to | ||||
|   *   configure the system clock before to branch to main program. | ||||
|   * | ||||
|   *   This file configures the system clock as follows: | ||||
|   *============================================================================= | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        System Clock source                    | MSI | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        SYSCLK(Hz)                             | 4000000 | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        HCLK(Hz)                               | 4000000 | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        AHB Prescaler                          | 1 | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        APB1 Prescaler                         | 1 | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        APB2 Prescaler                         | 1 | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        PLL_M                                  | 1 | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        PLL_N                                  | 8 | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        PLL_P                                  | 7 | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        PLL_Q                                  | 2 | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        PLL_R                                  | 2 | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        PLLSAI1_P                              | NA | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        PLLSAI1_Q                              | NA | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        PLLSAI1_R                              | NA | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *        Require 48MHz for USB OTG FS,          | Disabled | ||||
|   *        SDIO and RNG clock                     | | ||||
|   *----------------------------------------------------------------------------- | ||||
|   *============================================================================= | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * Copyright (c) 2019-2021 STMicroelectronics. | ||||
|   * All rights reserved. | ||||
|   * | ||||
|   * This software is licensed under terms that can be found in the LICENSE file | ||||
|   * in the root directory of this software component. | ||||
|   * If no LICENSE file comes with this software, it is provided AS-IS. | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /** @addtogroup CMSIS | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /** @addtogroup stm32WBxx_system | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /** @addtogroup stm32WBxx_System_Private_Includes | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| #include "stm32wbxx.h" | ||||
|  | ||||
| #if !defined  (HSE_VALUE) | ||||
|   #define HSE_VALUE    (32000000UL) /*!< Value of the External oscillator in Hz */ | ||||
| #endif /* HSE_VALUE */ | ||||
|  | ||||
| #if !defined  (MSI_VALUE) | ||||
|    #define MSI_VALUE    (4000000UL) /*!< Value of the Internal oscillator in Hz*/ | ||||
| #endif /* MSI_VALUE */ | ||||
|  | ||||
| #if !defined  (HSI_VALUE) | ||||
|   #define HSI_VALUE    (16000000UL) /*!< Value of the Internal oscillator in Hz*/ | ||||
| #endif /* HSI_VALUE */ | ||||
|  | ||||
| #if !defined  (LSI_VALUE)  | ||||
|  #define LSI_VALUE  (32000UL)       /*!< Value of LSI in Hz*/ | ||||
| #endif /* LSI_VALUE */  | ||||
|  | ||||
| #if !defined  (LSE_VALUE) | ||||
|   #define LSE_VALUE    (32768UL)    /*!< Value of LSE in Hz*/ | ||||
| #endif /* LSE_VALUE */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @addtogroup STM32WBxx_System_Private_TypesDefinitions | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @addtogroup STM32WBxx_System_Private_Defines | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /* Note: Following vector table addresses must be defined in line with linker | ||||
|          configuration. */ | ||||
| /*!< Uncomment the following line if you need to relocate CPU1 CM4 and/or CPU2 | ||||
|      CM0+ vector table anywhere in Sram or Flash. Else vector table will be kept | ||||
|      at address 0x00 which correspond to automatic remap of boot address selected */ | ||||
| /* #define USER_VECT_TAB_ADDRESS */ | ||||
| #if defined(USER_VECT_TAB_ADDRESS) | ||||
|  /*!< Uncomment this line for user vector table remap in Sram else user remap | ||||
|       will be done in Flash. */ | ||||
| /* #define VECT_TAB_SRAM */ | ||||
| #if defined(VECT_TAB_SRAM) | ||||
| #define VECT_TAB_BASE_ADDRESS   SRAM1_BASE      /*!< Vector Table base address field. | ||||
|                                                      This value must be a multiple of 0x200. */ | ||||
| #define VECT_TAB_OFFSET         0x00000000U     /*!< Vector Table base offset field. | ||||
|                                                      This value must be a multiple of 0x200. */ | ||||
| #else | ||||
| #define VECT_TAB_BASE_ADDRESS   FLASH_BASE      /*!< Vector Table base address field. | ||||
|                                                      This value must be a multiple of 0x200. */ | ||||
| #define VECT_TAB_OFFSET         0x00000000U     /*!< Vector Table base offset field. | ||||
|                                                      This value must be a multiple of 0x200. */ | ||||
| #endif | ||||
| #endif | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @addtogroup STM32WBxx_System_Private_Macros | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @addtogroup STM32WBxx_System_Private_Variables | ||||
|   * @{ | ||||
|   */ | ||||
|   /* The SystemCoreClock variable is updated in three ways: | ||||
|       1) by calling CMSIS function SystemCoreClockUpdate() | ||||
|       2) by calling HAL API function HAL_RCC_GetHCLKFreq() | ||||
|       3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency | ||||
|          Note: If you use this function to configure the system clock; then there | ||||
|                is no need to call the 2 first functions listed above, since SystemCoreClock | ||||
|                variable is updated automatically. | ||||
|   */ | ||||
|   uint32_t SystemCoreClock  = 4000000UL ; /*CPU1: M4 on MSI clock after startup (4MHz)*/ | ||||
|  | ||||
|   const uint32_t AHBPrescTable[16UL] = {1UL, 3UL, 5UL, 1UL, 1UL, 6UL, 10UL, 32UL, 2UL, 4UL, 8UL, 16UL, 64UL, 128UL, 256UL, 512UL}; | ||||
|  | ||||
|   const uint32_t APBPrescTable[8UL]  = {0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL}; | ||||
|  | ||||
|   const uint32_t MSIRangeTable[16UL] = {100000UL, 200000UL, 400000UL, 800000UL, 1000000UL, 2000000UL, \ | ||||
|                                       4000000UL, 8000000UL, 16000000UL, 24000000UL, 32000000UL, 48000000UL, 0UL, 0UL, 0UL, 0UL}; /* 0UL values are incorrect cases */ | ||||
|  | ||||
| #if defined(STM32WB55xx) || defined(STM32WB5Mxx) || defined(STM32WB35xx) || defined (STM32WB15xx) || defined (STM32WB10xx) | ||||
|   const uint32_t SmpsPrescalerTable[4UL][6UL]={{1UL,3UL,2UL,2UL,1UL,2UL}, \ | ||||
|                                         {2UL,6UL,4UL,3UL,2UL,4UL}, \ | ||||
|                                         {4UL,12UL,8UL,6UL,4UL,8UL}, \ | ||||
|                                         {4UL,12UL,8UL,6UL,4UL,8UL}}; | ||||
| #endif | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @addtogroup STM32WBxx_System_Private_FunctionPrototypes | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @addtogroup STM32WBxx_System_Private_Functions | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|   * @brief  Setup the microcontroller system. | ||||
|   * @param  None | ||||
|   * @retval None | ||||
|   */ | ||||
| void SystemInit(void) | ||||
| { | ||||
| #if defined(USER_VECT_TAB_ADDRESS) | ||||
|   /* Configure the Vector Table location add offset address ------------------*/ | ||||
|   SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; | ||||
| #endif | ||||
|  | ||||
|   /* FPU settings ------------------------------------------------------------*/ | ||||
|   #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) | ||||
|     SCB->CPACR |= ((3UL << (10UL*2UL))|(3UL << (11UL*2UL)));  /* set CP10 and CP11 Full Access */ | ||||
|   #endif | ||||
|    | ||||
|   /* Reset the RCC clock configuration to the default reset state ------------*/ | ||||
|   /* Set MSION bit */ | ||||
|   RCC->CR |= RCC_CR_MSION; | ||||
|  | ||||
|   /* Reset CFGR register */ | ||||
|   RCC->CFGR = 0x00070000U; | ||||
|  | ||||
|   /* Reset PLLSAI1ON, PLLON, HSECSSON, HSEON, HSION, and MSIPLLON bits */ | ||||
|   RCC->CR &= (uint32_t)0xFAF6FEFBU; | ||||
|  | ||||
|   /*!< Reset LSI1 and LSI2 bits */ | ||||
|   RCC->CSR &= (uint32_t)0xFFFFFFFAU; | ||||
|    | ||||
|   /*!< Reset HSI48ON  bit */ | ||||
|   RCC->CRRCR &= (uint32_t)0xFFFFFFFEU; | ||||
|      | ||||
|   /* Reset PLLCFGR register */ | ||||
|   RCC->PLLCFGR = 0x22041000U; | ||||
|  | ||||
| #if defined(STM32WB55xx) || defined(STM32WB5Mxx) | ||||
|   /* Reset PLLSAI1CFGR register */ | ||||
|   RCC->PLLSAI1CFGR = 0x22041000U; | ||||
| #endif | ||||
|    | ||||
|   /* Reset HSEBYP bit */ | ||||
|   RCC->CR &= 0xFFFBFFFFU; | ||||
|  | ||||
|   /* Disable all interrupts */ | ||||
|   RCC->CIER = 0x00000000; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Update SystemCoreClock variable according to Clock Register Values. | ||||
|   *         The SystemCoreClock variable contains the core clock (HCLK), it can | ||||
|   *         be used by the user application to setup the SysTick timer or configure | ||||
|   *         other parameters. | ||||
|   * | ||||
|   * @note   Each time the core clock (HCLK) changes, this function must be called | ||||
|   *         to update SystemCoreClock variable value. Otherwise, any configuration | ||||
|   *         based on this variable will be incorrect. | ||||
|   * | ||||
|   * @note   - The system frequency computed by this function is not the real | ||||
|   *           frequency in the chip. It is calculated based on the predefined | ||||
|   *           constant and the selected clock source: | ||||
|   * | ||||
|   *           - If SYSCLK source is MSI, SystemCoreClock will contain the MSI_VALUE(*) | ||||
|   * | ||||
|   *           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**) | ||||
|   * | ||||
|   *           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***) | ||||
|   * | ||||
|   *           - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***) | ||||
|   *             or HSI_VALUE(*) or MSI_VALUE(*) multiplied/divided by the PLL factors. | ||||
|   * | ||||
|   *         (*) MSI_VALUE is a constant defined in stm32wbxx_hal.h file (default value | ||||
|   *             4 MHz) but the real value may vary depending on the variations | ||||
|   *             in voltage and temperature. | ||||
|   * | ||||
|   *         (**) HSI_VALUE is a constant defined in stm32wbxx_hal_conf.h file (default value | ||||
|   *              16 MHz) but the real value may vary depending on the variations | ||||
|   *              in voltage and temperature. | ||||
|   * | ||||
|   *         (***) HSE_VALUE is a constant defined in stm32wbxx_hal_conf.h file (default value | ||||
|   *              32 MHz), user has to ensure that HSE_VALUE is same as the real | ||||
|   *              frequency of the crystal used. Otherwise, this function may | ||||
|   *              have wrong result. | ||||
|   * | ||||
|   *         - The result of this function could be not correct when using fractional | ||||
|   *           value for HSE crystal. | ||||
|   * | ||||
|   * @param  None | ||||
|   * @retval None | ||||
|   */ | ||||
| void SystemCoreClockUpdate(void) | ||||
| { | ||||
|   uint32_t tmp, msirange, pllvco, pllr, pllsource , pllm; | ||||
|  | ||||
|   /* Get MSI Range frequency--------------------------------------------------*/ | ||||
|  | ||||
|   /*MSI frequency range in Hz*/ | ||||
|   msirange = MSIRangeTable[(RCC->CR & RCC_CR_MSIRANGE) >> RCC_CR_MSIRANGE_Pos]; | ||||
|  | ||||
|   /* Get SYSCLK source -------------------------------------------------------*/ | ||||
|   switch (RCC->CFGR & RCC_CFGR_SWS) | ||||
|   { | ||||
|     case 0x00:   /* MSI used as system clock source */ | ||||
|       SystemCoreClock = msirange; | ||||
|       break; | ||||
|  | ||||
|     case 0x04:  /* HSI used as system clock source */ | ||||
|       /* HSI used as system clock source */ | ||||
|         SystemCoreClock = HSI_VALUE; | ||||
|       break; | ||||
|  | ||||
|     case 0x08:  /* HSE used as system clock source */ | ||||
|       SystemCoreClock = HSE_VALUE; | ||||
|       break; | ||||
|  | ||||
|     case 0x0C: /* PLL used as system clock  source */ | ||||
|       /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN | ||||
|          SYSCLK = PLL_VCO / PLLR | ||||
|          */ | ||||
|       pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC); | ||||
|       pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1UL ; | ||||
|  | ||||
|       if(pllsource == 0x02UL) /* HSI used as PLL clock source */ | ||||
|       { | ||||
|         pllvco = (HSI_VALUE / pllm); | ||||
|       } | ||||
|       else if(pllsource == 0x03UL) /* HSE used as PLL clock source */ | ||||
|       { | ||||
|         pllvco = (HSE_VALUE / pllm); | ||||
|       } | ||||
|       else /* MSI used as PLL clock source */ | ||||
|       { | ||||
|         pllvco = (msirange / pllm); | ||||
|       } | ||||
|        | ||||
|       pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos); | ||||
|       pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> RCC_PLLCFGR_PLLR_Pos) + 1UL); | ||||
|        | ||||
|       SystemCoreClock = pllvco/pllr; | ||||
|       break; | ||||
|  | ||||
|     default: | ||||
|       SystemCoreClock = msirange; | ||||
|       break; | ||||
|   } | ||||
|    | ||||
|   /* Compute HCLK clock frequency --------------------------------------------*/ | ||||
|   /* Get HCLK1 prescaler */ | ||||
|   tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos)]; | ||||
|   /* HCLK clock frequency */ | ||||
|   SystemCoreClock = SystemCoreClock / tmp; | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										394
									
								
								firmware/targets/f7/cube/Src/tim.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										394
									
								
								firmware/targets/f7/cube/Src/tim.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,394 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    tim.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of the TIM instances. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "tim.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| TIM_HandleTypeDef htim1; | ||||
| TIM_HandleTypeDef htim2; | ||||
| TIM_HandleTypeDef htim16; | ||||
|  | ||||
| /* TIM1 init function */ | ||||
| void MX_TIM1_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN TIM1_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM1_Init 0 */ | ||||
|  | ||||
|   TIM_ClockConfigTypeDef sClockSourceConfig = {0}; | ||||
|   TIM_MasterConfigTypeDef sMasterConfig = {0}; | ||||
|   TIM_OC_InitTypeDef sConfigOC = {0}; | ||||
|   TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; | ||||
|  | ||||
|   /* USER CODE BEGIN TIM1_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM1_Init 1 */ | ||||
|   htim1.Instance = TIM1; | ||||
|   htim1.Init.Prescaler = 0; | ||||
|   htim1.Init.CounterMode = TIM_COUNTERMODE_UP; | ||||
|   htim1.Init.Period = 65535; | ||||
|   htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; | ||||
|   htim1.Init.RepetitionCounter = 0; | ||||
|   htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; | ||||
|   if (HAL_TIM_Base_Init(&htim1) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; | ||||
|   if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   if (HAL_TIM_OC_Init(&htim1) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   if (HAL_TIM_PWM_Init(&htim1) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; | ||||
|   sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET; | ||||
|   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; | ||||
|   if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   sConfigOC.OCMode = TIM_OCMODE_TIMING; | ||||
|   sConfigOC.Pulse = 0; | ||||
|   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; | ||||
|   sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; | ||||
|   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; | ||||
|   sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; | ||||
|   sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; | ||||
|   if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   sConfigOC.OCMode = TIM_OCMODE_PWM1; | ||||
|   if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; | ||||
|   sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; | ||||
|   sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; | ||||
|   sBreakDeadTimeConfig.DeadTime = 0; | ||||
|   sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; | ||||
|   sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; | ||||
|   sBreakDeadTimeConfig.BreakFilter = 0; | ||||
|   sBreakDeadTimeConfig.BreakAFMode = TIM_BREAK_AFMODE_INPUT; | ||||
|   sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE; | ||||
|   sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH; | ||||
|   sBreakDeadTimeConfig.Break2Filter = 0; | ||||
|   sBreakDeadTimeConfig.Break2AFMode = TIM_BREAK_AFMODE_INPUT; | ||||
|   sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; | ||||
|   if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN TIM1_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END TIM1_Init 2 */ | ||||
|   HAL_TIM_MspPostInit(&htim1); | ||||
|  | ||||
| } | ||||
| /* TIM2 init function */ | ||||
| void MX_TIM2_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN TIM2_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM2_Init 0 */ | ||||
|  | ||||
|   TIM_ClockConfigTypeDef sClockSourceConfig = {0}; | ||||
|   TIM_MasterConfigTypeDef sMasterConfig = {0}; | ||||
|   TIM_IC_InitTypeDef sConfigIC = {0}; | ||||
|  | ||||
|   /* USER CODE BEGIN TIM2_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM2_Init 1 */ | ||||
|   htim2.Instance = TIM2; | ||||
|   htim2.Init.Prescaler = 64-1; | ||||
|   htim2.Init.CounterMode = TIM_COUNTERMODE_UP; | ||||
|   htim2.Init.Period = 4294967295; | ||||
|   htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; | ||||
|   htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; | ||||
|   if (HAL_TIM_Base_Init(&htim2) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; | ||||
|   if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   if (HAL_TIM_IC_Init(&htim2) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; | ||||
|   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; | ||||
|   if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING; | ||||
|   sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI; | ||||
|   sConfigIC.ICPrescaler = TIM_ICPSC_DIV1; | ||||
|   sConfigIC.ICFilter = 0; | ||||
|   if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING; | ||||
|   sConfigIC.ICSelection = TIM_ICSELECTION_INDIRECTTI; | ||||
|   if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_2) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN TIM2_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END TIM2_Init 2 */ | ||||
|  | ||||
| } | ||||
| /* TIM16 init function */ | ||||
| void MX_TIM16_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN TIM16_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM16_Init 0 */ | ||||
|  | ||||
|   TIM_OC_InitTypeDef sConfigOC = {0}; | ||||
|   TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; | ||||
|  | ||||
|   /* USER CODE BEGIN TIM16_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM16_Init 1 */ | ||||
|   htim16.Instance = TIM16; | ||||
|   htim16.Init.Prescaler = 500 - 1; | ||||
|   htim16.Init.CounterMode = TIM_COUNTERMODE_UP; | ||||
|   htim16.Init.Period = 291; | ||||
|   htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; | ||||
|   htim16.Init.RepetitionCounter = 0; | ||||
|   htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; | ||||
|   if (HAL_TIM_Base_Init(&htim16) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   if (HAL_TIM_PWM_Init(&htim16) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   sConfigOC.OCMode = TIM_OCMODE_PWM1; | ||||
|   sConfigOC.Pulse = 145; | ||||
|   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; | ||||
|   sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; | ||||
|   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; | ||||
|   sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; | ||||
|   sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; | ||||
|   if (HAL_TIM_PWM_ConfigChannel(&htim16, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; | ||||
|   sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; | ||||
|   sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; | ||||
|   sBreakDeadTimeConfig.DeadTime = 0; | ||||
|   sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; | ||||
|   sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; | ||||
|   sBreakDeadTimeConfig.BreakFilter = 0; | ||||
|   sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; | ||||
|   if (HAL_TIMEx_ConfigBreakDeadTime(&htim16, &sBreakDeadTimeConfig) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN TIM16_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END TIM16_Init 2 */ | ||||
|   HAL_TIM_MspPostInit(&htim16); | ||||
|  | ||||
| } | ||||
|  | ||||
| void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) | ||||
| { | ||||
|  | ||||
|   GPIO_InitTypeDef GPIO_InitStruct = {0}; | ||||
|   if(tim_baseHandle->Instance==TIM1) | ||||
|   { | ||||
|   /* USER CODE BEGIN TIM1_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM1_MspInit 0 */ | ||||
|     /* TIM1 clock enable */ | ||||
|     __HAL_RCC_TIM1_CLK_ENABLE(); | ||||
|  | ||||
|     /* TIM1 interrupt Init */ | ||||
|     HAL_NVIC_SetPriority(TIM1_TRG_COM_TIM17_IRQn, 5, 0); | ||||
|     HAL_NVIC_EnableIRQ(TIM1_TRG_COM_TIM17_IRQn); | ||||
|   /* USER CODE BEGIN TIM1_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM1_MspInit 1 */ | ||||
|   } | ||||
|   else if(tim_baseHandle->Instance==TIM2) | ||||
|   { | ||||
|   /* USER CODE BEGIN TIM2_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM2_MspInit 0 */ | ||||
|     /* TIM2 clock enable */ | ||||
|     __HAL_RCC_TIM2_CLK_ENABLE(); | ||||
|  | ||||
|     __HAL_RCC_GPIOA_CLK_ENABLE(); | ||||
|     /**TIM2 GPIO Configuration | ||||
|     PA0     ------> TIM2_CH1 | ||||
|     */ | ||||
|     GPIO_InitStruct.Pin = IR_RX_Pin; | ||||
|     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||||
|     GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||||
|     GPIO_InitStruct.Alternate = GPIO_AF1_TIM2; | ||||
|     HAL_GPIO_Init(IR_RX_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|     /* TIM2 interrupt Init */ | ||||
|     HAL_NVIC_SetPriority(TIM2_IRQn, 5, 0); | ||||
|     HAL_NVIC_EnableIRQ(TIM2_IRQn); | ||||
|   /* USER CODE BEGIN TIM2_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM2_MspInit 1 */ | ||||
|   } | ||||
|   else if(tim_baseHandle->Instance==TIM16) | ||||
|   { | ||||
|   /* USER CODE BEGIN TIM16_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM16_MspInit 0 */ | ||||
|     /* TIM16 clock enable */ | ||||
|     __HAL_RCC_TIM16_CLK_ENABLE(); | ||||
|   /* USER CODE BEGIN TIM16_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM16_MspInit 1 */ | ||||
|   } | ||||
| } | ||||
| void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) | ||||
| { | ||||
|  | ||||
|   GPIO_InitTypeDef GPIO_InitStruct = {0}; | ||||
|   if(timHandle->Instance==TIM1) | ||||
|   { | ||||
|   /* USER CODE BEGIN TIM1_MspPostInit 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM1_MspPostInit 0 */ | ||||
|     __HAL_RCC_GPIOB_CLK_ENABLE(); | ||||
|     /**TIM1 GPIO Configuration | ||||
|     PB9     ------> TIM1_CH3N | ||||
|     PB13     ------> TIM1_CH1N | ||||
|     */ | ||||
|     GPIO_InitStruct.Pin = IR_TX_Pin|RFID_OUT_Pin; | ||||
|     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||||
|     GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||||
|     GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; | ||||
|     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | ||||
|  | ||||
|   /* USER CODE BEGIN TIM1_MspPostInit 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM1_MspPostInit 1 */ | ||||
|   } | ||||
|   else if(timHandle->Instance==TIM16) | ||||
|   { | ||||
|   /* USER CODE BEGIN TIM16_MspPostInit 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM16_MspPostInit 0 */ | ||||
|  | ||||
|     __HAL_RCC_GPIOB_CLK_ENABLE(); | ||||
|     /**TIM16 GPIO Configuration | ||||
|     PB8     ------> TIM16_CH1 | ||||
|     */ | ||||
|     GPIO_InitStruct.Pin = SPEAKER_Pin; | ||||
|     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||||
|     GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||||
|     GPIO_InitStruct.Alternate = GPIO_AF14_TIM16; | ||||
|     HAL_GPIO_Init(SPEAKER_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|   /* USER CODE BEGIN TIM16_MspPostInit 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM16_MspPostInit 1 */ | ||||
|   } | ||||
|  | ||||
| } | ||||
|  | ||||
| void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) | ||||
| { | ||||
|  | ||||
|   if(tim_baseHandle->Instance==TIM1) | ||||
|   { | ||||
|   /* USER CODE BEGIN TIM1_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM1_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_TIM1_CLK_DISABLE(); | ||||
|  | ||||
|     /* TIM1 interrupt Deinit */ | ||||
|     HAL_NVIC_DisableIRQ(TIM1_TRG_COM_TIM17_IRQn); | ||||
|   /* USER CODE BEGIN TIM1_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM1_MspDeInit 1 */ | ||||
|   } | ||||
|   else if(tim_baseHandle->Instance==TIM2) | ||||
|   { | ||||
|   /* USER CODE BEGIN TIM2_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM2_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_TIM2_CLK_DISABLE(); | ||||
|  | ||||
|     /**TIM2 GPIO Configuration | ||||
|     PA0     ------> TIM2_CH1 | ||||
|     */ | ||||
|     HAL_GPIO_DeInit(IR_RX_GPIO_Port, IR_RX_Pin); | ||||
|  | ||||
|     /* TIM2 interrupt Deinit */ | ||||
|     HAL_NVIC_DisableIRQ(TIM2_IRQn); | ||||
|   /* USER CODE BEGIN TIM2_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM2_MspDeInit 1 */ | ||||
|   } | ||||
|   else if(tim_baseHandle->Instance==TIM16) | ||||
|   { | ||||
|   /* USER CODE BEGIN TIM16_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END TIM16_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_TIM16_CLK_DISABLE(); | ||||
|   /* USER CODE BEGIN TIM16_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END TIM16_MspDeInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										95
									
								
								firmware/targets/f7/cube/Src/usart.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								firmware/targets/f7/cube/Src/usart.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,95 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file    usart.c | ||||
|   * @brief   This file provides code for the configuration | ||||
|   *          of the USART instances. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "usart.h" | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| /* USART1 init function */ | ||||
|  | ||||
| void MX_USART1_UART_Init(void) | ||||
| { | ||||
|  | ||||
|   /* USER CODE BEGIN USART1_Init 0 */ | ||||
|  | ||||
|   /* USER CODE END USART1_Init 0 */ | ||||
|  | ||||
|   LL_USART_InitTypeDef USART_InitStruct = {0}; | ||||
|  | ||||
|   LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; | ||||
|  | ||||
|   /* Peripheral clock enable */ | ||||
|   LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); | ||||
|  | ||||
|   LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); | ||||
|   /**USART1 GPIO Configuration | ||||
|   PB6   ------> USART1_TX | ||||
|   PB7   ------> USART1_RX | ||||
|   */ | ||||
|   GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7; | ||||
|   GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; | ||||
|   GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; | ||||
|   GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; | ||||
|   GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; | ||||
|   GPIO_InitStruct.Alternate = LL_GPIO_AF_7; | ||||
|   LL_GPIO_Init(GPIOB, &GPIO_InitStruct); | ||||
|  | ||||
|   /* USER CODE BEGIN USART1_Init 1 */ | ||||
|  | ||||
|   /* USER CODE END USART1_Init 1 */ | ||||
|   USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1; | ||||
|   USART_InitStruct.BaudRate = 115200; | ||||
|   USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; | ||||
|   USART_InitStruct.StopBits = LL_USART_STOPBITS_1; | ||||
|   USART_InitStruct.Parity = LL_USART_PARITY_NONE; | ||||
|   USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX; | ||||
|   USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE; | ||||
|   USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16; | ||||
|   LL_USART_Init(USART1, &USART_InitStruct); | ||||
|   LL_USART_SetTXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); | ||||
|   LL_USART_SetRXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); | ||||
|   LL_USART_DisableFIFO(USART1); | ||||
|   LL_USART_EnableAutoBaudRate(USART1); | ||||
|   LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_STARTBIT); | ||||
|   LL_USART_ConfigAsyncMode(USART1); | ||||
|  | ||||
|   /* USER CODE BEGIN WKUPType USART1 */ | ||||
|  | ||||
|   /* USER CODE END WKUPType USART1 */ | ||||
|  | ||||
|   LL_USART_Enable(USART1); | ||||
|  | ||||
|   /* Polling USART1 initialisation */ | ||||
|   while(!(LL_USART_IsActiveFlag_TEACK(USART1))) | ||||
|   { | ||||
|   } | ||||
|   /* USER CODE BEGIN USART1_Init 2 */ | ||||
|  | ||||
|   /* USER CODE END USART1_Init 2 */ | ||||
|  | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										99
									
								
								firmware/targets/f7/cube/Src/usb_device.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								firmware/targets/f7/cube/Src/usb_device.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,99 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file           : usb_device.c | ||||
|   * @version        : v3.0_Cube | ||||
|   * @brief          : This file implements the USB Device | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
|  | ||||
| #include "usb_device.h" | ||||
| #include "usbd_core.h" | ||||
| #include "usbd_desc.h" | ||||
| #include "usbd_cdc.h" | ||||
| #include "usbd_cdc_if.h" | ||||
|  | ||||
| /* USER CODE BEGIN Includes */ | ||||
|  | ||||
| /* USER CODE END Includes */ | ||||
|  | ||||
| /* USER CODE BEGIN PV */ | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
|  | ||||
| /* USER CODE END PV */ | ||||
|  | ||||
| /* USER CODE BEGIN PFP */ | ||||
| /* Private function prototypes -----------------------------------------------*/ | ||||
|  | ||||
| /* USER CODE END PFP */ | ||||
|  | ||||
| extern void Error_Handler(void); | ||||
| /* USB Device Core handle declaration. */ | ||||
| USBD_HandleTypeDef hUsbDeviceFS; | ||||
| extern USBD_DescriptorsTypeDef CDC_Desc; | ||||
|  | ||||
| /* | ||||
|  * -- Insert your variables declaration here -- | ||||
|  */ | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| /* | ||||
|  * -- Insert your external function declaration here -- | ||||
|  */ | ||||
| /* USER CODE BEGIN 1 */ | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
|  | ||||
| /** | ||||
|   * Init USB device Library, add supported class and start the library | ||||
|   * @retval None | ||||
|   */ | ||||
| void MX_USB_Device_Init(void) | ||||
| { | ||||
|   /* USER CODE BEGIN USB_Device_Init_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE END USB_Device_Init_PreTreatment */ | ||||
|  | ||||
|   /* Init Device Library, add supported class and start the library. */ | ||||
|   if (USBD_Init(&hUsbDeviceFS, &CDC_Desc, DEVICE_FS) != USBD_OK) { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   if (USBD_Start(&hUsbDeviceFS) != USBD_OK) { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN USB_Device_Init_PostTreatment */ | ||||
|  | ||||
|   /* USER CODE END USB_Device_Init_PostTreatment */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										331
									
								
								firmware/targets/f7/cube/Src/usbd_cdc_if.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										331
									
								
								firmware/targets/f7/cube/Src/usbd_cdc_if.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,331 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file           : usbd_cdc_if.c | ||||
|   * @version        : v3.0_Cube | ||||
|   * @brief          : Usb device for Virtual Com Port. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "usbd_cdc_if.h" | ||||
|  | ||||
| /* USER CODE BEGIN INCLUDE */ | ||||
|  | ||||
| /* USER CODE END INCLUDE */ | ||||
|  | ||||
| /* Private typedef -----------------------------------------------------------*/ | ||||
| /* Private define ------------------------------------------------------------*/ | ||||
| /* Private macro -------------------------------------------------------------*/ | ||||
|  | ||||
| /* USER CODE BEGIN PV */ | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
|  | ||||
| /* USER CODE END PV */ | ||||
|  | ||||
| /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY | ||||
|   * @brief Usb device library. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /** @addtogroup USBD_CDC_IF | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_CDC_IF_Private_TypesDefinitions USBD_CDC_IF_Private_TypesDefinitions | ||||
|   * @brief Private types. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /* USER CODE BEGIN PRIVATE_TYPES */ | ||||
|  | ||||
| /* USER CODE END PRIVATE_TYPES */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_CDC_IF_Private_Defines USBD_CDC_IF_Private_Defines | ||||
|   * @brief Private defines. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /* USER CODE BEGIN PRIVATE_DEFINES */ | ||||
| /* USER CODE END PRIVATE_DEFINES */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_CDC_IF_Private_Macros USBD_CDC_IF_Private_Macros | ||||
|   * @brief Private macros. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /* USER CODE BEGIN PRIVATE_MACRO */ | ||||
|  | ||||
| /* USER CODE END PRIVATE_MACRO */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_CDC_IF_Private_Variables USBD_CDC_IF_Private_Variables | ||||
|   * @brief Private variables. | ||||
|   * @{ | ||||
|   */ | ||||
| /* Create buffer for reception and transmission           */ | ||||
| /* It's up to user to redefine and/or remove those define */ | ||||
| /** Received data over USB are stored in this buffer      */ | ||||
| uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; | ||||
|  | ||||
| /** Data to send over USB CDC are stored in this buffer   */ | ||||
| uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; | ||||
|  | ||||
| /* USER CODE BEGIN PRIVATE_VARIABLES */ | ||||
|  | ||||
| /* USER CODE END PRIVATE_VARIABLES */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables | ||||
|   * @brief Public variables. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| extern USBD_HandleTypeDef hUsbDeviceFS; | ||||
|  | ||||
| /* USER CODE BEGIN EXPORTED_VARIABLES */ | ||||
|  | ||||
| /* USER CODE END EXPORTED_VARIABLES */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_CDC_IF_Private_FunctionPrototypes USBD_CDC_IF_Private_FunctionPrototypes | ||||
|   * @brief Private functions declaration. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| static int8_t CDC_Init_FS(void); | ||||
| static int8_t CDC_DeInit_FS(void); | ||||
| static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length); | ||||
| static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len); | ||||
| static int8_t CDC_TransmitCplt_FS(uint8_t *pbuf, uint32_t *Len, uint8_t epnum); | ||||
|  | ||||
| /* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ | ||||
|  | ||||
| /* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = | ||||
| { | ||||
|   CDC_Init_FS, | ||||
|   CDC_DeInit_FS, | ||||
|   CDC_Control_FS, | ||||
|   CDC_Receive_FS, | ||||
|   CDC_TransmitCplt_FS | ||||
| }; | ||||
|  | ||||
| /* Private functions ---------------------------------------------------------*/ | ||||
| /** | ||||
|   * @brief  Initializes the CDC media low layer over the FS USB IP | ||||
|   * @retval USBD_OK if all operations are OK else USBD_FAIL | ||||
|   */ | ||||
| static int8_t CDC_Init_FS(void) | ||||
| { | ||||
|   /* USER CODE BEGIN 3 */ | ||||
|   /* Set Application Buffers */ | ||||
|   USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); | ||||
|   USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); | ||||
|   return (USBD_OK); | ||||
|   /* USER CODE END 3 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  DeInitializes the CDC media low layer | ||||
|   * @retval USBD_OK if all operations are OK else USBD_FAIL | ||||
|   */ | ||||
| static int8_t CDC_DeInit_FS(void) | ||||
| { | ||||
|   /* USER CODE BEGIN 4 */ | ||||
|   return (USBD_OK); | ||||
|   /* USER CODE END 4 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Manage the CDC class requests | ||||
|   * @param  cmd: Command code | ||||
|   * @param  pbuf: Buffer containing command data (request parameters) | ||||
|   * @param  length: Number of data to be sent (in bytes) | ||||
|   * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL | ||||
|   */ | ||||
| static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) | ||||
| { | ||||
|   /* USER CODE BEGIN 5 */ | ||||
|   switch(cmd) | ||||
|   { | ||||
|     case CDC_SEND_ENCAPSULATED_COMMAND: | ||||
|  | ||||
|     break; | ||||
|  | ||||
|     case CDC_GET_ENCAPSULATED_RESPONSE: | ||||
|  | ||||
|     break; | ||||
|  | ||||
|     case CDC_SET_COMM_FEATURE: | ||||
|  | ||||
|     break; | ||||
|  | ||||
|     case CDC_GET_COMM_FEATURE: | ||||
|  | ||||
|     break; | ||||
|  | ||||
|     case CDC_CLEAR_COMM_FEATURE: | ||||
|  | ||||
|     break; | ||||
|  | ||||
|   /*******************************************************************************/ | ||||
|   /* Line Coding Structure                                                       */ | ||||
|   /*-----------------------------------------------------------------------------*/ | ||||
|   /* Offset | Field       | Size | Value  | Description                          */ | ||||
|   /* 0      | dwDTERate   |   4  | Number |Data terminal rate, in bits per second*/ | ||||
|   /* 4      | bCharFormat |   1  | Number | Stop bits                            */ | ||||
|   /*                                        0 - 1 Stop bit                       */ | ||||
|   /*                                        1 - 1.5 Stop bits                    */ | ||||
|   /*                                        2 - 2 Stop bits                      */ | ||||
|   /* 5      | bParityType |  1   | Number | Parity                               */ | ||||
|   /*                                        0 - None                             */ | ||||
|   /*                                        1 - Odd                              */ | ||||
|   /*                                        2 - Even                             */ | ||||
|   /*                                        3 - Mark                             */ | ||||
|   /*                                        4 - Space                            */ | ||||
|   /* 6      | bDataBits  |   1   | Number Data bits (5, 6, 7, 8 or 16).          */ | ||||
|   /*******************************************************************************/ | ||||
|     case CDC_SET_LINE_CODING: | ||||
|  | ||||
|     break; | ||||
|  | ||||
|     case CDC_GET_LINE_CODING: | ||||
|  | ||||
|     break; | ||||
|  | ||||
|     case CDC_SET_CONTROL_LINE_STATE: | ||||
|  | ||||
|     break; | ||||
|  | ||||
|     case CDC_SEND_BREAK: | ||||
|  | ||||
|     break; | ||||
|  | ||||
|   default: | ||||
|     break; | ||||
|   } | ||||
|  | ||||
|   return (USBD_OK); | ||||
|   /* USER CODE END 5 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Data received over USB OUT endpoint are sent over CDC interface | ||||
|   *         through this function. | ||||
|   * | ||||
|   *         @note | ||||
|   *         This function will issue a NAK packet on any OUT packet received on | ||||
|   *         USB endpoint until exiting this function. If you exit this function | ||||
|   *         before transfer is complete on CDC interface (ie. using DMA controller) | ||||
|   *         it will result in receiving more data while previous ones are still | ||||
|   *         not sent. | ||||
|   * | ||||
|   * @param  Buf: Buffer of data to be received | ||||
|   * @param  Len: Number of data received (in bytes) | ||||
|   * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL | ||||
|   */ | ||||
| static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) | ||||
| { | ||||
|   /* USER CODE BEGIN 6 */ | ||||
|   USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); | ||||
|   USBD_CDC_ReceivePacket(&hUsbDeviceFS); | ||||
|   return (USBD_OK); | ||||
|   /* USER CODE END 6 */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  CDC_Transmit_FS | ||||
|   *         Data to send over USB IN endpoint are sent over CDC interface | ||||
|   *         through this function. | ||||
|   *         @note | ||||
|   * | ||||
|   * | ||||
|   * @param  Buf: Buffer of data to be sent | ||||
|   * @param  Len: Number of data to be sent (in bytes) | ||||
|   * @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY | ||||
|   */ | ||||
| uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) | ||||
| { | ||||
|   uint8_t result = USBD_OK; | ||||
|   /* USER CODE BEGIN 7 */ | ||||
|   USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; | ||||
|   if (hcdc->TxState != 0){ | ||||
|     return USBD_BUSY; | ||||
|   } | ||||
|   USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); | ||||
|   result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); | ||||
|   /* USER CODE END 7 */ | ||||
|   return result; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  CDC_TransmitCplt_FS | ||||
|   *         Data transmitted callback | ||||
|   * | ||||
|   *         @note | ||||
|   *         This function is IN transfer complete callback used to inform user that | ||||
|   *         the submitted Data is successfully sent over USB. | ||||
|   * | ||||
|   * @param  Buf: Buffer of data to be received | ||||
|   * @param  Len: Number of data received (in bytes) | ||||
|   * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL | ||||
|   */ | ||||
| static int8_t CDC_TransmitCplt_FS(uint8_t *Buf, uint32_t *Len, uint8_t epnum) | ||||
| { | ||||
|   uint8_t result = USBD_OK; | ||||
|   /* USER CODE BEGIN 13 */ | ||||
|   UNUSED(Buf); | ||||
|   UNUSED(Len); | ||||
|   UNUSED(epnum); | ||||
|   /* USER CODE END 13 */ | ||||
|   return result; | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ | ||||
|  | ||||
| /* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										810
									
								
								firmware/targets/f7/cube/Src/usbd_conf.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										810
									
								
								firmware/targets/f7/cube/Src/usbd_conf.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,810 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file           : usbd_conf.c | ||||
|   * @version        : v3.0_Cube | ||||
|   * @brief          : This file implements the board support package for the USB device library | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "stm32wbxx.h" | ||||
| #include "stm32wbxx_hal.h" | ||||
| #include "usbd_def.h" | ||||
| #include "usbd_core.h" | ||||
|  | ||||
| #include "usbd_cdc.h" | ||||
|  | ||||
| /* USER CODE BEGIN Includes */ | ||||
|  | ||||
| /* USER CODE END Includes */ | ||||
|  | ||||
| /* Private typedef -----------------------------------------------------------*/ | ||||
| /* Private define ------------------------------------------------------------*/ | ||||
| /* Private macro -------------------------------------------------------------*/ | ||||
|  | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PV */ | ||||
|  | ||||
| /* USER CODE END PV */ | ||||
|  | ||||
| PCD_HandleTypeDef hpcd_USB_FS; | ||||
| void Error_Handler(void); | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| /* Exported function prototypes ----------------------------------------------*/ | ||||
|  | ||||
| /* USER CODE BEGIN PFP */ | ||||
| /* Private function prototypes -----------------------------------------------*/ | ||||
|  | ||||
| /* USER CODE END PFP */ | ||||
|  | ||||
| /* Private functions ---------------------------------------------------------*/ | ||||
| static USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status); | ||||
| /* USER CODE BEGIN 1 */ | ||||
| static void SystemClockConfig_Resume(void); | ||||
|  | ||||
| /* USER CODE END 1 */ | ||||
| extern void SystemClock_Config(void); | ||||
|  | ||||
| /******************************************************************************* | ||||
|                        LL Driver Callbacks (PCD -> USB Device Library) | ||||
| *******************************************************************************/ | ||||
| /* MSP Init */ | ||||
|  | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACK == 1U) | ||||
| static void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) | ||||
| #else | ||||
| void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACK */ | ||||
| { | ||||
|   GPIO_InitTypeDef GPIO_InitStruct = {0}; | ||||
|   if(pcdHandle->Instance==USB) | ||||
|   { | ||||
|   /* USER CODE BEGIN USB_MspInit 0 */ | ||||
|  | ||||
|   /* USER CODE END USB_MspInit 0 */ | ||||
|  | ||||
|     __HAL_RCC_GPIOA_CLK_ENABLE(); | ||||
|     /**USB GPIO Configuration | ||||
|     PA11     ------> USB_DM | ||||
|     PA12     ------> USB_DP | ||||
|     */ | ||||
|     GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; | ||||
|     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||||
|     GPIO_InitStruct.Pull = GPIO_NOPULL; | ||||
|     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; | ||||
|     GPIO_InitStruct.Alternate = GPIO_AF10_USB; | ||||
|     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | ||||
|  | ||||
|     /* Peripheral clock enable */ | ||||
|     __HAL_RCC_USB_CLK_ENABLE(); | ||||
|  | ||||
|     /* Peripheral interrupt init */ | ||||
|     HAL_NVIC_SetPriority(USB_LP_IRQn, 5, 0); | ||||
|     HAL_NVIC_EnableIRQ(USB_LP_IRQn); | ||||
|   /* USER CODE BEGIN USB_MspInit 1 */ | ||||
|  | ||||
|   /* USER CODE END USB_MspInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACK == 1U) | ||||
| static void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) | ||||
| #else | ||||
| void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACK */ | ||||
| { | ||||
|   if(pcdHandle->Instance==USB) | ||||
|   { | ||||
|   /* USER CODE BEGIN USB_MspDeInit 0 */ | ||||
|  | ||||
|   /* USER CODE END USB_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_USB_CLK_DISABLE(); | ||||
|  | ||||
|     /**USB GPIO Configuration | ||||
|     PA11     ------> USB_DM | ||||
|     PA12     ------> USB_DP | ||||
|     */ | ||||
|     HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12); | ||||
|  | ||||
|     /* Peripheral interrupt Deinit*/ | ||||
|     HAL_NVIC_DisableIRQ(USB_LP_IRQn); | ||||
|  | ||||
|   /* USER CODE BEGIN USB_MspDeInit 1 */ | ||||
|  | ||||
|   /* USER CODE END USB_MspDeInit 1 */ | ||||
|   } | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Setup stage callback | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE END  HAL_PCD_SetupStageCallback_PreTreatment */ | ||||
|   USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); | ||||
|   /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PostTreatment */ | ||||
|  | ||||
|   /* USER CODE END  HAL_PCD_SetupStageCallback_PostTreatment */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Data Out stage callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @param  epnum: Endpoint number | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #else | ||||
| void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_DataOutStageCallback_PreTreatment */ | ||||
|   USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); | ||||
|   /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PostTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_DataOutStageCallback_PostTreatment */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Data In stage callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @param  epnum: Endpoint number | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #else | ||||
| void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_DataInStageCallback_PreTreatment */ | ||||
|   USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); | ||||
|   /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PostTreatment  */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_DataInStageCallback_PostTreatment */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  SOF callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_SOFCallback_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_SOFCallback_PreTreatment */ | ||||
|   USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); | ||||
|   /* USER CODE BEGIN HAL_PCD_SOFCallback_PostTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_SOFCallback_PostTreatment */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Reset callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_ResetCallback_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_ResetCallback_PreTreatment */ | ||||
|   USBD_SpeedTypeDef speed = USBD_SPEED_FULL; | ||||
|  | ||||
|   if ( hpcd->Init.speed != PCD_SPEED_FULL) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|     /* Set Speed. */ | ||||
|   USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); | ||||
|  | ||||
|   /* Reset Device. */ | ||||
|   USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); | ||||
|   /* USER CODE BEGIN HAL_PCD_ResetCallback_PostTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_ResetCallback_PostTreatment */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Suspend callback. | ||||
|   * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_SuspendCallback_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_SuspendCallback_PreTreatment */ | ||||
|   /* Inform USB library that core enters in suspend Mode. */ | ||||
|   USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); | ||||
|   /* Enter in STOP mode. */ | ||||
|   /* USER CODE BEGIN 2 */ | ||||
|   if (hpcd->Init.low_power_enable) | ||||
|   { | ||||
|     /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ | ||||
|     SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | ||||
|   } | ||||
|   /* USER CODE END 2 */ | ||||
|   /* USER CODE BEGIN HAL_PCD_SuspendCallback_PostTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_SuspendCallback_PostTreatment */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Resume callback. | ||||
|   * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_ResumeCallback_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_ResumeCallback_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE BEGIN 3 */ | ||||
|   if (hpcd->Init.low_power_enable) | ||||
|   { | ||||
|     /* Reset SLEEPDEEP bit of Cortex System Control Register. */ | ||||
|     SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | ||||
|     SystemClockConfig_Resume(); | ||||
|   } | ||||
|   /* USER CODE END 3 */ | ||||
|  | ||||
|   USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); | ||||
|   /* USER CODE BEGIN HAL_PCD_ResumeCallback_PostTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_ResumeCallback_PostTreatment */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  ISOOUTIncomplete callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @param  epnum: Endpoint number | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #else | ||||
| void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */ | ||||
|   USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); | ||||
|   /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  ISOINIncomplete callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @param  epnum: Endpoint number | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #else | ||||
| void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PreTreatment */ | ||||
|   USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); | ||||
|   /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PostTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PostTreatment */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Connect callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_ConnectCallback_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_ConnectCallback_PreTreatment */ | ||||
|   USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); | ||||
|   /* USER CODE BEGIN HAL_PCD_ConnectCallback_PostTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_ConnectCallback_PostTreatment */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Disconnect callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PreTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_DisconnectCallback_PreTreatment */ | ||||
|   USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); | ||||
|   /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PostTreatment */ | ||||
|  | ||||
|   /* USER CODE END HAL_PCD_DisconnectCallback_PostTreatment */ | ||||
| } | ||||
|  | ||||
|   /* USER CODE BEGIN LowLevelInterface */ | ||||
|  | ||||
|   /* USER CODE END LowLevelInterface */ | ||||
|  | ||||
| /******************************************************************************* | ||||
|                        LL Driver Interface (USB Device Library --> PCD) | ||||
| *******************************************************************************/ | ||||
|  | ||||
| /** | ||||
|   * @brief  Initializes the low level portion of the device driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) | ||||
| { | ||||
|   /* Init USB Ip. */ | ||||
|   hpcd_USB_FS.pData = pdev; | ||||
|   /* Link the driver to the stack. */ | ||||
|   pdev->pData = &hpcd_USB_FS; | ||||
| /* Enable USB power on Pwrctrl CR2 register. */ | ||||
|   HAL_PWREx_EnableVddUSB(); | ||||
|  | ||||
|   hpcd_USB_FS.Instance = USB; | ||||
|   hpcd_USB_FS.Init.dev_endpoints = 8; | ||||
|   hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; | ||||
|   hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; | ||||
|   hpcd_USB_FS.Init.Sof_enable = DISABLE; | ||||
|   hpcd_USB_FS.Init.low_power_enable = DISABLE; | ||||
|   hpcd_USB_FS.Init.lpm_enable = DISABLE; | ||||
|   hpcd_USB_FS.Init.battery_charging_enable = DISABLE; | ||||
|  | ||||
|   #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
|   /* register Msp Callbacks (before the Init) */ | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_MSPINIT_CB_ID, PCD_MspInit); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_MSPDEINIT_CB_ID, PCD_MspDeInit); | ||||
|   #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
|  | ||||
|   if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler( ); | ||||
|   } | ||||
|  | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
|   /* Register USB PCD CallBacks */ | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback); | ||||
|   /* USER CODE BEGIN RegisterCallBackFirstPart */ | ||||
|  | ||||
|   /* USER CODE END RegisterCallBackFirstPart */ | ||||
|   HAL_PCD_RegisterLpmCallback(&hpcd_USB_FS, PCDEx_LPM_Callback); | ||||
|   HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_FS, PCD_DataOutStageCallback); | ||||
|   HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_FS, PCD_DataInStageCallback); | ||||
|   HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_FS, PCD_ISOOUTIncompleteCallback); | ||||
|   HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_FS, PCD_ISOINIncompleteCallback); | ||||
|   /* USER CODE BEGIN RegisterCallBackSecondPart */ | ||||
|  | ||||
|   /* USER CODE END RegisterCallBackSecondPart */ | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
|   /* USER CODE BEGIN EndPoint_Configuration */ | ||||
|   HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); | ||||
|   HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); | ||||
|   /* USER CODE END EndPoint_Configuration */ | ||||
|   /* USER CODE BEGIN EndPoint_Configuration_CDC */ | ||||
|   HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0); | ||||
|   HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110); | ||||
|   HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100); | ||||
|   /* USER CODE END EndPoint_Configuration_CDC */ | ||||
|   return USBD_OK; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  De-Initializes the low level portion of the device driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
|  | ||||
|   hal_status = HAL_PCD_DeInit(pdev->pData); | ||||
|  | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
|  | ||||
|   return usb_status; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Starts the low level portion of the device driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
|  | ||||
|   hal_status = HAL_PCD_Start(pdev->pData); | ||||
|  | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
|  | ||||
|   return usb_status; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Stops the low level portion of the device driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
|  | ||||
|   hal_status = HAL_PCD_Stop(pdev->pData); | ||||
|  | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
|  | ||||
|   return usb_status; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Opens an endpoint of the low level driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @param  ep_type: Endpoint type | ||||
|   * @param  ep_mps: Endpoint max packet size | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
|  | ||||
|   hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); | ||||
|  | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
|  | ||||
|   return usb_status; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Closes an endpoint of the low level driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
|  | ||||
|   hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); | ||||
|  | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
|  | ||||
|   return usb_status; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Flushes an endpoint of the Low Level Driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
|  | ||||
|   hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); | ||||
|  | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
|  | ||||
|   return usb_status; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Sets a Stall condition on an endpoint of the Low Level Driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
|  | ||||
|   hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); | ||||
|  | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
|  | ||||
|   return usb_status; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Clears a Stall condition on an endpoint of the Low Level Driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
|  | ||||
|   hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); | ||||
|  | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
|  | ||||
|   return usb_status; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Returns Stall condition. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @retval Stall (1: Yes, 0: No) | ||||
|   */ | ||||
| uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | ||||
| { | ||||
|   PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; | ||||
|  | ||||
|   if((ep_addr & 0x80) == 0x80) | ||||
|   { | ||||
|     return hpcd->IN_ep[ep_addr & 0x7F].is_stall; | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; | ||||
|   } | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Assigns a USB address to the device. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  dev_addr: Device address | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
|  | ||||
|   hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); | ||||
|  | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
|  | ||||
|   return usb_status; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Transmits data over an endpoint. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @param  pbuf: Pointer to data to be sent | ||||
|   * @param  size: Data size | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
|  | ||||
|   hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); | ||||
|  | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
|  | ||||
|   return usb_status; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Prepares an endpoint for reception. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @param  pbuf: Pointer to data to be received | ||||
|   * @param  size: Data size | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
|  | ||||
|   hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); | ||||
|  | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
|  | ||||
|   return usb_status; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Returns the last transferred packet size. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @retval Received Data Size | ||||
|   */ | ||||
| uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | ||||
| { | ||||
|   return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Send LPM message to user layer | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @param  msg: LPM message | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) | ||||
| #else | ||||
| void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN LPM_Callback */ | ||||
|   switch (msg) | ||||
|   { | ||||
|   case PCD_LPM_L0_ACTIVE: | ||||
|     if (hpcd->Init.low_power_enable) | ||||
|     { | ||||
|       SystemClockConfig_Resume(); | ||||
|  | ||||
|       /* Reset SLEEPDEEP bit of Cortex System Control Register. */ | ||||
|       SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | ||||
|     } | ||||
|     USBD_LL_Resume(hpcd->pData); | ||||
|     break; | ||||
|  | ||||
|   case PCD_LPM_L1_ACTIVE: | ||||
|     USBD_LL_Suspend(hpcd->pData); | ||||
|  | ||||
|     /* Enter in STOP mode. */ | ||||
|     if (hpcd->Init.low_power_enable) | ||||
|     { | ||||
|       /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ | ||||
|       SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | ||||
|     } | ||||
|     break; | ||||
|   } | ||||
|   /* USER CODE END LPM_Callback */ | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Delays routine for the USB Device Library. | ||||
|   * @param  Delay: Delay in ms | ||||
|   * @retval None | ||||
|   */ | ||||
| void USBD_LL_Delay(uint32_t Delay) | ||||
| { | ||||
|   HAL_Delay(Delay); | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Static single allocation. | ||||
|   * @param  size: Size of allocated memory | ||||
|   * @retval None | ||||
|   */ | ||||
| void *USBD_static_malloc(uint32_t size) | ||||
| { | ||||
|   static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */ | ||||
|   return mem; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Dummy memory free | ||||
|   * @param  p: Pointer to allocated  memory address | ||||
|   * @retval None | ||||
|   */ | ||||
| void USBD_static_free(void *p) | ||||
| { | ||||
|  | ||||
| } | ||||
|  | ||||
| /* USER CODE BEGIN 5 */ | ||||
| /** | ||||
|   * @brief  Configures system clock after wake-up from USB resume callBack: | ||||
|   *         enable HSI, PLL and select PLL as system clock source. | ||||
|   * @retval None | ||||
|   */ | ||||
| static void SystemClockConfig_Resume(void) | ||||
| { | ||||
|   SystemClock_Config(); | ||||
| } | ||||
| /* USER CODE END 5 */ | ||||
|  | ||||
| /** | ||||
|   * @brief  Returns the USB status depending on the HAL status: | ||||
|   * @param  hal_status: HAL status | ||||
|   * @retval USB status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status) | ||||
| { | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
|  | ||||
|   switch (hal_status) | ||||
|   { | ||||
|     case HAL_OK : | ||||
|       usb_status = USBD_OK; | ||||
|     break; | ||||
|     case HAL_ERROR : | ||||
|       usb_status = USBD_FAIL; | ||||
|     break; | ||||
|     case HAL_BUSY : | ||||
|       usb_status = USBD_BUSY; | ||||
|     break; | ||||
|     case HAL_TIMEOUT : | ||||
|       usb_status = USBD_FAIL; | ||||
|     break; | ||||
|     default : | ||||
|       usb_status = USBD_FAIL; | ||||
|     break; | ||||
|   } | ||||
|   return usb_status; | ||||
| } | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
							
								
								
									
										396
									
								
								firmware/targets/f7/cube/Src/usbd_desc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										396
									
								
								firmware/targets/f7/cube/Src/usbd_desc.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,396 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * @file           : usbd_desc.c | ||||
|   * @version        : v3.0_Cube | ||||
|   * @brief          : This file implements the USB device descriptors. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
|  | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "usbd_core.h" | ||||
| #include "usbd_desc.h" | ||||
| #include "usbd_conf.h" | ||||
|  | ||||
| /* USER CODE BEGIN INCLUDE */ | ||||
|  | ||||
| /* USER CODE END INCLUDE */ | ||||
|  | ||||
| /* Private typedef -----------------------------------------------------------*/ | ||||
| /* Private define ------------------------------------------------------------*/ | ||||
| /* Private macro -------------------------------------------------------------*/ | ||||
|  | ||||
| /* USER CODE BEGIN PV */ | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
|  | ||||
| /* USER CODE END PV */ | ||||
|  | ||||
| /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /** @addtogroup USBD_DESC | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions | ||||
|   * @brief Private types. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /* USER CODE BEGIN PRIVATE_TYPES */ | ||||
|  | ||||
| /* USER CODE END PRIVATE_TYPES */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines | ||||
|   * @brief Private defines. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| #define USBD_VID     1155 | ||||
| #define USBD_LANGID_STRING     1033 | ||||
| #define USBD_MANUFACTURER_STRING     "Flipper" | ||||
| #define USBD_PID     22336 | ||||
| #define USBD_PRODUCT_STRING     "Flipper Control Virtual ComPort" | ||||
| #define USBD_CONFIGURATION_STRING     "CDC Config" | ||||
| #define USBD_INTERFACE_STRING     "CDC Interface" | ||||
|  | ||||
| /* USER CODE BEGIN PRIVATE_DEFINES */ | ||||
|  | ||||
| /* USER CODE END PRIVATE_DEFINES */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /* USER CODE BEGIN 0 */ | ||||
|  | ||||
| /* USER CODE END 0 */ | ||||
|  | ||||
| /** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros | ||||
|   * @brief Private macros. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /* USER CODE BEGIN PRIVATE_MACRO */ | ||||
|  | ||||
| /* USER CODE END PRIVATE_MACRO */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes | ||||
|   * @brief Private functions declaration. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| static void Get_SerialNum(void); | ||||
| static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len); | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes | ||||
|   * @brief Private functions declaration. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| uint8_t * USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t * USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t * USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t * USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t * USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t * USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t * USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables | ||||
|   * @brief Private variables. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| USBD_DescriptorsTypeDef CDC_Desc = | ||||
| { | ||||
|   USBD_CDC_DeviceDescriptor, | ||||
|   USBD_CDC_LangIDStrDescriptor, | ||||
|   USBD_CDC_ManufacturerStrDescriptor, | ||||
|   USBD_CDC_ProductStrDescriptor, | ||||
|   USBD_CDC_SerialStrDescriptor, | ||||
|   USBD_CDC_ConfigStrDescriptor, | ||||
|   USBD_CDC_InterfaceStrDescriptor | ||||
| }; | ||||
|  | ||||
| #if defined ( __ICCARM__ ) /* IAR Compiler */ | ||||
|   #pragma data_alignment=4 | ||||
| #endif /* defined ( __ICCARM__ ) */ | ||||
| /** USB standard device descriptor. */ | ||||
| __ALIGN_BEGIN uint8_t USBD_CDC_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = | ||||
| { | ||||
|   0x12,                       /*bLength */ | ||||
|   USB_DESC_TYPE_DEVICE,       /*bDescriptorType*/ | ||||
|   0x00,                       /*bcdUSB */ | ||||
|   0x02, | ||||
|   0x02,                       /*bDeviceClass*/ | ||||
|   0x02,                       /*bDeviceSubClass*/ | ||||
|   0x00,                       /*bDeviceProtocol*/ | ||||
|   USB_MAX_EP0_SIZE,           /*bMaxPacketSize*/ | ||||
|   LOBYTE(USBD_VID),           /*idVendor*/ | ||||
|   HIBYTE(USBD_VID),           /*idVendor*/ | ||||
|   LOBYTE(USBD_PID),           /*idProduct*/ | ||||
|   HIBYTE(USBD_PID),           /*idProduct*/ | ||||
|   0x00,                       /*bcdDevice rel. 2.00*/ | ||||
|   0x02, | ||||
|   USBD_IDX_MFC_STR,           /*Index of manufacturer  string*/ | ||||
|   USBD_IDX_PRODUCT_STR,       /*Index of product string*/ | ||||
|   USBD_IDX_SERIAL_STR,        /*Index of serial number string*/ | ||||
|   USBD_MAX_NUM_CONFIGURATION  /*bNumConfigurations*/ | ||||
| }; | ||||
|  | ||||
| /* USB_DeviceDescriptor */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables | ||||
|   * @brief Private variables. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| #if defined ( __ICCARM__ ) /* IAR Compiler */ | ||||
|   #pragma data_alignment=4 | ||||
| #endif /* defined ( __ICCARM__ ) */ | ||||
|  | ||||
| /** USB lang identifier descriptor. */ | ||||
| __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = | ||||
| { | ||||
|      USB_LEN_LANGID_STR_DESC, | ||||
|      USB_DESC_TYPE_STRING, | ||||
|      LOBYTE(USBD_LANGID_STRING), | ||||
|      HIBYTE(USBD_LANGID_STRING) | ||||
| }; | ||||
|  | ||||
| #if defined ( __ICCARM__ ) /* IAR Compiler */ | ||||
|   #pragma data_alignment=4 | ||||
| #endif /* defined ( __ICCARM__ ) */ | ||||
| /* Internal string descriptor. */ | ||||
| __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; | ||||
|  | ||||
| #if defined ( __ICCARM__ ) /*!< IAR Compiler */ | ||||
|   #pragma data_alignment=4 | ||||
| #endif | ||||
| __ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = { | ||||
|   USB_SIZ_STRING_SERIAL, | ||||
|   USB_DESC_TYPE_STRING, | ||||
| }; | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions | ||||
|   * @brief Private functions. | ||||
|   * @{ | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|   * @brief  Return the device descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   UNUSED(speed); | ||||
|   *length = sizeof(USBD_CDC_DeviceDesc); | ||||
|   return USBD_CDC_DeviceDesc; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Return the LangID string descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   UNUSED(speed); | ||||
|   *length = sizeof(USBD_LangIDDesc); | ||||
|   return USBD_LangIDDesc; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Return the product string descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   if(speed == 0) | ||||
|   { | ||||
|     USBD_GetString((uint8_t *)USBD_PRODUCT_STRING, USBD_StrDesc, length); | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     USBD_GetString((uint8_t *)USBD_PRODUCT_STRING, USBD_StrDesc, length); | ||||
|   } | ||||
|   return USBD_StrDesc; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Return the manufacturer string descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   UNUSED(speed); | ||||
|   USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); | ||||
|   return USBD_StrDesc; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Return the serial number string descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   UNUSED(speed); | ||||
|   *length = USB_SIZ_STRING_SERIAL; | ||||
|  | ||||
|   /* Update the serial number string descriptor with the data from the unique | ||||
|    * ID */ | ||||
|   Get_SerialNum(); | ||||
|  | ||||
|   /* USER CODE BEGIN USBD_CDC_SerialStrDescriptor */ | ||||
|  | ||||
|   /* USER CODE END USBD_CDC_SerialStrDescriptor */ | ||||
|  | ||||
|   return (uint8_t *) USBD_StringSerial; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Return the configuration string descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   if(speed == USBD_SPEED_HIGH) | ||||
|   { | ||||
|     USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING, USBD_StrDesc, length); | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING, USBD_StrDesc, length); | ||||
|   } | ||||
|   return USBD_StrDesc; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Return the interface string descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   if(speed == 0) | ||||
|   { | ||||
|     USBD_GetString((uint8_t *)USBD_INTERFACE_STRING, USBD_StrDesc, length); | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     USBD_GetString((uint8_t *)USBD_INTERFACE_STRING, USBD_StrDesc, length); | ||||
|   } | ||||
|   return USBD_StrDesc; | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Create the serial number string descriptor | ||||
|   * @param  None | ||||
|   * @retval None | ||||
|   */ | ||||
| static void Get_SerialNum(void) | ||||
| { | ||||
|   uint32_t deviceserial0, deviceserial1, deviceserial2; | ||||
|  | ||||
|   deviceserial0 = *(uint32_t *) DEVICE_ID1; | ||||
|   deviceserial1 = *(uint32_t *) DEVICE_ID2; | ||||
|   deviceserial2 = *(uint32_t *) DEVICE_ID3; | ||||
|  | ||||
|   deviceserial0 += deviceserial2; | ||||
|  | ||||
|   if (deviceserial0 != 0) | ||||
|   { | ||||
|     IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); | ||||
|     IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); | ||||
|   } | ||||
| } | ||||
|  | ||||
| /** | ||||
|   * @brief  Convert Hex 32Bits value into char | ||||
|   * @param  value: value to convert | ||||
|   * @param  pbuf: pointer to the buffer | ||||
|   * @param  len: buffer length | ||||
|   * @retval None | ||||
|   */ | ||||
| static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len) | ||||
| { | ||||
|   uint8_t idx = 0; | ||||
|  | ||||
|   for (idx = 0; idx < len; idx++) | ||||
|   { | ||||
|     if (((value >> 28)) < 0xA) | ||||
|     { | ||||
|       pbuf[2 * idx] = (value >> 28) + '0'; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       pbuf[2 * idx] = (value >> 28) + 'A' - 10; | ||||
|     } | ||||
|  | ||||
|     value = value << 4; | ||||
|  | ||||
|     pbuf[2 * idx + 1] = 0; | ||||
|   } | ||||
| } | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|   * @} | ||||
|   */ | ||||
|  | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
		Reference in New Issue
	
	Block a user