欧美性猛交xxxx免费看_牛牛在线视频国产免费_天堂草原电视剧在线观看免费_国产粉嫩高清在线观看_国产欧美日本亚洲精品一5区

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何通過(guò)RT-Thread Studio配置片上外設(shè)UART

嵌入式應(yīng)用開(kāi)發(fā) ? 來(lái)源:嵌入式應(yīng)用開(kāi)發(fā) ? 作者:嵌入式應(yīng)用開(kāi)發(fā) ? 2022-08-21 09:53 ? 次閱讀

通過(guò) RT-Thread Studio 配置 AB32VG1 片上外設(shè) UART 的功能,實(shí)現(xiàn)開(kāi)發(fā)板和 PC 進(jìn)行

通信。

1.2. 模塊介紹

AB32VG1 的串口 0 被用作系統(tǒng)調(diào)試串口,串口 1 可以用作通訊端口。RT-Thread 里做好了

UART0 和 UART1 的驅(qū)動(dòng),只要打開(kāi)相應(yīng)的設(shè)備即可。

pYYBAGMAwbKACBDUAAFj7qdEgWI091.png

開(kāi)發(fā)板上串口部分的電路圖如下圖所示:

pYYBAGMAwcaAZjDwAARVLt0JWsU068.png

從電路圖上看,串口 1 使用的是 PA3 和 PA4。

新建工程
2.1.1.文件->新鍵->RT-Thread 項(xiàng)目。
2.1.2.選擇基于開(kāi)發(fā)板,填寫(xiě)工程名字。
2.1.3.開(kāi)發(fā)板:AB32VG1-AB-PROUGEN。
2.1.4.BSP:1.0.8。
2.1.3.其他默認(rèn),點(diǎn)完成。一個(gè)新的項(xiàng)目就建成了。
2.2. 編寫(xiě)測(cè)試程序
在 applications 新鍵 task.c 文件。此例程源自 RT-Thread 文檔中心,引用時(shí)有修改。

/*
* 程序清單:這是一個(gè) 串口 設(shè)備使用例程
* 例程導(dǎo)出了 uart_sample 命令到控制終端
* 命令調(diào)用格式:uart_sample uart1
* 命令解釋?zhuān)好畹诙€(gè)參數(shù)是要使用的串口設(shè)備名稱(chēng),為空則使用默認(rèn)的串口設(shè)備
* 程序功能:通過(guò)串口輸出字符串"hello RT-Thread!",然后錯(cuò)位輸出輸入的字符
*/
#include 
#define SAMPLE_UART_NAME "uart1"
/* 用于接收消息的信號(hào)量 */
static struct rt_semaphore rx_sem;
static rt_device_t serial;
/* 接收數(shù)據(jù)回調(diào)函數(shù) */
static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
{
 /* 串口接收到數(shù)據(jù)后產(chǎn)生中斷,調(diào)用此回調(diào)函數(shù),然后發(fā)送接收信號(hào)量 */
 rt_sem_release(&rx_sem);
 return RT_EOK;
}
static void serial_thread_entry(void *parameter)
{
 char ch;
 while (1)
 {
 /* 從串口讀取一個(gè)字節(jié)的數(shù)據(jù),沒(méi)有讀取到則等待接收信號(hào)量 */
 while (rt_device_read(serial, -1, &ch, 1) != 1)
 {
 /* 阻塞等待接收信號(hào)量,等到信號(hào)量后再次讀取數(shù)據(jù) */
 rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
 }
 /* 讀取到的數(shù)據(jù)通過(guò)串口錯(cuò)位輸出 */
 ch = ch + 1;
 rt_device_write(serial, 0, &ch, 1);
 } }
