| | |
| | | ****************************************************************************** |
| | | */ |
| | | /* USER CODE END Header */ |
| | | |
| | | /* Includes ------------------------------------------------------------------*/ |
| | | #include "main.h" |
| | | |
| | |
| | | /* USER CODE END PM */ |
| | | |
| | | /* Private variables ---------------------------------------------------------*/ |
| | | ADC_HandleTypeDef hadc; |
| | | ADC_HandleTypeDef hadc; |
| | | |
| | | IWDG_HandleTypeDef hiwdg; |
| | | |
| | |
| | | /* Private function prototypes -----------------------------------------------*/ |
| | | void SystemClock_Config(void); |
| | | static void MX_GPIO_Init(void); |
| | | static void MX_LPTIM1_Init(void); |
| | | static void MX_USART1_UART_Init(void); |
| | | static void MX_SPI1_Init(void); |
| | | void MX_ADC_Init(void); |
| | | static void MX_ADC_Init(void); |
| | | static void MX_DMA_Init(void); |
| | | static void MX_LPTIM1_Init(void); |
| | | static void MX_SPI1_Init(void); |
| | | static void MX_USART1_UART_Init(void); |
| | | static void MX_IWDG_Init(void); |
| | | /* USER CODE BEGIN PFP */ |
| | | |
| | |
| | | extern uint8_t module_power; |
| | | extern float nomove_count; |
| | | uint8_t imu_enable,motor_enable; |
| | | void READC_Init(void) |
| | | { |
| | | MX_ADC_Init(); |
| | | } |
| | | u16 GetLPTime(void) |
| | | { |
| | | u16 count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | |
| | | |
| | | /* Initialize all configured peripherals */ |
| | | MX_GPIO_Init(); |
| | | MX_LPTIM1_Init(); |
| | | MX_DMA_Init(); |
| | | MX_USART1_UART_Init(); |
| | | MX_SPI1_Init(); |
| | | MX_ADC_Init(); |
| | | MX_DMA_Init(); |
| | | MX_LPTIM1_Init(); |
| | | MX_SPI1_Init(); |
| | | MX_USART1_UART_Init(); |
| | | MX_IWDG_Init(); |
| | | /* USER CODE BEGIN 2 */ |
| | | LED_LG_ON; |
| | |
| | | /** Configure the main internal regulator output voltage |
| | | */ |
| | | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
| | | |
| | | /** Configure LSE Drive Capability |
| | | */ |
| | | HAL_PWR_EnableBkUpAccess(); |
| | | __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH); |
| | | /** Initializes the CPU, AHB and APB busses clocks |
| | | __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW); |
| | | |
| | | /** Initializes the RCC Oscillators according to the specified parameters |
| | | * in the RCC_OscInitTypeDef structure. |
| | | */ |
| | | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI |
| | | |RCC_OSCILLATORTYPE_LSE; |
| | |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | /** Initializes the CPU, AHB and APB busses clocks |
| | | |
| | | /** Initializes the CPU, AHB and APB buses clocks |
| | | */ |
| | | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
| | | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
| | |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | void MX_ADC_Init(void) |
| | | static void MX_ADC_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN ADC_Init 0 */ |
| | |
| | | /* USER CODE BEGIN ADC_Init 1 */ |
| | | |
| | | /* USER CODE END ADC_Init 1 */ |
| | | |
| | | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) |
| | | */ |
| | | hadc.Instance = ADC1; |
| | |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | |
| | | /** Configure for the selected ADC regular channel to be converted. |
| | | */ |
| | | sConfig.Channel = ADC_CHANNEL_VREFINT; |
| | |
| | | |
| | | /*Configure GPIO pin Output Level */ |
| | | HAL_GPIO_WritePin(GPIOA, DW_WKUP_Pin|DW_CTRL_Pin|LED2_G_Pin, GPIO_PIN_RESET); |
| | | ////////////////////////////////// |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); |
| | | ////////////////////////////////// |
| | | GPIO_InitStruct.Pin = GPIO_PIN_15; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
| | | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | |
| | | /*Configure GPIO pin : PA0 */ |
| | | GPIO_InitStruct.Pin = GPIO_PIN_0; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; |
| | |
| | | |
| | | /*Configure GPIO pins : SCL_Pin SDA_Pin */ |
| | | GPIO_InitStruct.Pin = SCL_Pin|SDA_Pin; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
| | | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
| | | HAL_GPIO_Init(SPI_CS_GPIO_Port, &GPIO_InitStruct); |
| | | |
| | | /*Configure GPIO pin : BAT_MEAS_GND_Pin */ |
| | | GPIO_InitStruct.Pin = BAT_MEAS_GND_Pin; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; |
| | | /*Configure GPIO pins : BAT_MEAS_GND_Pin PB10 LED1_G_Pin LED1_R_Pin |
| | | RADIO_nRESET_Pin RADIO_NSS_Pin PB7 PWR_CTL_Pin */ |
| | | GPIO_InitStruct.Pin = BAT_MEAS_GND_Pin|GPIO_PIN_10|LED1_G_Pin|LED1_R_Pin |
| | | |RADIO_nRESET_Pin|RADIO_NSS_Pin|GPIO_PIN_7|PWR_CTL_Pin; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| | | HAL_GPIO_Init(BAT_MEAS_GND_GPIO_Port, &GPIO_InitStruct); |
| | | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | /*Configure GPIO pin : USER_KEY_Pin */ |
| | | GPIO_InitStruct.Pin = USER_KEY_Pin; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_EVT_FALLING; |
| | | GPIO_InitStruct.Pull = GPIO_PULLUP; |
| | | HAL_GPIO_Init(USER_KEY_GPIO_Port, &GPIO_InitStruct); |
| | | |
| | |
| | | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | HAL_GPIO_Init(RADIO_BUSY_GPIO_Port, &GPIO_InitStruct); |
| | | |
| | | /*Configure GPIO pins : PB10 LED1_G_Pin LED1_R_Pin RADIO_nRESET_Pin |
| | | RADIO_NSS_Pin PB7 PWR_CTL_Pin */ |
| | | GPIO_InitStruct.Pin = GPIO_PIN_10|LED1_G_Pin|LED1_R_Pin|RADIO_nRESET_Pin |
| | | |RADIO_NSS_Pin|GPIO_PIN_7|PWR_CTL_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 : INPUT_5V_Pin */ |
| | | GPIO_InitStruct.Pin = INPUT_5V_Pin; |
| | |
| | | /* USER CODE END 6 */ |
| | | } |
| | | #endif /* USE_FULL_ASSERT */ |
| | | |
| | | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |