在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

STM32G0開發筆記:FreeRTOS和CLI組件使用

CHANBAEK ? 來源:電子技術攻城獅 ? 作者: MakerInChina.cn ? 2023-01-16 14:47 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

使用Platformio平臺的libopencm3開發框架來開發STM32G0,以下為FreeRTOS和CLI組件使用。

1 新建項目

  • 建立freertos_cli項目

PIO的Home頁面新建項目,項目名稱freertos_cli,選擇開發板為 MonkeyPi_STM32_G070RB,開發框架選擇libopencm3;

  • 項目建立完成后在src目錄下新建main.c主程序文件;
  • 修改下載和調試方式,這里開發板使用的是DAPLink仿真器,因此修改platformio.ini文件如下:
1upload_protocol = cmsis-dap
2debug_tool = cmsis-dap

2 編寫程序

直接在之前的文章-FreeRTOS基本使用基礎上進行添加,在項目中添加好FreeRTOS源碼后,再將FreeRTOS源碼中的 FreeRTOS-Plus\\Source\\FreeRTOS-Plus-CLI 目錄放置到項目lib目錄下,目錄如下:

image-20220927232611980

2.1 串口設置
1void uart_setup(void)
 2{
 3
 4    //uart pin
 5    rcc_periph_clock_enable(RCC_USART1);
 6    rcc_periph_clock_enable(RCC_GPIOB);
 7
 8    gpio_mode_setup(GPIOB,GPIO_MODE_AF,GPIO_PUPD_NONE,GPIO6|GPIO7);
 9    gpio_set_af(GPIOB,GPIO_AF0,GPIO6|GPIO7);
10
11    usart_set_baudrate(USART1,115200);
12    usart_set_databits(USART1,8);
13    usart_set_stopbits(USART1,USART_STOPBITS_1);
14    usart_set_parity(USART1,USART_PARITY_NONE);
15    usart_set_flow_control(USART1,USART_FLOWCONTROL_NONE);
16    usart_set_mode(USART1,USART_MODE_TX_RX);
17
18    //uart isr
19    nvic_enable_irq(NVIC_USART1_IRQ);
20
21    usart_enable(USART1);
22
23    usart_enable_rx_interrupt(USART1);
24}
25
26/**
27 * @brief uart1 isr function
28 * 
29 */
30void usart1_isr(void)
31{
32    //receive interrupt
33    if (((USART_CR1(USART1) & USART_CR1_RXNEIE) != 0) &&
34        ((USART_ISR(USART1) & USART_ISR_RXNE) != 0)) {
35
36        char c = usart_recv(USART1);
37
38        xQueueSendFromISR(uart_queue, &c, NULL);
39    }
40}

開啟出口中斷,并在串口接收到數據時候發送到隊列;

2.2 命令程序

編寫執行命令后要進行的動作函數,這里為了簡單直接打印一個信息:

1static BaseType_t prvHelloCommand( 
 2    int8_t *pcWriteBuffer, 
 3    size_t xWriteBufferLen,
 4    const int8_t *pcCommandString ) 
 5{
 6
 7    sprintf(pcWriteBuffer, "hello world command");
 8
 9    /* Execution of this command is complete, so return pdFALSE. */
10    return pdFALSE;
11}
  • pcWriteBuffer 參數為要寫入的信息;
  • xWriteBufferLen 參數為寫入的緩沖大小;
  • pcCommandString 為整個命令字符串指針,可以使用 FreeRTOS_CLIGetParameter 來獲取命令的參數;
2.3 命令和函數進行映射
1static const CLI_Command_Definition_t xHelloCommand = 
2{
3    "hello",
4    "\\r\\nhello:\\r\\n This is a hello command for testing\\r\\n",
5    prvHelloCommand,
6    0
7};
  • 第一個參數為命令名字;
  • 第二個參數為命令描述;
  • 第三個參數為命令所需要的參數個數;
2.4 注冊命令
1    //register cli command
2    FreeRTOS_CLIRegisterCommand(&xHelloCommand);
2.5 命令任務

建立一個任務,用于處理CLI輸入輸出:

1static void hello_cli_task(void *args)
  2{
  3    //register cli command
  4    FreeRTOS_CLIRegisterCommand(&xHelloCommand);
  5
  6    char *outbuff;
  7    static int8_t inbuff[64];
  8    static int8_t lastinbuff[64];
  9    uint8_t index =  0;
 10    BaseType_t ret;
 11
 12    outbuff = FreeRTOS_CLIGetOutputBuffer();
 13
 14    printf(">");//command prompt
 15    fflush(stdout);
 16    // printf("\\r\\n");
 17
 18    char c;
 19
 20    while(1){
 21
 22        if( xQueueReceive(uart_queue, &c, 5) == pdPASS) {
 23            printf("%c",c);//echo
 24            fflush(stdout);
 25
 26            /* Was it the end of the line? */
 27            if( c == '\\n' || c == '\\r' )
 28            {
 29                printf("\\r\\n");
 30                fflush(stdout);
 31
 32                /* See if the command is empty, indicating that the last command is to be executed again. */
 33                if( index == 0 )
 34                {
 35                    /* Copy the last command back into the input string. */
 36                    strcpy( inbuff, lastinbuff );
 37                }
 38
 39                /* Pass the received command to the command interpreter.  The
 40                command interpreter is called repeatedly until it returns
 41                pdFALSE    (indicating there is no more output) as it might
 42                generate more than one string. */
 43                do
 44                {
 45                    /* Get the next output string from the command interpreter. */
 46                    ret = FreeRTOS_CLIProcessCommand( inbuff, outbuff, configCOMMAND_INT_MAX_OUTPUT_SIZE );
 47
 48                    /* Write the generated string to the UART. */
 49                    printf("%s",outbuff);
 50                    fflush(stdout);
 51
 52                } while( ret != pdFALSE );
 53
 54                /* All the strings generated by the input command have been
 55                sent.  Clear the input string ready to receive the next command.
 56                Remember the command that was just processed first in case it is
 57                to be processed again. */
 58                strcpy( lastinbuff, inbuff );
 59                index = 0;
 60                memset( inbuff, 0x00, 64 );
 61
 62                printf("\\r\\n>");
 63                fflush(stdout);
 64
 65            }
 66            else
 67            {
 68                if( c == '\\r' )
 69                {
 70                    /* Ignore the character. */
 71                }
 72                else if( ( c == '\\b' ) || ( c == 0x7f ) )//del
 73                {
 74                    /* Backspace was pressed.  Erase the last character in the
 75                    string - if any. */
 76                    if( index > 0 )
 77                    {
 78                        index--;
 79                        inbuff[ index ] = '\\0';
 80                    }
 81                }
 82                else
 83                {
 84                    /* A character was entered.  Add it to the string entered so
 85                    far.  When a \\n is entered the complete string will be
 86                    passed to the command interpreter. */
 87                    if( ( c >= ' ' ) && ( c <= '~' ) )
 88                    {
 89                        if( index < 64 )
 90                        {
 91                            inbuff[ index ] = c;
 92                            index++;
 93                        }
 94                    }
 95                }
 96            }
 97
 98        }
 99    }
100
101}

輸入這里直接從之前串口中斷獲取的數據隊列中得到;

輸出使用串口打印輸出即可;

3 燒寫測試

將程序燒寫到開發板,連接好串口后,執行命令測試:

