📄 serial.c
字号:
/*
* File : serial.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://openlab.rt-thread.com/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2009-02-05 Bernard first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <stm32f10x_lib.h> // STM32F10x Library Definitions
#define USARTx USART1 // USART1 is used
/**
* @addtogroup STM32
*/
/*@{*/
/**
* This function is used to display a string on console, normally, it's
* invoked by rt_kprintf
*
* @param str the displayed string
*/
void rt_console_puts(const char* str)
{
while (*str)
{
rt_serial_putc (*str++);
}
}
/**
* This function initializes serial
*/
void rt_serial_init()
{
}
/**
* This function read a character from serial without interrupt enable mode
*
* @return the read char
*/
char rt_serial_getc()
{
while (!(USARTx->SR & USART_FLAG_RXNE));
return ((char)(USARTx->DR & 0xFF));
}
/**
* This function will write a character to serial without interrupt enable mode
*
* @param c the char to write
*/
void rt_serial_putc(const char c)
{
/*
to be polite with serial console add a line feed
to the carriage return character
*/
if (c=='\n')rt_serial_putc('\r');
while (!(USARTx->SR & USART_FLAG_TXE));
USARTx->DR = (c & 0x1FF);
}
/*@}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -