|
本文分享基于FIFO实现串口驱动,方便提供好用的串口收发接口, 并基于串口驱动移植xprintf实现标准输入输出 FIFO的实现参考公众号文章 超级精简系列之十三:超级精简的循环FIFO,C实现https://mp.weixin.qq.com/s/MvL9eDesyuxD60fnbl1nag 串口驱动的实现参考公众号文章 超级精简系列之十六:基于IO模拟+FIFO的串口驱动https://mp.weixin.qq.com/s/vzjWu2LxpVGZw-msCooh8Q Xprintf移植参见公众号文章 极海半导体APM32F107VC 开发板-移植超轻量级标准输入输出函数库xprintf https://mp.weixin.qq.com/s/y4MHV3cd4T0b51L5M4J5Xg Shell实现参考公众号文章一个超级精简高可移植的shell命令行C实现 https://mp.weixin.qq.com/s/XLmbJn0SKoDT1aLdxHDrbg 代码如下详见附件
Main.c代码如下
- #include
- #include "main.h"
- #include "demo.h"
- #include "uart.h"
- #include "shell.h"
- #include "shell_func.h"
- #include "xprintf.h"
- static void xprintf_out(int ch){
- uint8_t c=(uint8_t)ch;
- uart_send(1, &c, 1);
- }
- static uint32_t shell_read(uint8_t *buff, uint32_t len)
- {
- return uart_read(1,buff,len);
- }
- static void shell_write(uint8_t *buff, uint32_t len)
- {
- uart_send(1,buff,len);
- }
- void Global_Interrupt_En(uint32_t s)
- {
- if(s & 0x00000008ul)
- set_csr(mstatus, 0x00000008ul);
- }
- uint32_t Global_Interrupt_Dis(void)
- {
- uint32_t s = read_csr(mstatus);
- clear_csr(mstatus, 0x00000008ul);
- return s;
- }
- void main(void)
- {
- uart_init(0,115200);
- Global_Interrupt_En(0x00000008ul);
- xdev_out(xprintf_out);
- xprintf("HelloWorldrn");
- while (1)
- {
- shell_set_itf(shell_read, shell_write, (shell_cmd_cfg*)g_shell_cmd_list_ast, 1);
- while(1){
- shell_exec();
- }
- //cf_delay_ms(1);
- }
- }
复制代码
运行打印如下
目前UART4接收还有问题,无法进入接收中断,也查询不到RXNE标志,所以暂时不能输入。
|