image-20220928203000256

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • STM32
    +關注

    關注

    2291

    文章

    11026

    瀏覽量

    363650
  • 串口
    +關注

    關注

    15

    文章

    1586

    瀏覽量

    79643
  • 開發板
    +關注

    關注

    25

    文章

    5629

    瀏覽量

    103717
  • FreeRTOS
    +關注

    關注

    12

    文章

    492

    瀏覽量

    64084
  • CLI
    CLI
    +關注

    關注

    1

    文章

    80

    瀏覽量

    8778
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    AN5096_介紹STM32G0系列硬件開發

    AN5096_介紹STM32G0系列硬件開發
    發表于 11-21 08:11 ?4次下載
    AN5096_介紹<b class='flag-5'>STM32G0</b>系列硬件<b class='flag-5'>開發</b>

    STM32G0開發筆記FreeRTOS和FreeModbus庫使用

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,以下為FreeRTOS和FreeModbus庫使用。
    的頭像 發表于 01-16 14:44 ?6899次閱讀
    <b class='flag-5'>STM32G0</b><b class='flag-5'>開發筆記</b>:<b class='flag-5'>FreeRTOS</b>和FreeModbus庫使用

    STM32G0開發筆記:使用FreeRTOS系統的隊列Queue

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,下面為使用FreeRTOS系統的隊列Queue。
    的頭像 發表于 01-16 14:50 ?1807次閱讀

    STM32G0開發筆記:使用FreeRTOS系統

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,下面為使用FreeRTOS系統。
    的頭像 發表于 01-16 15:07 ?2981次閱讀
    <b class='flag-5'>STM32G0</b><b class='flag-5'>開發筆記</b>:使用<b class='flag-5'>FreeRTOS</b>系統

    STM32G0開發筆記:使用ADC進行NTC溫度采集

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,以下使用ADC進行NTC溫度采集。
    的頭像 發表于 01-16 15:12 ?1.1w次閱讀
    <b class='flag-5'>STM32G0</b><b class='flag-5'>開發筆記</b>:使用ADC進行NTC溫度采集

    STM32G0開發筆記:用PWM來實現LED呼吸燈效果

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,下面使用PWM來實現LED呼吸燈效果。
    的頭像 發表于 01-16 15:15 ?2737次閱讀
    <b class='flag-5'>STM32G0</b><b class='flag-5'>開發筆記</b>:用PWM來實現LED呼吸燈效果

    STM32G0開發筆記:EEPROM M24C02的使用方法

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,以下為EEPROM M24C02的使用方法。
    的頭像 發表于 01-16 15:19 ?3430次閱讀
    <b class='flag-5'>STM32G0</b><b class='flag-5'>開發筆記</b>:EEPROM M24C02的使用方法

    STM32G0開發筆記:SD卡模塊的使用方法

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,下面介紹SD卡模塊的使用方法。
    的頭像 發表于 01-19 16:27 ?2827次閱讀
    <b class='flag-5'>STM32G0</b><b class='flag-5'>開發筆記</b>:SD卡模塊的使用方法

    STM32G0開發筆記:SPI接口的基本使用

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,下面介紹SPI接口的基本使用。
    的頭像 發表于 01-17 10:38 ?3682次閱讀
    <b class='flag-5'>STM32G0</b><b class='flag-5'>開發筆記</b>:SPI接口的基本使用

    STM32G0開發筆記:多通道ADC與DMA的使用

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,以下為多通道ADC與DMA的使用。
    的頭像 發表于 01-17 10:41 ?7926次閱讀
    <b class='flag-5'>STM32G0</b><b class='flag-5'>開發筆記</b>:多通道ADC與DMA的使用

    STM32G0開發筆記:定時器timer的基本使用方法

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,以下為定時器timer的基本使用方法。
    的頭像 發表于 01-17 10:43 ?4368次閱讀
    <b class='flag-5'>STM32G0</b><b class='flag-5'>開發筆記</b>:定時器timer的基本使用方法

    STM32G0開發筆記:串口中斷的使用

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,以下為串口中斷的使用。
    的頭像 發表于 01-17 10:46 ?2840次閱讀

    STM32G0開發筆記:GPIO接按鍵的使用方式

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,下面為GPIO接按鍵的使用方式。
    的頭像 發表于 01-17 10:48 ?2150次閱讀

    STM32G0開發筆記:LED燈示例

    使用Platformio平臺的libopencm3開發框架來開發STM32G0,下面為LED燈示例。
    的頭像 發表于 01-17 10:52 ?1755次閱讀
    <b class='flag-5'>STM32G0</b><b class='flag-5'>開發筆記</b>:LED燈示例

    STM32G0開發筆記:使用libopencm3庫

    使用Platformio平臺的libopencm3開發框架來開發STM32G0開發環境為VSCode+PIO插件,這里以開發
    的頭像 發表于 01-17 10:56 ?2451次閱讀
    <b class='flag-5'>STM32G0</b><b class='flag-5'>開發筆記</b>:使用libopencm3庫
    主站蜘蛛池模板: 中文字幕在线一区 | 色五月激情小说 | 色综合久久综合欧美综合网 | 国产免费久久 | 午夜男人网 | 日本aaaaa毛片动漫 | 午夜免费小视频 | 国产成人综合欧美精品久久 | 国内一区二区三区精品视频 | 中文字幕亚洲一区二区v@在线 | 中文字幕 亚洲一区 | 四虎在线最新永久免费播放 | 日韩一级在线 | 美女久久久久久 | 精品伊人久久大线蕉地址 | 久久午夜国产片 | 亚洲一区小说区中文字幕 | 亚洲 欧美 精品专区 极品 | 国产精品久久久久天天影视 | 奇米888在线看奇米999 | 天堂网久久 | 国产小视频在线观看免费 | 亚洲第一区视频在线观看 | 九九久久九九久久 | 黄色片视频网 | 在线观看亚洲一区二区 | 福利三区 | 国产色视频网站 | h视频在线免费看 | 亚洲一区二区三区高清 | 一级视频免费观看 | 天天摸夜夜摸成人免费视频 | 国产yw855.c免费观看网站 | 成人精品一区二区三区电影 | 国产精品免费久久久久影院 | 欧美一级黄色片 | 日本超黄视频 | 特黄特色三级在线观看 | 一二三区乱码一区二区三区码 | 久操久操久操 | 天天做天天爱夜夜想毛片 |