mirror of
https://github.com/peter-tanner/satellite-testing-system.git
synced 2024-11-30 12:30:16 +08:00
883 lines
24 KiB
C
883 lines
24 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file : main.c
|
|
* @brief : Main program body
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2024 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"
|
|
#include "cmsis_os.h"
|
|
#include "fatfs.h"
|
|
|
|
/* Private includes ----------------------------------------------------------*/
|
|
/* USER CODE BEGIN Includes */
|
|
// #include "mmc_ops.h"
|
|
#include "logging.h"
|
|
#include "usb_device.h"
|
|
#include "ringbuffer.h"
|
|
#include "entrypoint.h"
|
|
/* 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 ---------------------------------------------------------*/
|
|
CAN_HandleTypeDef hcan1;
|
|
|
|
CRC_HandleTypeDef hcrc;
|
|
|
|
I2C_HandleTypeDef hi2c3;
|
|
|
|
UART_HandleTypeDef hlpuart1;
|
|
UART_HandleTypeDef huart4;
|
|
UART_HandleTypeDef huart1;
|
|
UART_HandleTypeDef huart2;
|
|
UART_HandleTypeDef huart3;
|
|
|
|
MMC_HandleTypeDef hmmc1;
|
|
DMA_HandleTypeDef hdma_sdmmc1;
|
|
|
|
SPI_HandleTypeDef hspi2;
|
|
SPI_HandleTypeDef hspi3;
|
|
|
|
PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
|
|
|
osThreadId defaultTaskHandle;
|
|
osMessageQId usbRxQueueHandle;
|
|
/* USER CODE BEGIN PV */
|
|
osThreadId entrypointTaskHandle;
|
|
/* USER CODE END PV */
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
void SystemClock_Config(void);
|
|
void PeriphCommonClock_Config(void);
|
|
static void MX_GPIO_Init(void);
|
|
static void MX_DMA_Init(void);
|
|
static void MX_CAN1_Init(void);
|
|
static void MX_I2C3_Init(void);
|
|
static void MX_LPUART1_UART_Init(void);
|
|
static void MX_UART4_Init(void);
|
|
static void MX_USART1_UART_Init(void);
|
|
static void MX_USART2_UART_Init(void);
|
|
static void MX_USART3_UART_Init(void);
|
|
static void MX_SDMMC1_MMC_Init(void);
|
|
static void MX_SPI3_Init(void);
|
|
static void MX_SPI2_Init(void);
|
|
static void MX_CRC_Init(void);
|
|
static void MX_USB_OTG_FS_PCD_Init(void);
|
|
void StartDefaultTask(void const * argument);
|
|
|
|
/* USER CODE BEGIN PFP */
|
|
void StartMMCWriteTask(void const *argument);
|
|
/* 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();
|
|
|
|
/* Configure the peripherals common clocks */
|
|
PeriphCommonClock_Config();
|
|
|
|
/* USER CODE BEGIN SysInit */
|
|
// ring_buffer_init(&usb_rx_ringbuffer, usb_rx_buf, sizeof(usb_rx_buf));
|
|
/* USER CODE END SysInit */
|
|
|
|
/* Initialize all configured peripherals */
|
|
MX_GPIO_Init();
|
|
MX_DMA_Init();
|
|
MX_CAN1_Init();
|
|
MX_I2C3_Init();
|
|
MX_LPUART1_UART_Init();
|
|
MX_UART4_Init();
|
|
MX_USART1_UART_Init();
|
|
MX_USART2_UART_Init();
|
|
MX_USART3_UART_Init();
|
|
MX_SDMMC1_MMC_Init();
|
|
MX_SPI3_Init();
|
|
MX_SPI2_Init();
|
|
MX_CRC_Init();
|
|
MX_FATFS_Init();
|
|
MX_USB_OTG_FS_PCD_Init();
|
|
/* USER CODE BEGIN 2 */
|
|
HAL_PWREx_EnableVddUSB();
|
|
MX_USB_DEVICE_Init();
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
/* 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 */
|
|
|
|
/* Create the queue(s) */
|
|
/* definition and creation of usbRxQueue */
|
|
osMessageQDef(usbRxQueue, 16, uint16_t);
|
|
usbRxQueueHandle = osMessageCreate(osMessageQ(usbRxQueue), NULL);
|
|
|
|
/* USER CODE BEGIN RTOS_QUEUES */
|
|
/* add queues, ... */
|
|
|
|
#if 0
|
|
/* USER CODE END RTOS_QUEUES */
|
|
|
|
/* Create the thread(s) */
|
|
/* definition and creation of defaultTask */
|
|
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
|
|
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
|
|
|
|
/* USER CODE BEGIN RTOS_THREADS */
|
|
#endif
|
|
osThreadDef(entrypointTask, StartEntrypointTask, osPriorityNormal, 0, 128);
|
|
entrypointTaskHandle = osThreadCreate(osThread(entrypointTask), NULL);
|
|
/* definition and creation of mmcWriteTask */
|
|
/* USER CODE END RTOS_THREADS */
|
|
|
|
/* 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)
|
|
{
|
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
|
|
/** Configure the main internal regulator output voltage
|
|
*/
|
|
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/** Initializes the RCC Oscillators according to the specified parameters
|
|
* in the RCC_OscInitTypeDef structure.
|
|
*/
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
RCC_OscInitStruct.PLL.PLLM = 1;
|
|
RCC_OscInitStruct.PLL.PLLN = 10;
|
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
|
|
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV4;
|
|
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
|
|
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_DIV1;
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
|
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Peripherals Common Clock Configuration
|
|
* @retval None
|
|
*/
|
|
void PeriphCommonClock_Config(void)
|
|
{
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
|
|
|
/** Initializes the peripherals clock
|
|
*/
|
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB|RCC_PERIPHCLK_SDMMC1;
|
|
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
|
|
PeriphClkInit.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_PLLSAI1;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1N = 12;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV4;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV2;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_48M2CLK;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief CAN1 Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MX_CAN1_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN CAN1_Init 0 */
|
|
|
|
/* USER CODE END CAN1_Init 0 */
|
|
|
|
/* USER CODE BEGIN CAN1_Init 1 */
|
|
|
|
/* USER CODE END CAN1_Init 1 */
|
|
hcan1.Instance = CAN1;
|
|
hcan1.Init.Prescaler = 16;
|
|
hcan1.Init.Mode = CAN_MODE_NORMAL;
|
|
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
|
|
hcan1.Init.TimeSeg1 = CAN_BS1_3TQ;
|
|
hcan1.Init.TimeSeg2 = CAN_BS2_1TQ;
|
|
hcan1.Init.TimeTriggeredMode = DISABLE;
|
|
hcan1.Init.AutoBusOff = DISABLE;
|
|
hcan1.Init.AutoWakeUp = DISABLE;
|
|
hcan1.Init.AutoRetransmission = DISABLE;
|
|
hcan1.Init.ReceiveFifoLocked = DISABLE;
|
|
hcan1.Init.TransmitFifoPriority = DISABLE;
|
|
if (HAL_CAN_Init(&hcan1) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN CAN1_Init 2 */
|
|
|
|
/* USER CODE END CAN1_Init 2 */
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief CRC Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static 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 */
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief I2C3 Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MX_I2C3_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN I2C3_Init 0 */
|
|
|
|
/* USER CODE END I2C3_Init 0 */
|
|
|
|
/* USER CODE BEGIN I2C3_Init 1 */
|
|
|
|
/* USER CODE END I2C3_Init 1 */
|
|
hi2c3.Instance = I2C3;
|
|
hi2c3.Init.Timing = 0x10909CEC;
|
|
hi2c3.Init.OwnAddress1 = 0;
|
|
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
hi2c3.Init.OwnAddress2 = 0;
|
|
hi2c3.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
|
|
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/** Configure Analogue filter
|
|
*/
|
|
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/** Configure Digital filter
|
|
*/
|
|
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN I2C3_Init 2 */
|
|
|
|
/* USER CODE END I2C3_Init 2 */
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief LPUART1 Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MX_LPUART1_UART_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN LPUART1_Init 0 */
|
|
|
|
/* USER CODE END LPUART1_Init 0 */
|
|
|
|
/* USER CODE BEGIN LPUART1_Init 1 */
|
|
|
|
/* USER CODE END LPUART1_Init 1 */
|
|
hlpuart1.Instance = LPUART1;
|
|
hlpuart1.Init.BaudRate = 209700;
|
|
hlpuart1.Init.WordLength = UART_WORDLENGTH_7B;
|
|
hlpuart1.Init.StopBits = UART_STOPBITS_1;
|
|
hlpuart1.Init.Parity = UART_PARITY_NONE;
|
|
hlpuart1.Init.Mode = UART_MODE_TX_RX;
|
|
hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
|
hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
|
if (HAL_RS485Ex_Init(&hlpuart1, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN LPUART1_Init 2 */
|
|
|
|
/* USER CODE END LPUART1_Init 2 */
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief UART4 Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MX_UART4_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN UART4_Init 0 */
|
|
|
|
/* USER CODE END UART4_Init 0 */
|
|
|
|
/* USER CODE BEGIN UART4_Init 1 */
|
|
|
|
/* USER CODE END UART4_Init 1 */
|
|
huart4.Instance = UART4;
|
|
huart4.Init.BaudRate = 115200;
|
|
huart4.Init.WordLength = UART_WORDLENGTH_8B;
|
|
huart4.Init.StopBits = UART_STOPBITS_2;
|
|
huart4.Init.Parity = UART_PARITY_EVEN;
|
|
huart4.Init.Mode = UART_MODE_TX_RX;
|
|
huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
huart4.Init.OverSampling = UART_OVERSAMPLING_8;
|
|
huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
|
huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
|
if (HAL_UART_Init(&huart4) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN UART4_Init 2 */
|
|
|
|
/* USER CODE END UART4_Init 2 */
|
|
|
|
}
|
|
|
|
/**
|
|
* @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;
|
|
huart1.Init.BaudRate = 115200;
|
|
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_8;
|
|
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
|
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
|
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;
|
|
huart2.Init.BaudRate = 1000000;
|
|
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;
|
|
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
|
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
|
if (HAL_UART_Init(&huart2) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN USART2_Init 2 */
|
|
|
|
/* USER CODE END USART2_Init 2 */
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief USART3 Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MX_USART3_UART_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN USART3_Init 0 */
|
|
|
|
/* USER CODE END USART3_Init 0 */
|
|
|
|
/* USER CODE BEGIN USART3_Init 1 */
|
|
|
|
/* USER CODE END USART3_Init 1 */
|
|
huart3.Instance = USART3;
|
|
huart3.Init.BaudRate = 115200;
|
|
huart3.Init.WordLength = UART_WORDLENGTH_8B;
|
|
huart3.Init.StopBits = UART_STOPBITS_1;
|
|
huart3.Init.Parity = UART_PARITY_NONE;
|
|
huart3.Init.Mode = UART_MODE_TX_RX;
|
|
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
huart3.Init.OverSampling = UART_OVERSAMPLING_8;
|
|
huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_ENABLE;
|
|
huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
|
if (HAL_UART_Init(&huart3) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN USART3_Init 2 */
|
|
|
|
/* USER CODE END USART3_Init 2 */
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief SDMMC1 Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MX_SDMMC1_MMC_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN SDMMC1_Init 0 */
|
|
|
|
/* USER CODE END SDMMC1_Init 0 */
|
|
|
|
/* USER CODE BEGIN SDMMC1_Init 1 */
|
|
|
|
/* USER CODE END SDMMC1_Init 1 */
|
|
hmmc1.Instance = SDMMC1;
|
|
hmmc1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
|
|
hmmc1.Init.ClockBypass = SDMMC_CLOCK_BYPASS_DISABLE;
|
|
hmmc1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
|
|
hmmc1.Init.BusWide = SDMMC_BUS_WIDE_4B;
|
|
hmmc1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_ENABLE;
|
|
hmmc1.Init.ClockDiv = 0;
|
|
if (HAL_MMC_Init(&hmmc1) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
if (HAL_MMC_ConfigWideBusOperation(&hmmc1, SDMMC_BUS_WIDE_4B) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN SDMMC1_Init 2 */
|
|
/* USER CODE END SDMMC1_Init 2 */
|
|
|
|
}
|
|
|
|
/**
|
|
* @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_4BIT;
|
|
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
hspi2.Init.NSS = SPI_NSS_SOFT;
|
|
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
|
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 */
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief SPI3 Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MX_SPI3_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN SPI3_Init 0 */
|
|
|
|
/* USER CODE END SPI3_Init 0 */
|
|
|
|
/* USER CODE BEGIN SPI3_Init 1 */
|
|
|
|
/* USER CODE END SPI3_Init 1 */
|
|
/* SPI3 parameter configuration*/
|
|
hspi3.Instance = SPI3;
|
|
hspi3.Init.Mode = SPI_MODE_MASTER;
|
|
hspi3.Init.Direction = SPI_DIRECTION_2LINES;
|
|
hspi3.Init.DataSize = SPI_DATASIZE_4BIT;
|
|
hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
hspi3.Init.NSS = SPI_NSS_SOFT;
|
|
hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
|
hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
hspi3.Init.CRCPolynomial = 7;
|
|
hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
|
|
hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
|
|
if (HAL_SPI_Init(&hspi3) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN SPI3_Init 2 */
|
|
|
|
/* USER CODE END SPI3_Init 2 */
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief USB_OTG_FS Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MX_USB_OTG_FS_PCD_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN USB_OTG_FS_Init 0 */
|
|
|
|
/* USER CODE END USB_OTG_FS_Init 0 */
|
|
|
|
/* USER CODE BEGIN USB_OTG_FS_Init 1 */
|
|
|
|
/* USER CODE END USB_OTG_FS_Init 1 */
|
|
hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
|
|
hpcd_USB_OTG_FS.Init.dev_endpoints = 6;
|
|
hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
|
|
hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
|
|
hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
|
|
hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
|
|
hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
|
|
hpcd_USB_OTG_FS.Init.battery_charging_enable = DISABLE;
|
|
hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
|
|
hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
|
|
if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
/* USER CODE BEGIN USB_OTG_FS_Init 2 */
|
|
|
|
/* USER CODE END USB_OTG_FS_Init 2 */
|
|
|
|
}
|
|
|
|
/**
|
|
* Enable DMA controller clock
|
|
*/
|
|
static void MX_DMA_Init(void)
|
|
{
|
|
|
|
/* DMA controller clock enable */
|
|
__HAL_RCC_DMA2_CLK_ENABLE();
|
|
|
|
/* DMA interrupt init */
|
|
/* DMA2_Channel4_IRQn interrupt configuration */
|
|
HAL_NVIC_SetPriority(DMA2_Channel4_IRQn, 5, 0);
|
|
HAL_NVIC_EnableIRQ(DMA2_Channel4_IRQn);
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief GPIO Initialization Function
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void MX_GPIO_Init(void)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
|
/* USER CODE END MX_GPIO_Init_1 */
|
|
|
|
/* GPIO Ports Clock Enable */
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_15|GPIO_PIN_6, GPIO_PIN_RESET);
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
|
|
|GPIO_PIN_15, GPIO_PIN_RESET);
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_2|GPIO_PIN_6, GPIO_PIN_RESET);
|
|
|
|
/*Configure GPIO pins : PC13 PC15 PC6 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15|GPIO_PIN_6;
|
|
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 : PC14 PC2 PC3 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_2|GPIO_PIN_3;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : PA4 PA5 PA6 PA7
|
|
PA15 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
|
|
|GPIO_PIN_15;
|
|
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 pins : PB0 PB2 PB6 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_2|GPIO_PIN_6;
|
|
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 : PA8 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_8;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pin : PB7 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_7;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
|
/* USER CODE END MX_GPIO_Init_2 */
|
|
}
|
|
|
|
/* USER CODE BEGIN 4 */
|
|
|
|
/* USER CODE END 4 */
|
|
|
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
|
/**
|
|
* @brief Function implementing the defaultTask thread.
|
|
* @param argument: Not used
|
|
* @retval None
|
|
*/
|
|
/* USER CODE END Header_StartDefaultTask */
|
|
void StartDefaultTask(void const * argument)
|
|
{
|
|
/* USER CODE BEGIN 5 */
|
|
/* Infinite loop */
|
|
for (;;)
|
|
{
|
|
osDelay(1);
|
|
}
|
|
/* USER CODE END 5 */
|
|
}
|
|
|
|
/**
|
|
* @brief Period elapsed callback in non blocking mode
|
|
* @note This function is called when TIM15 interrupt took place, inside
|
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
|
* a global variable "uwTick" used as application time base.
|
|
* @param htim : TIM handle
|
|
* @retval None
|
|
*/
|
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
{
|
|
/* USER CODE BEGIN Callback 0 */
|
|
|
|
/* USER CODE END Callback 0 */
|
|
if (htim->Instance == TIM15) {
|
|
HAL_IncTick();
|
|
}
|
|
/* USER CODE BEGIN Callback 1 */
|
|
|
|
/* USER CODE END Callback 1 */
|
|
}
|
|
|
|
/**
|
|
* @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();
|
|
__BKPT();
|
|
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 */
|