雅特力AT32F403A移植FreeRtos-移植笔记

最近用到AT32的板子,想着以前使用STM32的时候用FreeRtos基本上都是CubeMx直接配置好了,现在正好新板子到了,手动移植下,并记录移植笔记。

首先找到freeRtos官网下载对应的源码,网址:FreeRTOS - Market leading RTOS (Real Time Operating System) for embedded systems with Internet of Things extensions

直接下载最新的就好了

可以看到里面文件结构是这样的

然后现在就是建议到自己的配置好的工程下面去添加一个freeRtos文件夹,将之前下载的source里面的全部拷贝到freeRtos文件夹里面

现在就是在工程里面去添加三个group:FreeRtos_INC、FreeRtos_CORE、FreeRtos_PORT并分别添加对应的文件,

CORE:

PORT:

添加:FreeRtos\portable\RVDS\ARM_CM4F路径下的port.c文件,FreeRtos\portable\MemMang下的heap_4.c文件

FreeRtos_INC:

将FreeRtos\include里面的.h文件全部添加到FreeRtos_INC里面。

最后将路径添加下

好到这里工作已经完成一大部分了。

大家可以先编译,发现找不到FreeRTOSConfig.h文件,官方给的source是没有给FreeRTOSConfig.h可以到之前下载的demo去找,里面有对应芯片型号的配置,可以直接用,但是AT32里面我没有找到,所以我就索性直接找大佬给的,大家详细参考网站:AT32应用整理贴(版主推荐) - - 21ic电子技术开发论坛

这里我就将代码直接粘贴出来了:

/*
    FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.
    All rights reserved

    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.

    This file is part of the FreeRTOS distribution.

    FreeRTOS is free software; you can redistribute it and/or modify it under
    the terms of the GNU General Public License (version 2) as published by the
    Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.

    ***************************************************************************
    >>!   NOTE: The modification to the GPL is included to allow you to     !<<
    >>!   distribute a combined work that includes FreeRTOS without being   !<<
    >>!   obliged to provide the source code for proprietary components     !<<
    >>!   outside of the FreeRTOS kernel.                                   !<<
    ***************************************************************************

    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE.  Full license text is available on the following
    link: http://www.freertos.org/a00114.html

    ***************************************************************************
     *                                                                       *
     *    FreeRTOS provides completely free yet professionally developed,    *
     *    robust, strictly quality controlled, supported, and cross          *
     *    platform software that is more than just the market leader, it     *
     *    is the industry's de facto standard.                               *
     *                                                                       *
     *    Help yourself get started quickly while simultaneously helping     *
     *    to support the FreeRTOS project by purchasing a FreeRTOS           *
     *    tutorial book, reference manual, or both:                          *
     *    http://www.FreeRTOS.org/Documentation                              *
     *                                                                       *
    ***************************************************************************

    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
    the FAQ page "My application does not run, what could be wrong?".  Have you
    defined configASSERT()?

    http://www.FreeRTOS.org/support - In return for receiving this top quality
    embedded software for free we request you assist our global community by
    participating in the support forum.

    http://www.FreeRTOS.org/training - Investing in training allows your team to
    be as productive as possible as early as possible.  Now you can receive
    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
    Ltd, and the world's leading authority on the world's leading RTOS.

    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
    including FreeRTOS+Trace - an indispensable productivity tool, a DOS
    compatible FAT file system, and our tiny thread aware UDP/IP stack.

    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.

    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
    licenses offer ticketed support, indemnification and commercial middleware.

    http://www.SafeRTOS.com - High Integrity Systems also provide a safety
    engineered and independently SIL3 certified version for use in safety and
    mission critical applications that require provable dependability.

    1 tab == 4 spaces!
*/

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
//针对不同的编译器调用不同的stdint.h文件
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
    #include <stdint.h>
    extern uint32_t system_core_clock;
#endif


  
/*-----------------------------------------------------------
 * Application specific definitions.
 *
 * These definitions should be adjusted for your particular hardware and
 * application requirements.
 *
 * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
 * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 
 *
 * See http://www.freertos.org/a00110.html.
 *----------------------------------------------------------*/
#define configUSE_PREEMPTION		1
#define configUSE_IDLE_HOOK			0
#define configUSE_TICK_HOOK			0
#define configCPU_CLOCK_HZ			( ( unsigned long ) 8000000 )	
#define configTICK_RATE_HZ			( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES		( 5 )
#define configMINIMAL_STACK_SIZE	( ( unsigned short ) 128 )//空闲任务的栈空间
#define configSUPPORT_DYNAMIC_ALLOCATION        1       //支持动态内存申请
#define configTOTAL_HEAP_SIZE		( ( size_t ) ( 30 * 1024 ) )
#define configMAX_TASK_NAME_LEN		( 16 )
#define configUSE_TRACE_FACILITY	0
#define configUSE_16_BIT_TICKS		0
#define configIDLE_SHOULD_YIELD		1


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

