工程创建
首先我们将 SiFli-SDK\example\get-started\hello_world\rtt 的 rtt 文件加拷贝到合适的位置,我这里拷贝到是桌面,如下图所示:
这里我们将新建终端,因为每次终端都需要重新加载环境(注:重新打开VScode也需要这个操作)。如下图所示:
VScode 操作如下:
点一下这个即可(我们开启了后)。
运行完上面的环境配置,接下来用VScode打开复制的rtt文件,点开 src 找到 mian.c 这里就是我们的主函数勒。
函数介绍
目前的黄山派的 SDK 使用 RT-Thread ,对于大部分外设都已经适配了RT-Thread 的设备框架,熟悉 RT-Thread 的开发者可以直接跳过该部分教程,RT-Thread文档。
线程毫秒延时
此函数将使当前线程延迟几毫秒。函数原型如下:
c
rt_err_t rt_thread_mdelay ( rt_int32_t ms )
1
函数参数和返回值含义如下:
- 参数:ms 延时时间
- 返回:RT_EOK ,这个是一个宏定义 其中只为 0 无错误
打印格式化字符串
此函数将打印格式化的字符串到系统控制台。函数原型如下:
c
void rt_kprintf ( const char * fmt,
...
)
1
2
3
2
3
函数参数和返回值含义如下:
- 参数:fmt 格式化字符串的格式
- 返回:空
程序编写
接下来我们再主函数里面添加如下所示:
c
#include "rtthread.h"
#include "bf0_hal.h"
#include "drv_io.h"
#include "stdio.h"
#include "string.h"
/**
* @brief Main program
* @param None
* @retval 0 if success, otherwise failure number
*/
int main(void)
{
/* Infinite loop */
while (1)
{
rt_kprintf("Hello HSPI\n");//打印Hello world!
rt_thread_mdelay(1000);//延时1000ms
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
在 VScode 中新建的需要切换到 project 目录下。如果是 powershell 也需要切换到 project 即可。然后用下面命令进行编译
c
scons --board=sf32lb52-lchspi-ulp -j8
1
执行下面命令进行烧录:
c
build_sf32lb52-lchspi-ulp_hcpu\uart_download.bat
1
需要输入对应的端口号
运行结果如下所示: