| | |
| | |
|
| | | #include "Globaldef.h"
|
| | | #include "Functions.h"
|
| | | #if (BOARD_TYPE == 14)
|
| | | #include "fp0.h"
|
| | | #endif
|
| | |
|
| | | /*
|
| | | if ((nCurTick &0xff) ==0)
|
| | |
| | | * @brief System Clock Configuration
|
| | | * @retval None
|
| | | */
|
| | |
|
| | | void SystemClock_Config(void)
|
| | | {
|
| | | RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
| | |
| | | RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
| | | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
| | | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
| | | // RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
| | |
|
| | | #if (XLAT_FREQ == 12)
|
| | | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4;
|
| | | RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV3;
|
| | | #else
|
| | | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
|
| | | RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2;
|
| | | #endif
|
| | | |
| | | RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
|
| | |
|
| | | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; |
| | | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
| | | {
|
| | | Error_Handler();
|
| | |
| | |
|
| | | /**Configure the Systick interrupt time
|
| | | */
|
| | | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/10000);
|
| | | // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/10000);
|
| | | HAL_SYSTICK_Config(48000000/10000);
|
| | |
|
| | | /**Configure the Systick
|
| | | */
|
| | |
| | | /* USER CODE END IWDG_Init 2 */
|
| | |
|
| | | }
|
| | | /**
|
| | | * @brief TIM6 Initialization Function
|
| | | * @param None
|
| | | * @retval None
|
| | | */
|
| | | void MX_TIM6_Init(void)
|
| | | {
|
| | |
|
| | | /* USER CODE BEGIN TIM6_Init 0 */
|
| | |
|
| | | /* USER CODE END TIM6_Init 0 */
|
| | |
|
| | | LL_TIM_InitTypeDef TIM_InitStruct = {0};
|
| | |
|
| | | /* Peripheral clock enable */
|
| | | LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM6);
|
| | |
|
| | | /* TIM6 interrupt Init */
|
| | | NVIC_SetPriority(TIM6_IRQn, 0);
|
| | | NVIC_EnableIRQ(TIM6_IRQn);
|
| | |
|
| | | /* USER CODE BEGIN TIM6_Init 1 */
|
| | |
|
| | | /* USER CODE END TIM6_Init 1 */
|
| | | TIM_InitStruct.Prescaler = 47;
|
| | | TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
| | | TIM_InitStruct.Autoreload = 999;
|
| | | LL_TIM_Init(TIM6, &TIM_InitStruct);
|
| | | LL_TIM_DisableARRPreload(TIM6);
|
| | | /* USER CODE BEGIN TIM6_Init 2 */
|
| | | LL_TIM_EnableIT_UPDATE(TIM6);
|
| | | /* USER CODE END TIM6_Init 2 */
|
| | |
|
| | | }
|
| | | /* ADC init function */
|
| | | void MX_ADC_Init(void)
|
| | | {
|
| | |
| | | void MX_SPI1_Init(void)
|
| | | {
|
| | |
|
| | | LL_SPI_InitTypeDef SPI_InitStruct;
|
| | | LL_SPI_InitTypeDef SPI_InitStruct = {0};
|
| | |
|
| | | LL_GPIO_InitTypeDef GPIO_InitStruct;
|
| | | LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
| | |
|
| | | /* Peripheral clock enable */
|
| | | LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SPI1);
|
| | |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
|
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
| | |
|
| | |
| | |
|
| | | /* SPI1 interrupt Init */
|
| | | NVIC_SetPriority(SPI1_IRQn, 0);
|
| | | NVIC_EnableIRQ(SPI1_IRQn);
|
| | | // NVIC_EnableIRQ(SPI1_IRQn);
|
| | | /* USER CODE BEGIN SPI1_Init 1 */
|
| | |
|
| | | #if (BOARD_TYPE == 13)
|
| | |
|
| | | NVIC_EnableIRQ(SPI1_IRQn);
|
| | | SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
|
| | | SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
|
| | | SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
|
| | | SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_HIGH; //LL_SPI_POLARITY_LOW;
|
| | | SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE ; //LL_SPI_PHASE_1EDGE;
|
| | | SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
|
| | | SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;
|
| | | SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
|
| | | SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
|
| | | SPI_InitStruct.CRCPoly = 7;
|
| | | LL_SPI_Init(SPI1, &SPI_InitStruct);
|
| | |
|
| | | LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
|
| | |
|
| | | LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER);
|
| | | // LL_SPI_EnableNSSPulseMgt(SPI1); |
| | |
|
| | | #elif (BOARD_TYPE == 14)
|
| | |
|
| | | NVIC_EnableIRQ(SPI1_IRQn);
|
| | | SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
|
| | | SPI_InitStruct.Mode = LL_SPI_MODE_SLAVE;
|
| | | SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
|
| | | SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; //LL_SPI_POLARITY_LOW;
|
| | | SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE ; //LL_SPI_PHASE_1EDGE;
|
| | | SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
|
| | | SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4;
|
| | | SPI_InitStruct.BitOrder = LL_SPI_LSB_FIRST;
|
| | | SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
|
| | | SPI_InitStruct.CRCPoly = 7;
|
| | | LL_SPI_Init(SPI1, &SPI_InitStruct);
|
| | |
|
| | | LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
|
| | | LL_SPI_DisableNSSPulseMgt(SPI1);
|
| | | LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER);
|
| | | // LL_SPI_EnableNSSPulseMgt(SPI1); |
| | |
|
| | | #else
|
| | |
|
| | | /* USER CODE END SPI1_Init 1 */
|
| | |
|
| | |
| | |
|
| | | LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
|
| | |
|
| | | LL_SPI_EnableNSSPulseMgt(SPI1);
|
| | | LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER);
|
| | | // LL_SPI_EnableNSSPulseMgt(SPI1);
|
| | |
|
| | | /* USER CODE BEGIN SPI1_Init 2 */
|
| | |
|
| | | #endif
|
| | |
|
| | | LL_SPI_Enable(SPI1);
|
| | | /* USER CODE END SPI1_Init 2 */
|
| | | }
|
| | |
| | | PA2 ------> USART2_TX
|
| | | PA3 ------> USART2_RX
|
| | | */
|
| | |
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_3;
|
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
| | | GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
|
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
| | |
| | | // LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_HIGH);
|
| | | LL_USART_SetDEAssertionTime(USART2, 3);
|
| | | LL_USART_SetDEDeassertionTime(USART2, 3);
|
| | | LL_USART_EnableOneBitSamp(USART2);
|
| | | // LL_USART_EnableOneBitSamp(USART2);
|
| | | // LL_USART_EnableAutoBaudRate(USART2);
|
| | | // LL_USART_SetAutoBaudRateMode(USART2, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE);
|
| | | LL_USART_DisableOverrunDetect(USART2);
|
| | |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
|
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
|
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOC);
|
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOF);
|
| | | /**/
|
| | |
|
| | |
|
| | | /**/
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_6 ; //|LL_GPIO_PIN_7;
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_6 |LL_GPIO_PIN_7;
|
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
| | |
| | | if (GetBoardType()==2)
|
| | | {
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7|
|
| | | LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15;
|
| | | LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15;
|
| | |
|
| | | }
|
| | | else if (GetBoardType()==9 || GetBoardType()==10 )
|
| | | else if (GetBoardType()==9 || GetBoardType()==10 || GetBoardType()==15 || BOARD_TYPE == 16 )
|
| | | {
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7|
|
| | | LL_GPIO_PIN_11|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10|
|
| | | LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15;
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7|
|
| | | LL_GPIO_PIN_11|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10|
|
| | | LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15;
|
| | | }
|
| | | else if ( GetBoardType() == 11 )
|
| | | {
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7|
|
| | | LL_GPIO_PIN_2|LL_GPIO_PIN_10|
|
| | | LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15;
|
| | | } else |
| | | LL_GPIO_PIN_2|LL_GPIO_PIN_10|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15;
|
| | | } else if (BOARD_TYPE == 14)
|
| | | {
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7|
|
| | | LL_GPIO_PIN_10|LL_GPIO_PIN_11|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_14|LL_GPIO_PIN_15;
|
| | | } else
|
| | | {
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7|
|
| | | LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10|
|
| | | LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15;
|
| | | } |
| | | LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10|
|
| | | LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15;
|
| | | }
|
| | |
|
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
| | |
|
| | | LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_3);
|
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_13|LL_GPIO_PIN_14;
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_13|LL_GPIO_PIN_14|LL_GPIO_PIN_15;
|
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_LOW;
|
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
| | |
| | | // RCC_LSEConfig( RCC_LSE_OFF ); /* ????????,PC14+PC15??????IO*/
|
| | | // BKP_TamperPinCmd(DISABLE); /* ????????,PC13??????IO*/
|
| | |
|
| | | #if (BORAD_TYPE == 13)
|
| | |
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_15 ;
|
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_OUTPUT_PUSHPULL;
|
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
| | |
|
| | | #elif (BOARD_TYPE == 14)
|
| | |
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7;
|
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
| | | LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_8); |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_9 ; //RST_PIN in
|
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
| | | |
| | | GPIO_InitStruct.Pin = SYN_PIN ; //SYN_PIN Pin in
|
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
| | | LL_GPIO_Init(SYN_PORT, &GPIO_InitStruct);
|
| | | |
| | | GPIO_InitStruct.Pin = ACK_PIN ; //ACK_PIN Pin out
|
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_OUTPUT_PUSHPULL;
|
| | | LL_GPIO_Init(ACK_PORT, &GPIO_InitStruct);
|
| | |
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_7 ; //485DE Pin out
|
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_OUTPUT_PUSHPULL;
|
| | | LL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
| | | |
| | | GPIO_InitStruct.Pin = OE_PIN ; // OE Pin in
|
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
| | | LL_GPIO_Init(OE_PORT, &GPIO_InitStruct);
|
| | |
|
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
| | |
|
| | | // Radio Pins
|
| | | // busy pin
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_7; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
| | | |
| | | // Dio 1 pin
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_12; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
| | | |
| | | |
| | | //Sel pin
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_15; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
| | | |
| | | |
| | | //RST pin
|
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_6; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
| | |
|
| | | #endif
|
| | |
|
| | | }
|