RT-Thread STM32 GoKit V2.1 開發(fā)板BSP說明
簡介
本文檔為劉恒為 GoKit V2.1 開發(fā)板提供的 BSP (板級支持包) 說明。
主要內(nèi)容如下:
- 開發(fā)板資源介紹
- BSP 快速上手
- 進(jìn)階使用方法
通過閱讀快速上手章節(jié)開發(fā)者可以快速地上手該 BSP,將 RT-Thread 運(yùn)行在開發(fā)板上。在進(jìn)階使用指南章節(jié),將會介紹更多高級功能,幫助開發(fā)者利用 RT-Thread 驅(qū)動(dòng)更多板載資源。
開發(fā)板介紹
GoKit V2.1 是機(jī)智云 (GizWits) 推出的一款基于 ARM Cortex-M3 內(nèi)核的開發(fā)板,最高主頻為 72Mhz,該開發(fā)板專為物聯(lián)網(wǎng)打造的硬件開發(fā)平臺原型,具有豐富的板載資源,可以充分發(fā)揮 STM32F103 的芯片性能。采用底板加擴(kuò)展板結(jié)構(gòu),方便擴(kuò)展模塊。
開發(fā)板外觀如下圖所示:
該開發(fā)板常用 板載資源 如下:
- MCU:STM32F103C8T6,主頻 72MHz,64KB FLASH ,20KB RAM
- 常用外設(shè)
- LED:4個(gè),LED1 - LED4,紅色
- 按鍵:1個(gè),RESET 復(fù)位
- 常用接口:USB 轉(zhuǎn)串口等
- 調(diào)試接口,標(biāo)準(zhǔn) SWD
開發(fā)板更多詳細(xì)信息請參考【機(jī)智云】 GoKit V2.1 開發(fā)板介紹。
外設(shè)支持
本 BSP 目前對外設(shè)的支持情況如下:
板載外設(shè) | 支持情況 | 備注 |
---|---|---|
USB 轉(zhuǎn)串口 | 支持 | |
LED | 支持 | |
RGB LED | 暫不支持 | |
片上外設(shè) | 支持情況 | 備注 |
GPIO | 支持 | PA0-PA15,PB0-PB15,PC13 |
UART | 支持 | UART1 |
SPI | 暫不支持 | |
I2C | 暫不支持 | |
SDIO | 暫不支持 | |
RTC | 暫不支持 | |
PWM | 暫不支持 | |
USB Device | 暫不支持 | |
USB Host | 暫不支持 | |
IWG | 暫不支持 | |
擴(kuò)展模塊 | 支持情況 | 備注 |
gokit v2.3 | 暫不支持 |
使用說明
使用說明分為如下兩個(gè)章節(jié):
-
快速上手
本章節(jié)是為剛接觸 RT-Thread 的新手準(zhǔn)備的使用說明,遵循簡單的步驟即可將 RT-Thread 操作系統(tǒng)運(yùn)行在該開發(fā)板上,看到實(shí)驗(yàn)效果 。
-
進(jìn)階使用
本章節(jié)是為需要在 RT-Thread 操作系統(tǒng)上使用更多開發(fā)板資源的開發(fā)者準(zhǔn)備的。通過使用 ENV 工具對 BSP 進(jìn)行配置,可以開啟更多板載資源,實(shí)現(xiàn)更多高級功能。
快速上手
本 BSP 為開發(fā)者提供 MDK4、MDK5 和 IAR 工程,并且支持 GCC 開發(fā)環(huán)境。下面以 MDK5 開發(fā)環(huán)境為例,介紹如何將系統(tǒng)運(yùn)行起來。
硬件連接
使用數(shù)據(jù)線連接開發(fā)板到 PC,打開電源開關(guān)。
編譯下載
雙擊 project.uvprojx 文件,打開 MDK5 工程,編譯并下載程序到開發(fā)板。
工程默認(rèn)配置使用 Jlink 仿真器下載程序,在通過 Jlink 連接開發(fā)板的基礎(chǔ)上,點(diǎn)擊下載按鈕即可下載程序到開發(fā)板
運(yùn)行結(jié)果
下載程序成功之后,系統(tǒng)會自動(dòng)運(yùn)行,LED4 閃爍。
連接開發(fā)板對應(yīng)串口到 PC , 在終端工具里打開相應(yīng)的串口(115200-8-1-N),復(fù)位設(shè)備后,可以看到 RT-Thread 的輸出信息:
\ | /
- RT - Thread Operating System
/ | \ 4.0.2 build Jun 7 2019
2006 - 2019 Copyright by rt-thread team
msh >
進(jìn)階使用
此 BSP 默認(rèn)只開啟了 GPIO 和 串口1 的功能,如果需使用擴(kuò)展模塊等更多高級功能,需要利用 ENV 工具對BSP 進(jìn)行配置,步驟如下:
-
在 bsp 下打開 env 工具。
-
輸入
menuconfig
命令配置工程,配置好之后保存退出。 -
輸入
pkgs --update
命令更新軟件包。 -
輸入
scons --target=mdk4/mdk5/iar
命令重新生成工程。
本章節(jié)更多詳細(xì)的介紹請參考 STM32 系列 BSP 外設(shè)驅(qū)動(dòng)使用教程。
注意事項(xiàng)
示例代碼
…\components\libc\compilers\armlibc\syscalls.c
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2012-11-23 Yihui The first version
* 2013-11-24 aozima fixed _sys_read()/_sys_write() issues.
* 2014-08-03 bernard If using msh, use system() implementation
* in msh.
* 2020-08-05 Meco Man fixed _sys_flen() compiling-warning when
* RT_USING_DFS is not defined
* 2020-02-13 Meco Man re-implement exit() and abort()
* 2020-02-14 Meco Man implement _sys_tmpnam()
*/
#include <rt_sys.h>
#include <rtthread.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <compiler_private.h>
#ifdef RT_USING_POSIX_STDIO
#include <posix/stdio.h>
#endif /* RT_USING_POSIX_STDIO */
#define DBG_TAG "armlibc.syscalls"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#ifdef __clang__
__asm(".global __use_no_semihosting\n\t");
#else
#pragma import(__use_no_semihosting_swi)
#endif
/* Standard IO device handles. */
#define STDIN 0
#define STDOUT 1
#define STDERR 2
/* Standard IO device name defines. */
const char __stdin_name[] = "STDIN";
const char __stdout_name[] = "STDOUT";
const char __stderr_name[] = "STDERR";
/**
* required by fopen() and freopen().
*
* @param name - file name with path.
* @param openmode - a bitmap hose bits mostly correspond directly to
* the ISO mode specification.
* @return -1 if an error occurs.
*/
FILEHANDLE _sys_open(const char *name, int openmode)
{
#ifdef DFS_USING_POSIX
int fd;
int mode = O_RDONLY;
#endif /* DFS_USING_POSIX */
/* Register standard Input Output devices. */
if (strcmp(name, __stdin_name) == 0)
return (STDIN);
if (strcmp(name, __stdout_name) == 0)
return (STDOUT);
if (strcmp(name, __stderr_name) == 0)
return (STDERR);
#ifndef DFS_USING_POSIX
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return -1; /* error */
#else
/* Correct openmode from fopen to open */
if (openmode & OPEN_PLUS)
{
if (openmode & OPEN_W)
{
mode |= (O_RDWR | O_TRUNC | O_CREAT);
}
else if (openmode & OPEN_A)
{
mode |= (O_RDWR | O_APPEND | O_CREAT);
}
else
mode |= O_RDWR;
}
else
{
if (openmode & OPEN_W)
{
mode |= (O_WRONLY | O_TRUNC | O_CREAT);
}
else if (openmode & OPEN_A)
{
mode |= (O_WRONLY | O_APPEND | O_CREAT);
}
}
fd = open(name, mode, 0);
if (fd < 0)
return -1; /* error */
else
return fd;
#endif /* DFS_USING_POSIX */
}
int _sys_close(FILEHANDLE fh)
{
#ifdef DFS_USING_POSIX
if (fh <= STDERR)
return 0; /* error */
return close(fh);
#else
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return 0; /* error */
#endif /* DFS_USING_POSIX */
}
/*
* Read from a file. Can return:
* - zero if the read was completely successful
* - the number of bytes _not_ read, if the read was partially successful
* - the number of bytes not read, plus the top bit set (0x80000000), if
* the read was partially successful due to end of file
* - -1 if some error other than EOF occurred
*
* It is also legal to signal EOF by returning no data but
* signalling no error (i.e. the top-bit-set mechanism need never
* be used).
*
* So if (for example) the user is trying to read 8 bytes at a time
* from a file in which only 5 remain, this routine can do three
* equally valid things:
*
* - it can return 0x80000003 (3 bytes not read due to EOF)
* - OR it can return 3 (3 bytes not read), and then return
* 0x80000008 (8 bytes not read due to EOF) on the next attempt
* - OR it can return 3 (3 bytes not read), and then return
* 8 (8 bytes not read, meaning 0 read, meaning EOF) on the next
* attempt
*
* `mode' exists for historical reasons and must be ignored.
*/
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
{
#ifdef DFS_USING_POSIX
int size;
if (fh == STDIN)
{
#ifdef RT_USING_POSIX_STDIO
if (rt_posix_stdio_get_console() < 0)
{
LOG_W("Do not invoke standard output before initializing Compiler");
return 0; /* error, but keep going */
}
size = read(STDIN_FILENO, buf, len);
return len - size; /* success */
#else
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
return 0; /* error */
#endif /* RT_USING_POSIX_STDIO */
}
else if (fh == STDOUT || fh == STDERR)
{
return -1; /* 100% error */
}
else
{
size = read(fh, buf, len);
if (size >= 0)
{
return len - size; /* success */
}
else
{
return 0; /* error */
}
}
#else
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return 0; /* error */
#endif /* DFS_USING_POSIX */
}
/*
* Write to a file. Returns 0 on success, negative on error, and
* the number of characters _not_ written on partial success.
* `mode' exists for historical reasons and must be ignored.
* The return value is either:
* A positive number representing the number of characters not written
* (so any nonzero return value denotes a failure of some sort).
* A negative number indicating an error.
*/
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
{
#ifdef DFS_USING_POSIX
int size;
#endif /* DFS_USING_POSIX */
if (fh == STDOUT || fh == STDERR)
{
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
rt_device_t console;
console = rt_console_get_device();
if (console)
{
rt_device_write(console, -1, buf, len);
}
return 0; /* success */
#else
return 0; /* error */
#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */
}
else if (fh == STDIN)
{
return -1; /* 100% error */
}
else
{
#ifdef DFS_USING_POSIX
size = write(fh, buf, len);
if (size >= 0)
{
/*
fflush doesn't have a good solution in Keil-MDK,
so it has to sync/flush when for each writen.
*/
fsync(fh);
return len - size; /* success */
}
else
{
return 0; /* error */
}
#else
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return 0; /* error */
#endif /* DFS_USING_POSIX */
}
}
/*
* Flush any OS buffers associated with fh, ensuring that the file
* is up to date on disk. Result is >=0 if OK, negative for an
* error.
* This function is deprecated. It is never called by any other library function,
* and you are not required to re-implement it if you are retargeting standard I/O (stdio).
*/
int _sys_ensure(FILEHANDLE fh)
{
#ifdef DFS_USING_POSIX
return fsync(fh);
#else
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return 0; /* error */
#endif /* DFS_USING_POSIX */
}
/*
* Move the file position to a given offset from the file start.
* Returns >=0 on success, <0 on failure.
*/
int _sys_seek(FILEHANDLE fh, long pos)
{
#ifdef DFS_USING_POSIX
if (fh < STDERR)
return 0; /* error */
/* position is relative to the start of file fh */
return lseek(fh, pos, 0);
#else
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
return 0; /* error */
#endif /* DFS_USING_POSIX */
}
/**
* used by tmpnam() or tmpfile()
*/
#if __ARMCC_VERSION >= 6190000
void _sys_tmpnam(char *name, int fileno, unsigned maxlength)
{
rt_snprintf(name, maxlength, "tem%03d", fileno);
}
#else
int _sys_tmpnam(char *name, int fileno, unsigned maxlength)
{
rt_snprintf(name, maxlength, "tem%03d", fileno);
return 1;
}
#endif /* __ARMCC_VERSION >= 6190000 */
char *_sys_command_string(char *cmd, int len)
{
/* no support */
return RT_NULL;
}
源碼下載
…\bsp\stm32\stm32f103-gizwits-gokitv21\project.uvproj
文章來源:http://www.zghlxwxcb.cn/news/detail-764619.html
RT-Thread STM32 GoKit V2.1 開發(fā)板BSP說明 源碼下載文章來源地址http://www.zghlxwxcb.cn/news/detail-764619.html
維護(hù)人:
- 華為奮斗者精神, 郵箱:1992152446@qq.com
到了這里,關(guān)于RT-Thread STM32 GoKit V2.1 開發(fā)板BSP說明的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!