RT-Thread STM32L431 Bear-Pi開發(fā)板BSP說明
簡介
本文檔為Bear-Pi 開發(fā)板的 BSP (板級支持包) 說明。
主要內(nèi)容如下:
- 開發(fā)板資源介紹
- BSP 快速上手
- 進(jìn)階使用方法
通過閱讀快速上手章節(jié)開發(fā)者可以快速地上手該 BSP,將 RT-Thread 運行在開發(fā)板上。在進(jìn)階使用指南章節(jié),將會介紹更多高級功能,幫助開發(fā)者利用 RT-Thread 驅(qū)動更多板載資源。
開發(fā)板介紹
對于 Bear-Pi,內(nèi)核是 Cortex-M4,這款芯片是低功耗系列,板載 ST-LINK/V2-1 調(diào)試器/編程器,迷你尺寸,mirco USB 接口,可數(shù)的外設(shè),Arduino? nano 兼容的接口。
開發(fā)板外觀如下圖所示:
該開發(fā)板常用 板載資源 如下:
- MCU:STM32L431RC,主頻 80MHz,256KB FLASH ,64KB RAM。
- 常用外設(shè)
- SPI FLASH: 8M
- 按鍵:2個功能鍵,一個復(fù)位按鍵。
- 支持E53系列傳感器案例擴(kuò)展板
- LCD: 240 * 240 tft
- LED:一個用戶LED, 上電指示燈,下載燈。
- 常用接口:USB 支持 3 種不同接口:虛擬 COM 端口、大容量存儲和調(diào)試端口。
- 調(diào)試接口:板載 ST-LINK/V2-1 調(diào)試器。
開發(fā)板更多詳細(xì)信息請參考【Bear-Pi 官網(wǎng)】 Bear-Pi。
外設(shè)支持
本 BSP 目前對外設(shè)的支持情況如下:
板載外設(shè) | 支持情況 | 備注 |
---|---|---|
板載 ST-LINK 轉(zhuǎn)串口 | 支持 | UART1 |
片上外設(shè) | 支持情況 | 備注 |
GPIO | 支持 | PA0, PA1… PC15 —> PIN: 0, 1…47 |
UART | 支持 | UART1 |
使用說明
使用說明分為如下兩個章節(jié):
-
快速上手
本章節(jié)是為剛接觸 RT-Thread 的新手準(zhǔn)備的使用說明,遵循簡單的步驟即可將 RT-Thread 操作系統(tǒng)運行在該開發(fā)板上,看到實驗效果 。
-
進(jìn)階使用
本章節(jié)是為需要在 RT-Thread 操作系統(tǒng)上使用更多開發(fā)板資源的開發(fā)者準(zhǔn)備的。通過使用 ENV 工具對 BSP 進(jìn)行配置,可以開啟更多板載資源,實現(xiàn)更多高級功能。
快速上手
本 BSP 為開發(fā)者提供 MDK5 和 IAR 工程,并且支持 GCC 開發(fā)環(huán)境。下面以 MDK5 開發(fā)環(huán)境為例,介紹如何將系統(tǒng)運行起來。
硬件連接
使用數(shù)據(jù)線連接開發(fā)板到 PC,打開電源開關(guān)。
編譯下載
雙擊 project.uvprojx 文件,打開 MDK5 工程,編譯并下載程序到開發(fā)板。
工程默認(rèn)配置使用 ST-LINK 仿真器下載程序,在通過 microUSB 連接開發(fā)板的基礎(chǔ)上,點擊下載按鈕即可下載程序到開發(fā)板
運行結(jié)果
下載程序成功之后,系統(tǒng)會自動運行,觀察開發(fā)板上 LED 的運行效果,紅色 D5、藍(lán)色 LED 會周期性閃爍。
USB 虛擬 COM 端口默認(rèn)連接串口 1,在終端工具里打開相應(yīng)的串口(115200-8-1-N),復(fù)位設(shè)備后,可以看到 RT-Thread 的輸出信息:
\ | /
- RT - Thread Operating System
/ | \ 4.0.3 build Dec 28 2020
2006 - 2020 Copyright by rt-thread team
---Welcome use BearPi---
msh >
進(jìn)階使用
此 BSP 默認(rèn)只開啟了 GPIO 和 串口2 的功能,如果需使用更多高級功能,需要利用 ENV 工具對 BSP 進(jìn)行配置,步驟如下:
-
在 bsp 下打開 env 工具。
-
輸入
menuconfig
命令配置工程,配置好之后保存退出。 -
輸入
pkgs --update
命令更新軟件包。 -
輸入
scons --target=mdk4/mdk5/iar
命令重新生成工程。
本章節(jié)更多詳細(xì)的介紹請參考 STM32 系列 BSP 外設(shè)驅(qū)動使用教程。
注意事項
- 開機(jī)時如果不能打印 RT-Thread 版本信息,請將BSP中串口 GPIO 速率調(diào)低
- 開機(jī)時如果不能打印 RT-Thread 版本信息,請重新選擇 PC 端串口調(diào)試軟件的串口號
示例代碼
…\rt-threadcode\src\ipc.c
/**
* @brief This function will try to take a mutex, if the mutex is unavailable, the thread returns immediately.
*
* @note This function is very similar to the rt_mutex_take() function, when the mutex is not available,
* except that rt_mutex_trytake() will return immediately without waiting for a timeout
* when the mutex is not available.
* In other words, rt_mutex_trytake(mutex) has the same effect as rt_mutex_take(mutex, 0).
*
* @see rt_mutex_take()
*
* @param mutex is a pointer to a mutex object.
*
* @return Return the operation status. ONLY When the return value is RT_EOK, the operation is successful.
* If the return value is any other values, it means that the mutex take failed.
*/
rt_err_t rt_mutex_trytake(rt_mutex_t mutex)
{
return rt_mutex_take(mutex, RT_WAITING_NO);
}
RTM_EXPORT(rt_mutex_trytake);
/**
* @brief This function will release a mutex. If there is thread suspended on the mutex, the thread will be resumed.
*
* @note If there are threads suspended on this mutex, the first thread in the list of this mutex object
* will be resumed, and a thread scheduling (rt_schedule) will be executed.
* If no threads are suspended on this mutex, the count value mutex->value of this mutex will increase by 1.
*
* @param mutex is a pointer to a mutex object.
*
* @return Return the operation status. When the return value is RT_EOK, the operation is successful.
* If the return value is any other values, it means that the mutex release failed.
*/
rt_err_t rt_mutex_release(rt_mutex_t mutex)
{
rt_base_t level;
struct rt_thread *thread;
rt_bool_t need_schedule;
/* parameter check */
RT_ASSERT(mutex != RT_NULL);
RT_ASSERT(rt_object_get_type(&mutex->parent.parent) == RT_Object_Class_Mutex);
need_schedule = RT_FALSE;
/* only thread could release mutex because we need test the ownership */
RT_DEBUG_IN_THREAD_CONTEXT;
/* get current thread */
thread = rt_thread_self();
level = rt_spin_lock_irqsave(&(mutex->spinlock));
LOG_D("mutex_release:current thread %s, hold: %d",
thread->parent.name, mutex->hold);
RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(mutex->parent.parent)));
/* mutex only can be released by owner */
if (thread != mutex->owner)
{
thread->error = -RT_ERROR;
rt_spin_unlock_irqrestore(&(mutex->spinlock), level);
return -RT_ERROR;
}
/* decrease hold */
mutex->hold --;
/* if no hold */
if (mutex->hold == 0)
{
/* remove mutex from thread's taken list */
rt_list_remove(&mutex->taken_list);
/* whether change the thread priority */
if ((mutex->ceiling_priority != 0xFF) || (thread->current_priority == mutex->priority))
{
rt_uint8_t priority = 0xff;
/* get the highest priority in the taken list of thread */
priority = _thread_get_mutex_priority(thread);
rt_thread_control(thread,
RT_THREAD_CTRL_CHANGE_PRIORITY,
&priority);
need_schedule = RT_TRUE;
}
/* wakeup suspended thread */
if (!rt_list_isempty(&mutex->parent.suspend_thread))
{
/* get the first suspended thread */
struct rt_thread *next_thread = rt_list_entry(mutex->parent.suspend_thread.next,
struct rt_thread,
tlist);
LOG_D("mutex_release: resume thread: %s",
next_thread->parent.name);
rt_spin_lock(&(next_thread->spinlock));
/* remove the thread from the suspended list of mutex */
rt_list_remove(&(next_thread->tlist));
/* set new owner and put mutex into taken list of thread */
mutex->owner = next_thread;
mutex->hold = 1;
rt_list_insert_after(&next_thread->taken_object_list, &mutex->taken_list);
/* cleanup pending object */
next_thread->pending_object = RT_NULL;
rt_spin_unlock(&(next_thread->spinlock));
/* resume thread */
rt_thread_resume(next_thread);
/* update mutex priority */
if (!rt_list_isempty(&(mutex->parent.suspend_thread)))
{
struct rt_thread *th;
th = rt_list_entry(mutex->parent.suspend_thread.next,
struct rt_thread,
tlist);
mutex->priority = th->current_priority;
}
else
{
mutex->priority = 0xff;
}
need_schedule = RT_TRUE;
}
else
{
/* clear owner */
mutex->owner = RT_NULL;
mutex->priority = 0xff;
}
}
rt_spin_unlock_irqrestore(&(mutex->spinlock), level);
/* perform a schedule */
if (need_schedule == RT_TRUE)
rt_schedule();
return RT_EOK;
}
RTM_EXPORT(rt_mutex_release);
/**
* @brief This function will set some extra attributions of a mutex object.
*
* @note Currently this function does not implement the control function.
*
* @param mutex is a pointer to a mutex object.
*
* @param cmd is a command word used to configure some attributions of the mutex.
*
* @param arg is the argument of the function to execute the command.
*
* @return Return the operation status. When the return value is RT_EOK, the operation is successful.
* If the return value is any other values, it means that this function failed to execute.
*/
rt_err_t rt_mutex_control(rt_mutex_t mutex, int cmd, void *arg)
{
/* parameter check */
RT_ASSERT(mutex != RT_NULL);
RT_ASSERT(rt_object_get_type(&mutex->parent.parent) == RT_Object_Class_Mutex);
return -RT_ERROR;
}
RTM_EXPORT(rt_mutex_control);
/**@}*/
#endif /* RT_USING_MUTEX */
源碼下載
…\bsp\stm32\stm32l431-BearPi\project.uvproj
文章來源:http://www.zghlxwxcb.cn/news/detail-763863.html
RT-Thread STM32L431 Bear-Pi開發(fā)板BSP說明 源碼下載文章來源地址http://www.zghlxwxcb.cn/news/detail-763863.html
維護(hù)人:
- 華為奮斗者精神, 郵箱:1992152446@qq.com
到了這里,關(guān)于RT-Thread STM32L431 Bear-Pi開發(fā)板BSP說明的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!