static int uart_sample(int argc, char *argv[])
{
 rt_err_t ret = RT_EOK;
 char uart_name[RT_NAME_MAX];
 char str[] = "hello RT-Thread!\r\n";
 if (argc == 2)
 {
 rt_strncpy(uart_name, argv[1], RT_NAME_MAX);
 }
 else
 {
 rt_strncpy(uart_name, SAMPLE_UART_NAME, RT_NAME_MAX);
 }
 /* 查找系統(tǒng)中的串口設(shè)備 */
 serial = rt_device_find(uart_name);
 if (!serial)
 {
 rt_kprintf("find %s failed!\n", uart_name);
 return RT_ERROR;
 }
 /* 初始化信號(hào)量 */
 rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
 /* 以中斷接收及輪詢發(fā)送模式打開(kāi)串口設(shè)備 */
 rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
 /* 設(shè)置接收回調(diào)函數(shù) */
 rt_device_set_rx_indicate(serial, uart_input);
 /* 發(fā)送字符串 */
 rt_device_write(serial, 0, str, (sizeof(str) - 1));
 /* 創(chuàng)建 serial 線程 */
 rt_thread_t thread = rt_thread_create("serial", serial_thread_entry, RT_NULL, 1024, 25, 10);
 /* 創(chuàng)建成功則啟動(dòng)線程 */
 if (thread != RT_NULL)
 {
 rt_thread_startup(thread);
 }
 else
 {
 ret = RT_ERROR;
 }
 return ret;
}
/* 導(dǎo)出到 msh 命令列表中 */
MSH_CMD_EXPORT(uart_sample, uart device sample);
由于在初始化串口時(shí),默認(rèn)波特率是 1500000,可以在 libraries->hal_drivers->drv_usart.c
中 int rt_hw_usart_init(void)做些修改。
int rt_hw_usart_init(void)
{
 rt_size_t obj_num = sizeof(uart_obj) / sizeof(struct ab32_uart);
 struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
 rt_err_t result = 0;
 rt_hw_interrupt_install(IRQ_UART0_2_VECTOR, uart_isr, RT_NULL, "ut_isr");
 for (int i = 0; i < obj_num; i++)
 {
 /* init UART object */
 uart_obj[i].config = &uart_config[i];
 uart_obj[i].rx_idx = 0;
 uart_obj[i].rx_idx_prev = 0;
 uart_obj[i].serial.ops = &ab32_uart_ops;
 uart_obj[i].serial.config = config;
 uart_obj[i].serial.config.baud_rate = 1500000;
 uart_obj[i].rx_buf = rt_malloc(uart_config[i].fifo_size);
 if (uart_obj[i].rx_buf == RT_NULL) {
 LOG_E("uart%d malloc failed!", i);
 continue;
 }
 //如果是串口 1,修改波特率位 115200
 if (i == 1)
 {
 uart_obj[i].serial.config.baud_rate = 115200;
 }
 //------------------
 /* register UART device */
 result = rt_hw_serial_register(&uart_obj[i].serial, uart_obj[i].config->name,
 RT_DEVICE_FLAG_RDWR
 | RT_DEVICE_FLAG_INT_RX
 | RT_DEVICE_FLAG_INT_TX
 | uart_obj[i].uart_dma_flag
 , NULL);
 RT_ASSERT(result == RT_EOK);
 }
 return result;
}
聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 嵌入式
    +關(guān)注

    關(guān)注

    5094

    文章

    19184

    瀏覽量

    307857
  • uart
    +關(guān)注

    關(guān)注

    22

    文章

    1244

    瀏覽量

    101799
  • RT-Thread
    +關(guān)注

    關(guān)注

    31

    文章

    1305

    瀏覽量

    40412
  • AB32VG1
    +關(guān)注

    關(guān)注

    1

    文章

    5

    瀏覽量

    579
