新手上路
- 积分
- 22
- 金钱
- 22
- 注册时间
- 2019-8-21
- 在线时间
- 7 小时
|

楼主 |
发表于 2019-11-14 13:31:43
|
显示全部楼层
void Printf_Init(void)
{
USART_InitTypeDef USART_InitStructure;
SystemCoreClockUpdate();
/* USARTx 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_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;
GW_COMInit(ConsolePort, &USART_InitStructure);
/* Output a message on Hyperterminal using printf function */
printf("%s", STM32F20x_STR);
printf("\r\n Booting...\r\n\r\n");
printf(" STM32F2XX_STDPERIPH_VERSION %d.%d.%d",
__STM32F2XX_STDPERIPH_VERSION_MAIN,
__STM32F2XX_STDPERIPH_VERSION_SUB1,
__STM32F2XX_STDPERIPH_VERSION_SUB2);
printf("\n\r Inchip Flash: 1024K bytes");
printf("\n\r System Core Clock): %dHz.\n\r", SystemCoreClock);
}
/**
* @brief Configures COM port.
* @param COM: Specifies the COM port to be configured.
* This parameter can be one of following parameters:
* @arg UplinkComPort
* @arg ConsolePort
* @param USART_InitStruct: pointer to a USART_InitTypeDef structure that
* contains the configuration information for the specified USART peripheral.
* @retval None
*/
void GW_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIO clock */
RCC_AHB1PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM], ENABLE);
if (COM == UplinkComPort)
{
/* Enable UART clock */
RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
}
else
{
/* Enable UART clock */
RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
}
/* Connect PXx to USARTx_Tx*/
GPIO_PinAFConfig(COM_TX_PORT[COM], COM_TX_PIN_SOURCE[COM], COM_TX_AF[COM]);
/* Connect PXx to USARTx_Rx*/
GPIO_PinAFConfig(COM_RX_PORT[COM], COM_RX_PIN_SOURCE[COM], COM_RX_AF[COM]);
/* Configure USART Tx as alternate function */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
/* Configure USART Rx as alternate function */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
/* USART configuration */
USART_Init(COM_USART[COM], USART_InitStruct);
/* Enable USART */
USART_Cmd(COM_USART[COM], ENABLE);
}
|
|