补充can,485测试说明文档和木兰协议

This commit is contained in:
hyl 2024-03-14 10:14:41 +08:00
parent 1e6f366843
commit 1044b26f14
4 changed files with 175 additions and 4 deletions

View File

@ -1,17 +1,31 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file can_test.c
* @brief test ch32v307 can
* @version 1.0
* @author AIIT XUOS Lab
* @date 2024-03-14
*/
#include "shell.h"
#include "ch32v30x.h"
#include "connect_can.h"
#include <connect_can.h>
#include <ch32v30x_gpio.h>
#include <ch32v30x_rcc.h>
#include <ch32v30x_misc.h>
static int init_can()
{
KPrintf("init can\r\n");
CAN_FilterInitTypeDef can1_filter;

View File

@ -0,0 +1,55 @@
0.该测试在Ubiquitous中测试通过将驱动中静态的收发初始化操作在测试文件中实现在APP_Framework的测试中BusFindBusFindDriverBusFindDevice可找到相应的设备但无法通过其进行读写等操作
```
// APP_Framework/Applications/main.c
#include <stdio.h>
#include <string.h>
#include <transform.h>
#include <bus.h>
#define CAN_BUS "can1"
#define CAN_DRIVER "can1_drv"
#define CAN_DEVICE "can1_dev1"
void TestCAN(void)
{
KPrintf("Test can start\n");
struct Bus *bus;
struct HardwareDev *dev;
struct Driver *drv;
char test_str[] = "Hello AIIT!\r\n";
/* find the serial bus pointer */
bus = BusFind(CAN_BUS);
if (NONE == bus)
{
KPrintf("BusFind %s failed\n", CAN_BUS);
return;
}
/* find the serial driver pointer */
drv = BusFindDriver(bus, CAN_DRIVER);
if (NONE == drv)
{
KPrintf("BusFindDriver %s failed\n", CAN_DRIVER);
return;
}
/* find the serial device pointer */
dev = BusFindDevice(bus, CAN_DEVICE);
if (NONE == dev)
{
KPrintf("BusFindDevice %s failed\n", CAN_DEVICE);
return;
}
}
PRIV_SHELL_CMD_FUNCTION(TestCAN, a can test sample, PRIV_SHELL_CMD_MAIN_ATTR);
```
1.make BOARD=ch32v307vct6 menuconfig中配置can相关参数 ch32v307vct6 feature ---> Using CAN device --->
2.在can_test.c中can_initstruction.CAN_Mode表示can的收发模式修改该参数可实现不同的收发方式有CAN_Mode_Normal,CAN_Mode_LoopBack,CAN_Mode_Silent,CAN_Mode_Silent_LoopBack四种模式此处用CAN_Mode_Silent_LoopBack该模式实现自收自发如果需要通过主机收发可修改为CAN_Mode_Normal
3.编译后将其烧录至开发板上执行test_can命令运行can测试。

View File

@ -0,0 +1,84 @@
0.该测试在Ubiquitous中测试通过将驱动中静态的收发操作在测试文件中实现在APP_Framework的测试中BusFindBusFindDriverBusFindDevice可找到相应的设备但无法通过其进行读写等操作
```
// APP_Framework/Applications/main.c
#include <stdio.h>
#include <string.h>
#include <transform.h>
#include <bus.h>
#define RS485_UART_BUS "uart5"
#define RS485_UART_DRV "uart5_drv"
#define RS485_UART_DEV "uart5_dev5"
void Test485(void)
{
/*
485的驱动使用UART5在connect_uart.c中添加UART5的初始化添加UART5的Kconfigborad.c中使用InstallConsole用uart5串口正常输出控制台信息在app_famework中加入app_test的485测试用例后出现
HardFault_Handler.
mepc :000f448
mcause:0000007
mtval :200100d4
报错控制台停止运行最后将Test485用例摘出放置main.c中发现将PrivOpen编译进bin就会报错没有实际执行
试了试busfindbus,bus_drv,bus_dev都能找到但是BusDevWriteData(dev, &write_param)编译进去后无法运行OS无法起来/没有实际执行Busdevclose导致程序崩溃
Test 485 start
[ERR][x_free] Freeing a unallocated address.
HardFault_Handler.
mepc :0000012
mcause:0000002
mtval :0000000
在Ubiquitous/XiZi_IIoT/board/ch32v307vct6/third_party_driver/uart/test测试中
可以通过485串口正常输出接收
*/
KPrintf("Test 485 start\n");
struct Bus *bus;
struct HardwareDev *dev;
struct Driver *drv;
char test_str[] = "Hello AIIT!\r\n";
/* find the serial bus pointer */
bus = BusFind(RS485_UART_BUS);
if (NONE == bus)
{
KPrintf("BusFind %s failed\n", RS485_UART_BUS);
return;
}
/* find the serial driver pointer */
drv = BusFindDriver(bus, RS485_UART_DRV);
if (NONE == drv)
{
KPrintf("BusFindDriver %s failed\n", RS485_UART_DRV);
return;
}
/* find the serial device pointer */
dev = BusFindDevice(bus, RS485_UART_DEV);
if (NONE == dev)
{
KPrintf("BusFindDevice %s failed\n", RS485_UART_DEV);
return;
}
struct BusBlockWriteParam write_param;
write_param.pos = 0;
write_param.buffer = (void *)test_str;
write_param.size = sizeof(test_str) - 1;
// BusDevWriteData(dev, &write_param);
// BusDevClose(dev);
return;
}
PRIV_SHELL_CMD_FUNCTION(Test485, a 485 test sample, PRIV_SHELL_CMD_MAIN_ATTR);
```
1.make BOARD=ch32v307vct6 menuconfig中配置UART相关参数 ch32v307vct6 feature ---> Enable UART5 --->
2.编译后将其烧录至开发板上连接485转USB硬件至主机主机使用串口工具打开执行test_rs485命令运行485收发测试。

View File

@ -1,4 +1,22 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file rs485_test.c
* @brief test ch32v307 485
* @version 1.0
* @author AIIT XUOS Lab
* @date 2024-03-14
*/
#include "shell.h"
#include "ch32v30x.h"
#include "ch32v30x_usart.h"