RT-Thread STM32L475 IoT Discovery kit BSP说明①
简介
本文档为 RT-Thread 开发团队为 STM32L475 IoT Discovery kit开发板提供的 BSP (板级支持包) 说明。
主要内容如下:
- 开发板资源介绍
- BSP 快速上手
- 进阶使用方法
通过阅读快速上手章节开发者可以快速地上手该 BSP,将 RT-Thread 运行在开发板上。在进阶使用指南章节,将会介绍更多高级功能,帮助开发者利用 RT-Thread 驱动更多板载资源。
开发板介绍
STM32L475 IoT Discovery kit 是 ST 官方推出的一款基于 ARM Cortex-M4 内核的开发板,最高主频为 80Mhz,该开发板具有丰富的板载资源,可以充分发挥 STM32L475 的芯片性能。
开发板外观如下图所示:
该开发板常用 板载资源 如下:
- MCU:STM32L475VGT6,主频 80MHz,1024KB FLASH ,128KB RAM
- 常用外设
- 姿态传感器
- 加速度传感器
- 磁力计
- 接近传感器
- 压力传感器
- 湿度传感器
- 扩音器
- 板载 ST LINK V2.1 功能
- 常用接口:USB OTG、Arduino Uno 和 Pmod 接口
- 调试接口:ST-LINK Micro USB 接口(ST-LINK 转串口对应 串口1)
- 支持 mbed
开发板更多详细信息请参考ST官方网站 STM32 开发板介绍
外设支持
本 BSP 目前对片上外设的支持情况如下:
片上外设 | 支持情况 | 备注 |
---|---|---|
GPIO | 支持 | |
UART | 支持 | UART1 |
使用说明
使用说明分为如下两个章节:
-
快速上手
本章节是为刚接触 RT-Thread 的新手准备的使用说明,遵循简单的步骤即可将 RT-Thread 操作系统运行在该开发板上,看到实验效果。
-
进阶使用
本章节是为需要在 RT-Thread 操作系统上使用更多开发板资源的开发者准备的。通过使用 ENV 工具对 BSP 进行配置,可以开启更多板载资源,实现更多高级功能。
快速上手
本 BSP 为开发者提供 MDK5 和 IAR 工程,并且支持 GCC 开发环境。下面以 MDK5 开发环境为例,介绍如何将系统运行起来。
硬件连接
使用数据线连接开发板到 PC。
编译下载
双击 project.uvprojx 文件,打开 MDK5 工程,编译并下载程序到开发板。
工程默认配置使用板载 ST-LINK 下载程序,只需一根 USB 线连接开发板,点击下载按钮即可下载程序到开发板
运行结果
下载程序成功之后,系统会自动运行,观察开发板上 LED 的运行效果,绿色 LED 会周期性闪烁。
连接开发板对应串口到 PC , 在终端工具里打开相应的串口(115200-8-1-N),复位设备后,可以看到 RT-Thread 的输出信息:
\ | /
- RT - Thread Operating System
/ | \ 4.0.1 build Mar 18 2019
2006 - 2019 Copyright by rt-thread team
进阶使用
此 BSP 默认只开启了 GPIO 和 串口1 的功能,如果需使用 更多高级功能,需要利用 ENV 工具对 BSP 进行配置,步骤如下:
-
在 bsp 下打开 env 工具。
-
输入
menuconfig
命令配置工程,配置好之后保存退出。 -
输入
pkgs --update
命令更新软件包。 -
输入
scons --target=mdk4/mdk5/iar
命令重新生成工程。
本章节更多详细的介绍请参考 STM32 系列 BSP 外设驱动使用教程。
注意事项
暂无
示例代码
…\src\ipc.c
static rt_ssize_t _rt_mq_recv(rt_mq_t mq,
void *buffer,
rt_size_t size,
rt_int32_t *prio,
rt_int32_t timeout,
int suspend_flag)
{
struct rt_thread *thread;
rt_base_t level;
struct rt_mq_message *msg;
rt_uint32_t tick_delta;
rt_err_t ret;
rt_size_t len;
/* parameter check */
RT_ASSERT(mq != RT_NULL);
RT_ASSERT(rt_object_get_type(&mq->parent.parent) == RT_Object_Class_MessageQueue);
RT_ASSERT(buffer != RT_NULL);
RT_ASSERT(size != 0);
/* current context checking */
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
/* initialize delta tick */
tick_delta = 0;
/* get current thread */
thread = rt_thread_self();
RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(mq->parent.parent)));
level = rt_spin_lock_irqsave(&(mq->spinlock));
/* for non-blocking call */
if (mq->entry == 0 && timeout == 0)
{
rt_spin_unlock_irqrestore(&(mq->spinlock), level);
return -RT_ETIMEOUT;
}
/* message queue is empty */
while (mq->entry == 0)
{
/* reset error number in thread */
thread->error = -RT_EINTR;
/* no waiting, return timeout */
if (timeout == 0)
{
/* enable interrupt */
rt_spin_unlock_irqrestore(&(mq->spinlock), level);
thread->error = -RT_ETIMEOUT;
return -RT_ETIMEOUT;
}
/* suspend current thread */
ret = _ipc_list_suspend(&(mq->parent.suspend_thread),
thread,
mq->parent.parent.flag,
suspend_flag);
if (ret != RT_EOK)
{
rt_spin_unlock_irqrestore(&(mq->spinlock), level);
return ret;
}
/* has waiting time, start thread timer */
if (timeout > 0)
{
/* get the start tick of timer */
tick_delta = rt_tick_get();
LOG_D("set thread:%s to timer list",
thread->parent.name);
/* reset the timeout of thread timer and start it */
rt_timer_control(&(thread->thread_timer),
RT_TIMER_CTRL_SET_TIME,
&timeout);
rt_timer_start(&(thread->thread_timer));
}
rt_spin_unlock_irqrestore(&(mq->spinlock), level);
/* re-schedule */
rt_schedule();
/* recv message */
if (thread->error != RT_EOK)
{
/* return error */
return thread->error;
}
level = rt_spin_lock_irqsave(&(mq->spinlock));
/* if it's not waiting forever and then re-calculate timeout tick */
if (timeout > 0)
{
tick_delta = rt_tick_get() - tick_delta;
timeout -= tick_delta;
if (timeout < 0)
timeout = 0;
}
}
/* get message from queue */
msg = (struct rt_mq_message *)mq->msg_queue_head;
/* move message queue head */
mq->msg_queue_head = msg->next;
/* reach queue tail, set to NULL */
if (mq->msg_queue_tail == msg)
mq->msg_queue_tail = RT_NULL;
/* decrease message entry */
if(mq->entry > 0)
{
mq->entry --;
}
rt_spin_unlock_irqrestore(&(mq->spinlock), level);
/* get real message length */
len = ((struct rt_mq_message *)msg)->length;
if (len > size)
len = size;
/* copy message */
rt_memcpy(buffer, GET_MESSAGEBYTE_ADDR(msg), len);
#ifdef RT_USING_MESSAGEQUEUE_PRIORITY
if (prio != RT_NULL)
*prio = msg->prio;
#endif
level = rt_spin_lock_irqsave(&(mq->spinlock));
/* put message to free list */
msg->next = (struct rt_mq_message *)mq->msg_queue_free;
mq->msg_queue_free = msg;
/* resume suspended thread */
if (!rt_list_isempty(&(mq->suspend_sender_thread)))
{
_ipc_list_resume(&(mq->suspend_sender_thread));
rt_spin_unlock_irqrestore(&(mq->spinlock), level);
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(mq->parent.parent)));
rt_schedule();
return len;
}
rt_spin_unlock_irqrestore(&(mq->spinlock), level);
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(mq->parent.parent)));
return len;
}
rt_ssize_t rt_mq_recv(rt_mq_t mq,
void *buffer,
rt_size_t size,
rt_int32_t timeout)
{
return _rt_mq_recv(mq, buffer, size, 0, timeout, RT_UNINTERRUPTIBLE);
}
RTM_EXPORT(rt_mq_recv);
rt_ssize_t rt_mq_recv_interruptible(rt_mq_t mq,
void *buffer,
rt_size_t size,
rt_int32_t timeout)
{
return _rt_mq_recv(mq, buffer, size, 0, timeout, RT_INTERRUPTIBLE);
}
RTM_EXPORT(rt_mq_recv_interruptible);
rt_ssize_t rt_mq_recv_killable(rt_mq_t mq,
void *buffer,
rt_size_t size,
rt_int32_t timeout)
{
return _rt_mq_recv(mq, buffer, size, 0, timeout, RT_KILLABLE);
}
#ifdef RT_USING_MESSAGEQUEUE_PRIORITY
rt_err_t rt_mq_send_wait_prio(rt_mq_t mq,
const void *buffer,
rt_size_t size,
rt_int32_t prio,
rt_int32_t timeout,
int suspend_flag)
{
return _rt_mq_send_wait(mq, buffer, size, prio, timeout, suspend_flag);
}
rt_ssize_t rt_mq_recv_prio(rt_mq_t mq,
void *buffer,
rt_size_t size,
rt_int32_t *prio,
rt_int32_t timeout,
int suspend_flag)
{
return _rt_mq_recv(mq, buffer, size, prio, timeout, suspend_flag);
}
#endif
RTM_EXPORT(rt_mq_recv_killable);
/**
* @brief This function will set some extra attributions of a messagequeue object.
*
* @note Currently this function only supports the RT_IPC_CMD_RESET command to reset the messagequeue.
*
* @param mq is a pointer to a messagequeue object.
*
* @param cmd is a command used to configure some attributions of the messagequeue.
*
* @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_mq_control(rt_mq_t mq, int cmd, void *arg)
{
rt_base_t level;
struct rt_mq_message *msg;
/* parameter check */
RT_ASSERT(mq != RT_NULL);
RT_ASSERT(rt_object_get_type(&mq->parent.parent) == RT_Object_Class_MessageQueue);
if (cmd == RT_IPC_CMD_RESET)
{
level = rt_spin_lock_irqsave(&(mq->spinlock));
/* resume all waiting thread */
_ipc_list_resume_all(&mq->parent.suspend_thread);
/* also resume all message queue private suspended thread */
_ipc_list_resume_all(&(mq->suspend_sender_thread));
/* release all message in the queue */
while (mq->msg_queue_head != RT_NULL)
{
/* get message from queue */
msg = (struct rt_mq_message *)mq->msg_queue_head;
/* move message queue head */
mq->msg_queue_head = msg->next;
/* reach queue tail, set to NULL */
if (mq->msg_queue_tail == msg)
mq->msg_queue_tail = RT_NULL;
/* put message to free list */
msg->next = (struct rt_mq_message *)mq->msg_queue_free;
mq->msg_queue_free = msg;
}
/* clean entry */
mq->entry = 0;
rt_spin_unlock_irqrestore(&(mq->spinlock), level);
rt_schedule();
return RT_EOK;
}
return -RT_ERROR;
}
RTM_EXPORT(rt_mq_control);
/**@}*/
#endif /* RT_USING_MESSAGEQUEUE */
/**@}*/
源码下载
…\bsp\stm32\stm32l475-st-discovery\project.uvproj
文章来源:https://www.toymoban.com/news/detail-783938.html
RT-Thread STM32L475 IoT Discovery kit BSP说明① 源码下载文章来源地址https://www.toymoban.com/news/detail-783938.html
维护人:
- 华为奋斗者精神, 邮箱:1992152446@qq.com
到了这里,关于RT-Thread STM32L475 IoT Discovery kit BSP说明①的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!