⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hardware.c

📁 用 Hitex 工具软件开发 stm32 的例子
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*Enable ext interrup 10*/
   NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStructure);

   /* Enable the USART2 Interrupt */
   NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStructure);

   /* Enable the USART1 Interrupt */
   NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStructure);

   /*Enable the Timer1 Interrupt*/
   NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQChannel;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStructure);
}

/*******************************************************************************
* Function Name  : GPIO_Configuration
* Description    : configure GPIO.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void GPIO_Configuration(void)
{
   /* Configure PB.00, PB.01, PB.05 Output push-pull */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_5;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOB, &GPIO_InitStructure);

   /* Configure USART3 Rx (PB11) as input floating */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
   GPIO_Init(GPIOB, &GPIO_InitStructure);

   /* Configure PB2 as input floating (EXTI Line2) */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
   GPIO_Init(GPIOB, &GPIO_InitStructure);

#ifdef Control
   /* Configure PC13 as input floating (startup-control) */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
   GPIO_Init(GPIOC, &GPIO_InitStructure);

   while (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) != Bit_SET);
#endif

   /* Configure USART3 Tx (PB10) as alternate function push-pull */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
   GPIO_Init(GPIOB, &GPIO_InitStructure);

   /* Configure PC.04 (ADC Channel14) as analog input */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
   GPIO_Init(GPIOC, &GPIO_InitStructure);

   /* Configure USB PullUp (PD2) as opend drain */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOD, &GPIO_InitStructure);
   GPIO_ResetBits(GPIOD, GPIO_Pin_2);
}
/*******************************************************************************
* Function Name  : USART_Configuration
* Description    : configure GPIO.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void USART_Configuration(void)
{
/* USART1 configured as follow:
         - BaudRate = 115200 baud
         - Word Length = 8 Bits
         - One Stop Bit
         - No parity
         - Hardware flow control disabled (RTS and CTS signals)
         - Receive and transmit enabled
         - USART Clock disabled
         - USART CPOL: Clock is active low
         - USART CPHA: Data is captured on the middle
   - USART LastBit: The clock pulse of the last data bit is not output to the SCLK pin
   */
   USART_Cmd(USART3, DISABLE);
   TxHead = TxTail = RxHead = RxTail = 0;
   USART_InitStructure.USART_BaudRate = 115200;
   USART_InitStructure.USART_WordLength = USART_WordLength_8b;
   USART_InitStructure.USART_StopBits = USART_StopBits_1;
   USART_InitStructure.USART_Parity = USART_Parity_No ;
   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
   USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
   USART_InitStructure.USART_Clock = USART_Clock_Disable;
   USART_InitStructure.USART_CPOL = USART_CPOL_Low;
   USART_InitStructure.USART_CPHA = USART_CPHA_2Edge;
   USART_InitStructure.USART_LastBit = USART_LastBit_Disable;

   USART_Init(USART3, &USART_InitStructure);

   /* Disable the USART Transmit interrupt. It will be enabled by the UART_SendData routine.
      This interrupt is generated when the USART3 transmit data register is empty */
   USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
   /* Enable the USART Receive interrupt: this interrupt is generated when the
      USART3 receive data register is not empty */
   USART_ITConfig(USART3, (USART_IT_RXNE), ENABLE);

   /* Enable USART3 */
   USART_Cmd(USART3, ENABLE);
}
/*******************************************************************************
* Function Name  : WDG_Configuration
* Description    : configure GPIO.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void WDG_Configuration(void)
{
   /* WWDG clock counter = (PCLK1/4096)/8 = 244 Hz (~4 ms)  */
   WWDG_SetPrescaler(WWDG_Prescaler_8);
   /* Set Window value to 0x41 */
   WWDG_SetWindowValue(0x41);
   /* Clear EWI flag */
   WWDG_ClearFlag();
   /* Enable EW interrupt */
}
/*******************************************************************************
* Function Name  : ADC_Configuration
* Description    : configure GPIO.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_Configuration(void)
{
   /* ADC1 Configuration ------------------------------------------------------*/
   ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
   ADC_InitStructure.ADC_ScanConvMode = DISABLE;
   ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
   ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
   ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
   ADC_InitStructure.ADC_NbrOfChannel = 1;
   ADC_Init(ADC1, &ADC_InitStructure);

   /* ADC1 Regular Channel14 Configuration */
   ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_13Cycles5);

   /* Enable ADC1 */
   ADC_Cmd(ADC1, ENABLE);

   /* Start ADC1 Software Conversion */
   ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
/*******************************************************************************
* Function Name  : Setup_HW_Config
* Description    : configure GPIO according the extension board.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Setup_HW_Config(void)
{
   switch (Setup_Data[1]) {
    case Ext_PatchBrd :
                            break;
    case Ext_BluetoothBrd :
                            break;
    case Ext_IOBrd :        /* Configure PC.04 (ADC Channel14) as analog input */
                            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4;
                            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
                            GPIO_Init(GPIOC, &GPIO_InitStructure);
                            break;
    case Ext_SensorBrd :
                            break;
    case Ext_None :
    default :
                            break;
   }

}
/*******************************************************************************
* Function Name  : Check_HW_Config
* Description    : check hardware extension board.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Check_HW_Config(void)
{
   u8 i = 0;
   vu16 DataValue;
   /* check the identification voltage of the board */
   if (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC))
      DataValue = ADC_GetConversionValue(ADC1);
   if (DataValue < Thres_Ext_None)
      Setup_Data[1] = Ext_None;
   else if (DataValue > Thres_Ext_PatchBrd)
      Setup_Data[1] = Ext_PatchBrd;
   else if (DataValue > Thres_Ext_BluetoothBrd)
      Setup_Data[1] = Ext_BluetoothBrd;
   else if (DataValue > Thres_Ext_IOBrd)
      Setup_Data[1] = Ext_IOBrd;
   else if (DataValue > Thres_Ext_SensorBrd)
      Setup_Data[1] = Ext_SensorBrd;
   else
      Setup_Data[1] = Ext_Unknown;
   Setup_HW_Config();
   /* insert hardware version number */
   Setup_Data[0] = (u8)HW_Version; /* Hardware Version of the Stick */
   Setup_Data[2] = 0;              /* until the hardware version of the board is read */
   protocol_SendFrame (Rep_Initial_String, (u8 *)Target_Initial_String, Target_Initial_String_Length);
}

/*******************************************************************************
* Function Name  : HW_ReConfig
* Description    : check hardware extension board.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void HW_ReConfig(void)
{
   RCC_APB1PeriphClockCmd(RCC_APB1ENR_Must | RCC_APB1Periph_TIM3, ENABLE);
   RCC_APB2PeriphClockCmd(RCC_APB2ENR_Must, ENABLE);

   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA, ENABLE);
   
   GPIO_Configuration();
   Setup_HW_Config();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -