第一次移植uC-OS3
·
基于AT32F413RCT6移植uC-OS3(有问题欢迎指正)
前情提要 #IAR #ARM-Corte-M #ARMv7-M
从思路入手 ->配置 ->接口 ->源文件
RealTime ->时基->systick
以下操作部分参考自Internet
所需文件
在工程目录新建UC-OS3文件

简单修改文件名 放进刚下载的3个文件

bsp_cpu.c 在\uC-CPU\BSP\Template
bsp_os_dt.c 在\uC-OS3\Template
cpu_a.asm 在\uC-CPU\ARM-Cortex-M\ARMv7-M\IAR
cpu_c.c 在\uC-CPU\ARM-Cortex-M\ARMv7-M
cpu_core.c 在\uC-OS3\uC-CPU
lib_ascii.c lib_math.c lib_mem.c lib_str.c 都在\uC-OS3\uC-LIB

os_app_hooks.c 在\uC-OS3\Cfg\Template
其他.c文件都在 \uC-OS3\Source
在Options快捷键选择工程按下alt+F7->C/C++ Compiler->Preprocesser中添加路径
$PROJ_DIR$\uC-OS3\uC-CPU\Cfg\Template
$PROJ_DIR$\uC-OS3\uC-CPU\ARM-Cortex-M\ARMv7-M\IAR
$PROJ_DIR$\uC-OS3\uC-CPU
$PROJ_DIR$\uC-OS3\uC-LIB\Cfg\Template
$PROJ_DIR$\uC-OS3\uC-LIB
$PROJ_DIR$\uC-OS3\uC-OS3\Cfg\Template
$PROJ_DIR$\uC-OS3\uC-OS3\Ports\ARM-Cortex-M\ARMv7-M\IAR
$PROJ_DIR$\uC-OS3\uC-OS3\Source

修改配置文件
cpu-cfg.h 使能32位时间戳

使能前导码0等待

使用中断分组4

os_cfg_app.h

修改启动文件 startup_at32f413.s

![[Pasted image 20260321224049.png]]

