Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
串口
瑞萨_Renesas
【开发板评测】Renesas RA2L1 开发板之UART
发布于 2022-10-17 16:03:16 浏览:691
订阅该版
[toc] ### 评测任务 首先非常感谢RT-Thread和Renesas给予测评CPK-RA2L1开发板的机会,本人所测评的模块是UART。这款R7FA2L1AB2DFM是本人使用过的第二款Renesas的芯片,同时也是第一次接触cortex-M23内核。 ### 裸机测试 首先跑一下裸机程序看开发板是否能正常工作,打开rasc创建工程 ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20221017/23b3fb85f31eaf82df98840ded06f35d.png.webp) 注意芯片型号一定不能选错 ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20221017/226faaa7e3cc75ae7fc1ce60bb58b734.png.webp) 配置uart0和led引脚 ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20221017/d8e089c45859fcb5ed184da3036b54a5.png.webp) ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20221017/240c3724e4094f5ca7d34dec81f30ad0.png.webp) 新建stack配置,并生成工程 ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20221017/79bf51e125ace4d31730ab0da824b3f1.png.webp) ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20221017/d3dd206ff4768e560742280788d97f04.png.webp) 在hal_entry中加入如下测试代码后编译。生成的工程默认不勾选生成hex文件,编译前记得勾选上,然后使用JFlashLite下载程序。程序下载后灯闪烁,串口打印abcdefg~。 ```c void user_uart0_callback (uart_callback_args_t * p_args) { if(p_args->event == UART_EVENT_TX_COMPLETE) { } } void hal_entry(void) { /* TODO: add your own code here */ R_SCI_UART_Open(&g_uart0_ctrl, &g_uart0_cfg); uint8_t *str = "abcdefg~"; R_SCI_UART_Write(&g_uart0_ctrl, str, strlen(str)); while (1) { R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_05_PIN_01, BSP_IO_LEVEL_HIGH); R_BSP_SoftwareDelay(500, BSP_DELAY_UNITS_MILLISECONDS); R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_05_PIN_01, BSP_IO_LEVEL_LOW); R_BSP_SoftwareDelay(500, BSP_DELAY_UNITS_MILLISECONDS); } #if BSP_TZ_SECURE_BUILD /* Enter non-secure code */ R_BSP_NonSecureEnter(); #endif } ``` ### rtt驱动测试 首先下载RT-Thread源码 `git clone https://gitee.com/rtthread/rt-thread.git` 下载完成后进入~\rt-thread\bsp\renesas\ra2l1-cpk文件夹运行Env工具,运行menuconfig命令,将RT-Thread Kernel -> Kernal Device Object里面的uart改为uart0,在Hardware Drivers Config -> On-chip Peripheral Drivers打开uart0和uart1 运行scons - -dist命令,先不管报错 ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20221017/532d6638b75473e329b87c4b48c84eda.png.webp) 将dist文件夹中的ra2l1-cpk拷贝出来,然后进入ra2l1-cpk文件夹双击project.uvprojx打开工程进行编译,报错如下 `1. ~/dist/ra2l1-cpk/ra/fsp/src/r_icu/r_icu.c(25): error: 'r_icu_cfg.h' file not found` `2. libraries/HAL_Drivers/drv_usart_v2.c(31): error: use of undeclared identifier 'g_uart1_ctrl'; did you mean 'g_uart9_ctrl'?` 先不管报错,打开rasc进行如下配置 ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20221017/9862be7a26e135e8e93ad88534eee5b1.png.webp) ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20221017/e0624cae3087f944c0567dc1f4bff71f.png.webp) ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20221017/29ac0cbfe484737a1186b7149a04cea1.png.webp) ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20221017/7368fe6db5d576625f1693be3741f01f.png.webp) 生成代码,新的错误如下。双击错误注释掉这行后只剩下几个警告,下载代码系统成功启动。 1. ra_cfg/fsp_cfg/bsp\bsp_cfg.h(6): error: 'board_cfg.h' file not found ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20221017/95b82b867997603ed32e7ec2a9ce7e67.png.webp) 以下给出一个空的模板以便大家使用 `git clone https://gitee.com/tjuye9/ra2l1-cpk-tmp.git` 跑一下[官方的串口设备使用例程](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/uart/uart_v1/uart?id=%e4%b8%b2%e5%8f%a3%e8%ae%be%e5%a4%87%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b)(注意把串口名改为uart1,uart0作为console) [串口设备演示视频1](https://club.rt-thread.org/file_download/96bd96f39e7e7c8e) 使用TFmini-S激光雷达模组测试串口收发,代码如下, [串口设备演示视频2](https://club.rt-thread.org/file_download/259e4424fbc5536e) ```c #include "hal_data.h" #include
#include
#define LED_PIN "P501" #define LASER_UART_NAME "uart1" /* data frame length = 7 */ #define DATA_FRAME_LENGTH (7 + 2) /* frame flag */ #define DATA_FRAME_FLAG 0x59 /* frame data concrete byte */ #define DATA_FRAME_DIS_LOW 0x03 #define DATA_FRAME_DIS_HIGH 0x04 #define DATA_FRAME_STR_LOW 0x05 #define DATA_FRAME_STR_HIGH 0x06 /* state machine */ #define STATE_IDLE 0x00 #define STATE_CHECK 0x01 #define STATE_RECV 0x02 /* state variable */ static rt_uint8_t curr_sta = STATE_IDLE; /* mutex for accessing the variable: distance */ //static rt_mutex_t laser_dis_mutex; /* semaphore for uart receive */ static rt_sem_t laser_rx_sem; /* uart device */ static rt_device_t laser_rx_dev; /* uart callback */ static rt_err_t laser_uart_input(rt_device_t dev, rt_size_t size) { rt_sem_release(laser_rx_sem); return RT_EOK; } /* uart receive thread */ static void laser_thread_entry(void *parameter) { /* save the data received */ static rt_uint8_t ch; static rt_uint8_t cnt = 0; static rt_uint16_t distance = 0; static rt_uint16_t strength = 0; while (1) { while (rt_device_read(laser_rx_dev, -1, &ch, 1) != 1) { rt_sem_take(laser_rx_sem, RT_WAITING_FOREVER); } /* the number of data received */ cnt += 1; if (curr_sta == STATE_IDLE) { /* idle state: reset the counter */ cnt = 0; if (ch == DATA_FRAME_FLAG) { curr_sta = STATE_CHECK; } else { curr_sta = STATE_IDLE; } } else if (curr_sta == STATE_CHECK) { if (ch == DATA_FRAME_FLAG) { /* the number of data received */ cnt = 2; curr_sta = STATE_RECV; } else { curr_sta = STATE_IDLE; } } else { switch (cnt) { /* distance: 16 bits, the third bit is distance low bit */ case DATA_FRAME_DIS_LOW: distance = ch; break; /* distance: 16 bits, the fourth bit is distance high bit */ case DATA_FRAME_DIS_HIGH: distance += (ch << 8); break; /* strength: 16 bits, the fifth bit is strength low bit */ case DATA_FRAME_STR_LOW: strength = ch; break; /* strength: 16 bits, the sixth bit is strength high bit */ case DATA_FRAME_STR_HIGH: strength += (ch << 8); break; /* in all 9 bits */ case DATA_FRAME_LENGTH: curr_sta = STATE_IDLE; break; default: break; } /* if the strength is less than 100, the data is invalid */ if ((strength >= 100) && (cnt == 6)) { rt_kprintf("distance:%d cm\n", distance); } else { strength = 0; } } } } /* uart sample */ static int laser_uart_test() { /* create the mutex for accessing the variable: distance */ //laser_dis_mutex = rt_mutex_create("laser_dis_mutex", RT_IPC_FLAG_FIFO); /* create the sem for data transmission */ laser_rx_sem = rt_sem_create("laser_rx_sem", 0, RT_IPC_FLAG_FIFO); /* find the uart device */ laser_rx_dev = rt_device_find(LASER_UART_NAME); if (laser_rx_dev == RT_NULL) { rt_kprintf("find %s failed!\n", LASER_UART_NAME); return RT_ERROR; } /* open the uart device */ rt_device_open(laser_rx_dev, RT_DEVICE_FLAG_INT_RX); /* set uart receive callback function */ rt_device_set_rx_indicate(laser_rx_dev, laser_uart_input); /* create uart receive thread */ rt_thread_t tid = rt_thread_create("laser_rx_thread", laser_thread_entry, RT_NULL, 1024, 25, 10); if (tid != RT_NULL) { /* start up this thread */ rt_thread_startup(tid); return RT_EOK; } else { return RT_ERROR; } } MSH_CMD_EXPORT(laser_uart_test, laser test); ``` ### 代码链接 `git clone https://gitee.com/tjuye9/ra2l1.git`
0
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
cir2way
这家伙很懒,什么也没写!
文章
5
回答
9
被采纳
0
关注TA
发私信
相关文章
1
串口DMA发送数据时,数据被覆盖
2
关于串口DMA模式下rt_device_close问题
3
利用stm32f427实现usb转串口,电脑端什么也没有识别到
4
finsh 控制台 适配 RS 485请大神指点????
5
uart_sample.c 中,读串口设备时偏移量pos要设置为-1而不是0?
6
【结贴】at_device软件包中对串口接收数据缺少判断导致数据接收异常
7
串口无法接受数据,但可以发送
8
串口如何有效的清除掉接收缓冲,而不必一个一个的去读取
9
串口接收使用方式问题
10
雅特力FINSH问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
UART
WIZnet_W5500
ota在线升级
PWM
cubemx
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
编译报错
Debug
rt_mq_消息队列_msg_queue
SFUD
keil_MDK
msh
ulog
MicroPython
C++_cpp
本月问答贡献
出出啊
1517
个答案
342
次被采纳
小小李sunny
1444
个答案
290
次被采纳
张世争
812
个答案
177
次被采纳
crystal266
547
个答案
161
次被采纳
whj467467222
1222
个答案
148
次被采纳
本月文章贡献
出出啊
1
篇文章
2
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
2
次点赞
crystal266
2
篇文章
2
次点赞
whj467467222
2
篇文章
2
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部