Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

提供STM32 HAL库裸机和FreeRTOS的demo参考(双环形队列缓冲,中断可用) #203

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions demo/easy_transplant/call_demo/user_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @file user_main.c
* @author fool_dog (2696652257@qq.com)
* @brief //> 此文件仅用于展示如何调用shell的逻辑,不要添加此文件进行编译
* @version 1.0
* @date 2024-08-09
*
* @copyright Copyright (c) 2024
*
*/

#include "../shell_all.h"

int user_main(void)
{
letter_shell_init(); // 初始化shell

for (;;)
{
letter_shell_task(); // 处理shell任务

// 建议隔一定时间调用这两个函数,可以在中断中调用,也可以在主循环中调用
{
port_tx_trigger();
port_rx_trigger();
}
}
}

//+********************************* 通常下面是接收和发送中断 **********************************/
void rx_end_callback()
{
// 在接收函数回调中或者实际接收到数据后调用
port_rx_end(-1); // 如果知道实际接收了多少个字节就传入实际的字节数,不然传入负数让其自动根据上次调用是传入的大小进行处理
}

void tx_end_callback()
{
// 在发送函数回调中,或者实际发送数据后调用
port_tx_end(-1); // 如果知道实际发送了多少个字节就传入实际的字节数,不然传入负数让其自动根据上次调用是传入的大小进行处理
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions demo/easy_transplant/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# easy_transplant demo

此目录文件为通用 letter-shell 移植的实例,目前仅提供了STM32 HAL库的适配文件

## 使用(以STM32 HAL库串口1 DMA适配为例)--AC6编译--AC5编译器已完善支持

在cubemx中开启串口,并且开启串口中断,添加串口的DMA发送和接收,DMA模式选择常规模式------其他时钟,调试接口之类的配置请自行配置

![1723214231937](image/readme/1723214231937.png)

生成工程后打开

此处以keil为例

~~ 将keil编译器切换为AC6,AC5太老了编译又慢,一定要选用AC5导致的编译报错请自行解决 ~~ 已完善AC5编译器支持

1. 将此文件夹下shell_all.c和stm32_HAL_adapt文件夹下stm32_HAL_adapt.c添加编译
2. 将shell根目录下src文件夹和extensions/shell_enhance和shell_all.h所在文件夹添加头文件包含

![1723216984202](image/readme/1723216984202.png)

在main.c中包含shell_all.h头文件,调用一次 `letter_shell_init`,轮询调用 `letter_shell_task`,轮询或定期调用 `port_tx_trigger`和 `port_rx_trigger`

![1723217000891](image/readme/1723217000891.png)

OK,编译,烧录完事

![1723217009356](image/readme/1723217009356.png)

# 其他移植可以参考stm32_HAL_adapt文件夹下实现

按照上诉方法进行移植也请看一下该文件夹下的实现,该实现下重写了STM32 HAL库的两个串口中断回调

# 其他说明

此例程移植力求不更改letter shell原仓库文件分布情况

shell对接最重要的在于read与write,通常是直接对接到外设上(例如串口),但是外设的速度是远低于内核的运行速度的,于是此例的移植对shell的输入输出都采用ringbuffer缓冲,这样方便解决在中断中调用shell读写(比如log组件)导致中断的的长时间运行,以及stm32_HAL_adapt中实现了支持FreeRTOS的情况下加锁之类的操作
Loading