main.c
/**
**************************************************************************
* @file main.c
* @brief main program
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
#include "at32f413_board.h"
#include "at32f413_clock.h"
#include "os_cfg.h"
#include "cpu_cfg.h"
#include "os_cfg_app.h"
#include "os.h"
#include "cpu_core.h"
/** @addtogroup AT32F413_periph_examples
* @{
*/
/** @addtogroup 413_GPIO_io_toggle GPIO_io_toggle
* @{
*/
#define MS_TICK (system_core_clock / 1000U)
static uint32_t systick_interrupt_config(uint32_t ticks)
{
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
{
return (1UL);
}
SysTick->LOAD = (uint32_t)(ticks - 1UL);
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL);
SysTick->VAL = 0UL;
SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk;
return (0UL);
}
/**
* @brief pa.01 gpio configuration.
* @param none
* @retval none
*/
void gpio_config(void)
{
gpio_init_type gpio_init_struct;
/* enable the gpioa clock */
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
/* set default parameter */
gpio_default_para_init(&gpio_init_struct);
/* configure the gpio */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_5;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct);
}
/**
* @brief main function.
* @param none
* @retval none
*/
uint8_t Num = 0x00;
#define APP_TASK_START_STK_SIZE 128
#define APP_TASK1_STK_SIZE 128
#define APP_TASK2_STK_SIZE 128
#define APP_TASK3_STK_SIZE 128
static OS_TCB AppTaskStartTCB;
static OS_TCB AppTask1TCB;
static OS_TCB AppTask2TCB;
static OS_TCB AppTask3TCB;
static CPU_STK AppTaskStartStk[APP_TASK_START_STK_SIZE];
static CPU_STK AppTask1Stk[APP_TASK_START_STK_SIZE];
static CPU_STK AppTask2Stk[APP_TASK_START_STK_SIZE];
static CPU_STK AppTask3Stk[APP_TASK_START_STK_SIZE];
static void AppTaskStart (void *p_arg);
static void AppTask1 ( void * p_arg );
static void AppTask2 ( void * p_arg );
static void AppTask3 ( void * p_arg );
uint16_t Num1 = 0;
uint16_t Num2 = 0;
uint16_t Num3 = 0;
//static void LED_Task (void* parameter)
//{
// while (1)
// {
// GPIOC->scr = GPIO_PINS_6;
// OSTimeDly (500,OS_OPT_TIME_DLY,&err); /* 延时 500 个 tick */ (2)
// GPIOC->clr = GPIO_PINS_6;
// OSTimeDly (500,OS_OPT_TIME_DLY,&err); /* 延时 500 个 tick */
// }
// }
int main(void)
{
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
system_clock_config();
systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV);
systick_interrupt_config(192000);
gpio_config();
OS_ERR err;
OSInit(&err);
OSTaskCreate( (OS_TCB *)&AppTaskStartTCB,
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR ) AppTaskStart,
(void *) 0,
(OS_PRIO ) 5,
(CPU_STK *)&AppTaskStartStk[0],
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE / 10,
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE,
(OS_MSG_QTY ) 5u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSStart(&err);
while(1)
{
}
}
static void AppTaskStart (void *p_arg)
{
OS_ERR err;
// while (1)
// {
// GPIOC->scr = GPIO_PINS_6;
// OSTimeDly (500,OS_OPT_TIME_DLY,&err);
// GPIOC->clr = GPIO_PINS_6;
// OSTimeDly (500,OS_OPT_TIME_DLY,&err); /* 延时 500 个 tick */
// }
OSTaskCreate((OS_TCB *)&AppTask1TCB,/*Create the Led1 task */
(CPU_CHAR *)"App Task1",
(OS_TASK_PTR ) AppTask1,
(void *) 0,
(OS_PRIO ) 5,
(CPU_STK *)&AppTask1Stk[0],
(CPU_STK_SIZE) APP_TASK1_STK_SIZE / 10,
(CPU_STK_SIZE) APP_TASK1_STK_SIZE,
(OS_MSG_QTY ) 5u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSTaskCreate((OS_TCB *)&AppTask2TCB, /*Create the Led2 task*/
(CPU_CHAR *)"App Task2",
(OS_TASK_PTR ) AppTask2,
(void *) 0,
(OS_PRIO ) 5,
(CPU_STK *)&AppTask2Stk[0],
(CPU_STK_SIZE) APP_TASK2_STK_SIZE / 10,
(CPU_STK_SIZE) APP_TASK2_STK_SIZE,
(OS_MSG_QTY ) 5u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSTaskCreate((OS_TCB *)&AppTask3TCB, /*Create the Led3 task*/
(CPU_CHAR *)"App Task3",
(OS_TASK_PTR ) AppTask3,
(void *) 0,
(OS_PRIO ) 5,
(CPU_STK *)&AppTask3Stk[0],
(CPU_STK_SIZE) APP_TASK3_STK_SIZE / 10,
(CPU_STK_SIZE) APP_TASK3_STK_SIZE,
(OS_MSG_QTY ) 5u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSTaskDel ( & AppTaskStartTCB, & err );
}
static void AppTask1 ( void * p_arg )
{
OS_ERR err;
(void)p_arg;
while (DEF_TRUE) {
Num1+=1;
OSTimeDly ( 1000, OS_OPT_TIME_DLY, & err );
}
}
static void AppTask2 ( void * p_arg )
{
OS_ERR err;
(void)p_arg;
while (DEF_TRUE) {
// Num2 += 2;
gpio_bits_set(GPIOB,GPIO_PINS_5);
OSTimeDly ( 100, OS_OPT_TIME_DLY, & err );
gpio_bits_reset(GPIOB,GPIO_PINS_5);
OSTimeDly ( 100, OS_OPT_TIME_DLY, & err );
}
}
static void AppTask3 ( void * p_arg )
{
OS_ERR err;
(void)p_arg;
while (DEF_TRUE) {
Num3 += 3;
OSTimeDly ( 1000, OS_OPT_TIME_DLY, & err );
}
}
/**
* @}
*/
/**
* @}
*/
每隔100ms翻转电平,周期200ms频率5hz

更多推荐
所有评论(0)