【火牛STM32F103VC】RT-Thread 开发测试环境搭建

前言

  • 最近STM32的芯片价格高的离谱,当然开发板也不例外,最近翻出来一块【火牛STM32F103VCT6】的开发板,吃灰很多年了,那就擦擦,跑跑RT-Thread,主要是我看上面有个【LCD】,想搞下【LVGL】显示
  • 经过擦拭一番,看上去像新的一样,买来没怎么研究,记得就被工作与其他的开发板【淹没了】

上电

  • 开发板的资料找不到了,还好在网上找到了【原理图】,有了原理图,就好办多了
  • 插入电源,发现电源【指示LED】不亮,用万用表测量,发现没有供电过去,看了一下原理图,发现需要一个跳线,跳线后,发现【开发板】电源LED红灯亮起,上电成功了
  • 使用的CN10【牛角座】5V 直流电源供电
    在这里插入图片描述
  • 排针:J5 需要跳线,才能正常的供电
    在这里插入图片描述

开发环境

  • Win10 64位
  • Keil MDK5
  • 【火牛开发板 STM32F103VCT6】
  • USB 转串口线(CH340),这里使用RS232的串口,注意区分 TTL电平的
  • 5V 直流电源,用于给开发板【牛角座】供电,当然可以使用USB线供电
  • J-Link V9,用于调试与下载程序,新的Keil MDK5,对J-Link V8 支持的不够友好

在这里插入图片描述

RT-Thread 移植

  • RT-Thread 对 STM32支持的很好,STM32系列的开发板,基本上很容易适配,也就是简单的配置,就可以让开发板运行RT-Thread 操作系统
  • 首先更新 RT-Thread 到最新版本,这里使用gitee的仓库,更新起来很快,整个仓库很大,主要是BSP目录下支持众多的开发板

git clone https://gitee.com/rtthread/rt-thread.git

工程搭建

  • 直接使用 git clone 下来的RT-Thread 源码包,发现体积太大,所以这里重新搭建一个最小环境,BSP只需要 STM32F103系列的,其他的不需要

  • 最小系统的搭建流程,可以参考我之前的【文章】,简单操作如下

  • 创建三个目录即可:

    • rt-thread:不包括 BSP、git相关的目录
    • libraries:STM32F103系列的HAL库与Drivers
    • led:这里从BSP目录中复制一个F103系列的,改下MCU型号,连接脚本改下Flash与SRAM的大小
    • 工程目录如下,其他的外设功能,都重新建一个,公用相同的libraries与rt-thread操作系统代码
      在这里插入图片描述
      在这里插入图片描述
      在这里插入图片描述
      在这里插入图片描述
  • 链接脚本的修改,我这里从STM32F103ZE 改为:STM32F103VC,需要调整Flash与SRAM的大小,RT-Thread 中,使用链接脚本,Keil MDK如:board\linker_scripts\link.sct
    在这里插入图片描述

  • 修改MUC的型号,这里修改的是:template.uvprojx 这个功能模板,因为使用RT-Thread ENV工具,scons 构建工程后,是从这个工程模板生成的,所以改这个工程模板

在这里插入图片描述

  • 调试改为:J-Link
    在这里插入图片描述
  • 调试改为:J-Link SW模式
    在这里插入图片描述
  • 保存模板工程即可

修复构建路径

  • 因为工程的目录调整了,所以需要根据目录调整一下,否则RT-Thread ENV 工具 menuconfig 或 scons 构建会报错

  • 修改工程的BSP目录下的Kconfig
    在这里插入图片描述

  • 修改工程的BSP目录下的SConstruct

在这里插入图片描述

构建与编译

  • RT-Thread ENV 工具:menuconfig,保存
  • 然后:scons --target=mdk5构建 Keil MDK5工程
  • 编译下载,发现LED默认配置的跟开发板不一致,串口 shell可以工作

LED 驱动

  • 查看原理图,配置正确的LED引脚
    在这里插入图片描述
  • led.c
#include <led.h>
#include <board.h>

int led_gpio_init(void)
{
    /* set LED0 pin mode to output */
    rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED2_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED3_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED4_PIN, PIN_MODE_OUTPUT);

    return 0;
}

void led1_power_on(rt_uint8_t bon)
{
    if (bon == 0x00)
    {
        rt_pin_write(LED1_PIN, PIN_LOW);
    }
    else
    {
        rt_pin_write(LED1_PIN, PIN_HIGH);
    }
}

void led2_power_on(rt_uint8_t bon)
{
    if (bon == 0x00)
    {
        rt_pin_write(LED2_PIN, PIN_LOW);
    }
    else
    {
        rt_pin_write(LED2_PIN, PIN_HIGH);
    }
}
void led3_power_on(rt_uint8_t bon)
{
    if (bon == 0x00)
    {
        rt_pin_write(LED3_PIN, PIN_LOW);
    }
    else
    {
        rt_pin_write(LED3_PIN, PIN_HIGH);
    }
}

void led4_power_on(rt_uint8_t bon)
{
    if (bon == 0x00)
    {
        rt_pin_write(LED4_PIN, PIN_LOW);
    }
    else
    {
        rt_pin_write(LED4_PIN, PIN_HIGH);
    }
}

  • led.h
#ifndef __LED_H__
#define __LED_H__

#include <rtthread.h>

/* defined the LED1 pin: PD8 */
#define LED1_PIN    GET_PIN(D, 8)

/* defined the LED2 pin: PD9 */
#define LED2_PIN    GET_PIN(D, 9)

/* defined the LED3 pin: PD10 */
#define LED3_PIN    GET_PIN(D, 10)

/* defined the LED4 pin: PD11 */
#define LED4_PIN    GET_PIN(D, 11)

int led_gpio_init(void);
void led1_power_on(rt_uint8_t bon);
void led2_power_on(rt_uint8_t bon);
void led3_power_on(rt_uint8_t bon);
void led4_power_on(rt_uint8_t bon);

#endif

LED点灯

  • 配置好LED引脚后,在main函数里执行点灯即可(备注:这个main函数,其实是个RT-Thread的线程,main 线程)
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include "key.h"
#include "led.h"
#include "joystick.h"

int main(void)
{
    led_gpio_init();
    key_gpio_init();
    joystick_gpio_init();

    while (1)
    {
        led1_power_on(1);
        rt_thread_mdelay(1000);
        led1_power_on(0);
        rt_thread_mdelay(1000);
    }
}
  • 测试发现LED 正常的闪烁起来,最小工程搭建完成

串口 shell

  • 连接好串口1,我使用的USB转RS232串口线
 \ | /
- RT -     Thread Operating System
 / | \     4.1.1 build May  8 2022 16:12:24
 2006 - 2022 Copyright by RT-Thread team
[D/key] key_gpio_init.

[D/key] PIN_KEY0=45,PIN_KEY1=0,PIN_KEY2=8

[D/joystick] joystick_gpio_init.

msh >
msh >help
RT-Thread shell commands:
reboot           - Reboot System
help             - RT-Thread shell help.
ps               - List threads in the system.
free             - Show the memory usage in the system.
clear            - clear the terminal screen
version          - show RT-Thread version information
list_thread      - list thread
list_sem         - list semaphore in system
list_event       - list event in system
list_mutex       - list mutex in system
list_mailbox     - list mail box in system
list_msgqueue    - list message queue in system
list_memheap     - list memory heap in system
list_mempool     - list memory pool in system
list_timer       - list timer in system
list_device      - list device in system
  • 串口正常跑起来了

小结

  • 搭建【火牛开发板】STM32F103VCT6 的RT-Thread 开发调试环境
  • 后面研究一下其他的外设,如点亮LCD等
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张世争

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值