RT-Thread STM32F4DISCOVERY开发板BSP说明
RT-Thread STM32F4DISCOVERY开发板BSP说明
简介
本文档为 RT-Thread 开发团队为 STM32F4DISCOVERY 开发板提供的 BSP (板级支持包) 说明。
主要内容如下:
- 开发板资源介绍
- BSP 快速上手
- 进阶使用方法
通过阅读快速上手章节开发者可以快速地上手该 BSP,将 RT-Thread 运行在开发板上。在进阶使用指南章节,将会介绍更多高级功能,帮助开发者利用 RT-Thread 驱动更多板载资源。
开发板介绍
STM32F4DISCOVERY 是 ST 推出的一款基于 ARM Cortex-M4 内核的开发板,最高主频为 168Mhz,该开发板具有丰富的板载资源,可以充分发挥 STM32F407 的芯片性能。
开发板外观如下图所示:
该开发板常用 板载资源 如下:
- MCU:STM32F407VGT6,主频 168MHz,1024KB FLASH ,192KB RAM
- 常用外设
- LED:4个用户 LEDs, LD3(orange,PD13),LD4(green,PD12),LD5 (red,PD14) and LD6 (blue,PD15)。
- 按键,2个,Reset 和 User。
- 调试接口,板载 ST-LINK/V2调试器,使用SWD调试模式。
开发板更多详细信息请参考 ST 官方 STM32F4DISCOVERY开发板介绍。
外设支持
本 BSP 目前对外设的支持情况如下:
片上外设 | 支持情况 | 备注 |
---|---|---|
GPIO | 支持 | PA0, PA1… PH1 —> PIN: 0, 1…144 |
UART | 支持 | UART1 |
SPI | 支持 | SPI1 |
I2C | 支持 | 软件 I2C |
使用说明
使用说明分为如下两个章节:
-
快速上手
本章节是为刚接触 RT-Thread 的新手准备的使用说明,遵循简单的步骤即可将 RT-Thread 操作系统运行在该开发板上,看到实验效果 。
-
进阶使用
本章节是为需要在 RT-Thread 操作系统上使用更多开发板资源的开发者准备的。通过使用 ENV 工具对 BSP 进行配置,可以开启更多板载资源,实现更多高级功能。
快速上手
本 BSP 为开发者提供 MDK4、MDK5 和 IAR 工程,并且支持 GCC 开发环境。下面以 MDK5 开发环境为例,介绍如何将系统运行起来。
硬件连接
使用数据线连接开发板到 PC,打开电源开关。
编译下载
双击 project.uvprojx 文件,打开 MDK5 工程,编译并下载程序到开发板。
工程默认配置使用 ST-LINK 下载程序,在通过ST-LINK 连接开发板的基础上,点击下载按钮即可下载程序到开发板
运行结果
下载程序成功之后,系统会自动运行,观察开发板上 LED 的运行效果,红色 LD1 和 LD2 常亮,红色 LD5 会周期性闪烁。
连接开发板对应串口到 PC , 在终端工具里打开相应的串口(115200-8-1-N),复位设备后,可以看到 RT-Thread 的输出信息:
\ | /
- RT - Thread Operating System
/ | \ 3.1.1 build Nov 19 2018
2006 - 2018 Copyright by rt-thread team
msh >
进阶使用
此 BSP 默认只开启了 GPIO 和 串口1 的功能,更多高级功能,需要利用 ENV 工具对 BSP 进行配置,步骤如下:
-
在 bsp 下打开 env 工具。
-
输入
menuconfig
命令配置工程,配置好之后保存退出。 -
输入
pkgs --update
命令更新软件包。 -
输入
scons --target=mdk4/mdk5/iar
命令重新生成工程。
本章节更多详细的介绍请参考 STM32 系列 BSP 外设驱动使用教程。
注意事项
暂无
示例代码
…\components\finsh\shell.c
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2006-04-30 Bernard the first version for FinSH
* 2006-05-08 Bernard change finsh thread stack to 2048
* 2006-06-03 Bernard add support for skyeye
* 2006-09-24 Bernard remove the code related with hardware
* 2010-01-18 Bernard fix down then up key bug.
* 2010-03-19 Bernard fix backspace issue and fix device read in shell.
* 2010-04-01 Bernard add prompt output when start and remove the empty history
* 2011-02-23 Bernard fix variable section end issue of finsh shell
* initialization when use GNU GCC compiler.
* 2016-11-26 armink add password authentication
* 2018-07-02 aozima add custom prompt support.
*/
#include <rthw.h>
#include <string.h>
#include <stdio.h>
#ifdef RT_USING_FINSH
#include "shell.h"
#include "msh.h"
#ifdef DFS_USING_POSIX
#include <unistd.h>
#include <fcntl.h>
#endif /* DFS_USING_POSIX */
/* finsh thread */
#ifndef RT_USING_HEAP
static struct rt_thread finsh_thread;
rt_align(RT_ALIGN_SIZE)
static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
struct finsh_shell _shell;
#endif
/* finsh symtab */
#ifdef FINSH_USING_SYMTAB
struct finsh_syscall *_syscall_table_begin = NULL;
struct finsh_syscall *_syscall_table_end = NULL;
#endif
struct finsh_shell *shell;
static char *finsh_prompt_custom = RT_NULL;
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__))
struct finsh_syscall *finsh_syscall_next(struct finsh_syscall *call)
{
unsigned int *ptr;
ptr = (unsigned int *)(call + 1);
while ((*ptr == 0) && ((unsigned int *)ptr < (unsigned int *) _syscall_table_end))
ptr ++;
return (struct finsh_syscall *)ptr;
}
#endif /* defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) */
#ifdef RT_USING_HEAP
int finsh_set_prompt(const char *prompt)
{
if (finsh_prompt_custom)
{
rt_free(finsh_prompt_custom);
finsh_prompt_custom = RT_NULL;
}
/* strdup */
if (prompt)
{
finsh_prompt_custom = (char *)rt_malloc(strlen(prompt) + 1);
if (finsh_prompt_custom)
{
strcpy(finsh_prompt_custom, prompt);
}
}
return 0;
}
#endif /* RT_USING_HEAP */
#define _MSH_PROMPT "msh "
const char *finsh_get_prompt(void)
{
static char finsh_prompt[RT_CONSOLEBUF_SIZE + 1] = {0};
/* check prompt mode */
if (!shell->prompt_mode)
{
finsh_prompt[0] = '\0';
return finsh_prompt;
}
if (finsh_prompt_custom)
{
strncpy(finsh_prompt, finsh_prompt_custom, sizeof(finsh_prompt) - 1);
}
else
{
strcpy(finsh_prompt, _MSH_PROMPT);
}
#if defined(DFS_USING_POSIX) && defined(DFS_USING_WORKDIR)
/* get current working directory */
getcwd(&finsh_prompt[rt_strlen(finsh_prompt)], RT_CONSOLEBUF_SIZE - rt_strlen(finsh_prompt));
#endif
strcat(finsh_prompt, ">");
return finsh_prompt;
}
/**
* @ingroup finsh
*
* This function get the prompt mode of finsh shell.
*
* @return prompt the prompt mode, 0 disable prompt mode, other values enable prompt mode.
*/
rt_uint32_t finsh_get_prompt_mode(void)
{
RT_ASSERT(shell != RT_NULL);
return shell->prompt_mode;
}
/**
* @ingroup finsh
*
* This function set the prompt mode of finsh shell.
*
* The parameter 0 disable prompt mode, other values enable prompt mode.
*
* @param prompt_mode the prompt mode
*/
void finsh_set_prompt_mode(rt_uint32_t prompt_mode)
{
RT_ASSERT(shell != RT_NULL);
shell->prompt_mode = prompt_mode;
}
int finsh_getchar(void)
{
#ifdef RT_USING_DEVICE
char ch = 0;
#ifdef RT_USING_POSIX_STDIO
if(read(STDIN_FILENO, &ch, 1) > 0)
{
return ch;
}
else
{
return -1; /* EOF */
}
#else
rt_device_t device;
RT_ASSERT(shell != RT_NULL);
device = shell->device;
if (device == RT_NULL)
{
return -1; /* EOF */
}
while (rt_device_read(device, -1, &ch, 1) != 1)
{
rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
if (shell->device != device)
{
device = shell->device;
if (device == RT_NULL)
{
return -1;
}
}
}
return ch;
#endif /* RT_USING_POSIX_STDIO */
#else
extern char rt_hw_console_getchar(void);
return rt_hw_console_getchar();
#endif /* RT_USING_DEVICE */
}
#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
{
RT_ASSERT(shell != RT_NULL);
/* release semaphore to let finsh thread rx data */
rt_sem_release(&shell->rx_sem);
return RT_EOK;
}
/**
* @ingroup finsh
*
* This function sets the input device of finsh shell.
*
* @param device_name the name of new input device.
*/
void finsh_set_device(const char *device_name)
{
rt_device_t dev = RT_NULL;
RT_ASSERT(shell != RT_NULL);
dev = rt_device_find(device_name);
if (dev == RT_NULL)
{
rt_kprintf("finsh: can not find device: %s\n", device_name);
return;
}
/* check whether it's a same device */
if (dev == shell->device) return;
/* open this device and set the new device in finsh shell */
if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | \
RT_DEVICE_FLAG_STREAM) == RT_EOK)
{
if (shell->device != RT_NULL)
{
/* close old finsh device */
rt_device_close(shell->device);
rt_device_set_rx_indicate(shell->device, RT_NULL);
}
/* clear line buffer before switch to new device */
rt_memset(shell->line, 0, sizeof(shell->line));
shell->line_curpos = shell->line_position = 0;
shell->device = dev;
rt_device_set_rx_indicate(dev, finsh_rx_ind);
}
}
源码下载
…\bsp\stm32\stm32f407-st-discovery\project.uvproj
RT-Thread STM32F4DISCOVERY开发板BSP说明 源码下载