mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
57 lines
2.0 KiB
C
57 lines
2.0 KiB
C
/***********************************************
|
||
* <09><><EFBFBD><EFBFBD><EFBFBD>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||
* <20><><EFBFBD><EFBFBD> <09><EFBFBD><DEB8><EFBFBD> <09><EFBFBD><DEB8><EFBFBD>Ϣ
|
||
--20210409 Magnin <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
************************************************/
|
||
|
||
/**************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>***************
|
||
UART1 TX -------------------------- PA9
|
||
UART1 RX -------------------------- PA10
|
||
***********************************************/
|
||
#include "uart.h"
|
||
#include "share.h"
|
||
#include "cm32m101a_conf.h"
|
||
#include <stdio.h>
|
||
|
||
static USART_InitType USART_InitStructure;
|
||
|
||
void Usart1_Init(void)
|
||
{
|
||
GPIO_InitType GPIO_InitStructure;
|
||
//<2F><><EFBFBD><EFBFBD>GPIO<49><4F>ʱ<EFBFBD><CAB1>
|
||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
|
||
//<2F><><EFBFBD><EFBFBD>USARTʱ<54><CAB1>
|
||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_USART1, ENABLE);
|
||
// <20><>ʼ<EFBFBD><CABC>GPIO<49>ṹ
|
||
GPIO_InitStruct(&GPIO_InitStructure);
|
||
//<2F><><EFBFBD><EFBFBD> USARTx Tx
|
||
GPIO_InitStructure.Pin = GPIO_PIN_9;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||
GPIO_InitStructure.GPIO_Alternate = GPIO_AF4_USART1; //<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
||
GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
|
||
//<2F><><EFBFBD><EFBFBD> USARTx Rx
|
||
GPIO_InitStructure.Pin = GPIO_PIN_10;
|
||
GPIO_InitStructure.GPIO_Pull = GPIO_Pull_Up;
|
||
GPIO_InitStructure.GPIO_Alternate = GPIO_AF4_USART1; //<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
||
GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
|
||
//<2F><><EFBFBD>ô<EFBFBD><C3B4>ڲ<EFBFBD><DAB2><EFBFBD>
|
||
USART_InitStructure.BaudRate = USART1_BANDRATE; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
USART_InitStructure.WordLength = USART_WL_8B; //<2F><><EFBFBD><EFBFBD>λ
|
||
USART_InitStructure.StopBits = USART_STPB_1; //ֹͣλ
|
||
USART_InitStructure.Parity = USART_PE_NO; //У<><D0A3>λ
|
||
USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE; //<2F>ر<EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
|
||
USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX; //<2F><><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD>ģʽ
|
||
//<2F><>ʼ<EFBFBD><CABC>USART1
|
||
USART_Init(USART1, &USART_InitStructure);
|
||
//ʹ<><CAB9>USART1
|
||
USART_Enable(USART1, ENABLE);
|
||
}
|
||
//<2F>ض<EFBFBD><D8B6><EFBFBD>fputc
|
||
int fputc(int ch, FILE* f)
|
||
{
|
||
USART_SendData(USART1, (uint8_t)ch); //<2F><>USART1<54><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
while (USART_GetFlagStatus(USART1, USART_FLAG_TXDE) == RESET) ; //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
return (ch);
|
||
}
|
||
|