| | |
| | | #include "Globaldef.h" |
| | | #include "Functions.h" |
| | | #if (BOARD_TYPE == 14) |
| | | #include "fp0.h" |
| | | #include "fpx.h" |
| | | #endif |
| | | |
| | | /* |
| | | if ((nCurTick &0xff) ==0) |
| | | { |
| | | if (freqdir) { freq+=1+freq/10;if (freq>=1500) {freq=1500;freqdir=0;}} |
| | | else {freq-=1+freq/10;if (freq<=10) {freq=10;freqdir=1;} } |
| | | } |
| | | */ |
| | | |
| | | /* |
| | | static int outputsum=0; |
| | | static int freq=10; |
| | | static int freqdir=1; |
| | | static int phase=0; |
| | | static int somb=0; |
| | | static int len=0; |
| | | static int curbb=0; |
| | | |
| | | if ((nCurTick &0x3ff) ==1) |
| | | { |
| | | curbb++; |
| | | if (curbb+1==len) |
| | | { |
| | | // freq=0; |
| | | }else if (curbb>=len) |
| | | { |
| | | somb=musictab1[cur_musicpos*2]; |
| | | len=musictab1[cur_musicpos*2+1]; |
| | | freq=freqtab[somb]; |
| | | curbb=0;cur_musicpos++; if (cur_musicpos >= Totalmusiccount) {cur_musicpos=0;} |
| | | } |
| | | } |
| | | if ((nCurTick &0x3ff) ==0x1ff) |
| | | { |
| | | if (curbb+1==len) |
| | | { |
| | | freq=0; |
| | | } |
| | | } |
| | | phase+=freq; |
| | | if (phase>=5000) {phase-=5000;} |
| | | |
| | | |
| | | if (outtype==1) |
| | | { |
| | | outputsum+=freq; |
| | | if (outputsum>=5000) |
| | | { |
| | | //LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3); |
| | | outputsum-=5000; |
| | | } |
| | | else |
| | | { |
| | | //LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | } |
| | | }else if (outtype==2) |
| | | { |
| | | const int volume = 2500; |
| | | int amp; |
| | | if (phase<1250) |
| | | { |
| | | amp=2500+sintab[(phase -0)*256/1250]*volume/256; |
| | | |
| | | }else if (phase <2500) |
| | | { |
| | | amp=2500+sintab[(2500-1-phase)*256/1250]*volume/256; |
| | | }else if (phase <3750) |
| | | { |
| | | amp=2500-sintab[(phase-2500)*256/1250]*volume/256; |
| | | }else |
| | | { |
| | | amp=2500-sintab[(5000-1-phase)*256/1250]*volume/256; |
| | | } |
| | | outputsum+=amp; |
| | | if (outputsum>=5000) |
| | | { |
| | | LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | //LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3); |
| | | outputsum-=5000; |
| | | } |
| | | else |
| | | { |
| | | LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | } |
| | | } |
| | | */ |
| | | |
| | | |
| | | /** |
| | | * @brief System Clock Configuration |
| | | * @retval None |
| | | */ |
| | | |
| | | void SystemClock_Config(void) |
| | | void SystemClock_Config_New(void) |
| | | { |
| | | LL_FLASH_SetLatency(LL_FLASH_LATENCY_1); |
| | | |
| | | if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_1) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | LL_RCC_HSE_Enable(); |
| | | |
| | | /* Wait till HSE is ready */ |
| | | while(LL_RCC_HSE_IsReady() != 1) |
| | | { |
| | | |
| | | } |
| | | LL_RCC_LSI_Enable(); |
| | | |
| | | /* Wait till LSI is ready */ |
| | | while(LL_RCC_LSI_IsReady() != 1) |
| | | { |
| | | |
| | | } |
| | | #if (XLAT_FREQ == 12) |
| | | LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_3, LL_RCC_PLL_MUL_12); |
| | | #else |
| | | LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_2, LL_RCC_PLL_MUL_12); |
| | | #endif |
| | | LL_RCC_PLL_Enable(); |
| | | |
| | | /* Wait till PLL is ready */ |
| | | while(LL_RCC_PLL_IsReady() != 1) |
| | | { |
| | | |
| | | } |
| | | LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); |
| | | LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); |
| | | LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); |
| | | |
| | | /* Wait till System clock is ready */ |
| | | while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) |
| | | { |
| | | |
| | | } |
| | | |
| | | LL_InitTick(48000000,10000); |
| | | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
| | | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
| | | |
| | | SysTick->CTRL = SysTick_CTRL_ENABLE_Msk |
| | | | SysTick_CTRL_TICKINT_Msk; |
| | | |
| | | LL_SetSystemCoreClock(48000000); |
| | | LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK1); |
| | | |
| | | } |
| | | |
| | | |
| | | void SystemClock_Config(void) |
| | | { |
| | | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
| | | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
| | | |
| | |
| | | |
| | | } |
| | | /** |
| | | * @brief TIM1 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | void MX_TIM1_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN TIM1_Init 0 */ |
| | | |
| | | /* USER CODE END TIM1_Init 0 */ |
| | | |
| | | LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
| | | LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; |
| | | LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0}; |
| | | |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| | | |
| | | /* Peripheral clock enable */ |
| | | LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM1); |
| | | |
| | | |
| | | /* USER CODE BEGIN TIM1_Init 1 */ |
| | | |
| | | /* USER CODE END TIM1_Init 1 */ |
| | | TIM_InitStruct.Prescaler = 0; |
| | | TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
| | | TIM_InitStruct.Autoreload = 1713; |
| | | TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; |
| | | TIM_InitStruct.RepetitionCounter = 0; |
| | | LL_TIM_Init(TIM1, &TIM_InitStruct); |
| | | LL_TIM_EnableARRPreload(TIM1); |
| | | LL_TIM_SetClockSource(TIM1, LL_TIM_CLOCKSOURCE_INTERNAL); |
| | | LL_TIM_OC_EnablePreload(TIM1, LL_TIM_CHANNEL_CH1); |
| | | |
| | | TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1; |
| | | TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.CompareValue = 857; |
| | | TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW; |
| | | TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW; |
| | | LL_TIM_OC_Init(TIM1, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); |
| | | LL_TIM_OC_DisableFast(TIM1, LL_TIM_CHANNEL_CH1); |
| | | |
| | | |
| | | LL_TIM_OC_EnablePreload(TIM1, LL_TIM_CHANNEL_CH4); |
| | | |
| | | TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1; |
| | | TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.CompareValue = 856; |
| | | LL_TIM_OC_Init(TIM1, LL_TIM_CHANNEL_CH4, &TIM_OC_InitStruct); |
| | | |
| | | |
| | | LL_TIM_OC_DisableFast(TIM1, LL_TIM_CHANNEL_CH4); |
| | | LL_TIM_SetTriggerInput(TIM1, LL_TIM_TS_ITR0); |
| | | LL_TIM_SetSlaveMode(TIM1, LL_TIM_SLAVEMODE_RESET); |
| | | LL_TIM_DisableIT_TRIG(TIM1); |
| | | LL_TIM_DisableDMAReq_TRIG(TIM1); |
| | | LL_TIM_SetTriggerOutput(TIM1, LL_TIM_TRGO_RESET); |
| | | LL_TIM_DisableMasterSlaveMode(TIM1); |
| | | |
| | | TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE; |
| | | TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE; |
| | | TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF; |
| | | TIM_BDTRInitStruct.DeadTime = 20; |
| | | TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE; |
| | | TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH; |
| | | TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE; |
| | | LL_TIM_BDTR_Init(TIM1, &TIM_BDTRInitStruct); |
| | | |
| | | |
| | | /* USER CODE BEGIN TIM1_Init 2 */ |
| | | |
| | | /* USER CODE END TIM1_Init 2 */ |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); |
| | | /**TIM1 GPIO Configuration |
| | | PB13 ------> TIM1_CH1N |
| | | PA8 ------> TIM1_CH1 |
| | | PA11 ------> TIM1_CH4 |
| | | */ |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_13; |
| | | 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_2; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_8; |
| | | 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_2; |
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_11; |
| | | 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_2; |
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | |
| | | } |
| | | /** |
| | | * @brief TIM6 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | |
| | | /* USER CODE END TIM6_Init 2 */ |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @brief TIM14 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | void MX_TIM14_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN TIM14_Init 0 */ |
| | | |
| | | /* USER CODE END TIM14_Init 0 */ |
| | | |
| | | LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
| | | |
| | | /* Peripheral clock enable */ |
| | | LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM14); |
| | | |
| | | /* USER CODE BEGIN TIM14_Init 1 */ |
| | | |
| | | /* USER CODE END TIM14_Init 1 */ |
| | | TIM_InitStruct.Prescaler = 2; |
| | | TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
| | | TIM_InitStruct.Autoreload = 2400; |
| | | TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; |
| | | LL_TIM_Init(TIM14, &TIM_InitStruct); |
| | | LL_TIM_EnableARRPreload(TIM14); |
| | | /* USER CODE BEGIN TIM14_Init 2 */ |
| | | |
| | | /* USER CODE END TIM14_Init 2 */ |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @brief TIM15 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | void MX_TIM15_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN TIM15_Init 0 */ |
| | | |
| | | /* USER CODE END TIM15_Init 0 */ |
| | | |
| | | LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
| | | LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; |
| | | LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0}; |
| | | |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| | | |
| | | /* Peripheral clock enable */ |
| | | LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM15); |
| | | |
| | | /* USER CODE BEGIN TIM15_Init 1 */ |
| | | |
| | | /* USER CODE END TIM15_Init 1 */ |
| | | TIM_InitStruct.Prescaler = 0; |
| | | TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
| | | TIM_InitStruct.Autoreload = 1713; |
| | | TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; |
| | | TIM_InitStruct.RepetitionCounter = 0; |
| | | LL_TIM_Init(TIM15, &TIM_InitStruct); |
| | | LL_TIM_EnableARRPreload(TIM15); |
| | | LL_TIM_SetClockSource(TIM15, LL_TIM_CLOCKSOURCE_INTERNAL); |
| | | |
| | | TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1; |
| | | TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.CompareValue = 856; |
| | | TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW; |
| | | TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW; |
| | | LL_TIM_OC_Init(TIM15, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); |
| | | LL_TIM_OC_DisableFast(TIM15, LL_TIM_CHANNEL_CH1); |
| | | |
| | | LL_TIM_OC_EnablePreload(TIM15, LL_TIM_CHANNEL_CH2); |
| | | TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM2; |
| | | TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.CompareValue = 100; |
| | | LL_TIM_OC_Init(TIM15, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct); |
| | | LL_TIM_OC_DisableFast(TIM15, LL_TIM_CHANNEL_CH2); |
| | | LL_TIM_SetTriggerOutput(TIM15, LL_TIM_TRGO_OC2REF); |
| | | LL_TIM_DisableMasterSlaveMode(TIM15); |
| | | |
| | | |
| | | TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE; |
| | | TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE; |
| | | TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF; |
| | | TIM_BDTRInitStruct.DeadTime = 5; |
| | | TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE; |
| | | TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH; |
| | | TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE; |
| | | LL_TIM_BDTR_Init(TIM15, &TIM_BDTRInitStruct); |
| | | /* USER CODE BEGIN TIM15_Init 2 */ |
| | | |
| | | /* USER CODE END TIM15_Init 2 */ |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | /**TIM15 GPIO Configuration |
| | | PB14 ------> TIM15_CH1 |
| | | PB15 ------> TIM15_CH1N |
| | | */ |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_14; |
| | | 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_1; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_15; |
| | | 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_3; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @brief TIM16 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | void MX_TIM16_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN TIM16_Init 0 */ |
| | | |
| | | /* USER CODE END TIM16_Init 0 */ |
| | | |
| | | LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
| | | LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; |
| | | LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0}; |
| | | |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| | | |
| | | /* Peripheral clock enable */ |
| | | LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM16); |
| | | /* TIM6 interrupt Init */ |
| | | NVIC_SetPriority(TIM16_IRQn, 0); |
| | | NVIC_EnableIRQ(TIM16_IRQn); |
| | | |
| | | /* USER CODE BEGIN TIM16_Init 1 */ |
| | | |
| | | /* USER CODE END TIM16_Init 1 */ |
| | | TIM_InitStruct.Prescaler = 100; |
| | | TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
| | | TIM_InitStruct.Autoreload = 1417; |
| | | TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; |
| | | TIM_InitStruct.RepetitionCounter = 0; |
| | | LL_TIM_Init(TIM16, &TIM_InitStruct); |
| | | LL_TIM_DisableARRPreload(TIM16); |
| | | |
| | | LL_TIM_OC_EnablePreload(TIM16, LL_TIM_CHANNEL_CH1); |
| | | TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_TOGGLE; |
| | | TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
| | | TIM_OC_InitStruct.CompareValue = 500; |
| | | TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH; |
| | | TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW; |
| | | TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW; |
| | | LL_TIM_OC_Init(TIM16, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); |
| | | LL_TIM_OC_DisableFast(TIM16, LL_TIM_CHANNEL_CH1); |
| | | TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE; |
| | | TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE; |
| | | TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF; |
| | | TIM_BDTRInitStruct.DeadTime = 6; |
| | | TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE; |
| | | TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH; |
| | | TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE; |
| | | LL_TIM_BDTR_Init(TIM16, &TIM_BDTRInitStruct); |
| | | |
| | | /* USER CODE BEGIN TIM16_Init 2 */ |
| | | |
| | | /* USER CODE END TIM16_Init 2 */ |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | /**TIM16 GPIO Configuration |
| | | PA6 ------> TIM16_CH1 |
| | | PB6 ------> TIM16_CH1N |
| | | */ |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_6; |
| | | 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.Alternate = LL_GPIO_AF_5; |
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_6; |
| | | 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.Alternate = LL_GPIO_AF_2; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | LL_TIM_EnableIT_UPDATE(TIM16); |
| | | } |
| | | |
| | | |
| | | /* ADC init function */ |
| | | void MX_ADC_Init(void) |
| | | { |
| | |
| | | // GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
| | | // LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | 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_UP; |
| | | // GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_15); |
| | | |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | /**SPI1 GPIO Configuration |
| | | PB3 ------> SPI1_SCK |
| | | PB4 ------> SPI1_MISO |
| | | PB5 ------> SPI1_MOSI |
| | | */ |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3; |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_3 | LL_GPIO_PIN_4 | LL_GPIO_PIN_5; |
| | | 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); |
| | | |
| | | /* |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_5; |
| | | 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_UP; |
| | | // GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_5); |
| | | */ |
| | | |
| | | /* |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_4; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
| | | 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); |
| | | /* USER CODE BEGIN SPI1_Init 1 */ |
| | | |
| | | #if (BOARD_TYPE == 13) |
| | | #if (BOARD_TYPE == 13 || BOARD_TYPE == 9) |
| | | |
| | | NVIC_EnableIRQ(SPI1_IRQn); |
| | | SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
| | |
| | | |
| | | 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); |
| | | LL_SPI_EnableIT_RXNE(SPI1); |
| | | |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | |
| | | 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_LOW; |
| | | SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; |
| | | SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
| | | SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; |
| | | 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); |
| | | |
| | |
| | | SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; //LL_SPI_POLARITY_HIGH;//LL_SPI_POLARITY_LOW; |
| | | SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; //LL_SPI_PHASE_1EDGE; |
| | | SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
| | | SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2; |
| | | SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; |
| | | SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; |
| | | SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; |
| | | SPI_InitStruct.CRCPoly = 7; |
| | |
| | | /* USER CODE END SPI2_Init 2 */ |
| | | } |
| | | |
| | | void Soft_I2C1_Init(void) |
| | | { |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
| | | /**I2C1 GPIO Configuration |
| | | PB6 ------> I2C1_SCL |
| | | PB7 ------> I2C1_SDA |
| | | */ |
| | | LL_GPIO_SetOutputPin(GPIOB,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_OUTPUT; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_6 | LL_GPIO_PIN_7); |
| | | |
| | | } |
| | | |
| | | /* USART1 init function */ |
| | | void MX_USART1_UART_Init(void) |
| | |
| | | // LL_USART_SetDEAssertionTime(USART1, 1); |
| | | // LL_USART_SetDEDeassertionTime(USART1, 1); |
| | | // LL_USART_EnableOneBitSamp(USART1); |
| | | |
| | | #if (USART1_AUTO_BAUDRATE == 1) |
| | | LL_USART_EnableAutoBaudRate(USART1); |
| | | LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
| | | LL_USART_DisableOverrunDetect(USART1); |
| | | #endif |
| | | |
| | | LL_USART_DisableOverrunDetect(USART1); |
| | | LL_USART_ConfigAsyncMode(USART1); |
| | | LL_USART_Enable(USART1); |
| | | } |
| | |
| | | LL_USART_EnableDEMode(USART2); |
| | | LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_LOW); |
| | | // LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_HIGH); |
| | | LL_USART_SetDEAssertionTime(USART2, 31); |
| | | LL_USART_SetDEDeassertionTime(USART2, 31); |
| | | LL_USART_SetDEAssertionTime(USART2, 15); |
| | | LL_USART_SetDEDeassertionTime(USART2, 15); |
| | | #else |
| | | |
| | | #endif |
| | |
| | | LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_8|LL_GPIO_PIN_11; |
| | | GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_8; //|LL_GPIO_PIN_11; |
| | | 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_UP; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | if (GetBoardType()==2) |
| | | { |
| | | #if (BOARD_TYPE==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; |
| | | |
| | | } |
| | | else if (GetBoardType()==9 || GetBoardType()==10 || GetBoardType()==15 || BOARD_TYPE == 16 ) |
| | | { |
| | | |
| | | #elif (BOARD_TYPE==9 || BOARD_TYPE==10) |
| | | GPIO_InitStruct.Pin = 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; |
| | | |
| | | #elif (BOARD_TYPE==15 || BOARD_TYPE == 16 ) |
| | | |
| | | 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 ) |
| | | { |
| | | #elif ( BOARD_TYPE == 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 if (BOARD_TYPE == 14) |
| | | { |
| | | #elif (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 |
| | | { |
| | | #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; |
| | | } |
| | | |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
| | | |
| | | #endif |
| | | |
| | | 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; |
| | |
| | | #endif |
| | | |
| | | } |
| | | |
| | | |
| | | /* |
| | | if ((nCurTick &0xff) ==0) |
| | | { |
| | | if (freqdir) { freq+=1+freq/10;if (freq>=1500) {freq=1500;freqdir=0;}} |
| | | else {freq-=1+freq/10;if (freq<=10) {freq=10;freqdir=1;} } |
| | | } |
| | | */ |
| | | |
| | | /* |
| | | static int outputsum=0; |
| | | static int freq=10; |
| | | static int freqdir=1; |
| | | static int phase=0; |
| | | static int somb=0; |
| | | static int len=0; |
| | | static int curbb=0; |
| | | |
| | | if ((nCurTick &0x3ff) ==1) |
| | | { |
| | | curbb++; |
| | | if (curbb+1==len) |
| | | { |
| | | // freq=0; |
| | | }else if (curbb>=len) |
| | | { |
| | | somb=musictab1[cur_musicpos*2]; |
| | | len=musictab1[cur_musicpos*2+1]; |
| | | freq=freqtab[somb]; |
| | | curbb=0;cur_musicpos++; if (cur_musicpos >= Totalmusiccount) {cur_musicpos=0;} |
| | | } |
| | | } |
| | | if ((nCurTick &0x3ff) ==0x1ff) |
| | | { |
| | | if (curbb+1==len) |
| | | { |
| | | freq=0; |
| | | } |
| | | } |
| | | phase+=freq; |
| | | if (phase>=5000) {phase-=5000;} |
| | | |
| | | |
| | | if (outtype==1) |
| | | { |
| | | outputsum+=freq; |
| | | if (outputsum>=5000) |
| | | { |
| | | //LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3); |
| | | outputsum-=5000; |
| | | } |
| | | else |
| | | { |
| | | //LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | } |
| | | }else if (outtype==2) |
| | | { |
| | | const int volume = 2500; |
| | | int amp; |
| | | if (phase<1250) |
| | | { |
| | | amp=2500+sintab[(phase -0)*256/1250]*volume/256; |
| | | |
| | | }else if (phase <2500) |
| | | { |
| | | amp=2500+sintab[(2500-1-phase)*256/1250]*volume/256; |
| | | }else if (phase <3750) |
| | | { |
| | | amp=2500-sintab[(phase-2500)*256/1250]*volume/256; |
| | | }else |
| | | { |
| | | amp=2500-sintab[(5000-1-phase)*256/1250]*volume/256; |
| | | } |
| | | outputsum+=amp; |
| | | if (outputsum>=5000) |
| | | { |
| | | LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | //LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3); |
| | | outputsum-=5000; |
| | | } |
| | | else |
| | | { |
| | | LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3); |
| | | } |
| | | } |
| | | */ |