Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
LoRa-Radio-Driver
ART-Pi_LoRa开发套件
LoRa
基于APT-Pi与LRS007的LoRa-Radio-Driver软件包应用笔记
发布于 2021-02-03 23:17:56 浏览:3914
订阅该版
[tocm]
# 1 前言 本文主要描述了如何在APT-Pi平台与LoRa扩展板(LRS007)从零开始使用lora-radio-driver软件包,开发环境采用RT-Thread Studio 2.0.0、MDK5.29。
LoRa-Radio-Driver软件包的使用可详见 《LoRa-Radio-Driver软件包使用说明》。 - [https://github.com/Forest-Rain/lora-radio-driver/tree/master/doc](https://github.com/Forest-Rain/lora-radio-driver/tree/master/doc) 
## 1.1 准备工作
### 1.1.1 所需硬件 - [ART-Pi 开源平台](https://art-pi.gitee.io/website) - RT-Thread官方开源硬件平台 - [LoRa扩展板(LRS007)](https://mp.weixin.qq.com/s/v_0raF-5KlEOjxc5_dui3Q) - LRS007是根据APT-Pi主板设计的LoRa模块扩展板,支持多种不同频点、不同类型的LoRa模块,可同时支持2路SPI的LoRa模块,可根据实际需要灵活组合 - [LSD4RF-2R717N40 (SX1268,470M频段)](http://bbs.lierda.com/forum.php?mod=viewthread&tid=87&extra=page%3D1) - [LSD4RFC-2L722N10 (LLCC68,470M频段)](http://bbs.lierda.com/forum.php?mod=viewthread&tid=87&extra=page%3D1) - [LSD4RF-2R822N30 (SX1262,868\\915M频段)](http://bbs.lierda.com/forum.php?mod=viewthread&tid=87&extra=page%3D1) - ...
### 1.1.2 所需软件 - IDE开发工具 - [RT-Thread Studio 最新版本](https://www.rt-thread.org/document/site/rtthread-studio/um/studio-user-begin/) - MDK5 - RT-Thread操作系统 - [https://github.com/RT-Thread/rt-thread](https://github.com/RT-Thread/rt-thread) - lora-radio-driver软件包 - lora spi驱动 - [https://github.com/forest-rain/lora-radio-driver](https://github.com/forest-rain/lora-radio-driver) - multi-rtimer软件包 - 低功耗定时模块 - [https://github.com/Forest-Rain/multi-rtimer](https://github.com/Forest-Rain/multi-rtimer)
# 2 基于RT-Thread Studio的开发
## 2.0 安装最新APT-Pi SDK包 若首次使用RT-Thread Studio\\ART-Pi或者需更新为最新SDK包,点击SDK管理器图标 ,在“Board_Support_Packages”——>“STMicroelectronics”选择最新的“STM32H750-RT-ART-Pi”安装。

## 2.1 新建RT-Thread Studio工程
### 2.1.2 新建项目 RT-Thread Studio“文件”——>“新建”——>“RT-Thread项目”

在弹出的“新建项目”对话中,选择“基于开发板”——>“开发板”——>“STM32H750-RT-ART-PI”——>“示例工程”——>“art_pi_blink_led”,根据实际需求,重命名“Project name”部分的内容.

“新建项目”的整体操作步骤如下图所示

## 2.2 配置lora-radio-driver软件包 lora-radio-driver已适配ART-Pi与LRS007,可根据实际需要,直接勾选lora-radio-driver软件包对应的功能配置。具体实现原理也可以查看lora-radio-driver的配置文件Kconfig - [https://github.com/RT-Thread/packages/tree/master/peripherals/lora_radio_driver](https://github.com/RT-Thread/packages/tree/master/peripherals/lora_radio_driver) 首先使能lora-radio-driver软件包,点击Studio工程左侧"RT-Thread Settings",勾选"软件包"->"peripheral libraries and drivers"->"lora_radio_driver"。
或者 在“软件包中心”点击“立即添加”,搜索lora关键字,选择“lora_radio_driver”——>“添加”

lora-radio-driver整体使用方式如下图所示

### 2.2.1 在[lora-radio-driver软件包]配置LoRa模块关联的GPIO口 在“lora_radio_drier”软件包中,可根据实际需要选择LRS007的RF通道(RF_A或者RF_B),然后配置APT-Pi与LRS007上LoRa模块实际工作所关联的GPIO口。 > PS:注意当前lora-radio-driver软件包当前只支持单实例(单通道)
#### 2.2.1.1 选用ART-Pi与LRS007的RF_A通道 若LRS007 RF_A通道M5位号贴装LSD4RF-2R717N40[SX1268],RF_A使用了SPI2,M5接口电路如下所示

lora-radio-driver软件包Kconfig配置实现,如下所示

#### 2.2.1.2 选用ART-Pi与LRS007的RF_B通道 若LRS007 RF_B通道M6位号贴装LSD4RF-2R717N40[SX1268](出厂默认),RF_B使用了SPI4,M6接口电路如下所示

lora-radio-driver软件包Kconfig配置实现,如下所示

### 2.2.2 在[Hardware Drivers Config]配置LoRa模块所使用的SPI外设
#### 2.2.2.1 Kconfig使能SPI外设 在完成上述“2.2.1”操作后,在ART-Pi硬件平台,RT-Thread Studio会根据lora-radio-driver软件包的Kconfig文件,自动使能LoRa模块所使用的SPI外设. 注意因为.config文件会保存上一次的值,如果是从已生效的配置切换为其他LoRa模块,则需要先删除.config的配置项"LORA_RADIO_SPI_SETUP",或者直接手动设置,比如“Setup LoRa Radio Spi Name” 由 spi2 修改为 spi4。
lora-radio-driver软件包的Kconfig使能所使用SPI外设的语法,如下示例: ``` menuconfig LORA_RADIO_DRIVER_USING_TRAGET_BOARD_ART_PI_AND_LRS007_RF_A bool "APR-Pi [STM32H750XB] and LRS007 RF_A Channel" config LORA_RADIO_SPI_SETUP bool select BSP_USING_SPI select BSP_USING_SPI2 default y ``` 可以在RT-Thread Studio的“硬件” -> “Hardware Drivers Config”——> “On-chip Periopheral”——> “Enable SPI”进一步查看SPI是否正确打开

注:
将lora radio driver软件包移植到新的硬件平台,则需根据实际情况,在board\\Kconfig增加实际LoRa模块所使用的SPI外设,然后手动勾选。
board\\Kconfig中使能SPI外设语法,如下所示 ```c menuconfig BSP_USING_SPI bool "Enable SPI" default n select RT_USING_SPI if BSP_USING_SPI config BSP_USING_SPI1 bool "Enable SPI1" default n config BSP_USING_SPI2 bool "Enable SPI2" default n config BSP_USING_SPI4 bool "Enable SPI4" default n endif ```
#### 2.2.2.2 使用STM32CubeMX配置SPI外设 点击\\board\\CubeMX_Config.ioc,根据实际使用的RF通道,使能对应的SPI外设。 - ART-Pi与LRS007的RF_A 通道使用SPI2 - ART-Pi与LRS007的RF_B 通道使用SPI4 
很重要的一步是手动更新 \\board\\board.c中的系统时钟配置函数system_clock_config(),如此处使能SPI2,因此需增加RCC_PERIPHCLK_SPI2初始化,如下所示 ```c void system_clock_config(int target_freq_mhz) { PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC|RCC_PERIPHCLK_USART3 |RCC_PERIPHCLK_UART4|RCC_PERIPHCLK_SPI4 |RCC_PERIPHCLK_SPI1|RCC_PERIPHCLK_SPI2|RCC_PERIPHCLK_SDMMC |RCC_PERIPHCLK_ADC|RCC_PERIPHCLK_USB |RCC_PERIPHCLK_FMC; } ```
### 2.2.3 定时服务 LoRa Radio Driver所需定时服务支持2种方式,分别是 - 基于RT-Thread内核RT_Tick - 基于multi-rtimer软件包 若使用multi-rtimer,则需要开启硬件RTC功能.
点击 ..\\project\\lrs007_lora_radio\\board\\CubeMX_Config\\CubeMX_Config.ioc,开启STM32CubeMX,然后使能RTC外设。

2.2.3.1 开启LSE支持
如果应用需要精确的ms级别的定时\\超时服务,需选择RTC的时钟源由外部低频晶振(LSE)来驱动。开启STM32CubeMX,使能RCC的LSE功能。 1. 使能LSE  2. RTC的时钟源选择为LSE 
将STM32CubeMX新生成的系统时钟配置(LSE关联部分)手动添加到project\\lrs007_lora_radio\\board.c\\system_clock_config()函数中 ```c void system_clock_config(int target_freq_mhz) { HAL_PWR_EnableBkUpAccess(); __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW); // ... RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE |RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.LSEState = RCC_LSE_ON; //.... PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { Error_Handler(); } } ```
# 3 基于MDK5的开发
## 3.1 新建MDK工程 1. 按照"2.1"章节新建一个示例工程 ,该示例工程包含了MDK的工程。
1. 点击新建工程目录下mklinks.bat 或者以管理员权限打开 windows 命令行 ,执行 mklink 命令,分别为 `rt-thread` 及 `libraries` 文件创建符号链接 ``` mklink /D rt-thread ..\..\rt-thread mklink /D libraries ..\..\libraries ```
### 3.1.1 配置MDK的APT-Pi下载算法 首次使用MDK,需要将sdk-bsp-stm32h750-realthread-artpi\\debug\\flm\\ART-Pi_W25Q64.FLM复制到MDK本地安装目录\\ARM\\Flash下。

连接APT-Pi后,“Debug”选择“ST-Link Debugger”,自动识别出下载算法。


## 3.2 配置lora-radio-driver软件包
使用 ENV 工具,使能"RT-Thread online packages "->"peripheral libraries and drivers"->"lora_radio_driver",根据实际需要配置lora-radio-driver软件包,然后保存退出。

使用 ENV 工具执行 scons --target=mdk5即可
# 4 LoRa-Radio-Driver软件包测试 使用lora-radio-driver自带的shell命令示例代码可以进行lora模块的功能测试与验证、空口数据抓包(监听)等。
在“lora-radio-driver”软件包中使能"Enable LoRa Radio Test Shell",编译后下载到APT-Pi。

LoRa点对点通信测试至少需要准备两个LoRa设备(一个作为主机(master),另外一个作为从机(slaver))。
lora-radio-driver自带的shell命令测试示例,如下图(lora-radio-llcc68-1268-v12-r.gif)所示。
## 4.1 测试Case1 默认配置 默认配置指的是不使能“Enable LoRa Radio Debug”、同时只使用rt_kprintf,未使能ulog日志输出的情况。
在msh输入lora probe,检测lora设备是否成功挂载并且SPI访问正常。

在从机侧msh输入lora ping -s,从机进入lora接收模式。 ``` msh >lora ping -s Slaver Address(SA):[0x1020304] Stay to Rx Continuous with freq=470300000, SF=7, CR=1, BW=0 ``` 在主机侧msh输入lora ping -m,开启lora双向通信测试.默认通信次数为10次ping pong测试,ping测试完成后,主机侧会输出本次测试结果。
可以在 lora ping -m命令后面设定测试次数,如lora ping -m 1000,设置测试次数为1000次

## 4.2 测试Case2 使能详细日志输出 使能“Enable LoRa Radio Debug”,根据需要勾选所需日志输出(spi访问、lora芯片驱动、radio上层驱动等)

在msh输入lora probe,检测lora设备是否成功挂载并且SPI访问正常。

在从机侧msh输入lora ping -s,从机进入lora接收模式。
在主机侧msh输入lora ping -m,开始lora双向通信测试,此时会看到增加了phy等日志信息的输出

## 4.3 测试Case3 开启ulog日志功能 在4.2的基础上,进一步设置“组件”——>“工具”——>勾选“使能ulog”——>并勾选“使能ISR日志”,
“日志最的最大宽度”根据RAM情况实际设置,这里建议设置为384,保证较长的日志输出完整。

在msh输入lora probe,检测lora设备是否成功挂载并且SPI访问正常。

在从机侧msh输入lora ping -s,从机进入lora接收模式。
在主机侧msh输入lora ping -m,开始lora双向通信测试,此时会看到进一步增加了ulog携带的日志信息的输出

# 5 注意事项 1. 使用RT-Thread Studio或者MDK下使用EVN工具,执行从一个LoRa模块切换到另外一个LoRa模块的时候(比如此处希望从LRS007 RF_B切换到LRS007 RF_A),可能会出现LoRa模块pin引脚号没有正确配置(使用的是之前的配置)的情况,解决方式: 1. 首先取消勾选所有LoRa模块选项并保存(以清除本地已有的配置信息.config,也可以手动删除.config已有的LoRa模块引脚定义) 1. 然后再次进入"Select Supported Target Board",并选择目标LoRa模块  2. 使用MDK出现"Can't open file "rt-thread/kconfig"错误 原因:因为没有为 `rt-thread` 及 `libraries` 文件创建符号链接
解决方式:可参考“3.1 新建MDK工程”中创建符号链接。

# 6 参考 - RT-Thread仓库 - [https://github.com/RT-Thread/rt-thread](https://github.com/RT-Thread/rt-thread) - lora-radio-driver软件包 - 《LoRa-Radio-Driver软件包使用说明》 - [https://github.com/Forest-Rain/lora-radio-driver/tree/master/doc](https://github.com/Forest-Rain/lora-radio-driver/tree/master/doc) - multi-rtimer软件包 - 《multi-rtimer软件包使用说明》 - [https://github.com/Forest-Rain/multi-rtimer/tree/master/doc](https://github.com/Forest-Rain/multi-rtimer/tree/master/doc)
3
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
ForestRain
这家伙很懒,什么也没写!
文章
12
回答
12
被采纳
5
关注TA
发私信
相关文章
1
lora_Radio_driver软件包 出现引脚映射错误
2
可以付费帮助设计开发版板吗?
3
可以付费帮助设计开发版板吗?
4
lora node软件包通信问题
5
lora-radio-driver软件包使用问题
6
lora_radio_driver包使用,ping不通
7
ART-PI开发板--LoRa开发
8
无线lora 主从机控制以及同步
9
半双工的模块收到和发送数据的问题
10
请问LoRa系列的软件包大概什么时候会更新组播内容呢
推荐文章
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
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
rt-smart
FAL
I2C_IIC
UART
ESP8266
cubemx
WIZnet_W5500
ota在线升级
PWM
BSP
flash
freemodbus
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
keil_MDK
ulog
SFUD
msh
C++_cpp
MicroPython
本月问答贡献
RTT_逍遥
10
个答案
3
次被采纳
xiaorui
3
个答案
2
次被采纳
winfeng
2
个答案
2
次被采纳
三世执戟
8
个答案
1
次被采纳
KunYi
8
个答案
1
次被采纳
本月文章贡献
catcatbing
3
篇文章
5
次点赞
lizimu
2
篇文章
9
次点赞
swet123
1
篇文章
4
次点赞
Days
1
篇文章
4
次点赞
YZRD
1
篇文章
2
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部