2022-12-06 17:34:02 +08:00
|
|
|
/* USER CODE BEGIN Header */
|
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @file : main.c
|
|
|
|
* @brief : Main program body
|
|
|
|
******************************************************************************
|
|
|
|
* @attention
|
|
|
|
*
|
|
|
|
* Copyright (c) 2022 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.
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
/* USER CODE END Header */
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
/* Private includes ----------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN Includes */
|
|
|
|
#include "user_asm330lhh.h"
|
|
|
|
#include "asm330lhh_reg.h"
|
2022-12-12 15:05:54 +08:00
|
|
|
#include "user_iam20680.h"
|
2022-12-06 17:34:02 +08:00
|
|
|
#include "rtklib.h"
|
2022-12-12 15:05:54 +08:00
|
|
|
#include "stdio.h"
|
2022-12-06 17:34:02 +08:00
|
|
|
/* 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 */
|
2022-12-12 15:05:54 +08:00
|
|
|
/* USER CODE BEGIN 1 */
|
2022-12-06 17:34:02 +08:00
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* USER CODE END 1 */
|
2022-12-06 17:34:02 +08:00
|
|
|
/* USER CODE END PM */
|
|
|
|
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
|
SPI_HandleTypeDef hspi1;
|
2022-12-12 15:05:54 +08:00
|
|
|
SPI_HandleTypeDef hspi2;
|
2022-12-06 17:34:02 +08:00
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
TIM_HandleTypeDef htim3;
|
2022-12-06 17:34:02 +08:00
|
|
|
|
|
|
|
UART_HandleTypeDef huart1;
|
|
|
|
UART_HandleTypeDef huart2;
|
2022-12-12 15:05:54 +08:00
|
|
|
DMA_HandleTypeDef hdma_usart2_rx;
|
2022-12-06 17:34:02 +08:00
|
|
|
|
|
|
|
/* USER CODE BEGIN PV */
|
2022-12-12 15:05:54 +08:00
|
|
|
uint8_t SPI2_INT_RD=0;
|
|
|
|
uint8_t SPI1_INT_RD=0;
|
|
|
|
double time_hh=23,time_mm=59,time_ss=40,time_ms;
|
|
|
|
uint8_t Rx_Buffer[2500];
|
|
|
|
extern int8_t flag;
|
|
|
|
extern int GPS_week;
|
|
|
|
extern double GPS_sec;
|
2022-12-06 17:34:02 +08:00
|
|
|
/* USER CODE END PV */
|
|
|
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
void SystemClock_Config(void);
|
|
|
|
static void MX_GPIO_Init(void);
|
2022-12-12 15:05:54 +08:00
|
|
|
static void MX_DMA_Init(void);
|
2022-12-06 17:34:02 +08:00
|
|
|
static void MX_SPI1_Init(void);
|
|
|
|
static void MX_USART1_UART_Init(void);
|
|
|
|
static void MX_USART2_UART_Init(void);
|
2022-12-12 15:05:54 +08:00
|
|
|
static void MX_SPI2_Init(void);
|
|
|
|
static void MX_TIM3_Init(void);
|
2022-12-06 17:34:02 +08:00
|
|
|
/* USER CODE BEGIN PFP */
|
|
|
|
|
|
|
|
/* USER CODE END PFP */
|
|
|
|
|
|
|
|
/* Private user code ---------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN 0 */
|
2022-12-12 15:05:54 +08:00
|
|
|
|
2022-12-06 17:34:02 +08:00
|
|
|
uint32_t time_100us=0;
|
|
|
|
nmea_t nmea={0};
|
|
|
|
extern IMU_mng IMU_mng_st;
|
|
|
|
extern IMU_mng IMU_mng_tdk;
|
|
|
|
/* 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();
|
2022-12-12 15:05:54 +08:00
|
|
|
MX_DMA_Init();
|
2022-12-06 17:34:02 +08:00
|
|
|
MX_SPI1_Init();
|
|
|
|
MX_USART1_UART_Init();
|
|
|
|
MX_USART2_UART_Init();
|
2022-12-12 15:05:54 +08:00
|
|
|
MX_SPI2_Init();
|
|
|
|
MX_TIM3_Init();
|
2022-12-06 17:34:02 +08:00
|
|
|
/* USER CODE BEGIN 2 */
|
2022-12-12 15:05:54 +08:00
|
|
|
HAL_TIM_Base_Start(&htim3);
|
2022-12-06 17:34:02 +08:00
|
|
|
user_dev_init();
|
2022-12-12 15:05:54 +08:00
|
|
|
user_dev_init1();
|
2022-12-06 17:34:02 +08:00
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
// iam20680_init(&spi2_dev);
|
2022-12-06 17:34:02 +08:00
|
|
|
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
|
|
/* Infinite loop */
|
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
|
while (1)
|
|
|
|
{
|
2022-12-12 15:05:54 +08:00
|
|
|
TIM3_Get_100us();
|
|
|
|
if(1 == SPI2_INT_RD)
|
|
|
|
{
|
2022-12-12 21:23:33 +08:00
|
|
|
SPI2_INT_RD = 0;
|
|
|
|
tdk_sample();
|
|
|
|
printf("{ GPS_week: %d week_sec: %.3lf \r\n", GPS_week,
|
|
|
|
GPS_sec + time_ms * 0.001);
|
|
|
|
printf("x_a=%.3fm/s2 y_a=%.3fm/s2 z_a=%.3fm/s2\r\n", iam20680.x_acc,
|
|
|
|
iam20680.y_acc, iam20680.z_acc);
|
|
|
|
printf("x_g=%.3fdeg/s y_g=%.3fdeg/s z_g=%.3fdeg/s }\r\n\r\n\r\n",
|
|
|
|
iam20680.x_gyro, iam20680.y_gyro, iam20680.z_gyro);
|
|
|
|
|
|
|
|
// application_task();
|
2022-12-12 15:05:54 +08:00
|
|
|
}
|
2022-12-12 21:23:33 +08:00
|
|
|
// if(1 == SPI1_INT_RD)
|
|
|
|
// {
|
|
|
|
// SPI1_INT_RD=0;
|
|
|
|
// asm_sample();
|
|
|
|
// printf("{ GPS_week: %d week_sec: %.3lf \rextern tdk_value iam20680;\n",GPS_week,GPS_sec+time_ms*0.001);
|
|
|
|
// printf("x_a=%.3fm/s2 y_a=%.3fm/s2 z_a=%.3fm/s2\r\n",asm330.x_acc,asm330.y_acc,asm330.z_acc);
|
|
|
|
// printf("x_g=%.3fdeg/s y_g=%.3fdeg/s z_g=%.3fdeg/s }\r\n\r\n\r\n",asm330.x_gyro,asm330.y_gyro,asm330.z_gyro);
|
|
|
|
//// printf("time: %.0lfh:%.0lfm:%.0lfs:%.3fms \r\n",time_hh,time_mm,time_ss,time_ms);
|
|
|
|
// }
|
2022-12-06 17:34:02 +08:00
|
|
|
/* USER CODE END WHILE */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
|
}
|
|
|
|
/* USER CODE END 3 */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief System Clock Configuration
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
void SystemClock_Config(void)
|
|
|
|
{
|
|
|
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
|
|
|
|
|
|
/** Initializes the RCC Oscillators according to the specified parameters
|
|
|
|
* in the RCC_OscInitTypeDef structure.
|
|
|
|
*/
|
|
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
|
|
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
|
|
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
|
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
|
|
|
|
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
|
|
|
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Initializes the CPU, AHB and APB buses clocks
|
|
|
|
*/
|
|
|
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
|
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
|
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
|
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
|
|
|
|
|
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief SPI1 Initialization Function
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
static 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 */
|
|
|
|
/* SPI1 parameter configuration*/
|
|
|
|
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_HIGH;
|
|
|
|
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
|
|
|
|
hspi1.Init.NSS = SPI_NSS_SOFT;
|
|
|
|
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
|
|
|
|
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
|
|
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
|
|
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
|
|
hspi1.Init.CRCPolynomial = 10;
|
|
|
|
if (HAL_SPI_Init(&hspi1) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
/* USER CODE BEGIN SPI1_Init 2 */
|
|
|
|
|
|
|
|
/* USER CODE END SPI1_Init 2 */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-12 15:05:54 +08:00
|
|
|
* @brief SPI2 Initialization Function
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
static 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 */
|
|
|
|
/* SPI2 parameter configuration*/
|
|
|
|
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_HIGH;
|
|
|
|
hspi2.Init.CLKPhase = SPI_PHASE_2EDGE;
|
|
|
|
hspi2.Init.NSS = SPI_NSS_SOFT;
|
|
|
|
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
|
|
|
|
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
|
|
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
|
|
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
|
|
hspi2.Init.CRCPolynomial = 10;
|
|
|
|
if (HAL_SPI_Init(&hspi2) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
/* USER CODE BEGIN SPI2_Init 2 */
|
|
|
|
|
|
|
|
/* USER CODE END SPI2_Init 2 */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TIM3 Initialization Function
|
2022-12-06 17:34:02 +08:00
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
2022-12-12 15:05:54 +08:00
|
|
|
static void MX_TIM3_Init(void)
|
2022-12-06 17:34:02 +08:00
|
|
|
{
|
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
/* USER CODE BEGIN TIM3_Init 0 */
|
2022-12-06 17:34:02 +08:00
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
/* USER CODE END TIM3_Init 0 */
|
2022-12-06 17:34:02 +08:00
|
|
|
|
|
|
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
|
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
/* USER CODE BEGIN TIM3_Init 1 */
|
|
|
|
|
|
|
|
/* USER CODE END TIM3_Init 1 */
|
|
|
|
htim3.Instance = TIM3;
|
|
|
|
htim3.Init.Prescaler = 6400-1;
|
|
|
|
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
|
|
htim3.Init.Period = 65535;
|
|
|
|
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
|
|
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
|
|
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
|
2022-12-06 17:34:02 +08:00
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
2022-12-12 15:05:54 +08:00
|
|
|
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
|
2022-12-06 17:34:02 +08:00
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
|
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
2022-12-12 15:05:54 +08:00
|
|
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
|
2022-12-06 17:34:02 +08:00
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
2022-12-12 15:05:54 +08:00
|
|
|
/* USER CODE BEGIN TIM3_Init 2 */
|
2022-12-06 17:34:02 +08:00
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
/* USER CODE END TIM3_Init 2 */
|
2022-12-06 17:34:02 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief USART1 Initialization Function
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
static void MX_USART1_UART_Init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* USER CODE BEGIN USART1_Init 0 */
|
|
|
|
|
|
|
|
/* USER CODE END USART1_Init 0 */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN USART1_Init 1 */
|
|
|
|
|
|
|
|
/* USER CODE END USART1_Init 1 */
|
|
|
|
huart1.Instance = USART1;
|
2022-12-12 15:05:54 +08:00
|
|
|
huart1.Init.BaudRate = 921600;
|
2022-12-06 17:34:02 +08:00
|
|
|
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
|
|
|
huart1.Init.StopBits = UART_STOPBITS_1;
|
|
|
|
huart1.Init.Parity = UART_PARITY_NONE;
|
|
|
|
huart1.Init.Mode = UART_MODE_TX_RX;
|
|
|
|
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
|
|
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
|
|
if (HAL_UART_Init(&huart1) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
/* USER CODE BEGIN USART1_Init 2 */
|
|
|
|
|
|
|
|
/* USER CODE END USART1_Init 2 */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief USART2 Initialization Function
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
static void MX_USART2_UART_Init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* USER CODE BEGIN USART2_Init 0 */
|
|
|
|
|
|
|
|
/* USER CODE END USART2_Init 0 */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN USART2_Init 1 */
|
|
|
|
|
|
|
|
/* USER CODE END USART2_Init 1 */
|
|
|
|
huart2.Instance = USART2;
|
2022-12-12 15:05:54 +08:00
|
|
|
huart2.Init.BaudRate = 460800;
|
2022-12-06 17:34:02 +08:00
|
|
|
huart2.Init.WordLength = UART_WORDLENGTH_8B;
|
|
|
|
huart2.Init.StopBits = UART_STOPBITS_1;
|
|
|
|
huart2.Init.Parity = UART_PARITY_NONE;
|
|
|
|
huart2.Init.Mode = UART_MODE_TX_RX;
|
|
|
|
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
|
|
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
|
|
if (HAL_UART_Init(&huart2) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
/* USER CODE BEGIN USART2_Init 2 */
|
2022-12-12 15:05:54 +08:00
|
|
|
__HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE);
|
|
|
|
HAL_UART_Receive_DMA(&huart2, Rx_Buffer, sizeof(Rx_Buffer));
|
2022-12-06 17:34:02 +08:00
|
|
|
/* USER CODE END USART2_Init 2 */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
/**
|
|
|
|
* Enable DMA controller clock
|
|
|
|
*/
|
|
|
|
static void MX_DMA_Init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* DMA controller clock enable */
|
|
|
|
__HAL_RCC_DMA1_CLK_ENABLE();
|
|
|
|
|
|
|
|
/* DMA interrupt init */
|
|
|
|
/* DMA1_Channel6_IRQn interrupt configuration */
|
|
|
|
HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 0, 0);
|
|
|
|
HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-12-06 17:34:02 +08:00
|
|
|
/**
|
|
|
|
* @brief GPIO Initialization Function
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
static void MX_GPIO_Init(void)
|
|
|
|
{
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
|
|
|
|
/* GPIO Ports Clock Enable */
|
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
2022-12-12 15:05:54 +08:00
|
|
|
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_SET);
|
|
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
|
|
HAL_GPIO_WritePin(SPI2_CSN_GPIO_Port, SPI2_CSN_Pin, GPIO_PIN_SET);
|
2022-12-06 17:34:02 +08:00
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
/*Configure GPIO pins : PA1 SPI2_INIT1_Pin */
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_1|SPI2_INIT1_Pin;
|
2022-12-06 17:34:02 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
/*Configure GPIO pin : SPI1_CSN_Pin */
|
|
|
|
GPIO_InitStruct.Pin = SPI1_CSN_Pin;
|
2022-12-06 17:34:02 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
2022-12-12 15:05:54 +08:00
|
|
|
HAL_GPIO_Init(SPI1_CSN_GPIO_Port, &GPIO_InitStruct);
|
2022-12-06 17:34:02 +08:00
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
/*Configure GPIO pin : SPI1_INIT1_Pin */
|
|
|
|
GPIO_InitStruct.Pin = SPI1_INIT1_Pin;
|
2022-12-06 17:34:02 +08:00
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
2022-12-12 15:05:54 +08:00
|
|
|
HAL_GPIO_Init(SPI1_INIT1_GPIO_Port, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
/*Configure GPIO pin : SPI2_CSN_Pin */
|
|
|
|
GPIO_InitStruct.Pin = SPI2_CSN_Pin;
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
|
|
HAL_GPIO_Init(SPI2_CSN_GPIO_Port, &GPIO_InitStruct);
|
2022-12-06 17:34:02 +08:00
|
|
|
|
|
|
|
/* EXTI interrupt init*/
|
2022-12-12 15:05:54 +08:00
|
|
|
HAL_NVIC_SetPriority(EXTI0_IRQn, 1, 0);
|
2022-12-06 17:34:02 +08:00
|
|
|
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
|
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
|
|
|
|
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
|
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 2, 0);
|
|
|
|
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
|
|
|
|
|
2022-12-06 17:34:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 4 */
|
2022-12-12 15:05:54 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
|
|
|
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
|
2022-12-06 17:34:02 +08:00
|
|
|
|
2022-12-12 15:05:54 +08:00
|
|
|
PUTCHAR_PROTOTYPE
|
|
|
|
{
|
|
|
|
|
|
|
|
HAL_UART_Transmit(&huart1, (uint8_t*)&ch, 1, HAL_MAX_DELAY);
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
#endif
|
2022-12-06 17:34:02 +08:00
|
|
|
/* 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 */
|