/* Set the following definitions to 1 to include the API function, or zero
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_xTaskGetCurrentTaskHandle 1
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
	/* __BVIC_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			0x0f

/* 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	0x01

/* Interrupt priorities used by the kernel port layer itself.  These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY 		( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#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( ;; ); }	
	
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler


#endif /* FREERTOS_CONFIG_H */

到此移植就差不多完成了:

我这边测试创建了三个任务测试了下,基本没问题

#include "FreeRTOS.h"		
	#include "task.h"


/* 开始任务优先级 */
#define START_TASK_PRIO 1
/* 开始任务堆栈大小 */
#define START_STK_SIZE 128 
/* 开始任务任务句柄 */
TaskHandle_t taskCreatHandle;

//任务1
#define START_TASK_PRIO_1		4						//优先级
#define START_STK_SIZE_1 		64 						//任务堆栈大小	
TaskHandle_t StartTask_Handler_1;					//任务句柄

//任务2
#define START_TASK_PRIO_2		3							//优先级
#define START_STK_SIZE_2 		64  					//任务堆栈大小
TaskHandle_t StartTask_Handler_2;					//任务句柄

//任务3	
#define START_TASK_PRIO_3		2							//优先级
#define START_STK_SIZE_3 		128  					//任务堆栈大小	
TaskHandle_t StartTask_Handler_3;					//任务句柄



//打印任务	1
void start_PrintTask(void *pvParameters); 

//数据传输任务	2
void task_ModbusDataSend(void);

//数据采集任务	3
void task_Adc(void);

//主任务处理函数
void MainTaskHandle(void);

//创建任务函数
void task_CreatHandle(void);

//任务创建函数
void task_CreatHandle(void)
{
	BaseType_t xReturn = pdPASS;/* 定义一个创建信息返回值,默认为 pdPASS */
	taskENTER_CRITICAL(); //进入临界区
	//创建打印任务
	xReturn = xTaskCreate((TaskFunction_t )start_PrintTask,       		//任务函数
            (const char*    )"start_task",          			//任务名称
            (uint16_t       )START_STK_SIZE_1,        		//任务堆栈大小
            (void*          )NULL,                  			//传递给任务函数的参数
            (UBaseType_t    )START_TASK_PRIO_1,       		//任务优先级
            (TaskHandle_t*  )&StartTask_Handler_1);   		//任务句柄  
						
	if(pdPASS == xReturn)
	{
		//创建采集任务
		xReturn = xTaskCreate((TaskFunction_t )task_Adc,       						//任务函数
            (const char*    )"task_adc",          				//任务名称
            (uint16_t       )START_STK_SIZE_2,        		//任务堆栈大小
            (void*          )NULL,                  			//传递给任务函数的参数
            (UBaseType_t    )START_TASK_PRIO_2,       		//任务优先级
            (TaskHandle_t*  )&StartTask_Handler_2);   		//任务句柄  
	}
	
	//数据传输任务
		xReturn = xTaskCreate((TaskFunction_t )task_ModbusDataSend,       						//任务函数
            (const char*    )"task_ModubsDtaaSend",          				//任务名称
            (uint16_t       )START_STK_SIZE_3,        		//任务堆栈大小
            (void*          )NULL,                  			//传递给任务函数的参数
            (UBaseType_t    )START_TASK_PRIO_3,       		//任务优先级
            (TaskHandle_t*  )&StartTask_Handler_3);   		//任务句柄  
	
	if(pdPASS == xReturn)
	{
		USART_PutString(USART1,"多任务创建成功\r\n");
	}
	//删除task_CreatHandle任务
	vTaskDelete(taskCreatHandle);
	//退出临界区
	taskEXIT_CRITICAL(); 
}

#if (!TEST_NO_DEBUG)
static void DataSend(void);
static void receiveHandle(void);
#endif
//******************************************************************************
// 函数功能: 入口函数
// 函数参数: 无
// 返 回 值: 无
// 说    明: 无
//******************************************************************************
int main(void)
{
	//初始化配置
	//这里自己添加自己的外设时钟初始化函数
	
	//创建开始任务
	xTaskCreate((TaskFunction_t )task_CreatHandle,
							(const char* )"start_task",
							(uint16_t )START_STK_SIZE,
							(void* )NULL,
							(UBaseType_t )START_TASK_PRIO,
							(TaskHandle_t* )&taskCreatHandle);
 //开启任务调度
	vTaskStartScheduler(); 
}

//任务1  打印数据
void start_PrintTask(void *pvParameters)
{ 
	while(1)
	{
		USART_PutString(USART1,"FreeRTOS移植成功!!!!!!\r\n");
		vTaskDelay(1000);
	}
}

//任务2		modbus  数据发送与采集
void task_ModbusDataSend(void)
{
	while(1)
	{
		//处理数据采集
		MainTaskHandle();
	}
}

//任务3		ADC 采集数据
void task_Adc(void)
{
	while(1)
	{
		//ADC数据采集更新
  	ADC_DataAcquisitionHandle();
		vTaskDelay(50);
	}
}

这里第三个任务就没法给大家看了,看其中两个吧。

移植到此结束,后面有问题会陆续记录出来,欢迎大佬指导!!!!!!!

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值