收藏 人收藏

    評(píng)論

    相關(guān)推薦

    通過(guò)RT-Thread Studio配置AB32VG1外設(shè)GPIO引腳控制RGB彩燈

    本篇文章通過(guò) RT-Thread Studio 配置 AB32VG1
    的頭像 發(fā)表于 11-03 17:38 ?1.3w次閱讀
    <b class='flag-5'>通過(guò)</b><b class='flag-5'>RT-Thread</b> <b class='flag-5'>Studio</b><b class='flag-5'>配置</b>AB32VG1<b class='flag-5'>片</b><b class='flag-5'>上</b><b class='flag-5'>外設(shè)</b>GPIO引腳控制RGB彩燈

    N32L40XCL-STB開(kāi)發(fā)板模塊之UART評(píng)測(cè)

    本章通過(guò)RT-Thread Studio配置外設(shè)
    的頭像 發(fā)表于 08-10 16:52 ?1299次閱讀
    N32L40XCL-STB開(kāi)發(fā)板模塊之<b class='flag-5'>UART</b>評(píng)測(cè)

    RT-Thread Studio配置rtthread CANFD驅(qū)動(dòng)來(lái)控制M3508電機(jī)

    本文旨在RT-Thread Studio配置rtthread CANFD驅(qū)動(dòng)來(lái)控制M3508電機(jī),不涉及任何原理 開(kāi)發(fā)環(huán)境:RT-Thread
    發(fā)表于 10-08 11:44 ?1397次閱讀
    在<b class='flag-5'>RT-Thread</b> <b class='flag-5'>Studio</b><b class='flag-5'>上</b><b class='flag-5'>配置</b>rtthread CANFD驅(qū)動(dòng)來(lái)控制M3508電機(jī)

    RT-Thread Studio 使用 RT-Thread Nano

    本文介紹了如何在 RT-Thread Studio 使用 RT-Thread Nano,并以創(chuàng)建 stm32f103RB 的 Nano 工程為例。準(zhǔn)備工作安裝
    發(fā)表于 05-18 15:59

    基于RT-Thread Studio的ADC外設(shè)使用方案介紹

    ART-Pi,創(chuàng)建模板工程。2、基于RT-Thread Studio 使用STM32單片機(jī)的ADC外設(shè)一、工程建立 工程建立和時(shí)鐘配置這里不再贅述,可以看上一篇文章,在 PWM 中詳細(xì)
    發(fā)表于 03-28 16:57

    RT-Thread Studio 主要亮點(diǎn)功能

    RT-Thread Studio V1.1.0 快速上手體驗(yàn) RT-Thread Studio 主要包括工程創(chuàng)建和管理,代碼編輯,SDK管理器,RT
    的頭像 發(fā)表于 06-19 11:45 ?5970次閱讀

    RT-Thread Studio快速配置GPIO進(jìn)行點(diǎn)燈

    本章通過(guò)RT-Thread Studio配置AB32VG1
    發(fā)表于 12-14 18:44 ?10次下載
    <b class='flag-5'>RT-Thread</b> <b class='flag-5'>Studio</b>快速<b class='flag-5'>配置</b>GPIO進(jìn)行點(diǎn)燈

    RT-Thread Studio配置連接WIFI模塊

    通過(guò) RT-Thread Studio 配置 AB32VG1
    發(fā)表于 12-20 19:11 ?16次下載
    <b class='flag-5'>RT-Thread</b> <b class='flag-5'>Studio</b><b class='flag-5'>配置</b>連接WIFI模塊

    RT-Thread Studio驅(qū)動(dòng)SD卡

    RT-Thread Studio驅(qū)動(dòng)SD卡前言一、創(chuàng)建基本工程1、創(chuàng)建Bootloader2、創(chuàng)建項(xiàng)目工程二、配置RT-Thread Settings三、代碼分析1.引入庫(kù)2.讀入數(shù)據(jù)
    發(fā)表于 12-27 19:13 ?20次下載
    <b class='flag-5'>RT-Thread</b> <b class='flag-5'>Studio</b>驅(qū)動(dòng)SD卡

    RT-Thread Studio配置外設(shè)GPIO的引腳

    通過(guò) RT-Thread Studio 配置 AB32VG1
    的頭像 發(fā)表于 08-21 09:49 ?3034次閱讀
    <b class='flag-5'>RT-Thread</b> <b class='flag-5'>Studio</b><b class='flag-5'>配置</b><b class='flag-5'>片</b><b class='flag-5'>上</b><b class='flag-5'>外設(shè)</b>GPIO的引腳

    RT-Thread文檔_UART 設(shè)備

    RT-Thread文檔_UART 設(shè)備
    發(fā)表于 02-22 18:32 ?2次下載
    <b class='flag-5'>RT-Thread</b>文檔_<b class='flag-5'>UART</b> 設(shè)備

    基于RT-Thread Studio學(xué)習(xí)

    前期準(zhǔn)備:從官網(wǎng)下載 RT-Thread Studio,弄個(gè)賬號(hào)登陸,開(kāi)啟rt-thread學(xué)習(xí)之旅。
    的頭像 發(fā)表于 05-15 11:00 ?4147次閱讀
    基于<b class='flag-5'>RT-Thread</b> <b class='flag-5'>Studio</b>學(xué)習(xí)

    使用RT-Thread Studio進(jìn)行智能家居終端的設(shè)計(jì)

    本次方案基于星火一號(hào)開(kāi)發(fā)板開(kāi)發(fā),使用RT-Thread Studio進(jìn)行工程創(chuàng)建,代碼編輯,RT-Thread配置,調(diào)試配置,程序下載等功能
    的頭像 發(fā)表于 07-28 16:41 ?1986次閱讀
    使用<b class='flag-5'>RT-Thread</b> <b class='flag-5'>Studio</b>進(jìn)行智能家居終端的設(shè)計(jì)

    通過(guò)RT-Thread Studio配置N32L406外設(shè)DAC的功能

    本文通過(guò) RT-Thread Studio 配置 N32L406
    的頭像 發(fā)表于 08-15 14:32 ?1421次閱讀
    <b class='flag-5'>通過(guò)</b><b class='flag-5'>RT-Thread</b> <b class='flag-5'>Studio</b><b class='flag-5'>配置</b>N32L406<b class='flag-5'>片</b><b class='flag-5'>上</b><b class='flag-5'>外設(shè)</b>DAC的功能

    試用RT-Thread Studio(VSCode)

    想嘗試RT-Thread studio (VSCode),先下載安裝VSCode,再搜索RT-Thread
    的頭像 發(fā)表于 10-12 10:58 ?1211次閱讀
    試用<b class='flag-5'>RT-Thread</b> <b class='flag-5'>Studio</b>(VSCode)