IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 嵌入式 -> 【GD32开发学习】四、FreeRTOS移植 -> 正文阅读

[嵌入式]【GD32开发学习】四、FreeRTOS移植

文章目录


前言

准备

1、GD32F系列开发版,我使用的事F427R-START开发版

2、安装有Keil的电脑,当前keil版本为v5.31.0.0

3、FreeRTOS版本 FreeRTOS Kernel V10.1.1

一、保留RTOS目录下这些文件

?

?

?

?

二、添加源文件到工程

?其中?heap_4.c 文件在FreeRTOS\Source\portable\MemMang文件夹下,

port.c在\FreeRTOS\Source\portable\RVDS\ARM_CM4F文件夹下

/*
 * FreeRTOS Kernel V10.0.1
 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://www.FreeRTOS.org
 * http://aws.amazon.com/freertos
 *
 * 1 tab == 4 spaces!
 */

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#if defined(__CC_ARM) || defined(__ICCARM__)
#include <stdint.h>
extern uint32_t SystemCoreClock;
#endif

#define configUSE_PREEMPTION                          1
#define configCPU_CLOCK_HZ                            ( SystemCoreClock )
#define configTICK_RATE_HZ                            ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES                          ( 8 )
#define configMINIMAL_STACK_SIZE                      ( ( unsigned short ) 130 )
#define configTOTAL_HEAP_SIZE                         ( ( size_t ) ( 16 * 1024 ) )
#define configMAX_TASK_NAME_LEN                       ( 16 )
#define configUSE_16_BIT_TICKS                        0
#define configIDLE_SHOULD_YIELD                       1
#define configUSE_MUTEXES                             1
#define configUSE_RECURSIVE_MUTEXES                   1
#define configUSE_COUNTING_SEMAPHORES                 1
#define configQUEUE_REGISTRY_SIZE                     8
#define configUSE_QUEUE_SETS                          0
#define configUSE_APPLICATION_TASK_TAG                0


/* hook function related definitions */
#define configUSE_IDLE_HOOK                           0
#define configUSE_TICK_HOOK                           0
#define configCHECK_FOR_STACK_OVERFLOW                0
#define configUSE_MALLOC_FAILED_HOOK                  0


#define configSUPPORT_STATIC_ALLOCATION               0
#define configUSE_TICKLESS_IDLE                       0
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS       0


#define configUSE_TRACE_FACILITY                      1
/* This demo makes use of one or more example stats formatting functions.  These
format the raw data provided by the uxTaskGetSystemState() function in to human
readable ASCII form.  See the notes in the implementation of vTaskList() within
FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS          0


/* Run time stats gathering definitions. */
#define configGENERATE_RUN_TIME_STATS                 0
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
#define portGET_RUN_TIME_COUNTER_VALUE()              0

/* co-routine definitions */
#define configUSE_CO_ROUTINES                         0
#define configMAX_CO_ROUTINE_PRIORITIES               ( 2 )

/* software timer definitions */
#define configUSE_TIMERS                              0
#define configTIMER_TASK_PRIORITY                     ( 2 )
#define configTIMER_QUEUE_LENGTH                      10
#define configTIMER_TASK_STACK_DEPTH                  ( configMINIMAL_STACK_SIZE * 2 )

/* set to 1 to include the API function, or 0 to exclude the API function */
#define INCLUDE_vTaskPrioritySet                      1
#define INCLUDE_uxTaskPriorityGet                     1
#define INCLUDE_vTaskDelete                           1
#define INCLUDE_vTaskCleanUpResources                 0
#define INCLUDE_vTaskSuspend                          1
#define INCLUDE_vTaskDelayUntil                       1
#define INCLUDE_vTaskDelay                            1
#define INCLUDE_eTaskGetState                         1
#define INCLUDE_xTimerPendFunctionCall                0
#define INCLUDE_xSemaphoreGetMutexHolder              0
#define INCLUDE_xTaskGetHandle                        1
#define INCLUDE_xTaskGetCurrentTaskHandle             1
#define INCLUDE_xTaskGetIdleTaskHandle                0
#define INCLUDE_xTaskAbortDelay                       0
#define INCLUDE_xTaskGetSchedulerState                1
#define INCLUDE_uxTaskGetStackHighWaterMark           1



/* Cortex-M specific definitions */
#ifdef __NVIC_PRIO_BITS
    /* __NVIC_PRIO_BITS will be specified when CMSIS is being used. */
    #define configPRIO_BITS                           __NVIC_PRIO_BITS
#else
    #define configPRIO_BITS                           4        /* 15 priority levels */
#endif

/* the lowest interrupt priority that can be used in a call to a "set priority" function */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY       0xf

/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions.  Do not call
interrupt safe freertos api functions from any interrupt that has a higher
priority than this! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY   2

/* interrupt priorities used by the kernel port layer itself */
#define configKERNEL_INTERRUPT_PRIORITY                ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY           ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )




/* normal assert() semantics without relying on the provision of an assert.h header file */
#define configASSERT( x )                              if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 

/* map the FreeRTOS port interrupt handlers to CMSIS standard names */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler



#endif /* FREERTOS_CONFIG_H */

其余\FreeRTOS\Source下

三、头文件包含

?编译报错,找不到?FreeRTOSConfig.h文件

可以从官方移植的例程中找到这个文件,放到\FreeRTOS\Source\include下即可

/*
 * FreeRTOS Kernel V10.0.1
 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://www.FreeRTOS.org
 * http://aws.amazon.com/freertos
 *
 * 1 tab == 4 spaces!
 */

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#if defined(__CC_ARM) || defined(__ICCARM__)
#include <stdint.h>
extern uint32_t SystemCoreClock;
#endif

#define configUSE_PREEMPTION                          1
#define configCPU_CLOCK_HZ                            ( SystemCoreClock )
#define configTICK_RATE_HZ                            ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES                          ( 8 )
#define configMINIMAL_STACK_SIZE                      ( ( unsigned short ) 130 )
#define configTOTAL_HEAP_SIZE                         ( ( size_t ) ( 16 * 1024 ) )
#define configMAX_TASK_NAME_LEN                       ( 16 )
#define configUSE_16_BIT_TICKS                        0
#define configIDLE_SHOULD_YIELD                       1
#define configUSE_MUTEXES                             1
#define configUSE_RECURSIVE_MUTEXES                   1
#define configUSE_COUNTING_SEMAPHORES                 1
#define configQUEUE_REGISTRY_SIZE                     8
#define configUSE_QUEUE_SETS                          0
#define configUSE_APPLICATION_TASK_TAG                0


/* hook function related definitions */
#define configUSE_IDLE_HOOK                           0
#define configUSE_TICK_HOOK                           0
#define configCHECK_FOR_STACK_OVERFLOW                0
#define configUSE_MALLOC_FAILED_HOOK                  0


#define configSUPPORT_STATIC_ALLOCATION               0
#define configUSE_TICKLESS_IDLE                       0
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS       0


#define configUSE_TRACE_FACILITY                      1
/* This demo makes use of one or more example stats formatting functions.  These
format the raw data provided by the uxTaskGetSystemState() function in to human
readable ASCII form.  See the notes in the implementation of vTaskList() within
FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS          0


/* Run time stats gathering definitions. */
#define configGENERATE_RUN_TIME_STATS                 0
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
#define portGET_RUN_TIME_COUNTER_VALUE()              0

/* co-routine definitions */
#define configUSE_CO_ROUTINES                         0
#define configMAX_CO_ROUTINE_PRIORITIES               ( 2 )

/* software timer definitions */
#define configUSE_TIMERS                              0
#define configTIMER_TASK_PRIORITY                     ( 2 )
#define configTIMER_QUEUE_LENGTH                      10
#define configTIMER_TASK_STACK_DEPTH                  ( configMINIMAL_STACK_SIZE * 2 )

/* set to 1 to include the API function, or 0 to exclude the API function */
#define INCLUDE_vTaskPrioritySet                      1
#define INCLUDE_uxTaskPriorityGet                     1
#define INCLUDE_vTaskDelete                           1
#define INCLUDE_vTaskCleanUpResources                 0
#define INCLUDE_vTaskSuspend                          1
#define INCLUDE_vTaskDelayUntil                       1
#define INCLUDE_vTaskDelay                            1
#define INCLUDE_eTaskGetState                         1
#define INCLUDE_xTimerPendFunctionCall                0
#define INCLUDE_xSemaphoreGetMutexHolder              0
#define INCLUDE_xTaskGetHandle                        1
#define INCLUDE_xTaskGetCurrentTaskHandle             1
#define INCLUDE_xTaskGetIdleTaskHandle                0
#define INCLUDE_xTaskAbortDelay                       0
#define INCLUDE_xTaskGetSchedulerState                1
#define INCLUDE_uxTaskGetStackHighWaterMark           1



/* Cortex-M specific definitions */
#ifdef __NVIC_PRIO_BITS
    /* __NVIC_PRIO_BITS will be specified when CMSIS is being used. */
    #define configPRIO_BITS                           __NVIC_PRIO_BITS
#else
    #define configPRIO_BITS                           4        /* 15 priority levels */
#endif

/* the lowest interrupt priority that can be used in a call to a "set priority" function */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY       0xf

/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions.  Do not call
interrupt safe freertos api functions from any interrupt that has a higher
priority than this! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY   2

/* interrupt priorities used by the kernel port layer itself */
#define configKERNEL_INTERRUPT_PRIORITY                ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY           ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )




/* normal assert() semantics without relying on the provision of an assert.h header file */
#define configASSERT( x )                              if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } 

/* map the FreeRTOS port interrupt handlers to CMSIS standard names */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler



#endif /* FREERTOS_CONFIG_H */

编译报错,port.o and gd32f4xx_it.o有几个函数重定义,屏蔽掉gd32f4xx_it中的这几个函数

?编译通过

?测试程序

/*!
    \file    main.c
    \brief   GPIO running led demo

    \version 2022-05-08, V2.0.0, demo for GD32F4xx
*/

/*
    Copyright (c) 2022, GigaDevice Semiconductor Inc.

    Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice, this
       list of conditions and the following disclaimer.
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
    3. Neither the name of the copyright holder nor the names of its contributors
       may be used to endorse or promote products derived from this software without
       specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/

#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "systick.h"
#include <stdio.h>
#include "gd32f427r_start.h"

#define INIT_TASK_PRIO   ( tskIDLE_PRIORITY + 1 )
#define LED_TASK_PRIO    ( tskIDLE_PRIORITY + 2 )
 
void LED1_task(void * pvParameters); 
void LED2_task(void * pvParameters);
void init_task(void * pvParameters);

/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    /* 系统时钟初始化为200M __SYSTEM_CLOCK_200M_PLL_25M_HXTAL */
    
    
    /* configure 4 bits pre-emption priority */
    nvic_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);    

    /* init task */
    xTaskCreate(init_task, "INIT", configMINIMAL_STACK_SIZE, NULL, INIT_TASK_PRIO, NULL);
    
    /* start scheduler */
    vTaskStartScheduler();
    while(1) 
    {

    }
}

/*!
    \brief      init task
    \param[in]  pvParameters not used
    \param[out] none
    \retval     none
*/
void init_task(void * pvParameters)
{
    /* 初始化按键 */
    gd_eval_key_init(KEY_USER, KEY_MODE_EXTI);
    /*LED 初始化*/
    gd_eval_led_init(LED1);
    gd_eval_led_on(LED1);
    /*LED 初始化*/    
    gd_eval_led_init(LED2);
    gd_eval_led_off(LED2);

    /* start toogle LED task every 250ms */
    xTaskCreate(LED1_task, "LED1", configMINIMAL_STACK_SIZE, NULL, LED_TASK_PRIO, NULL);
    xTaskCreate(LED2_task, "LED2", configMINIMAL_STACK_SIZE, NULL, LED_TASK_PRIO, NULL);
    for( ;; )
    {
        vTaskDelete(NULL);
    }
}

/*!
    \brief      LED1 task
    \param[in]  pvParameters not used
    \param[out] none
    \retval     none
*/
void LED1_task(void * pvParameters)
{  
    for( ;; )
    {
        /* toggle LED1 each 500ms */
        gd_eval_led_toggle(LED1);
        vTaskDelay(500 / portTICK_RATE_MS);
    }
}

/*!
    \brief      LED2 task
    \param[in]  pvParameters not used
    \param[out] none
    \retval     none
*/
void LED2_task(void * pvParameters)
{  
    BaseType_t err = pdFALSE;
    for( ;; )
    {
        /* toggle LED2 each 500ms */        
        gd_eval_led_toggle(LED2);
        vTaskDelay(500 / portTICK_RATE_MS);        
    }
}







创建两个任务 LED1_task()和LED2_task()、分别里面都对LED进行翻转,现象两个LED分别均匀闪烁


总结

  嵌入式 最新文章
基于高精度单片机开发红外测温仪方案
89C51单片机与DAC0832
基于51单片机宠物自动投料喂食器控制系统仿
《痞子衡嵌入式半月刊》 第 68 期
多思计组实验实验七 简单模型机实验
CSC7720
启明智显分享| ESP32学习笔记参考--PWM(脉冲
STM32初探
STM32 总结
【STM32】CubeMX例程四---定时器中断(附工
上一篇文章      下一篇文章      查看所有文章
加:2022-06-14 22:50:26  更:2022-06-14 22:51:46 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年12日历 -2024/12/29 8:22:30-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码
数据统计